diff --git a/rubin_scheduler/scheduler/features/conditions.py b/rubin_scheduler/scheduler/features/conditions.py index d4c91ee..52a929d 100644 --- a/rubin_scheduler/scheduler/features/conditions.py +++ b/rubin_scheduler/scheduler/features/conditions.py @@ -158,8 +158,6 @@ def __init__( during the current night. From interpolation. sunrise : `float` The MJD of sunrise during the current night. From interpolation - mjd_start : `float` - The starting MJD of the survey. moonrise : `float` The MJD of moonrise during the current night. From interpolation. moonset : `float` @@ -550,21 +548,71 @@ def set_auxtel_info( for key in auxtel_args.parameters.keys(): setattr(self, key, loc[key]) + potential_attrs = dir(self) for key in kwargs: + if key not in potential_attrs: + warnings.warn("Setting unexpected Conditions attribute %s" % key) setattr(self, key, kwargs[key]) - def set_maintel_info(self, mjd, **kwargs): + def set_maintel_info( + self, + mjd, + slewtime, + current_filter, + mounted_filters, + night, + skybrightness, + fwhm_eff, + moon_alt, + moon_az, + moon_ra, + moon_dec, + moon_phase, + sun_alt, + sun_az, + sun_ra, + sun_dec, + tel_ra, + tel_dec, + tel_alt, + tel_az, + wind_speed, + wind_direction, + sun_n12_setting, + sun_n12_rising, + sun_n18_setting, + sun_n18_rising, + moonrise, + moonset, + planet_positions, + tel_alt_limits, + tel_az_limits, + sky_alt_limits, + sky_az_limits, + **kwargs, + ): """Method to set all the information we expect will be required by a standard maintel scheduler. Extra attributes can be set via **kwargs. """ self._init_attributes() - maintel_args = signature(self.set_auxtel_info) + maintel_args = signature(self.set_maintel_info) loc = locals() for key in maintel_args.parameters.keys(): setattr(self, key, loc[key]) + potential_attrs = dir(self) + for key in kwargs: + if key not in potential_attrs: + warnings.warn("Setting unexpected Conditions attribute %s" % key) + setattr(self, key, kwargs[key]) + + def set_attrs(self, **kwargs): + """Convience function for setting lots of attributes at once.""" + potential_attrs = dir(self) for key in kwargs: + if key not in potential_attrs: + warnings.warn("Setting unexpected Conditions attribute %s" % key) setattr(self, key, kwargs[key]) def __repr__(self): @@ -661,7 +709,6 @@ def __str__(self): print(positions_deg.to_markdown(), file=output) events = ( - "mjd_start", "mjd", "sunset", "sun_n12_setting", diff --git a/rubin_scheduler/scheduler/model_observatory/model_observatory.py b/rubin_scheduler/scheduler/model_observatory/model_observatory.py index 7448b06..724058f 100644 --- a/rubin_scheduler/scheduler/model_observatory/model_observatory.py +++ b/rubin_scheduler/scheduler/model_observatory/model_observatory.py @@ -458,8 +458,6 @@ def return_conditions(self): sun_moon_info_start_of_night = self.almanac.get_sun_moon_positions(self.conditions.sunset) self.conditions.moon_phase_sunset = sun_moon_info_start_of_night["moon_phase"] - self.conditions.mjd_start = self.mjd_start - # Telescope limits self.conditions.sky_az_limits = self.sky_az_limits self.conditions.sky_alt_limits = self.sky_alt_limits diff --git a/tests/scheduler/test_conditions.py b/tests/scheduler/test_conditions.py index d4b2808..908f771 100644 --- a/tests/scheduler/test_conditions.py +++ b/tests/scheduler/test_conditions.py @@ -1,6 +1,8 @@ import unittest from inspect import signature +import numpy as np + from rubin_scheduler.scheduler.features import Conditions from rubin_scheduler.scheduler.model_observatory import ModelObservatory @@ -12,16 +14,45 @@ def test_conditions(self): mo = ModelObservatory() mo_conditions = mo.return_conditions() + # Fresh empty conditions conditions = Conditions() # Find the arguments that need to be set auxtel_args = signature(conditions.set_auxtel_info) - - to_pass = {} + + to_pass = [] + for key in auxtel_args.parameters.keys(): + if key != "kwargs": + to_pass.append(getattr(mo_conditions, key)) + + conditions.set_auxtel_info(*to_pass) + for key in auxtel_args.parameters.keys(): - to_pass[key] = getattr(mo_conditions, key) + if np.size(getattr(conditions, key)) == 1: + assert getattr(conditions, key) == getattr(mo_conditions, key) + else: + assert np.array_equal(getattr(conditions, key), getattr(mo_conditions, key), equal_nan=True) + + # Again for the maintel attrs + conditions = Conditions() + maintel_args = signature(conditions.set_maintel_info) + + to_pass = [] + for key in maintel_args.parameters.keys(): + if key != "kwargs": + to_pass.append(getattr(mo_conditions, key)) + + conditions.set_maintel_info(*to_pass) + + for key in maintel_args.parameters.keys(): + assert getattr(conditions, key) == getattr(mo_conditions, key) + + # check we can set some arbitrary attributes + conditions = Conditions() + conditions.set_attrs(mjd=62511, moon_alt=0.1) - conditions.set_auxtel_info(**to_pass) + with self.assertWarns(Warning): + conditions.set_attrs(not_an_attribute=10) if __name__ == "__main__":