Пример #1
0
    def __init__(self,
                 parent_network,
                 network,
                 name,
                 location,
                 x,
                 y,
                 z,
                 coord_system,
                 description,
                 id=None,
                 geom_station=None):
        Station.__init__(self,
                         network=network,
                         name=name,
                         location=location,
                         x=x,
                         y=y,
                         z=z,
                         coord_system=coord_system,
                         description=description,
                         id=id,
                         parent_network=parent_network)

        if geom_station is None:
            # Create a new database station instance.
            geom_station_orm = self.parent_inventory.project.dbTables[
                'geom_station']
            self.geom_station = geom_station_orm(self.network, self.name,
                                                 self.location, self.x, self.y,
                                                 self.z, self.coord_system,
                                                 self.description)
        else:
            self.geom_station = geom_station
Пример #2
0
    def test_add_network_to_inventory(self):
        inventory = Inventory('inventory_name')

        network1 = Network(name='XX')
        network2 = Network(name='YY')

        station1 = Station(name='station1_name',
                           location='station1_location',
                           x=10,
                           y=20,
                           z=30)

        # The network name should be overwritten when added to the network.
        station2 = Station(name='station2_name',
                           location='station2_location',
                           x=10,
                           y=20,
                           z=30)
        network1.add_station(station1)
        network2.add_station(station2)

        inventory.add_network(network1)
        inventory.add_network(network2)

        self.assertEqual(len(inventory.networks), 2)
        self.assertTrue(network1 in inventory.networks)
        self.assertTrue(network2 in inventory.networks)
        self.assertEqual(station2.network, 'YY')
Пример #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)
Пример #4
0
    def test_handle_station_in_array(self):
        inventory = Inventory('inventory_name')

        # First create a network and add some stations.
        network_1 = Network(name='XX')

        station_1 = Station(name='station_1_name',
                            location='station_1_location',
                            x=10,
                            y=20,
                            z=30)

        station_2 = Station(name='station_2_name',
                            location='station_2_location',
                            x=10,
                            y=20,
                            z=30)

        station_3 = Station(name='station_3_name',
                            location='station_3_location',
                            x=10,
                            y=20,
                            z=30)

        network_1.add_station(station_1)
        network_1.add_station(station_2)
        network_1.add_station(station_3)
        inventory.add_network(network_1)

        # Create two arrays and add them to the inventory.
        array_1 = Array(name='array_1')
        array_2 = Array(name='array_2')

        inventory.add_array(array_1)
        inventory.add_array(array_2)

        # Add some stations to the first array.
        start_time = UTCDateTime('2017-04-29')
        array_1.add_station(station_1, start_time=start_time, end_time=None)
        array_1.add_station(station_2, start_time=start_time, end_time=None)
        array_1.add_station(station_3, start_time=start_time, end_time=None)

        # Test for correct values.
        self.assertEqual(len(array_1.stations), 3)
        self.assertEqual(array_1.stations[0].item, station_1)
        self.assertEqual(array_1.stations[1].item, station_2)
        self.assertEqual(array_1.stations[2].item, station_3)

        # Remove one station.
        array_1.remove_station(name='station_2_name')

        # Test for correct values.
        self.assertEqual(len(array_1.stations), 2)
        self.assertEqual(array_1.stations[0].item, station_1)
        self.assertEqual(array_1.stations[1].item, station_3)
Пример #5
0
    def test_add_channel_to_station(self):
        station = Station(name='station_name',
                          location='station_location',
                          x=10,
                          y=20,
                          z=30)

        channel_2_add = Channel(name='channel_name')

        station.add_channel(channel_2_add)

        self.assertEqual(len(station.channels), 1)
        self.assertEqual(station.channels[0], channel_2_add)
Пример #6
0
    def process_stations(self, network, stations):
        ''' Process the station nodes of a network.

        Parameters
        ----------
        network : :class:`~psysmon.packages.geometry.inventory.Network`
            The network to which to add the stations.

        stations : xml station nodes
            The xml station nodes parsed using the findall method.
        '''
        for cur_station in stations:
            content = self.parse_node(cur_station)

            if self.check_completeness(cur_station, content,
                                       'station') is False:
                continue

            locations = cur_station.findall('location')

            for cur_location in locations:
                loc_content = self.parse_node(cur_location)

                if 'channel' in loc_content.keys():
                    loc_content.pop('channel')

                station_to_add = Station(name=cur_station.attrib['name'],
                                         location=cur_location.attrib['name'],
                                         **loc_content)

                network.add_station(station_to_add)

                channels = cur_location.findall('channel')
                self.process_channels(station_to_add, channels)
Пример #7
0
    def setUp(self):
        # Create the standart test station.
        station = Station(name='GUWA',
                          location='00',
                          x=15.346444,
                          y=47.696306,
                          z=880,
                          coordSystem='epsg:4326',
                          description='Gusswerk',
                          network='XX')

        self.station_loc_00 = DisplayStation(station=station)

        # Create a station with the '--' location.
        station = Station(name='GUWA',
                          location='--',
                          x=15.346444,
                          y=47.696306,
                          z=880,
                          coordSystem='epsg:4326',
                          description='Gusswerk',
                          network='XX')
        self.station_loc_none = DisplayStation(station=station)
Пример #8
0
    def test_station_creation(self):
        ''' Test the creation of a station.
        '''
        station = Station(name='TEST', location='test site', x=10, y=20, z=30)

        self.assertEqual(station.name, 'TEST')
        self.assertEqual(station.location, 'test site')
        self.assertEqual(station.x, 10)
        self.assertEqual(station.y, 20)
        self.assertEqual(station.z, 30)
        self.assertIsNone(station.id)
        self.assertEqual(station.channels, [])
        self.assertEqual(station.parent_inventory, None)
        self.assertFalse(station.has_changed)
Пример #9
0
    def test_add_station_to_inventory(self):
        inventory = Inventory('inventory_name')

        network1 = Network(name='XX')
        network2 = Network(name='YY')

        station1 = Station(name='station1_name',
                           location='station1_location',
                           x=10,
                           y=20,
                           z=30)

        station2 = Station(name='station2_name',
                           location='station2_location',
                           x=10,
                           y=20,
                           z=30)

        station3 = Station(name='station3_name',
                           location='station3_location',
                           x=10,
                           y=20,
                           z=30)

        inventory.add_network(network1)
        inventory.add_network(network2)
        inventory.add_station('XX', station1)
        inventory.add_station('YY', station2)
        inventory.add_station('ZZ', station3)

        self.assertIs(station1.parent_inventory, inventory)
        self.assertIs(station2.parent_inventory, inventory)
        self.assertIsNone(station3.parent_inventory)

        self.assertIs(station1.parent_network, network1)
        self.assertIs(station2.parent_network, network2)
        self.assertIsNone(station3.parent_network)
Пример #10
0
    def test_inventory_get_methods(self):
        inventory = Inventory('inventory_name')

        network1 = Network(name='XX', type='db')
        network2 = Network(name='YY', type='xml')
        network3 = Network(name='ZZ', type='xml')

        station1 = Station(name='station1_name',
                           location='station1_location',
                           x=10,
                           y=20,
                           z=30)

        station2 = Station(name='station2_name',
                           location='station2_location',
                           x=10,
                           y=20,
                           z=30)

        station3 = Station(name='station3_name',
                           location='station3_location',
                           x=10,
                           y=20,
                           z=30)

        station4 = Station(name='station4_name',
                           location='station4_location',
                           x=10,
                           y=20,
                           z=30)

        network1.add_station(station1)
        network2.add_station(station2)
        network2.add_station(station3)
        network3.add_station(station4)

        inventory.add_network(network1)
        inventory.add_network(network2)
        inventory.add_network(network3)

        # Test getting networks.
        cur_net = inventory.get_network()
        self.assertEqual(len(cur_net), 3)
        cur_net = inventory.get_network(name='XX')
        self.assertEqual(cur_net[0], network1)
        cur_net = inventory.get_network(name='YY')
        self.assertEqual(cur_net[0], network2)
        cur_net = inventory.get_network(name='ZZ')
        self.assertEqual(cur_net[0], network3)
        cur_net = inventory.get_network(type='db')
        self.assertEqual(cur_net[0], network1)
        cur_net = inventory.get_network(type='xml')
        self.assertEqual(len(cur_net), 2)
        self.assertTrue(network2 in cur_net)
        self.assertTrue(network3 in cur_net)
        cur_net = inventory.get_network(name='XX', type='db')
        self.assertEqual(cur_net[0], network1)
        cur_net = inventory.get_network(name='YY', type='xml')
        self.assertEqual(cur_net[0], network2)

        # Test getting stations.
        cur_stat = inventory.get_station()
        self.assertEqual(len(cur_stat), 4)