Example #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)
Example #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))
Example #3
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)
Example #4
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)
Example #5
0
    def process_recorder_streams(self, recorder, streams):
        ''' Process the stream nodes of a recorder.

        Parameters
        ----------
        recorder : :class:`~psysmon.packages.geometry.inventory.Recorder`
            The recorder to which to add the streams.

        streams : xml stream nodes
            The xml stream nodes parsed using the findall method.

        '''
        for cur_stream in streams:
            content = self.parse_node(cur_stream)

            if self.check_completeness(cur_stream, content, 'stream') is False:
                continue

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

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

            # Create the stream instance.
            stream_to_add = RecorderStream(name=cur_stream.attrib['name'],
                                           **content)
            recorder.add_stream(stream_to_add)

            stream_parameters = cur_stream.findall('stream_parameter')
            self.process_stream_parameters(stream_to_add, stream_parameters)

            assigned_components = cur_stream.findall('assigned_component')
            self.process_assigned_components(stream_to_add,
                                             assigned_components)
Example #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')
Example #7
0
    def test_get_component_from_stream(self):
        stream = RecorderStream(name='stream1_name', label='stream1_label')

        sensor1 = Sensor(serial='sensor1_serial',
                         model='sensor1_model',
                         producer='sensor1_producer')

        sensor2 = Sensor(serial='sensor2_serial',
                         model='sensor2_model',
                         producer='sensor2_producer')

        component1 = SensorComponent(name='comp1_name')
        component2 = SensorComponent(name='comp2_name')

        sensor1.add_component(component1)
        sensor2.add_component(component2)

        start_time1 = UTCDateTime('2014-01-01')
        end_time1 = UTCDateTime('2014-02-01')
        stream.components.append(TimeBox(component1, start_time1, end_time1))

        start_time2 = UTCDateTime('2014-03-01')
        end_time2 = UTCDateTime('2014-04-01')
        stream.components.append(TimeBox(component2, start_time2, end_time2))

        cur_sensor = stream.get_component(start_time=UTCDateTime('2014-01-01'))
        self.assertEqual(len(cur_sensor), 2)
        self.assertEqual(cur_sensor[0],
                         TimeBox(component1, start_time1, end_time1))
        self.assertEqual(cur_sensor[1],
                         TimeBox(component2, start_time2, end_time2))

        cur_sensor = stream.get_component(start_time=UTCDateTime('2014-02-01'))
        self.assertEqual(len(cur_sensor), 1)
        self.assertEqual(cur_sensor[0],
                         TimeBox(component2, start_time2, end_time2))

        cur_sensor = stream.get_component(start_time=UTCDateTime('2014-04-01'))
        self.assertEqual(len(cur_sensor), 0)

        cur_sensor = stream.get_component(end_time=UTCDateTime('2014-03-15'))
        self.assertEqual(len(cur_sensor), 2)
        self.assertEqual(cur_sensor[0],
                         TimeBox(component1, start_time1, end_time1))
        self.assertEqual(cur_sensor[1],
                         TimeBox(component2, start_time2, end_time2))

        cur_sensor = stream.get_component(end_time=UTCDateTime('2014-02-15'))
        self.assertEqual(len(cur_sensor), 1)
        self.assertEqual(cur_sensor[0],
                         TimeBox(component1, start_time1, end_time1))

        cur_sensor = stream.get_component(end_time=UTCDateTime('2014-01-01'))
        self.assertEqual(len(cur_sensor), 0)

        cur_sensor = stream.get_component(start_time=UTCDateTime('2013-12-01'),
                                          end_time=UTCDateTime('2014-05-01'))
        self.assertEqual(len(cur_sensor), 2)
        self.assertEqual(cur_sensor[0],
                         TimeBox(component1, start_time1, end_time1))
        self.assertEqual(cur_sensor[1],
                         TimeBox(component2, start_time2, end_time2))

        cur_sensor = stream.get_component(start_time=UTCDateTime('2013-12-01'),
                                          end_time=UTCDateTime('2014-02-15'))
        self.assertEqual(len(cur_sensor), 1)
        self.assertEqual(cur_sensor[0],
                         TimeBox(component1, start_time1, end_time1))

        cur_sensor = stream.get_component(start_time=UTCDateTime('2014-01-05'),
                                          end_time=UTCDateTime('2014-01-06'))
        self.assertEqual(len(cur_sensor), 1)
        self.assertEqual(cur_sensor[0],
                         TimeBox(component1, start_time1, end_time1))

        cur_sensor = stream.get_component(start_time=UTCDateTime('2014-01-05'),
                                          end_time=UTCDateTime('2014-03-06'))
        self.assertEqual(len(cur_sensor), 2)
        self.assertEqual(cur_sensor[0],
                         TimeBox(component1, start_time1, end_time1))
        self.assertEqual(cur_sensor[1],
                         TimeBox(component2, start_time2, end_time2))

        cur_sensor = stream.get_component(start_time=UTCDateTime('2014-01-05'),
                                          end_time=UTCDateTime('2014-03-06'),
                                          serial='sensor2_serial',
                                          name='comp2_name')
        self.assertEqual(len(cur_sensor), 1)
        self.assertEqual(cur_sensor[0],
                         TimeBox(component2, start_time2, end_time2))