StationsComponent

class lasif.components.stations.StationsComponent(stationxml_folder, seed_folder, resp_folder, cache_folder, communicator, component_name)[source]

Component responsible for dealing with station information in either StationXML, SEED, or RESP formats. The information is always bound to a specific channel and time and never to the whole station despite the name of this component. Always use this component to get the required station related information and do not do it yourself.

StationXML files must adhere to the naming scheme *.xml, SEED files to dataless.*, and RESP files to RESP.*. They must be stored in separate, non-nested folders.

The term channel_id always means the full SEED identifier, e.g. network, station , location, and channel codes.

Parameters:
  • stationxml_folder – The StationXML folder.
  • seed_folder – The dataless SEED folder.
  • resp_folder – The RESP files folder.
  • cache_folder – The folder where the cache file should be stored. The file will be named station_cache.sqlite.
  • communicator – The communicator instance.
  • component_name – The name of this component for the communicator.
file_count

Returns the total number of station files.

force_cache_update()[source]

Update the station cache.

The station cache is used to cache the information on stations so LASIF does not constantly open files which would be very slow. This method is only necessary if you change/add/remove a station file and need it to be reflected immediatly. The next invocation of LASIF will update the cache automatically.

get_all_channels()[source]

Get information about all available channels at all points in time.

Returns a list of dictionaries.

Mainly useful for testing and debugging. For real applications use get_all_channels_at_time() which will return all channels active at a certain point in time.

>>> comm = getfixture('stations_comm')
>>> import pprint
>>> pprint.pprint(sorted(comm.stations.get_all_channels(),
...                      key=lambda x: x["channel_id"], reverse=True))        
[{'channel_id': u'IU.PAB.00.BHE',
  'elevation_in_m': 950.0,
  'end_date': UTCDateTime(2009, 8, 13, 19, 0),
  'filename': u'.../station_files/seed/dataless.IU_PAB',
  'latitude': 39.5446,
  'local_depth_in_m': 0.0,
  'longitude': -4.349899,
  'start_date': UTCDateTime(1999, 2, 18, 10, 0)}, {...}, ...]

Returns a list of dictionaries, each with the following keys:

>>> sorted(comm.stations.get_all_channels()[0].keys())         
['channel_id', 'elevation_in_m', 'end_date', 'filename', 'latitude',
 'local_depth_in_m', 'longitude', 'start_date']

The values for end_date and local_depth_in_m can be None.

get_all_channels_at_time(time)[source]

Returns a dictionary with coordinates for all channels available at a certain point in time.

Parameters:time (int or UTCDateTime) – The time or timestamp at which to return available channels.
Returns:All available coordinates. The keys are the channel ids and the values are dictionaries with the coordinates.
>>> from obspy import UTCDateTime
>>> comm = getfixture('stations_comm')
>>> comm.stations.get_all_channels_at_time(UTCDateTime(2012, 1, 1))         
{u'BW.FURT..EHE': {'latitude': 48.162899, 'elevation_in_m': 565.0,
                   'local_depth_in_m': 0.0, 'longitude': 11.2752},
 ...}

It also works with timestamps.

>>> comm.stations.get_all_channels_at_time(1325376000)         
{u'BW.FURT..EHE': {'latitude': 48.162899, 'elevation_in_m': 565.0,
                   'local_depth_in_m': 0.0, 'longitude': 11.2752},
 ...}

The value for local_depth_in_m can be None.

get_channel_filename(channel_id, time)[source]

Returns the absolute path of the file storing the information for the given channel and time combination.

Parameters:
  • channel_id (str) – The id of the channel.
  • time (int or UTCDateTime) – The time at which to retrieve the information.
>>> import obspy
>>> comm = getfixture('stations_comm')

It works with UTCDateTime objects

>>> comm.stations.get_channel_filename(  
...     "IU.ANMO.10.BHZ", obspy.UTCDateTime(2012, 3, 14))
u'/.../IRIS_single_channel_with_response.xml'

and timestamps.

>>> comm.stations.get_channel_filename(  
...     "IU.ANMO.10.BHZ", 1331683200)
u'/.../IRIS_single_channel_with_response.xml'
get_details_for_filename(filename)[source]

Returns the details for a single file. Each file can have more than channel stored in it. Returns a list of dictionaries.

Parameters:filename (str) – The name of the station file.
>>> comm = getfixture('stations_comm')
>>> filename = sorted(comm.stations.get_all_channels())[1]["filename"]
>>> comm.stations.get_details_for_filename(filename)         
[{'local_depth_in_m': 0.0, 'end_date': None, 'elevation_in_m': 565.0,
  'longitude': 11.2752, 'filename':  u'/.../dataless.BW_FURT',
  'channel_id': u'BW.FURT..EHZ', 'latitude': 48.162899,
  'start_date': UTCDateTime(2001, 1, 1, ...}, ...]

The values for end_date and local_depth_in_m can be None.

get_station_filename(network, station, location, channel, file_format)[source]

Function returning the filename a station file of a certain format should be written to. Only useful as a callback function for downloaders or other modules saving data to LASIF.

Parameters:file_format (str) – ‘datalessSEED’, ‘StationXML’, or ‘RESP’
>>> comm = getfixture('stations_comm')
>>> comm.stations.get_station_filename(
...     "BW", "FURT", "", "BHZ", file_format="RESP")        
'/.../resp/RESP.BW.FURT..BHZ'
>>> comm.stations.get_station_filename(
...     "BW", "ALTM", "", "BHZ", file_format="datalessSEED")        
'/.../seed/dataless.BW_ALTM'
>>> comm.stations.get_station_filename(
...     "BW", "FURT", "", "BHZ", file_format="StationXML")        
'/.../stationxml/BW_FURT.xml'
has_channel(channel_id, time)[source]

Boolean test if information for the given channel and time is available.

Parameters:
  • channel_id (str) – The id of the channel.
  • time (int or UTCDateTime) – The time at which to retrieve the information.
>>> from obspy import UTCDateTime
>>> comm = getfixture('stations_comm')

It works with UTCDateTime objects

>>> comm.stations.has_channel('IU.ANMO.10.BHZ',
...                           UTCDateTime(2012, 3, 14))
True

and timestamps.

>>> comm.stations.has_channel('IU.ANMO.10.BHZ', 1331683200)
True
>>> comm.stations.has_channel('AA.BB.CC.DD', 1331683200)
False
total_file_size

Returns the filesize sum of all station files.