def test_duration_veto(observer): 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_no_exposures(field): obs = Observation(field, exp_time=17.5 * u.second, min_nexp=27, exp_set_size=9) assert obs.first_exposure is None assert obs.last_exposure is None
def add_observation(self, field_config): """Adds an `Observation` to the scheduler Args: field_config (dict): Configuration items for `Observation` """ assert field_config['name'] not in self._observations.keys(), \ self.logger.error("Cannot add duplicate field name") if 'exp_time' in field_config: field_config['exp_time'] = float( field_config['exp_time']) * u.second field = Field(field_config['name'], field_config['position']) try: if 'hdr_mode' in field_config: obs = DitheredObservation(field, **field_config) else: obs = Observation(field, **field_config) except Exception as e: self.logger.warning( "Skipping invalid field config: {}".format(field_config)) self.logger.warning(e) else: self._observations[field.name] = obs
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_print(field): obs = Observation(field, exp_time=17.5 * u.second, min_nexp=27, exp_set_size=9) assert str( obs ) == "Test Observation: 17.5 s exposures in blocks of 9, minimum 27, priority 100"
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_observation(camera): """ Tests functionality of take_observation() """ field = Field('Test Observation', '20h00m43.7135s +22d42m39.0645s') observation = Observation(field, exp_time=1.5 * u.second) camera.take_observation(observation, headers={}) time.sleep(7)
def test_last_exposure_and_reset(field): obs = Observation(field, exp_time=17.5 * u.second, min_nexp=27, exp_set_size=9) status = obs.status() assert status['current_exp'] == obs.current_exp # Mimic taking exposures obs.merit = 112.5 for i in range(5): obs.current_exp += 1 obs.exposure_list['image_{}'.format(i)] = 'full_image_path_{}'.format( i) last = obs.last_exposure assert isinstance(last, tuple) assert obs.merit > 0.0 assert obs.current_exp == 5 assert last[0] == 'image_4' assert last[1] == 'full_image_path_4' obs.reset() status2 = obs.status() assert status2['current_exp'] == 0 assert status2['merit'] == 0.0 assert isinstance(obs.first_exposure, tuple) assert obs.first_exposure[0] == 'image_0' assert obs.first_exposure[1] == 'full_image_path_0'
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, exp_time=17.5 * u.second, min_nexp=27, exp_set_size=9) status = obs.status() assert status['current_exp'] == obs.current_exp # Mimic taking exposures obs.merit = 112.5 for i in range(5): obs.current_exp += 1 obs.exposure_list['image_{}'.format(i)] = 'full_image_path_{}'.format(i) last = obs.last_exposure assert isinstance(last, tuple) assert obs.merit > 0.0 assert obs.current_exp == 5 assert last[0] == 'image_4' assert last[1] == 'full_image_path_4' obs.reset() status2 = obs.status() assert status2['current_exp'] == 0 assert status2['merit'] == 0.0 assert isinstance(obs.first_exposure, tuple) assert obs.first_exposure[0] == 'image_0' assert obs.first_exposure[1] == 'full_image_path_0'
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_create_observation_bad_field(): with pytest.raises(AssertionError): Observation('20h00m43.7135s +22d42m39.0645s')
def test_create_observation_exp_time_no_units(field): with pytest.raises(TypeError): Observation(field, exp_time=1.0)
def test_create_observation_exp_time_bad(field): with pytest.raises(AssertionError): Observation(field, exp_time=0.0 * u.second)
def test_seq_time(field): obs = Observation(field, exp_time=17.5 * u.second, min_nexp=27, exp_set_size=9) assert obs.seq_time is None
def test_create_observation_exp_time_minutes(field): obs = Observation(field, exp_time=5.0 * u.minute) assert obs.exp_time == 300 * u.second
def test_default_set_duration(field): obs = Observation(field) assert obs.set_duration == 1200 * u.second
def test_default_min_duration(field): obs = Observation(field) assert obs.minimum_duration == 7200 * u.second
def test_good_min_set_combo(field): obs = Observation(field, min_nexp=21, exp_set_size=3) assert isinstance(obs, Observation)
def test_bad_priority(field): with pytest.raises(AssertionError): Observation(field, priority=-1)
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 observation(field): return Observation(field)
def test_small_sets(field): obs = Observation(field, exp_time=1 * u.second, min_nexp=1, exp_set_size=1) assert obs.minimum_duration == 1 * u.second assert obs.set_duration == 1 * u.second