Commit a65ac0773d46a7391884c264e10c29e35760703d
1 parent
44b996a9
Exists in
dev
Add WCS in ImgProcessing
Showing
1 changed file
with
154 additions
and
14 deletions
Show diff stats
src/core/pyros_django/img_process/A_ImgProcessor.py
... | ... | @@ -80,7 +80,7 @@ class A_ImgProcessor(Agent): |
80 | 80 | |
81 | 81 | def _init(self): |
82 | 82 | super()._init() |
83 | - log.debug("end super init()") | |
83 | + log.debug("End super init()") | |
84 | 84 | log.info(f"self.TEST_MODE = {self.TEST_MODE}") |
85 | 85 | |
86 | 86 | # === Get the config object |
... | ... | @@ -203,7 +203,7 @@ class A_ImgProcessor(Agent): |
203 | 203 | |
204 | 204 | All files are in 'img_tmp' file context. |
205 | 205 | """ |
206 | - log.info("Bias correction done") | |
206 | + log.info("No correction needed") | |
207 | 207 | |
208 | 208 | def dark_correction(self): |
209 | 209 | |
... | ... | @@ -258,7 +258,9 @@ class A_ImgProcessor(Agent): |
258 | 258 | self._ima.fcontext = "img_tmp" |
259 | 259 | self._ima.load(self._fimg) |
260 | 260 | # - Dark correction |
261 | + log.info(f"Dark used: {fdark}") | |
261 | 262 | self._ima.sub(fdark) |
263 | + self._ima.save(self._fimg) | |
262 | 264 | log.info("Dark correction done") |
263 | 265 | else: |
264 | 266 | log.info("No dark correction") |
... | ... | @@ -314,21 +316,37 @@ class A_ImgProcessor(Agent): |
314 | 316 | if os.path.exists(fflat_out): |
315 | 317 | # - Load img and get infos |
316 | 318 | self._ima.fcontext = "img_tmp" |
317 | - self._ima.load(self._fimg) | |
319 | + #self._ima.load(self._fimg) | |
318 | 320 | # - Flat correction |
321 | + log.info(f"Flat used: {fflat}") | |
319 | 322 | self._ima.div(fflat, 10000) |
323 | + self._ima.save(self._fimg) | |
320 | 324 | log.info("Flat correction done") |
321 | 325 | else: |
322 | 326 | log.info("No flat correction") |
323 | 327 | |
324 | 328 | def inversion_correction(self): |
325 | - pass | |
329 | + log.info("No inversion correction needed") | |
326 | 330 | |
327 | 331 | def cosmetic_correction(self): |
328 | - pass | |
332 | + log.info("No cosmetic correction needed") | |
329 | 333 | |
330 | 334 | def wcs_calibration(self): |
331 | - return 0 | |
335 | + if True: | |
336 | + self._ima.fcontext = "img_tmp" | |
337 | + os.chdir(self._ima.rootdir) | |
338 | + self._ima.config("astrometrynet", API_KEY = "amxbkytvjishmehq") | |
339 | + settings = {} | |
340 | + settings["center_ra"] = self._ima.getkwd('RA') | |
341 | + settings["center_dec"] = self._ima.getkwd('DEC') | |
342 | + settings["radius"] = 1.0 | |
343 | + success, comment, detail = self._ima.calibwcs("upload", **settings) | |
344 | + log.info(f"WCS {success=}") | |
345 | + log.info(f"WCS {comment=}") | |
346 | + log.info(f"WCS {detail=}") | |
347 | + log.info("WCS correction done") | |
348 | + else: | |
349 | + log.info("No WCS correction needed") | |
332 | 350 | |
333 | 351 | def process_one_image(self, fitsfile: str): |
334 | 352 | """This is the general algorithm of processing |
... | ... | @@ -470,7 +488,7 @@ class A_ImgProcessor(Agent): |
470 | 488 | shutil.copyfile(file_in, file_out) |
471 | 489 | |
472 | 490 | # --- Build a bias image filled by zeros |
473 | - print("Build a test dark") | |
491 | + print("Build a test bias") | |
474 | 492 | try: |
475 | 493 | self._ima.fcontext = "cal_L1" |
476 | 494 | except Exception as e: |
... | ... | @@ -529,17 +547,139 @@ class A_ImgProcessor(Agent): |
529 | 547 | self._ima.save(file_out) |
530 | 548 | |
531 | 549 | def _create_test_images_2(self): |
550 | + | |
551 | + # --- Configure the simulator | |
532 | 552 | self._ima.etc.camera("Kepler 4040") |
533 | 553 | self._ima.etc.optics("Takahashi_180ED") |
534 | - self._ima.etc.params("msky",18) | |
554 | + bias_level = 0 | |
555 | + | |
556 | + # --- Set the target coordinates | |
535 | 557 | ra = 132.84583 |
536 | 558 | dec = 11.81333 |
537 | - at = self._ima.simulation("GAIA", "PHOTOM", shutter_mode="closed", t=50, ra=ra, dec=dec) | |
538 | - file_out = os.path.join(self._paths['ima_tmp'], "m67.ecsv") | |
539 | - print(f"STEP TOTO 1 = {at}") | |
540 | - at.t.write(file_out, format='astrotable', overwrite=True) | |
541 | - print(f"STEP TOTO 2") | |
542 | - date_obs = self.getkwd("DATE-OBS") | |
559 | + | |
560 | + # --- Get datedict | |
561 | + date_obs = guitastro.Date("now").iso(nb_subdigit=3) | |
562 | + print(f"Test image DATE-OBS: {date_obs}") | |
563 | + datedict = self._ima.naming_date(date_obs) | |
564 | + print(f"Test image night: {datedict['night']}") | |
565 | + | |
566 | + # --- Get the table of stars (simu_<channel>.ecsv) | |
567 | + shutter_mode = "synchro" | |
568 | + self._ima.etc.params("msky",19) | |
569 | + t = 10 | |
570 | + print("Build a test image") | |
571 | + try: | |
572 | + self._ima.fcontext = "img_tmp" | |
573 | + except Exception as e: | |
574 | + raise Exception(f"_create_test_images_2: {e}") | |
575 | + ext = self._ima.extension | |
576 | + self._ima.extension = ".ecsv" | |
577 | + fsimu = "simu_" + self._channel['symbol'] | |
578 | + fsimu = self._ima.join(fsimu) | |
579 | + self._ima.extension = ext | |
580 | + if os.path.exists(fsimu): | |
581 | + att = guitastro.AstroTable() | |
582 | + att.read(fsimu, format="ascii.ecsv") | |
583 | + at = self._ima.simulation("ASTROTABLE", att, shutter_mode=shutter_mode, t=t, ra=ra, dec=dec) | |
584 | + else: | |
585 | + at = self._ima.simulation("GAIA", "PHOTOM", shutter_mode=shutter_mode, t=t, ra=ra, dec=dec, column_filters = {"Gmag": "<14"}) | |
586 | + at.t.write(fsimu, format='ascii.ecsv', overwrite=True) | |
587 | + att = at | |
588 | + | |
589 | + # --- Save the image file name to be compatible with the img_L0 file context | |
590 | + id_sequence = 123452789 | |
591 | + try: | |
592 | + self._ima.fcontext = "img_L0" | |
593 | + except Exception as e: | |
594 | + raise Exception(f"_create_test_images_2: {e}") | |
595 | + param = {} | |
596 | + param['ftype'] = "L0A" | |
597 | + param['date'] = datedict['yyyymmdd'] | |
598 | + param['time'] = datedict['hhmmssssssss'] | |
599 | + param['unit'] = self.config.unit_name | |
600 | + param['version'] = 1 | |
601 | + param['channel'] = self._channel['symbol'] | |
602 | + param['id_seq'] = id_sequence | |
603 | + param['plane'] = 1 | |
604 | + param['frame'] = 1 | |
605 | + fname = self._ima.naming_set(param) | |
606 | + file_out = self._ima.join(fname) | |
607 | + self._ima.setkwd("DATE-OBS", date_obs) | |
608 | + self._ima.save(file_out) | |
609 | + | |
610 | + # --- Build a bias image | |
611 | + print("Build a test bias") | |
612 | + shutter_mode = "closed" | |
613 | + self._ima.simulation("ASTROTABLE", att, shutter_mode=shutter_mode, t=0.01, ra=ra, dec=dec) | |
614 | + try: | |
615 | + self._ima.fcontext = "cal_L1" | |
616 | + except Exception as e: | |
617 | + raise Exception(f"_create_test_images_2: {e}") | |
618 | + param = {} | |
619 | + param['ftype'] = "BI1" | |
620 | + param['date'] = datedict['yyyymmdd'] | |
621 | + param['time'] = datedict['hhmmssssssss'] | |
622 | + param['unit'] = self.config.unit_name | |
623 | + param['version'] = 1 | |
624 | + param['channel'] = self._channel['symbol'] | |
625 | + param['id_seq'] = id_sequence - 3 | |
626 | + param['plane'] = 1 | |
627 | + param['frame'] = 1 | |
628 | + fname = self._ima.naming_set(param) | |
629 | + file_out = self._ima.join(fname) | |
630 | + import numpy as np | |
631 | + print(f"{file_out=} MEAN={np.mean(self._ima._array)}") | |
632 | + self._ima.setkwd("DATE-OBS", date_obs) | |
633 | + self._ima.save(file_out) | |
634 | + | |
635 | + # --- Build a dark image | |
636 | + print("Build a test dark") | |
637 | + shutter_mode = "closed" | |
638 | + self._ima.simulation("ASTROTABLE", att, shutter_mode=shutter_mode, t=t, ra=ra, dec=dec) | |
639 | + param = {} | |
640 | + param['ftype'] = "DA1" | |
641 | + param['date'] = datedict['yyyymmdd'] | |
642 | + param['time'] = datedict['hhmmssssssss'] | |
643 | + param['unit'] = self.config.unit_name | |
644 | + param['version'] = 1 | |
645 | + param['channel'] = self._channel['symbol'] | |
646 | + param['id_seq'] = id_sequence - 2 | |
647 | + param['plane'] = 1 | |
648 | + param['frame'] = 1 | |
649 | + fname = self._ima.naming_set(param) | |
650 | + file_out = self._ima.join(fname) | |
651 | + print(f"{file_out=} MEAN={np.mean(self._ima._array)}") | |
652 | + self._ima.setkwd("DATE-OBS", date_obs) | |
653 | + self._ima.save(file_out) | |
654 | + | |
655 | + # --- Build a flat image normalized by cst=10000 | |
656 | + print("Build a test flat") | |
657 | + shutter_mode = "synchro" | |
658 | + self._ima.etc.params("msky",-1) | |
659 | + tf = t/1000000.0 | |
660 | + #tf = t | |
661 | + self._ima.simulation("ASTROTABLE", att, shutter_mode=shutter_mode, t=tf, ra=ra, dec=dec) | |
662 | + print(f"MEAN={np.mean(self._ima._array)}") | |
663 | + self._ima.offset(-bias_level) | |
664 | + flatnorm = 10000.0 | |
665 | + self._ima.ngain(flatnorm) | |
666 | + self._ima.setkwd("FLATNORM", flatnorm, "Normalisation of the superflat") | |
667 | + param = {} | |
668 | + param['ftype'] = "FL1" | |
669 | + param['date'] = datedict['yyyymmdd'] | |
670 | + param['time'] = datedict['hhmmssssssss'] | |
671 | + param['unit'] = self.config.unit_name | |
672 | + param['version'] = 1 | |
673 | + param['channel'] = self._channel['symbol'] | |
674 | + param['id_seq'] = id_sequence - 1 | |
675 | + param['plane'] = 1 | |
676 | + param['frame'] = 1 | |
677 | + fname = self._ima.naming_set(param) | |
678 | + file_out = self._ima.join(fname) | |
679 | + print(f"{file_out=} MEAN={np.mean(self._ima._array)}") | |
680 | + self._ima.setkwd("DATE-OBS", date_obs) | |
681 | + self._ima.save(file_out) | |
682 | + | |
543 | 683 | |
544 | 684 | def _plural(self, n: int) -> str: |
545 | 685 | """Return "s" if n>1 for plurals. | ... | ... |