def set_channel(self): self.channels = [] self.channels_raw = self.get_channels() p_datalogger = () p_sensor = () for channel in self.channels_raw: temp_channel = Channel(code=channel["code"], location_code=channel["location_code"], latitude=channel["latitude"], longitude=channel["longitude"], elevation=channel["elevation"], depth=channel["depth"], azimuth=channel["azimuth"], dip=channel["dip"], sample_rate=channel["sample_rate"]) temp_list = [] for value in channel["datalogger"].values(): if not value is None: temp_list.append(value) p_datalogger = tuple(temp_list) temp_list.clear() for value in channel["sensor"].values(): if not value is None: temp_list.append(value) p_sensor = tuple(temp_list) temp_channel.response = self.my_nrl.get_response( datalogger_keys=p_datalogger, sensor_keys=p_sensor) self.station.channels.append(temp_channel)
def do_xml(): nrl = NRL('http://ds.iris.edu/NRL/') datalogger_keys = ['REF TEK', 'RT 130 & 130-SMA', '1', '40'] sensor_keys = ['Streckeisen', 'STS-2', '1500', '3 - installed 04/97 to present'] response = nrl.get_response(sensor_keys=sensor_keys, datalogger_keys=datalogger_keys) channel = Channel(code='BHZ', location_code='10', # required latitude=0, # required longitude=0, # required elevation=0.0, # required depth=0., # required ) channel.response = response station = Station(code='ABCD', latitude=0, longitude=0, elevation=0.0, creation_date=UTCDateTime(1970, 1, 1), # required site=Site(name='Fake Site'), # required channels=[channel], ) network = Network(code='XX', stations=[station]) inventory = Inventory(networks=[network], source="demo") inventory.write("Test.xml", format="stationxml", validate=True)
def clone_inv(inv, net_name, sta_name): net = Network( # This is the network code according to the SEED standard. code=net_name, # A list of stations. We'll add one later. stations=[], # description="A test stations.", # Start-and end dates are optional. # start_date=obspy.UTCDateTime(2016, 1, 2)) ) sta = Station( # This is the station code according to the SEED standard. code=sta_name, latitude=inv[0][0].latitude, longitude=inv[0][0].longitude, elevation=inv[0][0].elevation, creation_date=obspy.UTCDateTime(2016, 1, 2), site=Site(name="station with cloned inv")) cha = Channel( # This is the channel code according to the SEED standard. code="HHZ", # This is the location code according to the SEED standard. location_code="", # Note that these coordinates can differ from the station coordinates. start_date=inv[0][0][0].start_date, latitude=inv[0][0][0].latitude, longitude=inv[0][0][0].longitude, elevation=inv[0][0][0].elevation, depth=inv[0][0][0].depth, # azimuth=0.0, # dip=-90.0, sample_rate=inv[0][0][0].sample_rate) # Now tie it all together. cha.response = inv[0][0][0].response #response sta.channels.append(cha) net.stations.append(sta) inv.networks.append(net) return inv
def set_channel(self, p_code="", p_location_code="", p_latitude=0, p_longitude=0, p_elevation=0, p_depth=0, p_azimuth=0, p_dip=0, p_sample_rate=0, p_sensor=None, p_datalogger=None): self.channels_raw = { "code": p_code, "location_code": p_location_code, "latitude": p_latitude, "longitude": p_longitude, "elevation": p_elevation, "depth": p_depth, "azimuth": p_azimuth, "dip": p_dip, "sample_rate": p_sample_rate, "sensor": p_sensor, "datalogger": p_datalogger } temp_channel = Channel( code=self.channels_raw["code"], location_code=self.channels_raw["location_code"], latitude=self.channels_raw["latitude"], longitude=self.channels_raw["longitude"], elevation=self.channels_raw["elevation"], depth=self.channels_raw["depth"], azimuth=self.channels_raw["azimuth"], dip=self.channels_raw["dip"], sample_rate=self.channels_raw["sample_rate"]) temp_channel.response = self.my_nrl.get_response( datalogger_keys=p_datalogger, sensor_keys=p_sensor) self.channels.append(temp_channel)
def stats2inv(stats, resp=None, filexml=None, locs=None): # We'll first create all the various objects. These strongly follow the # hierarchy of StationXML files. inv = Inventory(networks=[], source="japan_from_resp") if locs is None: net = Network( # This is the network code according to the SEED standard. code=stats.network, # A list of stations. We'll add one later. stations=[], description="Marine created from SAC and resp files", # Start-and end dates are optional. start_date=stats.starttime) sta = Station( # This is the station code according to the SEED standard. code=stats.station, latitude=stats.sac["stla"], longitude=stats.sac["stlo"], elevation=stats.sac["stel"], creation_date=stats.starttime, site=Site(name="First station")) cha = Channel( # This is the channel code according to the SEED standard. code=stats.channel, # This is the location code according to the SEED standard. location_code=stats.location, # Note that these coordinates can differ from the station coordinates. latitude=stats.sac["stla"], longitude=stats.sac["stlo"], elevation=stats.sac["stel"], depth=-stats.sac["stel"], azimuth=stats.sac["cmpaz"], dip=stats.sac["cmpinc"], sample_rate=stats.sampling_rate) else: ista = locs[locs['station'] == stats.station].index.values.astype( 'int64')[0] net = Network( # This is the network code according to the SEED standard. code=locs.iloc[ista]["network"], # A list of stations. We'll add one later. stations=[], description="Marine created from SAC and resp files", # Start-and end dates are optional. start_date=stats.starttime) sta = Station( # This is the station code according to the SEED standard. code=locs.iloc[ista]["station"], latitude=locs.iloc[ista]["latitude"], longitude=locs.iloc[ista]["longitude"], elevation=locs.iloc[ista]["elevation"], creation_date=stats.starttime, site=Site(name="First station")) cha = Channel( # This is the channel code according to the SEED standard. code=stats.channel, # This is the location code according to the SEED standard. location_code=stats.location, # Note that these coordinates can differ from the station coordinates. latitude=locs.iloc[ista]["latitude"], longitude=locs.iloc[ista]["longitude"], elevation=locs.iloc[ista]["elevation"], depth=-locs.iloc[ista]["elevation"], azimuth=0, dip=0, sample_rate=stats.sampling_rate) response = obspy.core.inventory.response.Response() if resp is not None: print('i dont have the response') # By default this accesses the NRL online. Offline copies of the NRL can # also be used instead # nrl = NRL() # The contents of the NRL can be explored interactively in a Python prompt, # see API documentation of NRL submodule: # http://docs.obspy.org/packages/obspy.clients.nrl.html # Here we assume that the end point of data logger and sensor are already # known: #response = nrl.get_response( # doctest: +SKIP # sensor_keys=['Streckeisen', 'STS-1', '360 seconds'], # datalogger_keys=['REF TEK', 'RT 130 & 130-SMA', '1', '200']) # Now tie it all together. cha.response = response sta.channels.append(cha) net.stations.append(sta) inv.networks.append(net) # And finally write it to a StationXML file. We also force a validation against # the StationXML schema to ensure it produces a valid StationXML file. # # Note that it is also possible to serialize to any of the other inventory # output formats ObsPy supports. if filexml is not None: inv.write(filexml, format="stationxml", validate=True) return inv
def test_channel_str(self): """ Tests the __str__ method of the channel object. """ c = Channel(code="BHE", location_code="10", latitude=1, longitude=2, elevation=3, depth=4, azimuth=5, dip=6) assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n") # Adding channel types. c.types = ["A", "B"] assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n") # Adding channel types. c.sample_rate = 10.0 assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n") # "Adding" response c.response = True assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tResponse information available" ) # Adding an empty sensor. c.sensor = Equipment(type=None) assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tSensor (Description): None (None)\n" "\tResponse information available" ) # Adding a sensor with only a type. c.sensor = Equipment(type="random") assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tSensor (Description): random (None)\n" "\tResponse information available" ) # Adding a sensor with only a description c.sensor = Equipment(description="some description") assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tSensor (Description): None (some description)\n" "\tResponse information available" ) # Adding a sensor with type and description c.sensor = Equipment(type="random", description="some description") assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tSensor (Description): random (some description)\n" "\tResponse information available" )
def test_channel_str(self): """ Tests the __str__ method of the channel object. """ c = Channel(code="BHE", location_code="10", latitude=1, longitude=2, elevation=3, depth=4, azimuth=5, dip=6) assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n") # Adding channel types. c.types = ["A", "B"] assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n") # Adding channel types. c.sample_rate = 10.0 assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n") # "Adding" response c.response = True assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tResponse information available") # Adding an empty sensor. c.sensor = Equipment(type=None) assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tSensor (Description): None (None)\n" "\tResponse information available") # Adding a sensor with only a type. c.sensor = Equipment(type="random") assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tSensor (Description): random (None)\n" "\tResponse information available") # Adding a sensor with only a description c.sensor = Equipment(description="some description") assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tSensor (Description): None (some description)\n" "\tResponse information available") # Adding a sensor with type and description c.sensor = Equipment(type="random", description="some description") assert str(c) == ( "Channel 'BHE', Location '10' \n" "\tTime range: -- - --\n" "\tLatitude: 1.00, Longitude: 2.00, Elevation: 3.0 m, " "Local Depth: 4.0 m\n" "\tAzimuth: 5.00 degrees from north, clockwise\n" "\tDip: 6.00 degrees down from horizontal\n" "\tChannel types: A, B\n" "\tSampling Rate: 10.00 Hz\n" "\tSensor (Description): random (some description)\n" "\tResponse information available")
def surf_4100_to_inv(location_file, response_inv, plot=False): """ Combine the xyz Homestake locations and MMF calibration responses into an Inventory object for the 4100L """ converter = SURF_converter() sta_df = pd.read_csv(location_file) inv = Inventory() serial_map = {'GMF1': '21010', 'GMF2': '21015', 'GMF3': '21027'} inv.networks = [Network(code='CB')] for _, row in sta_df.iterrows(): print(row) sta_code = row['Sensor name'] # Station location # Convert from SURF coords to lat lon, but keep local for actual use lon, lat, elev = converter.to_lonlat( (row['x_ft'] * 0.3048, row['y_ft'] * 0.3048, row['z_ft'] * 0.3048)) print(lon, lat, elev) # Just leave as zero here and convert HMC feet elevation to m depth = 0.0 # Save HMC coords to custom attributes of Station and Channel extra = AttribDict({ 'hmc_east': { 'value': row['x_ft'], 'namespace': 'smi:local/hmc' }, 'hmc_north': { 'value': row['y_ft'], 'namespace': 'smi:local/hmc' }, 'hmc_elev': { 'value': row['z_ft'] * 0.3048, 'namespace': 'smi:local/hmc' } }) if sta_code.startswith('TS'): # Hydrophone or CASSM, wet well if 'SS' in sta_code: # Cassm (Y for unspecified instrument) chan_code = 'XY1' chans = [ Channel(code=chan_code, location_code='', latitude=lat, longitude=lon, elevation=elev, depth=depth, response=Response()) ] else: # Hydrophone (D), Downhole (H) per SEED manual chan_code = 'XDH' chans = [ Channel(code=chan_code, location_code='', latitude=lat, longitude=lon, elevation=elev, depth=depth, response=Response()) ] elif 'S' in sta_code: # Grouted CASSM chan_code = 'XY1' chans = [ Channel(code=chan_code, location_code='', latitude=lat, longitude=lon, elevation=elev, depth=depth, response=Response()) ] else: # Grouted accelerometer chans = [] try: serial = serial_map[sta_code] except KeyError: serial = '9999' for chan_code in ['XNX', 'XNY', 'XNZ']: # Set samp_rate to 40 kHz so that Nyquist is below max shake f chan = Channel(code=chan_code, location_code='', latitude=lat, longitude=lon, elevation=elev, depth=0., sample_rate=40000., sensor=Equipment( type='IEPE Accelerometer', description='Piezoelectric accelerometer', manufacturer='MMF', model='KS943B.100', serial_number=serial)) # Apply exact response for the three tested sensors, # ...otherwise use the average avg_resp = response_inv.select( station='AVG', channel=chan_code)[0][0][0].response chan.response = avg_resp chans.append(chan) sta = Station(code=sta_code, latitude=chans[0].latitude, longitude=chans[0].longitude, elevation=chans[0].elevation, channels=chans) sta.extra = extra inv[0].stations.append(sta) return inv
def MMF_calibration_to_response(directory, plot=False): """ Take directory of MMF calibration spreadsheets and convert to Obspy inventory object """ inv = Inventory(networks=[Network(code='MMF')]) lat = Latitude(0.) lon = Longitude(0.) chan_map = { 'Tabellenblatt3': 'X', 'Tabellenblatt4': 'Y', 'Tabellenblatt5': 'Z' } calibs = glob('{}/*.xls'.format(directory)) avg_amp = {'XNZ': [], 'XNY': [], 'XNX': []} avg_phase = {'XNZ': [], 'XNY': [], 'XNX': []} avg_sensitivity = {'XNZ': [], 'XNY': [], 'XNX': []} avg_freq = [] for c in calibs: serial = c.split()[-2] sta = Station(code=serial[1:], latitude=lat, longitude=lon, elevation=0.) # Tables slightly shifted for each channel due to comments dict_xyz = pd.read_excel(c, sheet_name=['Tabellenblatt3'], header=14, usecols=list(np.arange(4, 14)), nrows=37) dict_xyz.update( pd.read_excel(c, sheet_name=['Tabellenblatt4'], header=14, usecols=list(np.arange(5, 15)), nrows=37)) dict_xyz.update( pd.read_excel(c, sheet_name=['Tabellenblatt5'], header=13, usecols=list(np.arange(9, 20)), nrows=37)) # Get array of sensitivities at 80 Hz for X, Y, Z sens = pd.read_excel(c, sheet_name=['Tabellenblatt2'], header=84, usecols=[27], nrows=3)['Tabellenblatt2'].values.squeeze() # mV/m/s**2 to V/m/s**2 sens_dict = { 'Tabellenblatt3': float(sens[0].replace(',', '.')) * 1e-3, 'Tabellenblatt4': float(sens[1].replace(',', '.')) * 1e-3, 'Tabellenblatt5': float(sens[2].replace(',', '.')) * 1e-3 } # Resp for each channel for nm, df in dict_xyz.items(): # Dummy channel chan_code = 'XN{}'.format(chan_map[nm]) # Set samp_rate to 40 kHz so that Nyquist is below max shake freq chan = Channel(code=chan_code, location_code='', latitude=lat, longitude=lon, elevation=0., depth=0., sample_rate=40000., sensor=Equipment( type='IEPE Accelerometer', description='Piezoelectric accelerometer', manufacturer='MMF', model='KS943B.100', serial_number=serial)) values = df[['[Hz]', '[m/s²]', '[°]']].values # Add to dict for average channel estimate later avg_amp[chan_code].append(values[:, 1]) avg_phase[chan_code].append(values[:, 2]) avg_sensitivity[chan_code].append(float(sens_dict[nm])) avg_freq = values[:, 0] response_elements = [ ResponseListElement(frequency=values[i][0], amplitude=values[i][1], phase=values[i][2]) for i in range(values.shape[0]) ] # Add a value at zero to avoid deconvolution errors response_elements.insert( 0, ResponseListElement(frequency=0., amplitude=values[0][1], phase=values[0][2])) resp_stage = ResponseListResponseStage( response_list_elements=response_elements, stage_gain=1, stage_gain_frequency=80., input_units='M/S**2', output_units='V', stage_sequence_number=1) sensitivity = InstrumentSensitivity(value=float(sens_dict[nm]), frequency=80., input_units='M/S**2', output_units='V', frequency_range_start=5, frequency_range_end=15850, frequency_range_db_variation=3) response = Response(instrument_sensitivity=sensitivity, response_stages=[resp_stage]) chan.response = response sta.channels.append(chan) # chan.response.plot(min_freq=2.4, sampling_rate=40000.) inv[0].stations.append(sta) # Now make an 'average' channel for the other sensors avg_sta = Station(code='AVG', latitude=lat, longitude=lon, elevation=0.) for c in ['XNX', 'XNY', 'XNZ']: chan = Channel(code=c, location_code='', latitude=lat, longitude=lon, elevation=0., depth=0., sample_rate=40000., sensor=Equipment( type='IEPE Accelerometer', description='Piezoelectric accelerometer', manufacturer='MMF', model='KS943B.100', serial_number='9999')) amp = np.array(avg_amp[c]).mean(axis=0) pha = np.array(avg_phase[c]).mean(axis=0) response_elements = [ ResponseListElement(frequency=avg_freq[i], amplitude=amp[i], phase=pha[i]) for i in range(avg_freq.size) ] # Add a value at zero to avoid deconvolution errors response_elements.insert( 0, ResponseListElement(frequency=0., amplitude=amp[0], phase=pha[0])) resp_stage = ResponseListResponseStage( response_list_elements=response_elements, stage_gain=1, stage_gain_frequency=80., input_units='M/S**2', output_units='V', stage_sequence_number=1) sensitivity = InstrumentSensitivity(value=np.array( avg_sensitivity[c]).mean(), frequency=80., input_units='M/S**2', output_units='V', frequency_range_start=5, frequency_range_end=15850, frequency_range_db_variation=3) response = Response(instrument_sensitivity=sensitivity, response_stages=[resp_stage]) chan.response = response avg_sta.channels.append(chan) inv[0].stations.append(avg_sta) if plot: inv.plot_response(min_freq=2.4, plot_degrees=True) return inv
def create_new_skeleton_inventory_file(path2xmlfile): """ write a NEW skeleton inventory xml file :param path2xmlfile: path to a new xml file. :return: """ # We'll first create all the various objects. These strongly follow the # hierarchy of StationXML files. inv = Inventory( # We'll add networks later. networks=[], # The source should be the id whoever create the file. source="ObsPy-Tutorial") net = Network( # This is the network code according to the SEED standard. code="XX", # A list of stations. We'll add one later. stations=[], description="A test stations.", # Start-and end dates are optional. start_date=obspy.UTCDateTime(2016, 1, 2)) sta = Station( # This is the station code according to the SEED standard. code="ABC", latitude=1.0, longitude=2.0, elevation=345.0, creation_date=obspy.UTCDateTime(2016, 1, 2), site=Site(name="First station")) cha = Channel( # This is the channel code according to the SEED standard. code="HHZ", # This is the location code according to the SEED standard. location_code="", # Note that these coordinates can differ from the station coordinates. latitude=1.0, longitude=2.0, elevation=345.0, depth=10.0, azimuth=0.0, dip=-90.0, sample_rate=200) # By default this accesses the NRL online. Offline copies of the NRL can # also be used instead nrl = NRL() # The contents of the NRL can be explored interactively in a Python prompt, # see API documentation of NRL submodule: # http://docs.obspy.org/packages/obspy.clients.nrl.html # Here we assume that the end point of data logger and sensor are already # known: response = nrl.get_response( # doctest: +SKIP sensor_keys=['Streckeisen', 'STS-1', '360 seconds'], datalogger_keys=['REF TEK', 'RT 130 & 130-SMA', '1', '200']) # Now tie it all together. cha.response = response sta.channels.append(cha) net.stations.append(sta) inv.networks.append(net) # And finally write it to a StationXML file. We also force a validation against # the StationXML schema to ensure it produces a valid StationXML file. # # Note that it is also possible to serialize to any of the other inventory # output formats ObsPy supports. inv.write(path2xmlfile, format="stationxml", validate=True)
# By default this accesses the always up-to-date NRL online. # Offline copies of the NRL can also be used instead. nrl = NRL() # The contents of the NRL can be explored interactively in a Python prompt, # see API documentation of NRL submodule: # http://docs.obspy.org/packages/obspy.clients.nrl.html # Here we assume that the end point of data logger and sensor are already # known: response = nrl.get_response( sensor_keys=['Nanometrics', 'Trillium Compact 120 (Vault, Posthole, OBS)', '1500 V/m/s'], datalogger_keys=['REF TEK', 'RT 130 & 130-SMA', '1', '200']) # Now tie it all together. cha.response = response sta.channels.append(cha) net.stations.append(sta) inv.networks.append(net) # And finally write it to a StationXML file. We also force a validation against # the StationXML schema to ensure it produces a valid StationXML file. # # Note that it is also possible to serialize to any of the other inventory # output formats ObsPy supports. print(inv) print(inv[0][0][0]) inv.write("station.xml", format="stationxml", validate=True) # + cha = inv[0][0][0]
def main(): chans = "EHZ,EHN,EHE" # Get StationXML file print(f"Interactive StaXML builder") print(f"Work in progress...some things hardwired\n\n") inv_name = input(f"Enter StationXML file name: ") if (os.path.isfile(inv_name)): inv = read_inventory(inv_name) else: print(f"Making new inventory: {inv_name}\n") inv = Inventory(networks=[], source="Weston") # Net code ques = f"Enter Network Code ({str(netc)}) :" net_code = str(input(ques) or netc) net = Network(code=net_code, stations=[]) print(f"\n") # connect to NRL nrl = NRL() # Datalogger info ret = 0 digi = f"REF TEK|RT 130S & 130-SMHR|1|200" print(f"Input NRL Digi info ( | separated, careful with spaces)....") print(f"E.g manufacturer| model| gain| sps\n") while ret == 0: ques = f"Enter DIGI info ({digi}) :" digi = str(input(ques) or digi) print(f"\n") try: nrl.get_datalogger_response(digi.split('|')) ret = 1 print("!!!!! DATA LOGGER SUCCESS!!!\n") except Exception as e: print(f"Try again ... {e}") # Sensor info ret = 0 sensor = f"Streckeisen,STS-1,360 seconds" print(f"Input NRL Sensor info ....\n") print(f"E.g Manufact|model|Sensitivy\n") print(f"Guralp|CMG-40T,30s - 100Hz|800") print(f"Sercel/Mark Products|L-22D|5470 Ohms|20000 Ohms") print(f"Streckeisen|STS-1|360 seconds") print(f"Nanometrics|Trillium Compact 120 (Vault, Posthole, OBS)|754 V/m/s") while ret == 0: ques = f"Enter sensor info {str(sensor)} :" sensor = str(input(ques) or sensor) try: nrl.get_sensor_response(sensor.split('|')) ret = 1 inst_info = f"{sensor.split('|')[0]} {sensor.split('|')[1]}" print("Sensor success!!!!") except Exception as e: print(f"Try again ... {e}") print("Getting full response...") try: response = nrl.get_response(sensor_keys=sensor.split('|'), datalogger_keys=digi.split('|')) print("Full response success \n\n") except Exception as e: print(f"Oops .. {e}") # nstas = int( input( "Enter number of stations to add with same sensor/digitizer (default 1):" ) or 1) for i in range(0, nstas): ques = "Station code (" + str(scode) + ") :" sta_code = str(input(ques) or scode) ques = "Station latitude (" + str(geolat) + ") :" sta_lat = float(input(ques) or geolat) ques = "Station longitude (" + str(geolon) + ") :" sta_lon = float(input(ques) or geolat) ques = "Station elev(" + str(geoelev) + ") :" sta_elev = float(input(ques) or geoelev) ques = "Station ondate (" + str(date) + ") :" sta_ondate = str(input(ques) or date) ques = "Station offdate (" + str(date) + ") :" sta_offdate = str(input(ques) or date) ques = "Station long name (" + str(longname) + ") :" sta_sitename = str(input(ques) or longname) sta = Station(code=sta_code, latitude=sta_lat, longitude=sta_lon, elevation=sta_elev, creation_date=UTCDateTime(sta_ondate), site=Site(name=sta_sitename)) # add station to network net.stations.append(sta) # Default chan info coords = { 'latitude': sta_lat, 'longitude': sta_lon, 'elevation': sta_elev, 'depth': 0.0, 'sample_rate': sps } n = -1 ques = f"Enter channel names, comma separated ({chans}) :" chans = str(input(ques) or chans) for j in chans.split(','): n += 1 chantmp = j print("Doing channel ", chantmp) aztmp = azims[n] diptmp = dips[n] loc = locs[n] for k in coords.keys(): ques = str(chantmp) + " enter " + k + "(" + str( coords[k]) + "):" coords[k] = float(input(ques) or coords[k]) chan = Channel(code=chantmp, location_code=loc, latitude=coords['latitude'], longitude=coords['longitude'], elevation=coords['elevation'], depth=coords['depth'], azimuth=aztmp, dip=diptmp, sample_rate=coords['sample_rate'], sensor=Equipment(description=inst_info)) chan.response = response sta.channels.append(chan) inv.networks.append(net) inv.write(inv_name, format="STATIONXML")