macro-consortium / pyscope

pyscope is a pure-Python package for control of small robotic telescopes.
https://pyscope.readthedocs.io
GNU Affero General Public License v3.0
12 stars 10 forks source link

[ENHANCEMENT] Asynchronously save images #132

Open pgriffin17 opened 6 months ago

pgriffin17 commented 6 months ago

Is your feature request related to a problem? Please describe. The Observatory.save_last_image function takes some time to complete (1.6 seconds on my machine in a Jupyter notebook with my 4 MB images). I suspect this will take at least as much time, if not longer, for images to save when used with pyscope under typical circumstances. Over nights where we take 800 images, this could add up to around 20 minutes of image save time during which no new images could be taken.

Describe the solution you'd like Images should be saved asynchronously so that the telescope can either begin slewing to a new location or a new image can be requested once the previous image is downloaded. I believe that NINA saves images asynchronously, maybe we can gain insight from their implementation. SharpCap also downloads images from the camera into a temporary RAM buffer before saving out, allowing several short exposure images to be taken quickly (until that buffer fills up, at which point the image cadence slows).

pgriffin17 commented 6 months ago

It may make sense to have a header-writing queue that we have as a dictionary. This dictionary would include the filename of the file in question, as well as a dictionary of FITS header cards. We would have Observatory obtain all of the FITS header cards from the observatory while/during/directly after the image is taken, save those into this dictionary, and send this dictionary to an asynchronous process to save that dictionary to a file which contains the queue of image filenames and header info to write into them. A separate process could look at this queue, load the image, write the header data to the file, and then platesolve the image, saving the image with the WCS solution. This will help to minimize down-time between successive images, especially helping in instances of short images on the same target, such as for exoplanet or asteroid lightcurves.