def test_evalresp_with_output_from_seed(self): """ The StationXML file has been converted to SEED with the help of a tool provided by IRIS: https://seiscode.iris.washington.edu/projects/stationxml-converter """ t_samp = 0.05 nfft = 16384 # Test for different output units. units = ["DISP", "VEL", "ACC"] filenames = ["IRIS_single_channel_with_response", "XM.05", "AU.MEEK"] for filename in filenames: xml_filename = os.path.join(self.data_dir, filename + os.path.extsep + "xml") seed_filename = os.path.join(self.data_dir, filename + os.path.extsep + "seed") p = Parser(seed_filename) # older systems don't like an end date in the year 2599 t_ = UTCDateTime(2030, 1, 1) if p.blockettes[50][0].end_effective_date > t_: p.blockettes[50][0].end_effective_date = None if p.blockettes[52][0].end_date > t_: p.blockettes[52][0].end_date = None resp_filename = p.getRESP()[0][-1] inv = read_inventory(xml_filename) network = inv[0].code station = inv[0][0].code location = inv[0][0][0].location_code channel = inv[0][0][0].code date = inv[0][0][0].start_date for unit in units: resp_filename.seek(0, 0) seed_response, seed_freq = evalresp(t_samp, nfft, resp_filename, date=date, station=station, channel=channel, network=network, locid=location, units=unit, freq=True) xml_response, xml_freq = \ inv[0][0][0].response.get_evalresp_response(t_samp, nfft, output=unit) self.assertTrue(np.allclose(seed_freq, xml_freq, rtol=1E-5)) self.assertTrue( np.allclose(seed_response, xml_response, rtol=1E-5))
def test_evalresp_with_output_from_seed(self): """ The StationXML file has been converted to SEED with the help of a tool provided by IRIS: https://seiscode.iris.washington.edu/projects/stationxml-converter """ t_samp = 0.05 nfft = 16384 # Test for different output units. units = ["DISP", "VEL", "ACC"] filenames = ["IRIS_single_channel_with_response", "XM.05", "AU.MEEK"] for filename in filenames: xml_filename = os.path.join(self.data_dir, filename + os.path.extsep + "xml") seed_filename = os.path.join(self.data_dir, filename + os.path.extsep + "seed") p = Parser(seed_filename) # older systems don't like an end date in the year 2599 t_ = UTCDateTime(2030, 1, 1) if p.blockettes[50][0].end_effective_date > t_: p.blockettes[50][0].end_effective_date = None if p.blockettes[52][0].end_date > t_: p.blockettes[52][0].end_date = None resp_filename = p.getRESP()[0][-1] inv = read_inventory(xml_filename) network = inv[0].code station = inv[0][0].code location = inv[0][0][0].location_code channel = inv[0][0][0].code date = inv[0][0][0].start_date for unit in units: resp_filename.seek(0, 0) seed_response, seed_freq = evalresp( t_samp, nfft, resp_filename, date=date, station=station, channel=channel, network=network, locid=location, units=unit, freq=True) xml_response, xml_freq = \ inv[0][0][0].response.get_evalresp_response(t_samp, nfft, output=unit) self.assertTrue(np.allclose(seed_freq, xml_freq, rtol=1E-5)) self.assertTrue(np.allclose(seed_response, xml_response, rtol=1E-5))
def format(request, data, res_name): """ """ channel = str(request.args0.get('channel', '')).upper() try: p = Parser() p.read(data) resp_list = p.getRESP() # Create a ZIP archive. zip_fh = StringIO() if channel == '': zip_file = zipfile.ZipFile(zip_fh, "w") for response in resp_list: response[1].seek(0, 0) zip_file.writestr(response[0], response[1].read()) zip_file.close() zip_fh.seek(0) data = zip_fh.read() res_name += os.extsep + "zip" else: for response in resp_list: if response[0][-3:] != channel: continue response[1].seek(0, 0) data = response[1].read() res_name = response[0] break except: return data if channel == '': # set content type request.setHeader('content-type', 'application/zip') # set file name request.setHeader('Content-Disposition', 'attachment; filename=%s' % res_name) return data
print chan + ": ", unit_known_to_evalresp = True with warnings.catch_warnings(): warnings.simplefilter("ignore") try: p = Parser(seed_file) except: faulty_seed_files.append(seed_file) counter["random_error"] += 1 print_warning("Failed to read SEED file!") continue try: all_resps = p.getRESP() except: counter["random_error"] += 1 print_warning("getRESP() failed. Very likely a faulty SEED file") continue resp_string = "RESP.%s.%s.%s.%s" % (net_id, stat_id, loc_id, chan_id) all_resps = [_i for _i in all_resps if _i[0] == resp_string] if len(all_resps) != 1: msg = "Something fishy going on..." print_error(msg) break filename = all_resps[0][-1] for unit in units:
print chan + ": ", unit_known_to_evalresp = True with warnings.catch_warnings(): warnings.simplefilter("ignore") try: p = Parser(seed_file) except: faulty_seed_files.append(seed_file) counter["random_error"] += 1 print_warning("Failed to read SEED file!") continue try: all_resps = p.getRESP() except: counter["random_error"] += 1 print_warning("getRESP() failed. Very likely a faulty SEED file") continue resp_string = "RESP.%s.%s.%s.%s" % (net_id, stat_id, loc_id, chan_id) all_resps = [_i for _i in all_resps if _i[0] == resp_string] if len(all_resps) != 1: msg = "Something fishy going on..." print_error(msg) break filename = all_resps[0][-1] for unit in units: