def test_add_component_to_sensor(self): sensor1 = Sensor(serial='sensor1_name', model='sensor1_model', producer='sensor1_producer') component1 = SensorComponent(name='comp1_name', input_unit='m', output_unit='m/s', deliver_unit='V') component2 = SensorComponent(name='comp2_name', input_unit='m', output_unit='m/s', deliver_unit='V') component3 = SensorComponent(name='comp3_name', input_unit='m', output_unit='m/s', deliver_unit='V') sensor1.add_component(component1) sensor1.add_component(component2) sensor1.add_component(component3) self.assertEqual(len(sensor1.components), 3) self.assertTrue(component1 in sensor1.components) self.assertTrue(component2 in sensor1.components) self.assertTrue(component3 in sensor1.components) self.assertIs(component1.parent_sensor, sensor1) self.assertIs(component2.parent_sensor, sensor1) self.assertIs(component3.parent_sensor, sensor1)
def process_components(self, sensor, components): ''' Process the component nodes of a sensor. Parameters ---------- sensor : :class:`~psysmon.packages.geometry.inventory.Sensor` The sensor to which to add the components. components : xml component nodes The xml component nodes parsed using the findall method. ''' for cur_component in components: component_content = self.parse_node(cur_component) if self.check_completeness(cur_component, component_content, 'component') is False: continue if 'component_parameter' in component_content: component_content.pop('component_parameter') component_to_add = SensorComponent( name=cur_component.attrib['name'], **component_content) sensor.add_component(component_to_add) parameters = cur_component.findall('component_parameter') self.process_component_parameters(component_to_add, parameters)
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)
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))
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)
def test_add_parameter_to_component(self): sensor1 = Sensor(serial='sensor1_name', model='sensor1_model', producer='sensor1_producer') component1 = SensorComponent(name='comp1_name') component2 = SensorComponent(name='comp2_name') component3 = SensorComponent(name='comp3_name') cur_start_time = UTCDateTime('2014-01-01') cur_end_time = UTCDateTime('2014-02-01') parameter1 = SensorComponentParameter(sensitivity=1, start_time=cur_start_time, end_time=cur_end_time) component1.add_parameter(parameter1) sensor1.add_component(component1) sensor1.add_component(component2) sensor1.add_component(component3) self.assertEqual(len(sensor1.components), 3) self.assertTrue(component1 in sensor1.components) self.assertTrue(component2 in sensor1.components) self.assertTrue(component3 in sensor1.components) self.assertIs(component1.parent_sensor, sensor1) self.assertIs(component2.parent_sensor, sensor1) self.assertIs(component3.parent_sensor, sensor1) self.assertEqual(len(component1.parameters), 1) self.assertIs(component1.parameters[0], parameter1)
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))