Exemplo n.º 1
0
    def test_remove_sensor_component(self):
        inventory = Inventory('inventory_name')
        recorder1 = Recorder(serial='rec1_serial',
                             model='rec1_model',
                             producer='rec1_producer')

        stream1 = RecorderStream(name='stream1_name', label='stream1_label')
        recorder1.add_stream(stream1)
        inventory.add_recorder(recorder1)

        sensor1 = Sensor(serial='sensor1_serial',
                         model='sensor1_model',
                         producer='sensor1_producer')
        component1 = SensorComponent(name='comp1_name')
        sensor1.add_component(component1)
        inventory.add_sensor(sensor1)

        cur_starttime = UTCDateTime('2014-01-01')
        cur_endtime = UTCDateTime('2014-02-01')
        stream1.add_component(serial='sensor1_serial',
                              name='comp1_name',
                              start_time=cur_starttime,
                              end_time=cur_endtime)

        assigned_streams = component1.assigned_streams
        self.assertEqual(len(assigned_streams), 1)
        self.assertIs(assigned_streams[0], stream1)
        removed_component = sensor1.pop_component_by_instance(component1)
        self.assertIsNone(removed_component)
        self.assertIs(assigned_streams[0].components[0].item, component1)
Exemplo n.º 2
0
    def test_add_component_to_stream(self):
        inventory = Inventory('inventory_name')
        recorder1 = Recorder(serial='rec1_serial',
                             model='rec1_model',
                             producer='rec1_producer')

        stream1 = RecorderStream(name='stream1_name', label='stream1_label')
        recorder1.add_stream(stream1)
        inventory.add_recorder(recorder1)

        sensor1 = Sensor(serial='sensor1_serial',
                         model='sensor1_model',
                         producer='sensor1_producer')
        component1 = SensorComponent(name='comp1_name')
        sensor1.add_component(component1)
        inventory.add_sensor(sensor1)

        cur_starttime = UTCDateTime('2014-01-01')
        cur_endtime = UTCDateTime('2014-02-01')
        stream1.add_component(serial='sensor1_serial',
                              name='comp1_name',
                              start_time=cur_starttime,
                              end_time=cur_endtime)

        self.assertEqual(len(stream1.components), 1)
        self.assertEqual(stream1.components[0],
                         TimeBox(component1, cur_starttime, cur_endtime))
Exemplo n.º 3
0
    def test_remove_recorder_stream(self):
        inventory = Inventory('inventory_name')
        recorder1 = Recorder(serial='rec1_serial',
                             model='rec1_model',
                             producer='rec1_producer')

        stream1 = RecorderStream(name='stream1_name', label='stream1_label')
        recorder1.add_stream(stream1)
        inventory.add_recorder(recorder1)

        sensor1 = Sensor(serial='sensor1_serial',
                         model='sensor1_model',
                         producer='sensor1_producer')
        component1 = SensorComponent(name='comp1_name')
        sensor1.add_component(component1)
        inventory.add_sensor(sensor1)

        cur_starttime = UTCDateTime('2014-01-01')
        cur_endtime = UTCDateTime('2014-02-01')
        stream1.add_component(serial='sensor1_serial',
                              name='comp1_name',
                              start_time=cur_starttime,
                              end_time=cur_endtime)

        network1 = Network(name='XX')
        station1 = Station(name='station1_name',
                           location='station1_location',
                           x=10,
                           y=20,
                           z=30)
        channel1 = Channel(name='channel_1')
        channel2 = Channel(name='channel_2')
        station1.add_channel(channel1)
        station1.add_channel(channel2)

        network1.add_station(station1)
        inventory.add_network(network1)

        channel1.add_stream(serial='rec1_serial',
                            model='rec1_model',
                            producer='rec1_producer',
                            name='stream1_name',
                            start_time=None,
                            end_time=None)

        assigned_channels = stream1.assigned_channels
        self.assertEqual(len(assigned_channels), 1)
        self.assertIs(assigned_channels[0], channel1)
        removed_stream = recorder1.pop_stream_by_instance(stream1)
        self.assertIsNone(removed_stream)
        self.assertIs(assigned_channels[0].streams[0].item, stream1)

        # Remove the assignement of the channel to the stream.
        channel1.remove_stream('rec1_serial', 'stream1_name')
        self.assertEqual(len(channel1.streams), 0)
        self.assertEqual(len(stream1.assigned_channels), 0)
Exemplo n.º 4
0
    def process_recorders(self, inventory, recorders):
        ''' Process the extracted recorder nodes.

        Parameters
        ----------
        inventory : :class:`~psysmon.packages.geometry.inventory.Inventory`
            The inventory to which to add the parsed sensors.

        recorders : xml recorder nodes
            The xml recorder nodes parsed using the findall method.

        '''
        self.logger.debug("Processing the recorders.")
        for cur_recorder in recorders:
            content = self.parse_node(cur_recorder)

            if self.check_completeness(cur_recorder, content,
                                       'recorder') is False:
                continue

            if 'stream' in content.keys():
                content.pop('stream')

            # Create the Recorder instance.
            rec_to_add = Recorder(serial=cur_recorder.attrib['serial'],
                                  **content)
            inventory.add_recorder(rec_to_add)

            # Process the streams of the recorder.
            streams = cur_recorder.findall('stream')
            self.process_recorder_streams(rec_to_add, streams)
Exemplo n.º 5
0
    def __init__(self,
                 parent_inventory,
                 serial,
                 type,
                 description,
                 id=None,
                 geom_recorder=None):
        Recorder.__init__(self,
                          id=id,
                          serial=serial,
                          type=type,
                          parent_inventory=parent_inventory)

        if geom_recorder is None:
            # Create a new database recorder instance.
            geom_recorder_orm = self.parent_inventory.project.dbTables[
                'geom_recorder']
            self.geom_recorder = geom_recorder_orm(self.serial, self.type)
        else:
            self.geom_recorder = geom_recorder
Exemplo n.º 6
0
    def test_get_stream_from_recorder(self):
        recorder = Recorder(serial='AAAA',
                            model='test_model',
                            producer='test_producer')

        stream_2_add = RecorderStream(name='stream1_name',
                                      label='stream1_label')
        recorder.add_stream(stream_2_add)

        stream_2_add = RecorderStream(name='stream2_name',
                                      label='stream2_label')

        recorder.add_stream(stream_2_add)

        self.assertEqual(len(recorder.streams), 2)

        cur_stream = recorder.get_stream(name='stream1_name')
        self.assertEqual(len(cur_stream), 1)
        self.assertEqual(cur_stream[0].name, 'stream1_name')
        self.assertEqual(cur_stream[0].label, 'stream1_label')
Exemplo n.º 7
0
    def test_add_stream_to_recorder(self):
        recorder = Recorder(serial='AAAA',
                            model='test_model',
                            producer='test_producer')

        stream1 = RecorderStream(name='stream1_name', label='stream1_label')
        recorder.add_stream(stream1)

        self.assertEqual(len(recorder.streams), 1)
        self.assertIs(recorder.streams[0], stream1)

        stream2 = RecorderStream(name='stream2_name', label='stream2_label')
        recorder.add_stream(stream2)

        self.assertEqual(len(recorder.streams), 2)
        self.assertIs(recorder.streams[1], stream2)

        stream3 = RecorderStream(name='stream3_name', label='stream3_label')
        recorder.add_stream(stream3)

        self.assertEqual(len(recorder.streams), 3)
        self.assertIs(recorder.streams[2], stream3)

        # Remove the streams.
        popped_stream = recorder.pop_stream(name='stream2_name')
        self.assertEqual(len(recorder.streams), 2)
        self.assertIs(popped_stream[0], stream2)

        popped_stream = recorder.pop_stream(name='stream1_name')
        self.assertEqual(len(recorder.streams), 1)
        self.assertIs(popped_stream[0], stream1)

        popped_stream = recorder.pop_stream(label='stream3_label')
        self.assertEqual(len(recorder.streams), 0)
        self.assertIs(popped_stream[0], stream3)