diff --git a/src/core/pyros_django/img_process/A_ImgProcessor.py b/src/core/pyros_django/img_process/A_ImgProcessor.py index 379daca..ca3dfae 100755 --- a/src/core/pyros_django/img_process/A_ImgProcessor.py +++ b/src/core/pyros_django/img_process/A_ImgProcessor.py @@ -80,7 +80,7 @@ class A_ImgProcessor(Agent): def _init(self): super()._init() - log.debug("end super init()") + log.debug("End super init()") log.info(f"self.TEST_MODE = {self.TEST_MODE}") # === Get the config object @@ -203,7 +203,7 @@ class A_ImgProcessor(Agent): All files are in 'img_tmp' file context. """ - log.info("Bias correction done") + log.info("No correction needed") def dark_correction(self): @@ -258,7 +258,9 @@ class A_ImgProcessor(Agent): self._ima.fcontext = "img_tmp" self._ima.load(self._fimg) # - Dark correction + log.info(f"Dark used: {fdark}") self._ima.sub(fdark) + self._ima.save(self._fimg) log.info("Dark correction done") else: log.info("No dark correction") @@ -314,21 +316,37 @@ class A_ImgProcessor(Agent): if os.path.exists(fflat_out): # - Load img and get infos self._ima.fcontext = "img_tmp" - self._ima.load(self._fimg) + #self._ima.load(self._fimg) # - Flat correction + log.info(f"Flat used: {fflat}") self._ima.div(fflat, 10000) + self._ima.save(self._fimg) log.info("Flat correction done") else: log.info("No flat correction") def inversion_correction(self): - pass + log.info("No inversion correction needed") def cosmetic_correction(self): - pass + log.info("No cosmetic correction needed") def wcs_calibration(self): - return 0 + if True: + self._ima.fcontext = "img_tmp" + os.chdir(self._ima.rootdir) + self._ima.config("astrometrynet", API_KEY = "amxbkytvjishmehq") + settings = {} + settings["center_ra"] = self._ima.getkwd('RA') + settings["center_dec"] = self._ima.getkwd('DEC') + settings["radius"] = 1.0 + success, comment, detail = self._ima.calibwcs("upload", **settings) + log.info(f"WCS {success=}") + log.info(f"WCS {comment=}") + log.info(f"WCS {detail=}") + log.info("WCS correction done") + else: + log.info("No WCS correction needed") def process_one_image(self, fitsfile: str): """This is the general algorithm of processing @@ -470,7 +488,7 @@ class A_ImgProcessor(Agent): shutil.copyfile(file_in, file_out) # --- Build a bias image filled by zeros - print("Build a test dark") + print("Build a test bias") try: self._ima.fcontext = "cal_L1" except Exception as e: @@ -529,17 +547,139 @@ class A_ImgProcessor(Agent): self._ima.save(file_out) def _create_test_images_2(self): + + # --- Configure the simulator self._ima.etc.camera("Kepler 4040") self._ima.etc.optics("Takahashi_180ED") - self._ima.etc.params("msky",18) + bias_level = 0 + + # --- Set the target coordinates ra = 132.84583 dec = 11.81333 - at = self._ima.simulation("GAIA", "PHOTOM", shutter_mode="closed", t=50, ra=ra, dec=dec) - file_out = os.path.join(self._paths['ima_tmp'], "m67.ecsv") - print(f"STEP TOTO 1 = {at}") - at.t.write(file_out, format='astrotable', overwrite=True) - print(f"STEP TOTO 2") - date_obs = self.getkwd("DATE-OBS") + + # --- Get datedict + date_obs = guitastro.Date("now").iso(nb_subdigit=3) + print(f"Test image DATE-OBS: {date_obs}") + datedict = self._ima.naming_date(date_obs) + print(f"Test image night: {datedict['night']}") + + # --- Get the table of stars (simu_.ecsv) + shutter_mode = "synchro" + self._ima.etc.params("msky",19) + t = 10 + print("Build a test image") + try: + self._ima.fcontext = "img_tmp" + except Exception as e: + raise Exception(f"_create_test_images_2: {e}") + ext = self._ima.extension + self._ima.extension = ".ecsv" + fsimu = "simu_" + self._channel['symbol'] + fsimu = self._ima.join(fsimu) + self._ima.extension = ext + if os.path.exists(fsimu): + att = guitastro.AstroTable() + att.read(fsimu, format="ascii.ecsv") + at = self._ima.simulation("ASTROTABLE", att, shutter_mode=shutter_mode, t=t, ra=ra, dec=dec) + else: + at = self._ima.simulation("GAIA", "PHOTOM", shutter_mode=shutter_mode, t=t, ra=ra, dec=dec, column_filters = {"Gmag": "<14"}) + at.t.write(fsimu, format='ascii.ecsv', overwrite=True) + att = at + + # --- Save the image file name to be compatible with the img_L0 file context + id_sequence = 123452789 + try: + self._ima.fcontext = "img_L0" + except Exception as e: + raise Exception(f"_create_test_images_2: {e}") + param = {} + param['ftype'] = "L0A" + param['date'] = datedict['yyyymmdd'] + param['time'] = datedict['hhmmssssssss'] + param['unit'] = self.config.unit_name + param['version'] = 1 + param['channel'] = self._channel['symbol'] + param['id_seq'] = id_sequence + param['plane'] = 1 + param['frame'] = 1 + fname = self._ima.naming_set(param) + file_out = self._ima.join(fname) + self._ima.setkwd("DATE-OBS", date_obs) + self._ima.save(file_out) + + # --- Build a bias image + print("Build a test bias") + shutter_mode = "closed" + self._ima.simulation("ASTROTABLE", att, shutter_mode=shutter_mode, t=0.01, ra=ra, dec=dec) + try: + self._ima.fcontext = "cal_L1" + except Exception as e: + raise Exception(f"_create_test_images_2: {e}") + param = {} + param['ftype'] = "BI1" + param['date'] = datedict['yyyymmdd'] + param['time'] = datedict['hhmmssssssss'] + param['unit'] = self.config.unit_name + param['version'] = 1 + param['channel'] = self._channel['symbol'] + param['id_seq'] = id_sequence - 3 + param['plane'] = 1 + param['frame'] = 1 + fname = self._ima.naming_set(param) + file_out = self._ima.join(fname) + import numpy as np + print(f"{file_out=} MEAN={np.mean(self._ima._array)}") + self._ima.setkwd("DATE-OBS", date_obs) + self._ima.save(file_out) + + # --- Build a dark image + print("Build a test dark") + shutter_mode = "closed" + self._ima.simulation("ASTROTABLE", att, shutter_mode=shutter_mode, t=t, ra=ra, dec=dec) + param = {} + param['ftype'] = "DA1" + param['date'] = datedict['yyyymmdd'] + param['time'] = datedict['hhmmssssssss'] + param['unit'] = self.config.unit_name + param['version'] = 1 + param['channel'] = self._channel['symbol'] + param['id_seq'] = id_sequence - 2 + param['plane'] = 1 + param['frame'] = 1 + fname = self._ima.naming_set(param) + file_out = self._ima.join(fname) + print(f"{file_out=} MEAN={np.mean(self._ima._array)}") + self._ima.setkwd("DATE-OBS", date_obs) + self._ima.save(file_out) + + # --- Build a flat image normalized by cst=10000 + print("Build a test flat") + shutter_mode = "synchro" + self._ima.etc.params("msky",-1) + tf = t/1000000.0 + #tf = t + self._ima.simulation("ASTROTABLE", att, shutter_mode=shutter_mode, t=tf, ra=ra, dec=dec) + print(f"MEAN={np.mean(self._ima._array)}") + self._ima.offset(-bias_level) + flatnorm = 10000.0 + self._ima.ngain(flatnorm) + self._ima.setkwd("FLATNORM", flatnorm, "Normalisation of the superflat") + param = {} + param['ftype'] = "FL1" + param['date'] = datedict['yyyymmdd'] + param['time'] = datedict['hhmmssssssss'] + param['unit'] = self.config.unit_name + param['version'] = 1 + param['channel'] = self._channel['symbol'] + param['id_seq'] = id_sequence - 1 + param['plane'] = 1 + param['frame'] = 1 + fname = self._ima.naming_set(param) + file_out = self._ima.join(fname) + print(f"{file_out=} MEAN={np.mean(self._ima._array)}") + self._ima.setkwd("DATE-OBS", date_obs) + self._ima.save(file_out) + def _plural(self, n: int) -> str: """Return "s" if n>1 for plurals. -- libgit2 0.21.2