Skip to content

Commit

Permalink
Merge pull request #838 from aaronwmorris/dev
Browse files Browse the repository at this point in the history
Implemented time estimation in the dark exposures
  • Loading branch information
aaronwmorris authored Jul 15, 2023
2 parents e4f2902 + d356164 commit ce45d07
Showing 1 changed file with 74 additions and 4 deletions.
78 changes: 74 additions & 4 deletions indi_allsky/darks.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,27 @@ def _pre_shoot_reconfigure(self):
self.indiclient.configureCcdDevice(self.config['INDI_CONFIG_DEFAULTS'])


@staticmethod
def _format_time(seconds):
"""Take an integer number of seconds and return a string in the format HH:MM:SS."""
hours, remainder = divmod(seconds, 3600)
minutes, seconds = divmod(remainder, 60)
return "{:02}:{:02}:{:02}".format(int(hours), int(minutes), int(seconds))


def _estimate_runtime(self, remaining_exposures, remaining_configs, overhead_per_exposure):
"""Estimate the remaining runtime in seconds of the _run function."""

# Initialize time to zero
total_time = 0

# Add the time for each exposure plus overhead.
total_exposure_time = sum(remaining_exposures) * self.count + len(remaining_exposures) * overhead_per_exposure
total_time += total_exposure_time * remaining_configs

return total_time


def _run(self, stacking_class):

ccd_bits = int(self.ccd_info['CCD_INFO']['CCD_BITSPERPIXEL']['current'])
Expand Down Expand Up @@ -618,6 +639,9 @@ def _run(self, stacking_class):


### take darks
remaining_configs = len(night_darks_odict.keys()) + 1 # include daytime
overhead_per_exposure = 30.0 # seconds, initial estimate
completed_exposures = 0


# take day darks with cooling disabled
Expand All @@ -630,17 +654,48 @@ def _run(self, stacking_class):
### DAY DARKS ###
day_params = (self.config['CCD_CONFIG']['DAY']['GAIN'], self.config['CCD_CONFIG']['DAY']['BINNING'])
if day_params not in night_darks_odict.keys():
total_exposures = len(dark_exposures) * remaining_configs
estimated_time_left = self._estimate_runtime(dark_exposures, remaining_configs, overhead_per_exposure)
logger.info(f"Processing {total_exposures} darks, {self.count} exposures each. Estimated time left: {self._format_time(int(estimated_time_left))}")


self.indiclient.setCcdGain(self.config['CCD_CONFIG']['DAY']['GAIN'])
self.indiclient.setCcdBinning(self.config['CCD_CONFIG']['DAY']['BINNING'])

# day will rarely exceed 1 second
for exposure in dark_exposures:
# day will rarely exceed 1 second (with good cameras and proper conditions)
for index, exposure in enumerate(dark_exposures):
# Create a temporary list of remaining exposures
remaining_exposures = dark_exposures[index + 1:]

start = time.time()
self._take_exposures(exposure, dark_filename_t, bpm_filename_t, ccd_bits, stacking_class)
elapsed_s = time.time()
exposure_time = elapsed_s - start

completed_exposures += 1

# Calculate the overhead for this exposure
overhead_per_exposure = exposure_time - exposure * float(self.count)
estimated_time_left = self._estimate_runtime(remaining_exposures, remaining_configs, overhead_per_exposure)
logger.info(f"Exposure {completed_exposures}/{total_exposures} done. Estimated time left: {self._format_time(int(estimated_time_left))}")

remaining_configs -= 1

else:
remaining_configs -= 1 # daytime parameters included in night configs

else:
logger.warning('Daytime dark processing is disabled')

remaining_configs -= 1 # skip daytime

time.sleep(8.0)


total_exposures = len(dark_exposures) * remaining_configs
estimated_time_left = self._estimate_runtime(dark_exposures, remaining_configs, overhead_per_exposure)
logger.info(f"Processing {total_exposures} darks, {self.count} exposures each. Estimated time left: {self._format_time(int(estimated_time_left))}")


# take night darks with cooling enabled
if self.config.get('CCD_COOLING'):
Expand All @@ -650,15 +705,29 @@ def _run(self, stacking_class):
self.indiclient.setCcdTemperature(ccd_temp, sync=True, timeout=1200.0)



### NIGHT DARKS ###
for gain, binmode in night_darks_odict.keys():
self.indiclient.setCcdGain(gain)
self.indiclient.setCcdBinning(binmode)

for exposure in dark_exposures:
for index, exposure in enumerate(dark_exposures):
# Create a temporary list of remaining exposures
remaining_exposures = dark_exposures[index + 1:]

start = time.time()
self._take_exposures(exposure, dark_filename_t, bpm_filename_t, ccd_bits, stacking_class)
elapsed_s = time.time()
exposure_time = elapsed_s - start

completed_exposures += 1

# Calculate the overhead for this exposure
overhead_per_exposure = exposure_time - exposure * float(self.count)
estimated_time_left = self._estimate_runtime(remaining_exposures, remaining_configs, overhead_per_exposure)
logger.info(f"Exposure {completed_exposures}/{total_exposures} done. Estimated time left: {self._format_time(int(estimated_time_left))}")

remaining_configs -= 1

# shutdown
self.indiclient.disableCcdCooler()
Expand All @@ -677,8 +746,9 @@ def _take_exposures(self, exposure, dark_filename_t, bpm_filename_t, ccd_bits, s
image_bitpix = None

i = 1
while i <= self._count:
while i <= self.count:
# sometimes image data is bad, take images until we reach the desired number
logger.info(f"Starting image {i}/{self.count}.")
start = time.time()

self._pre_shoot_reconfigure()
Expand Down

0 comments on commit ce45d07

Please sign in to comment.