def dump_responses(self, path): from pyrocko.io import stationxml logger.debug('Writing out StationXML...') path_responses = op.join(path, 'meta') util.ensuredir(path_responses) fn_stationxml = op.join(path_responses, 'stations.xml') stations = self.station_generator.get_stations() sxml = stationxml.FDSNStationXML.from_pyrocko_stations(stations) sunit = { 'displacement': 'M', 'velocity': 'M/S', 'acceleration': 'M/S**2', 'counts': 'COUNTS' }[self.seismogram_quantity] response = stationxml.Response( instrument_sensitivity=stationxml.Sensitivity( value=1., frequency=1., input_units=stationxml.Units(sunit), output_units=stationxml.Units('COUNTS')), stage_list=[]) for net, station, channel in sxml.iter_network_station_channels(): channel.response = response sxml.dump_xml(filename=fn_stationxml) return [path_responses]
def iload_fh(f): '''Read RESP information from open file handle.''' for sc, cc, rcs in parse3(f): nslc = (pcode(get1(sc, b'16')), pcode(get1(sc, b'03')), ploc(get1(cc, b'03', b'')), pcode(get1(cc, b'04'))) try: tmin = pdate(get1(cc, b'22')) tmax = pdate(get1(cc, b'23')) except util.TimeStrError as e: raise RespError('invalid date in RESP information. (%s)' % str(e)) stage_elements = {} istage = -1 for block, content in rcs: if block not in bdefs: raise RespError('unknown block type found: %s' % block) istage_temp, x = bdefs[block]['parse'](content) if istage_temp != -1: istage = istage_temp if x is None: continue x.validate() if istage not in stage_elements: stage_elements[istage] = [] stage_elements[istage].append(x) istages = sorted(stage_elements.keys()) stages = [] totalgain = None for istage in istages: elements = stage_elements[istage] if istage == 0: totalgain = gett1(elements, sxml.Gain) else: stage = sxml.ResponseStage( number=istage, poles_zeros_list=gett(elements, sxml.PolesZeros), coefficients_list=gett(elements, sxml.Coefficients), fir=gett1o(elements, sxml.FIR), decimation=gett1o(elements, sxml.Decimation), stage_gain=gett1o(elements, sxml.Gain)) stages.append(stage) if stages: resp = sxml.Response(stage_list=stages) if totalgain: totalgain_value = totalgain.value totalgain_frequency = totalgain.frequency else: totalgain_value = 1. gain_frequencies = [] for stage in stages: totalgain_value *= stage.stage_gain.value gain_frequencies.append(stage.stage_gain.frequency) totalgain_frequency = gain_frequencies[0] if not all(f == totalgain_frequency for f in gain_frequencies): logger.warn( 'no total gain reported and inconsistent gain ' 'frequency values found in resp file for %s.%s.%s.%s: ' 'omitting total gain and frequency from created ' 'instrument sensitivity object' % nslc) totalgain_value = None totalgain_frequency = None resp.instrument_sensitivity = sxml.Sensitivity( value=totalgain_value, frequency=totalgain_frequency, input_units=stages[0].input_units, output_units=stages[-1].output_units) yield ChannelResponse(codes=nslc, start_date=tmin, end_date=tmax, response=resp) else: raise RespError('incomplete response information')
from pyrocko.io import stationxml as fdsn from pyrocko import model from pyrocko.example import get_example_data get_example_data('stations.txt') stations = model.load_stations('stations.txt') station_xml = fdsn.FDSNStationXML.from_pyrocko_stations(stations) for network in station_xml.network_list: for station in network.station_list: for channel in station.channel_list: channel.response = fdsn.Response( instrument_sensitivity=fdsn.Sensitivity( value=1.0, frequency=1.0, input_units=fdsn.Units('M'), output_units=fdsn.Units('COUNTS'))) station_xml.validate() # print(station_xml.dump_xml()) station_xml.dump_xml(filename='stations_flat_displacement.xml')