def setup(self):
        self.target = ICRSTarget(
            name='deneb',
            # ra  = '20 41 25.91',
            # dec = '+45 16 49.22',
            ra=310.35795833333333,
            dec=45.280338888888885,
            epoch=2000,
        )

        self.telescope = dict(
            name='maui',
            latitude=20.7069444444,
            longitude=-156.258055556,
        )

        self.proposal = Proposal(
            proposal_name='LCOSchedulerTest',
            user='******',
            tag='admin',
            time_remaining=10,  # In hours
            priority=1)

        self.instrument_config = dict(
            exposure_count=1,
            bin_x=2,
            bin_y=2,
            exposure_time=20,
            extra_params={},
            optical_elements={'filter': 'BSSL-UX-020'})

        self.guiding_config = dict(mode='ON',
                                   optional=True,
                                   optical_elements={},
                                   extra_params={},
                                   exposure_time=10)

        self.acquisition_config = dict(mode='OFF', extra_params={})

        self.constraints = {'max_airmass': None, 'min_lunar_distance': 0}

        self.configuration = Configuration(
            dict(id=5,
                 target=self.target,
                 type='expose',
                 instrument_type='1M0-SCICAM-SBIG',
                 priority=1,
                 instrument_configs=[self.instrument_config],
                 acquisition_config=self.acquisition_config,
                 guiding_config=self.guiding_config,
                 extra_params={},
                 constraints=self.constraints))

        self.semester_start = datetime(2011, 11, 1, 0, 0, 0)
        self.semester_end = datetime(2011, 11, 8, 0, 0, 0)
        self.windows = [(self.semester_start, self.semester_end)]

        self.duration = 60
        self.id = 1
Ejemplo n.º 2
0
    def test_build_rr_observation(self):
        reservation = Reservation(priority=None,
                                  duration=10,
                                  possible_windows_dict={})
        reservation.scheduled_start = 0
        reservation.scheduled_resource = '1m0a.doma.bpl'

        proposal = Proposal({
            'id': 'testPro',
            'tag': 'tagPro',
            'tac_priority': 39,
            'pi': 'me'
        })
        target = ICRSTarget({'name': 'test', 'ra': 23.3, 'dec': 22.2})

        request_group = RequestGroup(operator='single',
                                     requests=None,
                                     proposal=proposal,
                                     expires=None,
                                     rg_id=333333,
                                     is_staff=False,
                                     name=None,
                                     ipp_value=1.0,
                                     observation_type="RAPID_RESPONSE",
                                     submitter='')

        configuration = Mock()
        configuration.guiding_config = {'mode': 'ON', 'optional': True}
        configuration.type = 'EXPOSE'
        configuration.instrument_type = '1M0-FAKE-SCICAM'
        configuration.constraints = {}
        configuration.id = 13
        configuration.target = target

        request = Request(
            configurations=[configuration],
            windows=None,
            request_id=22223,
        )

        reservation.request = request
        reservation.request_group = request_group
        configdb_interface = Mock()
        configdb_interface.get_specific_instrument.return_value = 'xx03'
        configdb_interface.get_autoguider_for_instrument.return_value = 'xx04'
        received = build_observation(reservation, self.start,
                                     configdb_interface)

        assert_equal(received['request'], 22223)
        assert_equal(received['site'], 'bpl')
        assert_equal(received['enclosure'], 'doma')
        assert_equal(received['telescope'], '1m0a')
        assert_equal(received['configuration_statuses'][0]['configuration'],
                     13)
        assert_equal(received['configuration_statuses'][0]['instrument_name'],
                     'xx03')
        assert_equal(
            received['configuration_statuses'][0]['guide_camera_name'], 'xx04')
Ejemplo n.º 3
0
    def setup(self):
        # Metadata missing proposal and tag parameters
        self.proposal = Proposal(pi='Eric Saunders')

        self.configdb_interface = ConfigDBInterface(
            configdb_url='',
            telescope_classes=[],
            telescopes_file='test/telescopes.json',
            active_instruments_file='test/active_instruments.json')

        self.valid_proposal = Proposal(
            pi='Eric Saunders',
            id='Scheduler Testing',
            tag='admin',
            tac_priority=2,
        )

        self.valid_target = ICRSTarget(
            name='deneb',
            type='ICRS',
            # ra  = '20 41 25.91',
            # dec = '+45 16 49.22',
            ra=310.35795833333333,
            dec=45.280338888888885,
            rot_mode='SKY',
            rot_angle=0.0,
            acquire_mode='OPTIONAL',
        )

        self.valid_expose_mol = dict(
            type='expose',
            exposure_count=1,
            bin_x=2,
            bin_y=2,
            instrument_name='1m0-SciCam-SINISTRO',
            filter='B',
            exposure_time=30,
            priority=1,
            ag_mode='Optional',
            defocus=0.0,
        )
    def test_build_request_group_returns_invalid_request_groups(
            self, mock_proposal, mock_semester):
        mock_semester.return_value = {
            'id': '2013A',
            'start': datetime(2013, 1, 1),
            'end': datetime(2014, 1, 1)
        }
        mock_proposal.return_value = Proposal({
            'id': 'TestProposal',
            'pi': '',
            'tag': '',
            'tac_priority': 10
        })
        bad_configurations = copy.deepcopy(self.configurations)
        bad_configurations[0]['target']['type'] = 'POTATOES'
        bad_configurations[0]['target']['name'] = 'Potato Target'
        bad_req_dict = {
            'configurations': bad_configurations,
            'location': self.location,
            'windows': self.windows,
            'id': '2',
            'duration': 10,
            'state': self.state,
        }

        good_req_dict = {
            'configurations': self.configurations,
            'location': self.location,
            'windows': self.windows,
            'id': '3',
            'duration': 10,
            'state': self.state,
        }

        cr_dict = {
            'proposal': 'TestProposal',
            'expires': '2014-10-29 12:12:12',
            'name': '',
            'id': '1',
            'is_staff': False,
            'ipp_value': '1.0',
            'operator': 'many',
            'observation_type': 'NORMAL',
            'submitter': '',
            'requests': [bad_req_dict, good_req_dict]
        }

        request_group_model, invalid_requests = self.mb.build_request_group(
            cr_dict)

        assert_equal(1, len(request_group_model.requests))
        assert_equal(1, len(invalid_requests))
        assert_equal(bad_req_dict, invalid_requests[0])
 def test_valid_request_type_does_not_raise_exception(self):
     valid_res_type = 'and'
     request = Request(
         configurations=[self.configuration],
         windows=self.windows,
         request_id=self.id,
     )
     RequestGroup(operator=valid_res_type,
                  requests=[request],
                  name='Group 1',
                  proposal=Proposal(),
                  rg_id=1,
                  is_staff=False,
                  observation_type='NORMAL',
                  ipp_value=1.0,
                  expires=datetime(2999, 1, 1),
                  submitter='')
    def make_request_group(self, requests, operator='single'):
        proposal = Proposal({
            'id': 'TestProposal',
            'tag': 'Test Proposal',
            'pi': '',
            'tac_priority': 10
        })
        rg = RequestGroup(operator=operator,
                          requests=requests,
                          proposal=proposal,
                          submitter='',
                          expires=datetime(2999, 1, 1),
                          rg_id=1,
                          is_staff=False,
                          name='test group id',
                          ipp_value=1.0,
                          observation_type='NORMAL')

        return rg
    def test_drop_empty_children(self):
        r_mock1 = mock.MagicMock()
        r_mock1.has_windows.return_value = True

        r_mock2 = mock.MagicMock()
        r_mock2.has_windows.return_value = False

        rg = RequestGroup(operator='many',
                          requests=[r_mock1, r_mock2],
                          name='Group 1',
                          proposal=Proposal(),
                          rg_id=1,
                          is_staff=False,
                          observation_type='NORMAL',
                          ipp_value=1.0,
                          expires=datetime(2999, 1, 1),
                          submitter='')

        rg.drop_empty_children()

        assert_equal(len(rg.requests), 1)
        assert_equal(rg.requests[0], r_mock1)
    def test_build_request_observation_type_rapid_response(
            self, mock_proposal, mock_semester):
        mock_semester.return_value = {
            'id': '2013A',
            'start': datetime(2013, 1, 1),
            'end': datetime(2014, 1, 1)
        }
        mock_proposal.return_value = Proposal({
            'id': 'TestProposal',
            'pi': '',
            'tag': '',
            'tac_priority': 10
        })
        req_dict = {
            'configurations': self.configurations,
            'location': self.location,
            'windows': self.windows,
            'id': self.id,
            'duration': 10,
            'state': self.state,
        }

        cr_dict = {
            'proposal': 'TestProposal',
            'expires': '2014-10-29 12:12:12',
            'name': '',
            'id': '1',
            'ipp_value': '1.0',
            'operator': 'many',
            'requests': [
                req_dict,
            ],
            'observation_type': 'RAPID_RESPONSE',
        }

        request_group_model, invalid_requests = self.mb.build_request_group(
            cr_dict)
        assert_equal(request_group_model.observation_type, 'RAPID_RESPONSE')
    def test_dont_accept_unsupported_observation_type(self, mock_proposal,
                                                      mock_semester):
        mock_semester.return_value = {
            'id': '2013A',
            'start': datetime(2013, 1, 1),
            'end': datetime(2014, 1, 1)
        }
        mock_proposal.return_value = Proposal({
            'id': 'TestProposal',
            'pi': '',
            'tag': '',
            'tac_priority': 10
        })
        req_dict = {
            'configurations': self.configurations,
            'location': self.location,
            'windows': self.windows,
            'id': self.id,
            'duration': 10.0,
            'state': self.state,
        }

        cr_dict = {
            'proposal': 'TestProposal',
            'expires': '2014-10-29 12:12:12',
            'name': '',
            'id': '1',
            'ipp_value': '1.0',
            'operator': 'many',
            'requests': [
                req_dict,
            ],
            'observation_type': 'ABNORMAL',
        }

        self.mb.build_request_group(cr_dict)
    def _build_request_group(self, base_priority=1.0, ipp_value=1.0):
        operator = 'single'

        proposal = Proposal(id='LCOSchedulerTest',
                            pi='Eric Saunders',
                            tag='admin',
                            tac_priority=base_priority)

        instrument_config = dict(exposure_count=1,
                                 bin_x=2,
                                 bin_y=2,
                                 exposure_time=20,
                                 extra_params={},
                                 optical_elements={'filter': 'BSSL-UX-020'})

        guiding_config = dict(mode='ON',
                              optional=True,
                              optical_elements={},
                              extra_params={},
                              exposure_time=10)

        acquisition_config = dict(mode='OFF', extra_params={})

        constraints = {'max_airmass': None, 'min_lunar_distance': 0.0}

        configuration1 = Configuration(
            dict(id=5,
                 target=None,
                 type='expose',
                 instrument_type='1M0-SCICAM-SBIG',
                 priority=1,
                 instrument_configs=[instrument_config],
                 acquisition_config=acquisition_config,
                 guiding_config=guiding_config,
                 extra_params={},
                 constraints=constraints))

        telescope = dict(
            name='maui',
            latitude=20.7069444444,
            longitude=-156.258055556,
        )
        window_dict = {
            'start': "2013-03-01T00:00:00Z",
            'end': "2013-03-01T00:30:00Z",
        }
        w = Window(window_dict=window_dict, resource=telescope['name'])
        windows = Windows()
        windows.append(w)

        r = Request(configurations=[configuration1],
                    windows=windows,
                    request_id='0000000003',
                    duration=10)

        rg = RequestGroup(operator=operator,
                          requests=[r],
                          proposal=proposal,
                          expires=None,
                          rg_id=4,
                          is_staff=False,
                          ipp_value=ipp_value,
                          observation_type='NORMAL',
                          name=None,
                          submitter='Eric Saunders')

        return rg
Ejemplo n.º 11
0
class TestObservations(object):
    def setup(self):
        # Metadata missing proposal and tag parameters
        self.proposal = Proposal(pi='Eric Saunders')

        self.configdb_interface = ConfigDBInterface(
            configdb_url='',
            telescope_classes=[],
            telescopes_file='test/telescopes.json',
            active_instruments_file='test/active_instruments.json')

        self.valid_proposal = Proposal(
            pi='Eric Saunders',
            id='Scheduler Testing',
            tag='admin',
            tac_priority=2,
        )

        self.valid_target = ICRSTarget(
            name='deneb',
            type='ICRS',
            # ra  = '20 41 25.91',
            # dec = '+45 16 49.22',
            ra=310.35795833333333,
            dec=45.280338888888885,
            rot_mode='SKY',
            rot_angle=0.0,
            acquire_mode='OPTIONAL',
        )

        self.valid_expose_mol = dict(
            type='expose',
            exposure_count=1,
            bin_x=2,
            bin_y=2,
            instrument_name='1m0-SciCam-SINISTRO',
            filter='B',
            exposure_time=30,
            priority=1,
            ag_mode='Optional',
            defocus=0.0,
        )

    def test_proposal_lists_missing_fields(self):
        missing = self.proposal.list_missing_fields()

        assert_equal(missing, ['id', 'tag', 'tac_priority'])

    @raises(ScheduleException)
    @responses.activate
    def test_no_observation_portal_connection_okay(self):
        tels = {'1m0a.doma.elp': [], '1m0a.doma.coj': []}
        start = datetime(2013, 10, 3)
        end = datetime(2013, 11, 3)

        host = os.getenv('OBSERVATION_PORTAL_URL',
                         'http://observation-portal-dev.lco.gtn')
        get_endpoint = host + '/api/observations/'
        responses.add(
            responses.GET,
            get_endpoint,
            json={"error": 'failed to get Observation Portal observations'},
            status=500)

        observation_schedule_interface = ObservationScheduleInterface(
            host=host)
        rr_blocks = observation_schedule_interface._get_rr_observations_by_telescope(
            tels, start, end)
        assert_equal({}, rr_blocks)

    def test_scicam_instrument_resolves_to_a_specific_camera(self):
        instrument_type = '1M0-SCICAM-SINISTRO'
        site, obs, tel = ('lsc', 'doma', '1m0a')
        received = resolve_instrument(instrument_type, site, obs, tel,
                                      self.configdb_interface)
        assert_equal(received, 'fl15')

    @raises(InstrumentResolutionError)
    def test_no_matching_instrument_raises_an_exception(self):
        instrument_type = '1M0-SCICAM-SINISTRO'
        site, obs, tel = ('looloo', 'doma', '1m0a')
        resolve_instrument(instrument_type, site, obs, tel,
                           self.configdb_interface)

    def test_scicam_autoguider_resolves_to_primary_instrument(self):
        self_guide = True
        specific_inst_name = 'fl15'
        site, obs, tel = ('lsc', 'doma', '1m0a')
        received = resolve_autoguider(self_guide, specific_inst_name, site,
                                      obs, tel, self.configdb_interface)
        assert_equal(received, 'fl15')

    def test_no_autoguider_resolves_to_preferred_autoguider(self):
        self_guide = False
        inst_name = 'fl15'
        site, obs, tel = ('lsc', 'doma', '1m0a')
        received = resolve_autoguider(self_guide, inst_name, site, obs, tel,
                                      self.configdb_interface)
        assert_equal(received, 'ef06')

    @raises(InstrumentResolutionError)
    def test_no_matching_autoguider_raises_an_exception(self):
        self_guide = True
        inst_name = 'abcd'
        site, obs, tel = ('looloo', 'doma', '1m0a')
        resolve_autoguider(self_guide, inst_name, site, obs, tel,
                           self.configdb_interface)
    def setup(self):
        self.target = ICRSTarget(
            name='deneb',
            ra=310.35795833333333,
            dec=45.280338888888885,
            epoch=2000,
        )

        self.telescope = dict(name='1m0a.doma.ogg',
                              latitude=20.7069444444,
                              longitude=-156.258055556,
                              tel_class='1m0',
                              horizon=15,
                              status='online',
                              ha_limit_neg=-4.6,
                              ha_limit_pos=4.6,
                              zenith_blind_spot=0.0)
        self.telescopes = {'1m0a.doma.ogg': self.telescope}

        self.proposal = Proposal(id='LCOSchedulerTest',
                                 pi='Eric Saunders',
                                 tag='admin',
                                 tac_priority=1)

        self.instrument_config = dict(exposure_count=1,
                                      bin_x=2,
                                      bin_y=2,
                                      exposure_time=60 * 25,
                                      optical_elements={'filter': 'b'})

        self.guiding_config = dict(mode='ON',
                                   optional=True,
                                   optical_elements={},
                                   exposure_time=10)

        self.acquisition_config = dict(mode='OFF')

        self.constraints = {'max_airmass': None, 'min_lunar_distance': 0}

        self.configuration = Configuration(
            **dict(id=5,
                   target=self.target,
                   type='expose',
                   instrument_type='1M0-SCICAM-SBIG',
                   priority=1,
                   instrument_configs=[self.instrument_config],
                   acquisition_config=self.acquisition_config,
                   guiding_config=self.guiding_config,
                   constraints=self.constraints))

        self.base_time = datetime(2016, 9, 14, 6, 0)

        resource_1 = '1m0a.doma.ogg'
        self.window_1 = Window(
            {
                'start': self.base_time,
                'end': self.base_time + timedelta(hours=0, minutes=30)
            }, resource_1)
        self.windows_1 = Windows()
        self.windows_1.append(self.window_1)

        resource_2 = '1m0a.doma.ogg'
        self.window_2 = Window(
            {
                'start': self.base_time + timedelta(hours=0, minutes=30),
                'end': self.base_time + timedelta(hours=1, minutes=0)
            }, resource_2)
        self.windows_2 = Windows()
        self.windows_2.append(self.window_2)
        self.resource_3 = '1m0a.doma.ogg'
        self.window_3 = Window(
            {
                'start': self.base_time + timedelta(hours=1, minutes=0),
                'end': self.base_time + timedelta(hours=1, minutes=30)
            }, self.resource_3)
        self.windows_3 = Windows()
        self.windows_3.append(self.window_3)

        self.request_1 = Request(configurations=[self.configuration],
                                 windows=self.windows_1,
                                 request_id=1,
                                 duration=1750)

        self.request_2 = Request(configurations=[self.configuration],
                                 windows=self.windows_2,
                                 request_id=2,
                                 duration=1750)

        self.request_3 = Request(configurations=[self.configuration],
                                 windows=self.windows_2,
                                 request_id=3,
                                 duration=1750)

        self.request_4 = Request(configurations=[self.configuration],
                                 windows=self.windows_3,
                                 request_id=4,
                                 duration=1750)

        self.request_5 = Request(configurations=[self.configuration],
                                 windows=self.windows_3,
                                 request_id=5,
                                 duration=1750)

        self.and_request_group_1 = RequestGroup(
            operator='and',
            requests=[self.request_1, self.request_2],
            proposal=self.proposal,
            expires=datetime(2050, 1, 1),
            rg_id=1,
            is_staff=False,
            observation_type='NORMAL',
            ipp_value=1.0,
            name='ur 1',
            submitter='')
        self.and_request_group_2 = RequestGroup(
            operator='and',
            requests=[self.request_3, self.request_4],
            proposal=self.proposal,
            expires=datetime(2050, 1, 1),
            rg_id=2,
            is_staff=False,
            observation_type='NORMAL',
            ipp_value=1.0,
            name='ur 2',
            submitter='')
        self.many_request_group_1 = RequestGroup(
            operator='many',
            requests=[self.request_1, self.request_2],
            proposal=self.proposal,
            expires=datetime(2050, 1, 1),
            rg_id=3,
            is_staff=False,
            observation_type='NORMAL',
            ipp_value=1.5,
            name='ur 3',
            submitter='')
        self.many_request_group_2 = RequestGroup(
            operator='many',
            requests=[self.request_3, self.request_4],
            proposal=self.proposal,
            expires=datetime(2050, 1, 1),
            rg_id=4,
            is_staff=False,
            observation_type='NORMAL',
            ipp_value=1.5,
            name='ur 4',
            submitter='')
        self.rr_request_group_1 = RequestGroup(
            operator='many',
            requests=[self.request_5],
            proposal=self.proposal,
            expires=datetime(2050, 1, 1),
            rg_id=5,
            is_staff=False,
            observation_type='RAPID_RESPONSE',
            ipp_value=1.5,
            name='ur 5',
            submitter='')
        self.rr_request_group_2 = RequestGroup(
            operator='many',
            requests=[self.request_1, self.request_3],
            proposal=self.proposal,
            expires=datetime(2050, 1, 1),
            rg_id=6,
            is_staff=False,
            observation_type='RAPID_RESPONSE',
            ipp_value=1.5,
            name='ur 6',
            submitter='')