def test_already_visited(observer): avc = AlreadyVisited() time = Time('2016-08-13 10:00:00') # HD189733 observation1 = Observation( Field('HD189733', '20h00m43.7135s +22d42m39.0645s')) # Hat-P-16 observation2 = Observation(Field('Hat-P-16', '00h38m17.59s +42d27m47.2s')) # Sabik observation3 = Observation(Field('Sabik', '17h10m23s -15d43m30s')) observed_list = OrderedDict() observation1.seq_time = '01:00' observation2.seq_time = '02:00' observation3.seq_time = '03:00' observed_list[observation1.seq_time] = observation1 observed_list[observation2.seq_time] = observation2 veto1, score1 = avc.get_score(time, observer, observation1, observed_list=observed_list) veto2, score2 = avc.get_score(time, observer, observation3, observed_list=observed_list) assert veto1 is True assert veto2 is False
def test_duration_veto(observer, field_list): dc = Duration(30 * u.degree) time = Time('2016-08-13 17:42:00.034059') sunrise = observer.tonight(time=time, horizon=18 * u.degree)[-1] hd189733 = field_list[0] observation = Observation(Field(**hd189733), **hd189733) veto, score = dc.get_score(time, observer, observation, sunrise=sunrise) assert veto is True wasp33 = field_list[-3] observation = Observation(Field(**wasp33), **wasp33) veto, score = dc.get_score(time, observer, observation, sunrise=sunrise) assert veto is False
def test_print(field): obs = Observation(field, exptime=17.5 * u.second, min_nexp=27, exp_set_size=9) test_str = "Test Observation: 17.5 s exposures in blocks of 9, minimum 27, priority 100" assert str(obs) == test_str
def add_observation(self, field_config): """Adds an `Observation` to the scheduler Args: field_config (dict): Configuration items for `Observation` """ with suppress(KeyError): field_config['exptime'] = float( get_quantity_value(field_config['exptime'], unit=u.second)) * u.second self.logger.debug(f"Adding field_config={field_config!r} to scheduler") field = Field(field_config['name'], field_config['position']) self.logger.debug(f"Created field.name={field.name!r}") try: self.logger.debug(f"Creating observation for {field_config!r}") obs = Observation(field, **field_config) self.logger.debug( f"Observation created for field.name={field.name!r}") except Exception as e: raise error.InvalidObservation( f"Skipping invalid field: {field_config!r} {e!r}") else: if field.name in self._observations: self.logger.debug( f"Overriding existing entry for field.name={field.name!r}") self._observations[field.name] = obs self.logger.debug(f"obs={obs!r} added")
def test_duration_score(observer): dc = Duration(30 * u.degree) time = Time('2016-08-13 10:00:00') sunrise = observer.tonight(time=time, horizon=18 * u.degree)[-1] observation1 = Observation( Field('HD189733', '20h00m43.7135s +22d42m39.0645s')) # HD189733 observation2 = Observation(Field('Hat-P-16', '00h38m17.59s +42d27m47.2s')) # Hat-P-16 veto1, score1 = dc.get_score(time, observer, observation1, sunrise=sunrise) veto2, score2 = dc.get_score(time, observer, observation2, sunrise=sunrise) assert veto1 is False and veto2 is False assert score2 > score1
def test_no_exposures(field): obs = Observation(field, exptime=17.5 * u.second, min_nexp=27, exp_set_size=9) assert obs.first_exposure is None assert obs.last_exposure is None assert obs.pointing_image is None
def test_moon_avoidance(observer): mac = MoonAvoidance() time = Time('2016-08-13 10:00:00') moon = get_moon(time, observer.location) observation1 = Observation( Field('HD189733', '20h00m43.7135s +22d42m39.0645s')) # HD189733 observation2 = Observation(Field('Hat-P-16', '00h38m17.59s +42d27m47.2s')) # Hat-P-16 veto1, score1 = mac.get_score(time, observer, observation1, moon=moon) veto2, score2 = mac.get_score(time, observer, observation2, moon=moon) assert veto1 is False and veto2 is False assert score2 > score1
def test_custom_altitude(observer, field_list, horizon_line): time = Time('2018-01-19 07:10:00') m44 = field_list[-1] # Then check veto with block horizon_line = horizon_utils.Horizon(obstructions=[[[40, 70], [40, 80]]], ) ac = Altitude(horizon_line) observation = Observation(Field(**m44), **m44) veto, score = ac.get_score(time, observer, observation) assert veto is True
def test_basic_altitude(observer, field_list, horizon_line): # Target is at ~34 degrees altitude and 79 degrees azimuth time = Time('2018-01-19 07:10:00') m44 = field_list[-1] # First check out with default horizon ac = Altitude(horizon_line) observation = Observation(Field(**m44), **m44) veto, score = ac.get_score(time, observer, observation) assert veto is False
def test_moon_veto(observer): mac = MoonAvoidance() time = Time('2016-08-13 10:00:00') moon = get_moon(time, observer.location) observation1 = Observation(Field('Sabik', '17h10m23s -15d43m30s')) # Sabik veto1, score1 = mac.get_score(time, observer, observation1, moon=moon) assert veto1 is True
def test_last_exposure_and_reset(field): obs = Observation(field, exptime=17.5 * u.second, min_nexp=27, exp_set_size=9) status = obs.status assert status['current_exp'] == obs.current_exp_num # Mimic taking exposures obs.merit = 112.5 for i in range(5): obs.exposure_list[f'image_{i}'] = f'full_image_path_{i}' last = obs.last_exposure assert isinstance(last, tuple) assert obs.merit > 0.0 assert obs.current_exp_num == 5 assert last[0] == 'image_4' assert last[1] == 'full_image_path_4' assert isinstance(obs.first_exposure, tuple) assert obs.first_exposure[0] == 'image_0' assert obs.first_exposure[1] == 'full_image_path_0' obs.reset() status2 = obs.status assert status2['current_exp'] == 0 assert status2['merit'] == 0.0 assert obs.first_exposure is None assert obs.last_exposure is None assert obs.seq_time is None
def test_big_wall(observer, field_list): time = Time('2018-01-19 07:10:00') horizon_line = horizon_utils.Horizon(obstructions=[[[90, 0], [90, 359]]], ) vetoes = list() for field in field_list: observation = Observation(Field(**field), **field) ac = Altitude(horizon_line) veto, score = ac.get_score(time, observer, observation) vetoes.append(veto) assert all(vetoes)
def test_default_min_duration(field): obs = Observation(field) assert obs.minimum_duration == 7200 * u.second
def test_create_observation_bad_field(): with pytest.raises(AssertionError): Observation('20h00m43.7135s +22d42m39.0645s')
def test_create_observation_exptime_no_units(field): with pytest.raises(TypeError): Observation(field, exptime=1.0)
def test_create_observation_exptime_bad(field): with pytest.raises(AssertionError): Observation(field, exptime=0.0 * u.second)
def test_bad_priority(field): with pytest.raises(AssertionError): Observation(field, priority=-1)
def test_create_observation_exptime_minutes(field): obs = Observation(field, exptime=5.0 * u.minute) assert obs.exptime == 300 * u.second
def test_priority_str(field): obs = Observation(field, priority="5") assert obs.priority == 5.0
def test_good_priority(field): obs = Observation(field, priority=5.0) assert obs.priority == 5.0
def test_seq_time(field): obs = Observation(field, exptime=17.5 * u.second, min_nexp=27, exp_set_size=9) assert obs.seq_time is None
def test_bad_min_set_combo(field): with pytest.raises(AssertionError): Observation(field, exp_set_size=7) with pytest.raises(AssertionError): Observation(field, min_nexp=57)
def test_create_observation_no_field(): with pytest.raises(TypeError): Observation()
def test_small_sets(field): obs = Observation(field, exptime=1 * u.second, min_nexp=1, exp_set_size=1) assert obs.minimum_duration == 1 * u.second assert obs.set_duration == 1 * u.second
def test_good_min_set_combo(field): obs = Observation(field, min_nexp=21, exp_set_size=3) assert isinstance(obs, Observation)
def observation(field): return Observation(field)
def test_default_set_duration(field): obs = Observation(field) assert obs.set_duration == 1200 * u.second