Commit 20aa8b1c authored by vertighel's avatar vertighel
Browse files

Managed exceptions for several kind of missing values

parent b778eb25
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ def custom_float():
        fits.card._format_float = _original_astropy_format_float


def header_round(value, num_digits):
def header_round(value, num_digits=0):
    """
    Returns a FormattedFloat instance that, when assigned to an Astropy FITS header
    within the 'custom_fits_float_formatter_context', will be formatted
+77 −55
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ class Noche:
        config = self._load_config(path)

        for section in config.sections():
            for key, value in config.items(section):
            for k, value in config.items(section):
                try:
                    val, comment = value.split("|")
#                    val, typ, fmt, comment = value.split("|")
@@ -111,7 +111,8 @@ class Noche:
                    val, comment = value, None

                val = self._parse(val)
                self.header[key] = val, comment
                log.debug(f"{k:<11}: initializing with: {val} / {comment}")
                self.header[k] = val, comment

        self._update()

@@ -164,9 +165,18 @@ class Noche:
        self.set_location(loc["OBS-LONG"], loc["OBS-LAT"], loc["OBS-ELEV"])

        for k in loc.keys():
            log.info(k)

            if not (k in self.header):
                log.error(f"{k} not in header template")
                continue

            val = self._parse(loc[k])
            if k in self.header:

            if val is None:
                log.warning(f"{k:<8} : fixed value missing! Leave blank")
                pass
            else:
                log.info(f"{k:<11} : set to fixed value, value: {val:<28}")
                self.header[k] = val

        if fits_file:
@@ -207,14 +217,26 @@ class Noche:
        for k in loc.keys():

            if not (k in self.header):
                log.error(f"{k} not in header")
                log.error(f"{k} not in header template")
                continue

            fits_keyword = loc[k]

            try:
                fits_value = fits_file_header[fits_keyword]
                val = self._parse(fits_value)
                self.header[k] = val
            log.info(f"{k:<8} : {val}")
                log.info(f"{k:<11} : mapped to {fits_keyword:<11}, value: {val:<28}")
            except TypeError as e:
                log.debug(e)
                log.warning(f"{k:<8} : mapped to {fits_keyword:<11}, but empty! Leave empty.")
            except KeyError as e:
                log.debug(e)
                if fits_keyword is None:
                    log.warning(f"{k:<8} : mapped to {fits_keyword:<11}, but missing! Leave blank.")
                else:
                    log.warning(f"{k:<8} : mapped to nothing! Leave blank.")
                pass

            if k in pre_formulas:
                x = self.header[k]
@@ -222,9 +244,9 @@ class Noche:
                new_val = eval(pre_formulas[k])
                try:
                    self.header[k] = header_round(new_val, digits)
                    log.warning(f"{k:<8} (Pre): from {x} to {self.header[k]}")
                    log.warning(f"{k:<11}: pre-formula from {x:<28} to {self.header[k]:<28}")
                except Exception as e:
                    log.error(f"Failed to evaluate PreFormula for {k}: {e}")
                    log.error(f"Failed to evaluate pre-formula for {k}: {e}")

        self.set_coordinates(self.header["RA"],
                             self.header["DEC"],
@@ -238,11 +260,11 @@ class Noche:
                new_val = eval(formula)
                try:
                    self.header[k] = header_round(new_val, digits)
                    log.warning(f"{k:<8} (Post): from {x} to {self.header[k]}")
                    log.warning(f"{k:<8}: tweak from {x:<28} to {self.header[k]:<28}")
                except Exception as e:
                    log.error(f"Failed to evaluate PostFormula for {k}: {e}")
                    log.error(f"Failed to evaluate tweak for {k}: {e}")
            else:
                log.warning(f"PostFormula skipped: {k} not in header")
                log.warning(f"{k:<8}: skipped as not in header")

        self.header["FILEORIG"] = filename.name

@@ -465,10 +487,10 @@ class Noche:
            self.header['CRVAL2'] = header_round(crval_dec, 7)
            self.header['CDELT1'] = header_round(cdelt1 * flip, 7)
            self.header['CDELT2'] = header_round(cdelt2, 7)
            self.header["PC1_1"] = +np.cos(angle)
            self.header["PC1_2"] = -np.sin(angle)
            self.header["PC2_1"] = +np.sin(angle)
            self.header["PC2_2"] = +np.cos(angle)
            self.header["PC1_1"] = header_round(+np.cos(angle), 5)
            self.header["PC1_2"] = header_round(-np.sin(angle), 5)
            self.header["PC2_1"] = header_round(+np.sin(angle), 5)
            self.header["PC2_2"] = header_round(+np.cos(angle), 5)


    def set_ambient(self):
@@ -520,7 +542,7 @@ class Noche:

        for k in self.header:
            if self.header[k] == None:
                print(k, self.header[k])
                log.warning(f"{k:<8}: still empty ({self.header[k]})")

    def load_fits(self, fits_file):
        log.debug(sys._getframe().f_code.co_name)
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ FILTER = FILTER # Photometric filter used
EXPTIME = EXPTIME                 # [s] Exposure time
XBINNING = XBINNING               # Binning factor in X
YBINNING = YBINNING               # Binning factor in Y
# TEMPERAT = AOCAMBT                # [C] Ambient temperature
TEMPERAT =                        # [C] Ambient temperature
SWCREATE = SWCREATE               # Software that created FILEORIG

[Formula]
+42 −0
Original line number Diff line number Diff line
[Fixed]
TELESCOP = OASDG                  # Telescope name
APTDIA = 300                      # [mm] Telescope aperture diameter
FOCALLEN = 1950                   # [mm] Telescope focal length
OBS-LONG = 14.5639669             # [deg] Observatory longitude (East > 0)  
OBS-LAT = 40.6239113              # [deg] Observatory latitude (North > 0)  
OBS-ELEV = 647                    # [m] Observatory altitude above sea level
INSTRUME = Agerola instrument     # Instrument name
OBSTYPE = Imaging                 # Observation type
DETECTOR = QHY174MM               # Detector identifier
DETSIZE = [1:1900,1:1200]         # [px] [1:x,1:y] Physical CCD dimensions
DETROT = 0.0                      # [deg] Rotation offset of the detector
XPIXSZ = 5.86                     # [um] Pixel X axis size
YPIXSZ = 5.86                     # [um] Pixel Y axis size
PIXSCALE = 0.62                   # [arcsec/px] Plate scale in binning 1
GAIN =                            # [e-/ADU] Gain
RDNOISE =                         # [e- RMS] Readout noise

[Mapping]
NAXIS1 = NAXIS1                   # [px] X Dimensions of detector
NAXIS2 = NAXIS2                   # [px] Y dimension of detector
OBSERVER = OBSERVER               # Observer name
OBJECT   = OBJECT                 # Name of observed object
RA = OBJCTRA                      # In sexagesimal or decimal format
DEC = OBJCTDEC                    # In sexagesimal or decimal format
DATE-OBS = DATE-OBS               # [YYYY-MM-DDTHH:MM:SS] UTC observation date
FOCUSTEM = FOCUSTEM               # [C] Focuser temperature
FOCUSPOS = FOCUSPOS               # [um] Focuser position
SET-TEMP = SET-TEMP               # [C] CCD temperature set point
CCD-TEMP = CCD-TEMP               # [C] CCD temperature
IMAGETYP = IMAGETYP               # Frame type
FILTER = FILTER                   # Photometric filter used
EXPTIME = EXPTIME                 # [s] Exposure time
XBINNING = XBINNING               # Binning factor in X
YBINNING = YBINNING               # Binning factor in Y
TEMPERAT =                        # [C] Ambient temperature
SWCREATE = SWCREATE               # Software that created FILEORIG

[Formula]


[Tweak]
+2 −2
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ INSTRUME = OGG obs instrument # Instrument name
OBSTYPE = Imaging                 # Observation type
DETECTOR = CMOS QHY268            # Detector identifier
DETSIZE = [1:6280,1:4210]         # [px] [1:x,1:y] Physical CCD dimensions
DETROT = 180                      # [deg] Rotation offset of the detector
DETROT = 180.0                    # [deg] Rotation offset of the detector
XPIXSZ = 3.7                      # [um] Pixel X axis size
YPIXSZ = 3.7                      # [um] Pixel Y axis size
PIXSCALE = 1                      # [arcsec/px] Plate scale in binning 1
@@ -24,7 +24,7 @@ OBJECT = OBJECT # Name of observed object
RA = OBJCTRA                      # In sexagesimal or decimal format
DEC = OBJCTDEC                    # In sexagesimal or decimal format
DATE-OBS = DATE-OBS               # [YYYY-MM-DDTHH:MM:SS] UTC observation date
# FOCUSTEM = FOCUSTEM               # [C] Focuser temperature
FOCUSTEM = FOCUSTEM               # [C] Focuser temperature
FOCUSPOS = FOCUS                  # [um] Focuser position
SET-TEMP = SET-TEMP               # [C] CCD temperature set point
CCD-TEMP = CCD-TEMP               # [C] CCD temperature
Loading