diff --git a/pyscope/observatory/observatory.py b/pyscope/observatory/observatory.py index 537bea35..37aba2a7 100644 --- a/pyscope/observatory/observatory.py +++ b/pyscope/observatory/observatory.py @@ -507,9 +507,9 @@ def __init__(self, config_path=None, **kwargs): self._config["cover_calibrator"][ "cover_calibrator_driver" ] = self._cover_calibrator_driver - self._config["cover_calibrator"][ - "cover_calibrator_kwargs" - ] = _kwargs_to_config(self._cover_calibrator_kwargs) + self._config["cover_calibrator"]["cover_calibrator_kwargs"] = ( + _kwargs_to_config(self._cover_calibrator_kwargs) + ) # Dome self._dome = kwargs.get("dome", self._dome) @@ -563,9 +563,9 @@ def __init__(self, config_path=None, **kwargs): self._config["observing_conditions"][ "observing_conditions_driver" ] = self._observing_conditions_driver - self._config["observing_conditions"][ - "observing_conditions_kwargs" - ] = _kwargs_to_config(self._observing_conditions_kwargs) + self._config["observing_conditions"]["observing_conditions_kwargs"] = ( + _kwargs_to_config(self._observing_conditions_kwargs) + ) # Rotator self._rotator = kwargs.get("rotator", self._rotator) diff --git a/pyscope/telrun/reports.py b/pyscope/telrun/reports.py index 4c8659cf..74f7cd36 100644 --- a/pyscope/telrun/reports.py +++ b/pyscope/telrun/reports.py @@ -197,11 +197,13 @@ def summary_report_cli( [hdr["MOONANGL"] for hdr in headers], [hdr["MOONPHAS"] for hdr in headers], [ - coord.SkyCoord( - hdr["OBJCTRA"], hdr["OBJCTDEC"], unit=("hourangle", "deg") + ( + coord.SkyCoord( + hdr["OBJCTRA"], hdr["OBJCTDEC"], unit=("hourangle", "deg") + ) + if None not in (hdr.get("OBJCTRA", None), hdr.get("OBJCTDEC", None)) + else None ) - if None not in (hdr.get("OBJCTRA", None), hdr.get("OBJCTDEC", None)) - else None for hdr in headers ], ], @@ -267,17 +269,22 @@ def summary_report_cli( # Pointing errors in arcsec dra = np.array( [ - (tbl["sched coords"][i].ra.deg - tbl["obj coords"][i].ra.deg) / u.arcsec - if tbl["obj coords"][i] is not None - else np.nan + ( + (tbl["sched coords"][i].ra.deg - tbl["obj coords"][i].ra.deg) / u.arcsec + if tbl["obj coords"][i] is not None + else np.nan + ) for i in range(len(tbl)) ] ) ddec = np.array( [ - (tbl["sched coords"][i].dec.deg - tbl["obj coords"][i].dec.deg) / u.arcsec - if tbl["obj coords"][i] is not None - else np.nan + ( + (tbl["sched coords"][i].dec.deg - tbl["obj coords"][i].dec.deg) + / u.arcsec + if tbl["obj coords"][i] is not None + else np.nan + ) for i in range(len(tbl)) ] ) diff --git a/pyscope/telrun/schedtab.py b/pyscope/telrun/schedtab.py index 590d767a..0d909f69 100644 --- a/pyscope/telrun/schedtab.py +++ b/pyscope/telrun/schedtab.py @@ -42,22 +42,26 @@ def blocks_to_table(observing_blocks): # Populate simple columns t["name"] = [ - block.name - if type(block) is astroplan.ObservingBlock - else "TransitionBlock" - if type(block) is astroplan.TransitionBlock - else "EmptyBlock" + ( + block.name + if type(block) is astroplan.ObservingBlock + else ( + "TransitionBlock" + if type(block) is astroplan.TransitionBlock + else "EmptyBlock" + ) + ) for block in observing_blocks ] t["start_time"] = astrotime.Time( np.ma.array( [ - block.start.jd - if type(block) is astroplan.Slot - else 0 - if block.start_time is None - else block.start_time.jd + ( + block.start.jd + if type(block) is astroplan.Slot + else 0 if block.start_time is None else block.start_time.jd + ) for block in observing_blocks ], mask=unscheduled_blocks_mask, @@ -68,11 +72,11 @@ def blocks_to_table(observing_blocks): t["end_time"] = astrotime.Time( np.ma.array( [ - block.end.jd - if type(block) is astroplan.Slot - else 0 - if block.end_time is None - else block.end_time.jd + ( + block.end.jd + if type(block) is astroplan.Slot + else 0 if block.end_time is None else block.end_time.jd + ) for block in observing_blocks ], mask=unscheduled_blocks_mask, @@ -82,9 +86,11 @@ def blocks_to_table(observing_blocks): t["target"] = coord.SkyCoord( [ - block.target.to_string("hmsdms") - if type(block) is astroplan.ObservingBlock - else "0h0m0.0s -90d0m0.0s" + ( + block.target.to_string("hmsdms") + if type(block) is astroplan.ObservingBlock + else "0h0m0.0s -90d0m0.0s" + ) for block in observing_blocks ] ) @@ -98,9 +104,11 @@ def blocks_to_table(observing_blocks): ) temp_list = [ - block.configuration["observer"] - if type(block) is astroplan.ObservingBlock - else [""] + ( + block.configuration["observer"] + if type(block) is astroplan.ObservingBlock + else [""] + ) for block in observing_blocks ] t["observer"] = np.ma.array( @@ -109,9 +117,11 @@ def blocks_to_table(observing_blocks): t["code"] = np.ma.array( [ - block.configuration["code"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["code"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -119,9 +129,11 @@ def blocks_to_table(observing_blocks): t["title"] = np.ma.array( [ - block.configuration["title"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["title"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -129,9 +141,11 @@ def blocks_to_table(observing_blocks): t["filename"] = np.ma.array( [ - block.configuration["filename"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["filename"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -139,9 +153,11 @@ def blocks_to_table(observing_blocks): t["type"] = np.ma.array( [ - block.configuration["type"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["type"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -149,9 +165,11 @@ def blocks_to_table(observing_blocks): t["backend"] = np.ma.array( [ - block.configuration["backend"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["backend"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -159,9 +177,11 @@ def blocks_to_table(observing_blocks): t["filter"] = np.ma.array( [ - block.configuration["filter"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["filter"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -169,9 +189,11 @@ def blocks_to_table(observing_blocks): t["exposure"] = np.ma.array( [ - block.configuration["exposure"] - if type(block) is astroplan.ObservingBlock - else 0 + ( + block.configuration["exposure"] + if type(block) is astroplan.ObservingBlock + else 0 + ) for block in observing_blocks ], mask=open_slots_mask, @@ -179,18 +201,22 @@ def blocks_to_table(observing_blocks): t["nexp"] = np.ma.array( [ - block.configuration["nexp"] - if type(block) is astroplan.ObservingBlock - else 0 + ( + block.configuration["nexp"] + if type(block) is astroplan.ObservingBlock + else 0 + ) for block in observing_blocks ], mask=open_slots_mask, ) temp_list = [ - block.configuration["repositioning"] - if type(block) is astroplan.ObservingBlock - else (0, 0) + ( + block.configuration["repositioning"] + if type(block) is astroplan.ObservingBlock + else (0, 0) + ) for block in observing_blocks ] t["repositioning"] = np.ma.array( @@ -199,9 +225,11 @@ def blocks_to_table(observing_blocks): t["shutter_state"] = np.ma.array( [ - block.configuration["shutter_state"] - if type(block) is astroplan.ObservingBlock - else False + ( + block.configuration["shutter_state"] + if type(block) is astroplan.ObservingBlock + else False + ) for block in observing_blocks ], mask=open_slots_mask, @@ -209,18 +237,22 @@ def blocks_to_table(observing_blocks): t["readout"] = np.ma.array( [ - block.configuration["readout"] - if type(block) is astroplan.ObservingBlock - else 0 + ( + block.configuration["readout"] + if type(block) is astroplan.ObservingBlock + else 0 + ) for block in observing_blocks ], mask=open_slots_mask, ) temp_list = [ - block.configuration["binning"] - if type(block) is astroplan.ObservingBlock - else (1, 1) + ( + block.configuration["binning"] + if type(block) is astroplan.ObservingBlock + else (1, 1) + ) for block in observing_blocks ] t["binning"] = np.ma.array( @@ -228,9 +260,11 @@ def blocks_to_table(observing_blocks): ) temp_list = [ - block.configuration["frame_position"] - if type(block) is astroplan.ObservingBlock - else (0, 0) + ( + block.configuration["frame_position"] + if type(block) is astroplan.ObservingBlock + else (0, 0) + ) for block in observing_blocks ] t["frame_position"] = np.ma.array( @@ -238,9 +272,11 @@ def blocks_to_table(observing_blocks): ) temp_list = [ - block.configuration["frame_size"] - if type(block) is astroplan.ObservingBlock - else (0, 0) + ( + block.configuration["frame_size"] + if type(block) is astroplan.ObservingBlock + else (0, 0) + ) for block in observing_blocks ] t["frame_size"] = np.ma.array( @@ -249,9 +285,11 @@ def blocks_to_table(observing_blocks): t["pm_ra_cosdec"] = np.ma.array( [ - block.configuration["pm_ra_cosdec"].to(u.arcsec / u.hour).value - if type(block) is astroplan.ObservingBlock - else 0 + ( + block.configuration["pm_ra_cosdec"].to(u.arcsec / u.hour).value + if type(block) is astroplan.ObservingBlock + else 0 + ) for block in observing_blocks ], mask=open_slots_mask, @@ -259,9 +297,11 @@ def blocks_to_table(observing_blocks): t["pm_dec"] = np.ma.array( [ - block.configuration["pm_dec"].to(u.arcsec / u.hour).value - if type(block) is astroplan.ObservingBlock - else 0 + ( + block.configuration["pm_dec"].to(u.arcsec / u.hour).value + if type(block) is astroplan.ObservingBlock + else 0 + ) for block in observing_blocks ], mask=open_slots_mask, @@ -269,9 +309,11 @@ def blocks_to_table(observing_blocks): t["comment"] = np.ma.array( [ - block.configuration["comment"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["comment"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -279,9 +321,11 @@ def blocks_to_table(observing_blocks): t["sch"] = np.ma.array( [ - block.configuration["sch"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["sch"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -289,9 +333,11 @@ def blocks_to_table(observing_blocks): t["ID"] = np.ma.array( [ - block.configuration["ID"] - if type(block) is astroplan.ObservingBlock - else astrotime.Time(0, format="jd") + ( + block.configuration["ID"] + if type(block) is astroplan.ObservingBlock + else astrotime.Time(0, format="jd") + ) for block in observing_blocks ], mask=open_slots_mask, @@ -299,9 +345,11 @@ def blocks_to_table(observing_blocks): t["status"] = np.ma.array( [ - block.configuration["status"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["status"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -309,9 +357,11 @@ def blocks_to_table(observing_blocks): t["message"] = np.ma.array( [ - block.configuration["message"] - if type(block) is astroplan.ObservingBlock - else "" + ( + block.configuration["message"] + if type(block) is astroplan.ObservingBlock + else "" + ) for block in observing_blocks ], mask=open_slots_mask, @@ -319,9 +369,11 @@ def blocks_to_table(observing_blocks): t["sched_time"] = np.ma.array( [ - block.configuration["sched_time"] - if type(block) is astroplan.ObservingBlock - else astrotime.Time(0, format="jd") + ( + block.configuration["sched_time"] + if type(block) is astroplan.ObservingBlock + else astrotime.Time(0, format="jd") + ) for block in observing_blocks ], mask=open_slots_mask, @@ -333,9 +385,11 @@ def blocks_to_table(observing_blocks): len(observing_blocks), np.max( [ - len(block.constraints) - if type(block) is astroplan.ObservingBlock - else 0 + ( + len(block.constraints) + if type(block) is astroplan.ObservingBlock + else 0 + ) for block in observing_blocks ] ), @@ -346,9 +400,11 @@ def blocks_to_table(observing_blocks): constraint_list = np.full( np.max( [ - len(block.constraints) - if type(block) is astroplan.ObservingBlock - else 0 + ( + len(block.constraints) + if type(block) is astroplan.ObservingBlock + else 0 + ) for block in observing_blocks ] ), @@ -369,21 +425,25 @@ def blocks_to_table(observing_blocks): elif type(constraint) is astroplan.AtNightConstraint: constraint_dict = { "type": "AtNightConstraint", - "max_solar_altitude": constraint.max_solar_altitude.to( - u.deg - ).value - if constraint.max_solar_altitude is not None - else 0, + "max_solar_altitude": ( + constraint.max_solar_altitude.to(u.deg).value + if constraint.max_solar_altitude is not None + else 0 + ), } elif type(constraint) is astroplan.AltitudeConstraint: constraint_dict = { "type": "AltitudeConstraint", - "min": constraint.min.to(u.deg).value - if constraint.min is not None - else 0, - "max": constraint.max.to(u.deg).value - if constraint.max is not None - else 90, + "min": ( + constraint.min.to(u.deg).value + if constraint.min is not None + else 0 + ), + "max": ( + constraint.max.to(u.deg).value + if constraint.max is not None + else 90 + ), "boolean_constraint": constraint.boolean_constraint, } elif type(constraint) is astroplan.AirmassConstraint: @@ -391,19 +451,25 @@ def blocks_to_table(observing_blocks): "type": "AirmassConstraint", "min": constraint.min if constraint.min is not None else 0, "max": constraint.max if constraint.max is not None else 100, - "boolean_constraint": constraint.boolean_constraint - if constraint.boolean_constraint is not None - else False, + "boolean_constraint": ( + constraint.boolean_constraint + if constraint.boolean_constraint is not None + else False + ), } elif type(constraint) is astroplan.MoonSeparationConstraint: constraint_dict = { "type": "MoonSeparationConstraint", - "min": constraint.min.to(u.deg).value - if constraint.min is not None - else 0, - "max": constraint.max.to(u.deg).value - if constraint.max is not None - else 360, + "min": ( + constraint.min.to(u.deg).value + if constraint.min is not None + else 0 + ), + "max": ( + constraint.max.to(u.deg).value + if constraint.max is not None + else 360 + ), } elif constraint is None: continue @@ -591,7 +657,7 @@ def validate(schedule_table, observatory=None): raise ValueError( f"Column '{column.name}' must be of type str, not {column.dtype}" ) - case ("start_time" | "end_time" | "sched_time"): + case "start_time" | "end_time" | "sched_time": if type(column) is not astrotime.Time: logger.error( f"Column '{column.name}' must be of type astropy.time.Time, not {type(column)}" @@ -599,7 +665,7 @@ def validate(schedule_table, observatory=None): raise ValueError( f"Column '{column.name}' must be of type astropy.time.Time, not {type(column)}" ) - case ("target"): + case "target": if type(column) is not coord.SkyCoord: logger.error( f"Column '{column.name}' must be of type astropy.coordinates.SkyCoord, not {type(column)}" @@ -623,7 +689,7 @@ def validate(schedule_table, observatory=None): raise ValueError( f"Column '{column.name}' must be of type int64, not {column.dtype}" ) - case ("exposure" | "pm_ra_cosdec" | "pm_dec"): + case "exposure" | "pm_ra_cosdec" | "pm_dec": if not np.issubdtype(column.dtype, np.dtype("float64")): logger.error( f"Column '{column.name}' must be of type float64, not {column.dtype}" @@ -631,7 +697,7 @@ def validate(schedule_table, observatory=None): raise ValueError( f"Column '{column.name}' must be of type float64, not {column.dtype}" ) - case ("shutter_state"): + case "shutter_state": if column.dtype != bool: logger.error( f"Column '{column.name}' must be of type bool, not {column.dtype}" diff --git a/pyscope/telrun/telrun_operator.py b/pyscope/telrun/telrun_operator.py index 5a887468..dbf103a7 100644 --- a/pyscope/telrun/telrun_operator.py +++ b/pyscope/telrun/telrun_operator.py @@ -295,7 +295,14 @@ def __init__(self, config_path="./config/", gui=True, **kwargs): case None | "None" | "none": logger.info("dome_type is None, setting to None") self._dome_type = "None" - case "dome" | "safety-monitor" | "safety_monitor" | "safetymonitor" | "safety monitor" | "both": + case ( + "dome" + | "safety-monitor" + | "safety_monitor" + | "safetymonitor" + | "safety monitor" + | "both" + ): pass case _: raise TelrunException( @@ -637,7 +644,9 @@ def execute_schedule(self, schedule, *args): self.observatory.dome.FindHome() self._dome_status = "Idle" logger.info("Found.") - case "safety-monitor" | "safety_monitor" | "safetymonitor" | "safety monitor": + case ( + "safety-monitor" | "safety_monitor" | "safetymonitor" | "safety monitor" + ): logger.info("Designating first safety monitor state as dome...") if self.observatory.safety_monitor is not None: status = False @@ -951,7 +960,9 @@ def execute_block(self, *args, **kwargs): ] = "Dome shutter is not open" return ("F", "Dome shutter is not open", block) - case "safety-monitor" | "safety_monitor" | "safetymonitor" | "safety monitor": + case ( + "safety-monitor" | "safety_monitor" | "safetymonitor" | "safety monitor" + ): if self.observatory.safety_monitor is not None: status = False if self.observatory.safety_monitor is not (iter, tuple, list): @@ -1550,11 +1561,12 @@ def execute_block(self, *args, **kwargs): self._current_block = None if self.update_block_status: block["configuration"]["status"] = "F" - block["configuration"][ - "message" - ] = "Requested starty and numy of %i, %i is not supported" % ( - block["configuration"]["frame_position"][1], - block["configuration"]["frame_size"][1], + block["configuration"]["message"] = ( + "Requested starty and numy of %i, %i is not supported" + % ( + block["configuration"]["frame_position"][1], + block["configuration"]["frame_size"][1], + ) ) return ( "F",