#### Calculating optimal exposure times for flats

Taking flats with a robotic telescope like MONET is way more convenient than doing it manually. While exposing images, we can easily calculate the optimal exposure time for the next image. If C_opt is the optimal mean count rate in the images that we aim at (usually ~30,000), we can take the mean count rate C_last of the last image, and together with the mean count C_bias rate in a bias, we can derive the counts C_1=(C_last-C_bias)/T_last, which added to C_bias, is the number of counts we would currently get with a 1s exposure. Now it's easy to find the optimal exposure time T_opt using the last exposure time T_last using the rule of three:

T_opt = T_last / (C_last  - C_bias) * (C_opt - C_bias).

Of course, the optimal exposure time changes during twilight, but with short exposures, this is good enough.

#### Measuring time span in which taking flats is possible

But, there is one big problem: how do we find the best time to start taking flats? While in morning twilight we can just take images until we reach a given mean count rate in the images, this is impossible in evening twilight without creating tons of over-exposed images. So, what can we do about that?

We measure it!

Here is a plot with the optimal exposure time in 3x3 over the elevation of the sun over the horizon for several filters: The lines are fits of exponential functions to the data, which we can use to predict exposure times. This tells us now that, for instance, in evening twilight we should not start taking B flats in 3x3 before the sun has dropped to ~4.5 degrees below the horizon.

But why does the plot only show times for 3x3 binning? Simple: we can scale the 1x1 and 2x2 times by multiplying them by 9 and 4/9 respectively!

#### Combining flat exposures

Unfortunately, our current pipeline has some problems processing the flat images (that's one reason, why we're working on a new one!). Have a look at the final master flat for observation 20180429S-0116: One problem is the weird pattern, that we still need to work out. But there are also stars in the final flat! The reason for this is that we used the average to combine the images, which doesn't completely remove the stars. It would be better to use the median. But we cannot do this, because we're rotation the image by 180 degrees mid-way through the flat series.

To explain this, let's do a combination using the median, but separately for the first and the last 15 images for the same observation as shown above (mirrored vertically thanks to AstroImageJ):  Here you can actually see the reason for rotating the camera: there is a gradient in the sky during twilight! The first 15 images (left image) are taken with North up, the last 15 images (right image) with South up. And that's why we cannot simply use the median for all images, since the pattern actually changes due to the rotation.

During the night we don't have this gradient anymore, so we want to get rid of it. Which we can simply do by using the average of the two images above: And this is how we will process the flat fields in the future!