def test_readwrite(self): """ Test calculating amplitudes """ fmin = 0.001 inv = read_inventory( str(Path(self.testing_path) / "stations_mayobs.xml"), 'STATIONXML') for net in inv: for sta in net: # print(f'{sta.code=}') ch = sta.select(channel='*[Z3]')[0] info_str = f'{sta.code}.{ch.code}' resp = ch.response # fig = resp.plot(min_freq=fmin, label=info_str, show=False) paz = PAZ.from_obspy_response(resp) # paz.plot(min_freq=fmin, label='PAZ', axes=fig.axes, sym='g.', # show=False) fname = f'{info_str}.json' paz.write_json_pz(fname) paz2 = PAZ.read_json_pz(fname) paz2.input_units = paz.input_units self.assertEqual(paz, paz2) self.assertTextFilesEqual(fname, Path(self.testing_path) / fname) os.remove(fname)
def test_norm_factor(self): """ Test calculating norm_factor """ obja = PAZ(poles=[6.228 + 6.228j, 6.228 - 6.228j], zeros=[0, 0], input_units='m/s', output_units='counts', ref_gain=1500., ref_freq=1.) self.assertAlmostEqual(obja.norm_factor, 2.205, places=3) obja.input_units = 'nm' self.assertAlmostEqual(obja.calc_norm_factor(), 0.3509, places=3)
def test_file_reads(self): """ Test reading response files """ paz = [] paz.append(PAZ.read_baillard_pz(self.data_path / "SPOBS2_response.txt")) paz.append(PAZ.read_json_pz(self.data_path / "SPOBS2_response.json")) paz.append( PAZ.read_gse_response(self.data_path / "SPOBS2_response.GSE")) paz.append(PAZ.read_sac_pz(self.data_path / "SPOBS2_response.SACPZ")) paz[-1].ref_freq = 10. paz.append( PAZ.read_stationxml(str(self.data_path / "1T.MOSE.STATION.xml"), '*3')) for pz in paz[1:]: pz.input_units = 'nm' self.assertEqual(paz[0], pz)
def test_sacpz_readwrite(self): """ Test reading and writing to sac pz file """ in_file = self.data_path / "SPOBS2_response.SACPZ" out_file = Path("SPOBS2_response.SACPZ") paz = PAZ.read_sac_pz(in_file) paz.write_sac_pz(out_file) self.assertTextFilesEqual(in_file, out_file) out_file.unlink()
def test_paz(self): """ Test calculating amplitudes """ obj = PAZ(poles=[6.228 + 6.228j, 6.228 - 6.228j], zeros=[0, 0], input_units='m/s', output_units='counts', ref_gain=1500., ref_freq=1.) obj_nm = PAZ(poles=[6.228 + 6.228j, 6.228 - 6.228j], zeros=[0, 0, 0], input_units='nm', output_units='counts', ref_gain=9.42e-6, ref_freq=1.) self.assertNotEqual(obj, obj_nm) self.assertAlmostEqual(obj.norm_factor, 2.205, places=3) obj.input_units = 'nm' self.assertAlmostEqual(obj.calc_norm_factor(), 0.3509, places=3) self.assertEqual(obj, obj_nm)