Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
    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")
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
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
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
def test_create_field():
    names = ['oneWord', 'Two Words', '3 Whole - Words']
    right_ascensions = [
        ('20h00m43.7135s', Longitude('20h00m43.7135s', unit=u.degree)),
        ('0d0m0.0s', Longitude(0, unit=u.degree)),
        ('-0d0m0.0s', Longitude(0, unit=u.degree)),
        ('+0d0m0.0s', Longitude(0, unit=u.degree)),
    ]
    declinations = [
        ('22d42m39.0645', Latitude('22d42m39.0645', unit=u.degree)),
        ('+22d42m39.0645', Latitude('22d42m39.0645', unit=u.degree)),
        ('-22d42m39.0645', Latitude('-22d42m39.0645', unit=u.degree)),
        ('0d0m0.0s', Latitude(0, unit=u.degree)),
        ('+0d0m0.0s', Latitude(0, unit=u.degree)),
        ('-0d0m0.0s', Latitude(0, unit=u.degree)),
    ]

    for name in names:
        for ra_str, ra in right_ascensions:
            for dec_str, dec in declinations:
                field = Field(name, '%s %s' % (ra_str, dec_str))
                assert field.name == name
                assert field.coord.ra == ra
                assert field.coord.dec == dec
Exemplo n.º 11
0
def field():
    return Field('Test Observation', '20h00m43.7135s +22d42m39.0645s')
Exemplo n.º 12
0
def test_create_field_no_params():
    with pytest.raises(TypeError):
        Field()
Exemplo n.º 13
0
def test_create_field_Observation_name():
    field = Field('Test Field - 32b', '20h00m43.7135s +22d42m39.0645s')
    assert field.field_name == 'TestField32B'
Exemplo n.º 14
0
def test_equinox_none():
    field = Field('Test Field - 32b',
                  '20h00m43.7135s +22d42m39.0645s',
                  equinox=None)
    assert field.coord.equinox == 'J2000'
Exemplo n.º 15
0
def test_create_field_bad_name():
    with pytest.raises(ValueError):
        Field('', '20h00m43.7135s +22d42m39.0645s')
    with pytest.raises(ValueError):
        Field(' - ', '20h00m43.7135s +22d42m39.0645s')
Exemplo n.º 16
0
def test_create_field_bad_position():
    with pytest.raises(ValueError):
        Field('TestObservation', 'Bad Position')