InventoryDBComponent

class lasif.components.inventory_db.InventoryDBComponent(db_file, communicator, component_name)[source]

Component dealing with station coordinates from web services or manual entry. This is used if station coordinates could not be retrieved by other means. The component will attempt to request the station coordinates from IRIS and ORFEUS. Each station will only be requested once and the result will be stored in the database instance.

Parameters:
  • db_file – The full path of the inventory SQLITE file.
  • communicator – The communicator instance.
  • component_name – The name of this component for the communicator.
get_all_coordinates()[source]

Returns a dictionary with all stations coordinates defined in the inventory database. All entries will be None if a webservice request has been attempted but returned nothing. This is to prevent successive requests.

>>> comm = getfixture('inventory_db_comm')
>>> comm.inventory_db.get_all_coordinates()         
{u'AA.BB': {'latitude': 1.0, 'elevation_in_m': 3.0,
            'local_depth_in_m': 4.0, 'longitude': 2.0},
 u'CC.DD': {'latitude': 2.0, 'elevation_in_m': 2.0,
            'local_depth_in_m': 2.0, 'longitude': 2.0},
 u'EE.FF': {'latitude': None, 'elevation_in_m': None,
            'local_depth_in_m': None, 'longitude': None}}
get_coordinates(station_id)[source]

Returns a dictionary containing latitude, longitude, elevation_in_m, and local_depth_in_m keys. If the station is not yet in the database, it will attempt to download the coordinates from the web services.

>>> comm = getfixture('inventory_db_comm')
>>> comm.inventory_db.get_coordinates("AA.BB")         
{'latitude': 1.0, 'elevation_in_m': 3.0, 'local_depth_in_m': 4.0,
 'longitude': 2.0}

A station whose coordinates have already been requested but whose request failed will have None for all coordinate values.

>>> comm.inventory_db.get_coordinates("EE.FF")         
{'latitude': None, 'elevation_in_m': None, 'local_depth_in_m': None,
 'longitude': None}
remove_coordinate_less_stations()[source]

Simple command removing all stations that have no associated coordinates. This means it will attempt to download them again on the next run.

>>> comm = getfixture('inventory_db_comm')
>>> comm.inventory_db.get_all_coordinates()         
{u'AA.BB': {'latitude': 1.0, 'elevation_in_m': 3.0,
            'local_depth_in_m': 4.0, 'longitude': 2.0},
 u'CC.DD': {'latitude': 2.0, 'elevation_in_m': 2.0,
            'local_depth_in_m': 2.0, 'longitude': 2.0},
 u'EE.FF': {'latitude': None, 'elevation_in_m': None,
            'local_depth_in_m': None, 'longitude': None}}
>>> comm.inventory_db.remove_coordinate_less_stations()
>>> comm.inventory_db.get_all_coordinates()         
{u'AA.BB': {'latitude': 1.0, 'elevation_in_m': 3.0,
            'local_depth_in_m': 4.0, 'longitude': 2.0},
 u'CC.DD': {'latitude': 2.0, 'elevation_in_m': 2.0,
            'local_depth_in_m': 2.0, 'longitude': 2.0}}
save_station_coordinates(station_id, latitude, longitude, elevation_in_m, local_depth_in_m)[source]

Saves the coordinates for some station in the database.

Used internally but can also be used to save coordinates from other sources in the project.

>>> comm = getfixture('inventory_db_comm')
>>> comm.inventory_db.save_station_coordinates(station_id="XX.YY",
... latitude=10.0, longitude=11.0, elevation_in_m=12.0,
... local_depth_in_m=13.0)
>>> comm.inventory_db.get_coordinates("XX.YY")         
{'latitude': 10.0, 'elevation_in_m': 12.0, 'local_depth_in_m': 13.0,
'longitude': 11.0}

Inserting once again will update the entry.

>>> comm.inventory_db.save_station_coordinates(station_id="XX.YY",
... latitude=20.0, longitude=21.0, elevation_in_m=22.0,
... local_depth_in_m=23.0)
>>> comm.inventory_db.get_coordinates("XX.YY")         
{'latitude': 20.0, 'elevation_in_m': 22.0, 'local_depth_in_m': 23.0,
 'longitude': 21.0}