From a7d9bfd10b5832a08b33c1b861be46296679eb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20S=C3=A1nchez-Gallego?= Date: Fri, 12 Jan 2024 21:21:14 +0000 Subject: [PATCH] Replace NaNs with None in FITS headers --- python/lvmscp/delegate.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/python/lvmscp/delegate.py b/python/lvmscp/delegate.py index 3b4db9f..9b16a58 100644 --- a/python/lvmscp/delegate.py +++ b/python/lvmscp/delegate.py @@ -199,13 +199,21 @@ async def post_process(self, fdata: FetchDataDict): # Add SDSS MJD. header["SMJD"][0] = get_sjd("LCO") - header["PRESSURE"][0] = self.pressure_data.get(f"{ccd}_pressure", -999.0) + header["PRESSURE"][0] = self.pressure_data.get(f"{ccd}_pressure", numpy.nan) depth_camera = self.depth_data.get("camera", "") for ch in ["A", "B", "C"]: - depth = self.depth_data[ch] if ccd == depth_camera else -999.0 + depth = self.depth_data[ch] if ccd == depth_camera else numpy.nan header[f"DEPTH{ch}"][0] = depth + # Replace NaNs in headers. FITS does not support NaNs. + for key, value in header.items(): + try: + if numpy.isnan(value[0]): + header[key][0] = None + except Exception: + continue + async def get_shutter_status(self, spec: str) -> dict | Literal[False]: """Returns the status of the shutter for a spectrograph.""" @@ -260,8 +268,8 @@ async def get_sensors(self, spec: str): try: sensors = cmd.replies.get(f"{spec}_sensors") - self.header_data["LABTEMP"] = sensors.get("t3", -999.0) - self.header_data["LABHUMID"] = sensors.get("rh3", -999.0) + self.header_data["LABTEMP"] = sensors.get("t3", numpy.nan) + self.header_data["LABHUMID"] = sensors.get("rh3", numpy.nan) except KeyError: self.command.warning(f"{spec}: failed retrieving sensor values.") @@ -332,14 +340,14 @@ async def get_telescope_info(self): else: pwi_status = pwi_cmd.replies[-1].body - ra_h: float = pwi_status.get("ra_j2000_hours", -999.0) + ra_h: float = pwi_status.get("ra_j2000_hours", numpy.nan) if ra_h > 0: ra_d = ra_h * 15.0 else: ra_d = ra_h self.header_data[f"TE{telescope.upper()}RA"] = numpy.round(ra_d, 6) - dec = pwi_status.get("dec_j2000_degs", -999.0) + dec = pwi_status.get("dec_j2000_degs", numpy.nan) self.header_data[f"TE{telescope.upper()}DE"] = numpy.round(dec, 6) alt = pwi_status.get("altitude_degs", None)