Пример #1
0
 def test_issue_358(self):
     """
     Test case for issue #358.
     """
     filename = os.path.join(self.path, 'CL.AIO.dataless')
     parser = Parser()
     parser.read(filename)
     dt = UTCDateTime('2012-01-01')
     parser.get_paz('CL.AIO.00.EHZ', dt)
Пример #2
0
 def test_issue_358(self):
     """
     Test case for issue #358.
     """
     filename = os.path.join(self.path, 'CL.AIO.dataless')
     parser = Parser()
     parser.read(filename)
     dt = UTCDateTime('2012-01-01')
     parser.get_paz('CL.AIO.00.EHZ', dt)
Пример #3
0
    def test_issue165(self):
        """
        Test cases related to #165:
         - number of poles or zeros can be 0
         - an unsupported response information somewhere in the metadata should
           not automatically raise an Error, if the desired information can
           still be retrieved

        This test also tests if a warning is raised if no startime is given.
        """
        parser = Parser()
        file = os.path.join(self.path, "bug165.dataless")
        t = UTCDateTime("2010-01-01T00:00:00")
        # raises UserWarning
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            # Trigger a warning.
            parser.read(file)
            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[-1].category, UserWarning))
            self.assertTrue('date' and 'required' in
                            str(w[-1].message).lower())
            # Triggers a warning.
            paz = parser.get_paz("NZ.DCZ.20.HNZ", t)
            result = {'digitizer_gain': 419430.0, 'gain': 24595700000000.0,
                      'poles': [(-981 + 1009j), (-981 - 1009j),
                                (-3290 + 1263j), (-3290 - 1263j)],
                      'seismometer_gain': 1.01885, 'sensitivity': 427336.0,
                      'zeros': []}
            self.assertEqual(paz, result)
Пример #4
0
 def test_issue165(self):
     """
     Test cases related to #165:
      - number of poles or zeros can be 0
      - an unsupported response information somewhere in the metadata should
        not automatically raise an Error, if the desired information can
        still be retrieved
     """
     parser = Parser(strict=True)
     file = os.path.join(self.path, "bug165.dataless")
     t = UTCDateTime("2010-01-01T00:00:00")
     parser.read(file)
     paz = parser.get_paz("NZ.DCZ.20.HNZ", t)
     result = {
         'digitizer_gain':
         419430.0,
         'gain':
         24595700000000.0,
         'poles': [(-981 + 1009j), (-981 - 1009j), (-3290 + 1263j),
                   (-3290 - 1263j)],
         'seismometer_gain':
         1.01885,
         'sensitivity':
         427336.0,
         'zeros': []
     }
     self.assertEqual(paz, result)
Пример #5
0
def parser_sensor_resp(dir, sName, type):
    par = Parser(dir + '.resp')
    par.write_xseed(dir + '.xml')
    par.write_seed(dir + '.dataless')

    channel = par.blockettes[52][0].channel_identifier
    paz = par.get_paz(channel)
    if (len(paz['zeros']) <= len(paz['poles'])):
        plot_Freq_Amp_Phase(dir + '.freq_amp_phase.png', paz, sName, type)
        (Ymax, Ymin, Tmax, Tmin, Tzero) = plot_Seep_Response(dir + '.impulse.png', paz, sName, type)
        return (paz, Ymax, Ymin, Tmax, Tmin, Tzero)
    else:
        print(
            "sName Error! , zeros number is larger than poles, Can't Calculate Response and Bode Diagram, Check it!!!")
        return (paz, 0, 0, 0, 0, 0)
Пример #6
0
 def test_get_paz_from_xseed(self):
     """
     Get PAZ from XSEED file, testcase for #146
     """
     filename = os.path.join(self.path, 'dataless.seed.BW_FURT')
     sp1 = Parser(filename)
     sp2 = Parser(sp1.get_xseed())
     paz = sp2.get_paz('EHE')
     result = {'gain': 1.00000e+00,
               'zeros': [0j, 0j, 0j],
               'poles': [(-4.44400e+00 + 4.44400e+00j),
                         (-4.44400e+00 - 4.44400e+00j),
                         (-1.08300e+00 + 0.00000e+00j)],
               'sensitivity': 6.71140E+08,
               'seismometer_gain': 4.00000E+02,
               'digitizer_gain': 1677850.0}
     self.assertEqual(sorted(paz.items()), sorted(result.items()))
Пример #7
0
 def test_get_paz_from_xseed(self):
     """
     Get PAZ from XSEED file, testcase for #146
     """
     filename = os.path.join(self.path, 'dataless.seed.BW_FURT')
     sp1 = Parser(filename)
     sp2 = Parser(sp1.get_xseed())
     paz = sp2.get_paz('EHE')
     result = {'gain': 1.00000e+00,
               'zeros': [0j, 0j, 0j],
               'poles': [(-4.44400e+00 + 4.44400e+00j),
                         (-4.44400e+00 - 4.44400e+00j),
                         (-1.08300e+00 + 0.00000e+00j)],
               'sensitivity': 6.71140E+08,
               'seismometer_gain': 4.00000E+02,
               'digitizer_gain': 1677850.0}
     self.assertEqual(sorted(paz.items()), sorted(result.items()))
Пример #8
0
 def test_issue165(self):
     """
     Test cases related to #165:
      - number of poles or zeros can be 0
      - an unsupported response information somewhere in the metadata should
        not automatically raise an Error, if the desired information can
        still be retrieved
     """
     parser = Parser(strict=True)
     file = os.path.join(self.path, "bug165.dataless")
     t = UTCDateTime("2010-01-01T00:00:00")
     parser.read(file)
     paz = parser.get_paz("NZ.DCZ.20.HNZ", t)
     result = {'digitizer_gain': 419430.0, 'gain': 24595700000000.0,
               'poles': [(-981 + 1009j), (-981 - 1009j),
                         (-3290 + 1263j), (-3290 - 1263j)],
               'seismometer_gain': 1.01885, 'sensitivity': 427336.0,
               'zeros': []}
     self.assertEqual(paz, result)
Пример #9
0
def parser_digitizer_resp(dir, sName):
    filename = dir + '.resp'
    par = Parser(filename)
    par.write_xseed(dir + '.xml')
    par.write_seed(dir + '.dataless')

    channel = par.blockettes[52][0].channel_identifier
    sample_rate = par.blockettes[52][0].sample_rate
    paz = par.get_paz(channel)
    sensitivity = paz['digitizer_gain']
    if (sample_rate < 1):
        sample_rate = 1

    inv = read_inventory(filename, "RESP")
    resp = inv[0][0][0].response
    # print(resp)
    response, freqs = resp.get_evalresp_response(1. / (sample_rate * 2.), 65536 * 16, output="VEL")
    plot_Digitizer_Freq_Amp(dir + '.freq_amp.png', sName, sample_rate, sensitivity, response, freqs)
    return (sample_rate, sensitivity)
Пример #10
0
 def test_issue_361(self):
     """
     Test case for issue #361.
     """
     filename = os.path.join(self.path, 'G.SPB.dataless')
     parser = Parser()
     parser.read(filename)
     # 1 - G.SPB..BHZ - no Laplace transform - works
     parser.get_paz('G.SPB..BHZ')
     # 2 - G.SPB.00.BHZ - raises exception because of multiple results
     self.assertRaises(SEEDParserException, parser.get_paz, 'G.SPB.00.BHZ')
     # 3 - G.SPB.00.BHZ with datetime - no Laplace transform - works
     dt = UTCDateTime('2007-01-01')
     parser.get_paz('G.SPB.00.BHZ', dt)
     # 4 - G.SPB.00.BHZ with later datetime works
     dt = UTCDateTime('2012-01-01')
     parser.get_paz('G.SPB.00.BHZ', dt)
Пример #11
0
 def test_issue_361(self):
     """
     Test case for issue #361.
     """
     filename = os.path.join(self.path, 'G.SPB.dataless')
     parser = Parser()
     parser.read(filename)
     # 1 - G.SPB..BHZ - no Laplace transform - works
     parser.get_paz('G.SPB..BHZ')
     # 2 - G.SPB.00.BHZ - raises exception because of multiple results
     self.assertRaises(SEEDParserException, parser.get_paz, 'G.SPB.00.BHZ')
     # 3 - G.SPB.00.BHZ with datetime - no Laplace transform - works
     dt = UTCDateTime('2007-01-01')
     parser.get_paz('G.SPB.00.BHZ', dt)
     # 4 - G.SPB.00.BHZ with later datetime works
     dt = UTCDateTime('2012-01-01')
     parser.get_paz('G.SPB.00.BHZ', dt)
Пример #12
0
    def test_issue165(self):
        """
        Test cases related to #165:
         - number of poles or zeros can be 0
         - an unsupported response information somewhere in the metadata should
           not automatically raise an Error, if the desired information can
           still be retrieved

        This test also tests if a warning is raised if no startime is given.
        """
        parser = Parser()
        file = os.path.join(self.path, "bug165.dataless")
        t = UTCDateTime("2010-01-01T00:00:00")
        # raises UserWarning
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            # Trigger a warning.
            parser.read(file)
            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[-1].category, UserWarning))
            self.assertTrue('date'
                            and 'required' in str(w[-1].message).lower())
            # Triggers a warning.
            paz = parser.get_paz("NZ.DCZ.20.HNZ", t)
            result = {
                'digitizer_gain':
                419430.0,
                'gain':
                24595700000000.0,
                'poles': [(-981 + 1009j), (-981 - 1009j), (-3290 + 1263j),
                          (-3290 - 1263j)],
                'seismometer_gain':
                1.01885,
                'sensitivity':
                427336.0,
                'zeros': []
            }
            self.assertEqual(paz, result)
Пример #13
0
 def test_get_paz(self):
     """
     Test extracting poles and zeros information
     """
     filename = os.path.join(self.path, 'arclink_full.seed')
     sp = Parser(filename)
     paz = sp.get_paz('BHE')
     self.assertEqual(paz['gain'], +6.00770e+07)
     self.assertEqual(paz['zeros'], [0j, 0j])
     self.assertEqual(
         paz['poles'],
         [(-3.70040e-02 + 3.70160e-02j),
          (-3.70040e-02 - 3.70160e-02j), (-2.51330e+02 + 0.00000e+00j),
          (-1.31040e+02 - 4.67290e+02j), (-1.31040e+02 + 4.67290e+02j)])
     self.assertEqual(paz['sensitivity'], +7.86576e+08)
     self.assertEqual(paz['seismometer_gain'], +1.50000E+03)
     # Raise exception for undefined channels
     self.assertRaises(SEEDParserException, sp.get_paz, 'EHE')
     #
     # Do the same for another dataless file
     #
     filename = os.path.join(self.path, 'dataless.seed.BW_FURT')
     sp = Parser(filename)
     paz = sp.get_paz('EHE')
     self.assertEqual(paz['gain'], +1.00000e+00)
     self.assertEqual(paz['zeros'], [0j, 0j, 0j])
     self.assertEqual(paz['poles'], [(-4.44400e+00 + 4.44400e+00j),
                                     (-4.44400e+00 - 4.44400e+00j),
                                     (-1.08300e+00 + 0.00000e+00j)])
     self.assertEqual(paz['sensitivity'], +6.71140E+08)
     self.assertEqual(paz['seismometer_gain'], 4.00000E+02)
     # Raise exception for undefined channels
     self.assertRaises(SEEDParserException, sp.get_paz, 'BHE')
     # Raise UserWarning if not a Laplacian transfer function ('A').
     # Modify transfer_fuction_type on the fly
     for blk in sp.blockettes[53]:
         blk.transfer_function_types = 'X'
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("error", UserWarning)
         self.assertRaises(UserWarning, sp.get_paz, 'EHE')
     #
     # And the same for yet another dataless file
     #
     filename = os.path.join(self.path, 'nied.dataless.gz')
     with gzip.open(filename) as g:
         f = io.BytesIO(g.read())
     sp = Parser(f)
     gain = [+3.94857E+03, +4.87393E+04, +3.94857E+03]
     zeros = [[+0.00000E+00 + 0.00000E+00j, +0.00000E+00 + 0.00000E+00j],
              [+0.00000E+00 + 0.00000E+00j, +0.00000E+00 + 0.00000E+00j,
               -6.32511E+02 + 0.00000E+00j],
              [+0.00000E+00 + 0.00000E+00j, +0.00000E+00 + 0.00000E+00j]]
     poles = [[-1.23413E-02 + 1.23413E-02j, -1.23413E-02 - 1.23413E-02j,
               -3.91757E+01 + 4.91234E+01j, -3.91757E+01 - 4.91234E+01j],
              [-3.58123E-02 - 4.44766E-02j, -3.58123E-02 + 4.44766E-02j,
               -5.13245E+02 + 0.00000E+00j, -6.14791E+04 + 0.00000E+00j],
              [-1.23413E-02 + 1.23413E-02j, -1.23413E-02 - 1.23413E-02j,
               -3.91757E+01 + 4.91234E+01j, -3.91757E+01 - 4.91234E+01j]]
     sensitivity = [+4.92360E+08, +2.20419E+06, +9.84720E+08]
     seismometer_gain = [+2.29145E+03, +1.02583E+01, +2.29145E+03]
     for i, channel in enumerate(['BHZ', 'BLZ', 'LHZ']):
         paz = sp.get_paz(channel)
         self.assertEqual(paz['gain'], gain[i])
         self.assertEqual(paz['zeros'], zeros[i])
         self.assertEqual(paz['poles'], poles[i])
         self.assertEqual(paz['sensitivity'], sensitivity[i])
         self.assertEqual(paz['seismometer_gain'], seismometer_gain[i])
     sp = Parser(os.path.join(self.path, 'dataless.seed.BW_RJOB'))
     paz = sp.get_paz("BW.RJOB..EHZ", UTCDateTime("2007-01-01"))
     result = {'gain': 1.0,
               'poles': [(-4.444 + 4.444j), (-4.444 - 4.444j),
                         (-1.083 + 0j)],
               'seismometer_gain': 400.0,
               'sensitivity': 671140000.0,
               'zeros': [0j, 0j, 0j],
               'digitizer_gain': 1677850.0}
     self.assertEqual(paz, result)
     paz = sp.get_paz("BW.RJOB..EHZ", UTCDateTime("2010-01-01"))
     result = {'gain': 60077000.0,
               'poles': [(-0.037004000000000002 + 0.037016j),
                         (-0.037004000000000002 - 0.037016j),
                         (-251.33000000000001 + 0j),
                         (-131.03999999999999 - 467.29000000000002j),
                         (-131.03999999999999 + 467.29000000000002j)],
               'seismometer_gain': 1500.0,
               'sensitivity': 2516800000.0,
               'zeros': [0j, 0j],
               'digitizer_gain': 1677850.0}
     self.assertEqual(sorted(paz.items()), sorted(result.items()))
     # check arg name changed in [3722]
     result = {'gain': 60077000.0,
               'poles': [(-0.037004000000000002 + 0.037016j),
                         (-0.037004000000000002 - 0.037016j),
                         (-251.33000000000001 + 0j),
                         (-131.03999999999999 - 467.29000000000002j),
                         (-131.03999999999999 + 467.29000000000002j)],
               'seismometer_gain': 1500.0,
               'sensitivity': 2516800000.0,
               'zeros': [0j, 0j],
               'digitizer_gain': 1677850.0}
     paz = sp.get_paz(seed_id="BW.RJOB..EHZ",
                      datetime=UTCDateTime("2010-01-01"))
     self.assertEqual(sorted(paz.items()), sorted(result.items()))
     # test for multiple blockette 53s using II dataless
     sp = Parser(os.path.join(self.path, 'dataless.seed.II_COCO'))
     paz = sp.get_paz("II.COCO.00.BHZ", UTCDateTime("2013-01-01"))
     result = {'gain': 1057.5083723679224,
               'poles': [(-0.004799989149937387 + 0j),
                         (-0.07341022385496342 + 0j),
                         (-21.852101684280665 + 23.497667916231002j),
                         (-21.852101684280665 - 23.497667916231002j)],
               'seismometer_gain': 2164.8,
               'sensitivity': 3598470000.0,
               'zeros': [0j, 0j],
               'digitizer_gain': 1662150.0}
     self.assertEqual(sorted(paz.items()), sorted(result.items()))
Пример #14
0
 def test_get_paz(self):
     """
     Test extracting poles and zeros information
     """
     filename = os.path.join(self.path, 'arclink_full.seed')
     sp = Parser(filename)
     paz = sp.get_paz('BHE')
     self.assertEqual(paz['gain'], +6.00770e+07)
     self.assertEqual(paz['zeros'], [0j, 0j])
     self.assertEqual(paz['poles'], [(-3.70040e-02 + 3.70160e-02j),
                                     (-3.70040e-02 - 3.70160e-02j),
                                     (-2.51330e+02 + 0.00000e+00j),
                                     (-1.31040e+02 - 4.67290e+02j),
                                     (-1.31040e+02 + 4.67290e+02j)])
     self.assertEqual(paz['sensitivity'], +7.86576e+08)
     self.assertEqual(paz['seismometer_gain'], +1.50000E+03)
     # Raise exception for undefined channels
     self.assertRaises(SEEDParserException, sp.get_paz, 'EHE')
     #
     # Do the same for another dataless file
     #
     filename = os.path.join(self.path, 'dataless.seed.BW_FURT')
     sp = Parser(filename)
     paz = sp.get_paz('EHE')
     self.assertEqual(paz['gain'], +1.00000e+00)
     self.assertEqual(paz['zeros'], [0j, 0j, 0j])
     self.assertEqual(paz['poles'], [(-4.44400e+00 + 4.44400e+00j),
                                     (-4.44400e+00 - 4.44400e+00j),
                                     (-1.08300e+00 + 0.00000e+00j)])
     self.assertEqual(paz['sensitivity'], +6.71140E+08)
     self.assertEqual(paz['seismometer_gain'], 4.00000E+02)
     # Raise exception for undefined channels
     self.assertRaises(SEEDParserException, sp.get_paz, 'BHE')
     # Raise UserWarning if not a Laplacian transfer function ('A').
     # Modify transfer_fuction_type on the fly
     for blk in sp.blockettes[53]:
         blk.transfer_function_types = 'X'
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("error", UserWarning)
         self.assertRaises(UserWarning, sp.get_paz, 'EHE')
     #
     # And the same for yet another dataless file
     #
     filename = os.path.join(self.path, 'nied.dataless.gz')
     with gzip.open(filename) as g:
         f = io.BytesIO(g.read())
     sp = Parser(f)
     gain = [+3.94857E+03, +4.87393E+04, +3.94857E+03]
     zeros = [[+0.00000E+00 + 0.00000E+00j, +0.00000E+00 + 0.00000E+00j],
              [
                  +0.00000E+00 + 0.00000E+00j, +0.00000E+00 + 0.00000E+00j,
                  -6.32511E+02 + 0.00000E+00j
              ], [+0.00000E+00 + 0.00000E+00j, +0.00000E+00 + 0.00000E+00j]]
     poles = [[
         -1.23413E-02 + 1.23413E-02j, -1.23413E-02 - 1.23413E-02j,
         -3.91757E+01 + 4.91234E+01j, -3.91757E+01 - 4.91234E+01j
     ],
              [
                  -3.58123E-02 - 4.44766E-02j, -3.58123E-02 + 4.44766E-02j,
                  -5.13245E+02 + 0.00000E+00j, -6.14791E+04 + 0.00000E+00j
              ],
              [
                  -1.23413E-02 + 1.23413E-02j, -1.23413E-02 - 1.23413E-02j,
                  -3.91757E+01 + 4.91234E+01j, -3.91757E+01 - 4.91234E+01j
              ]]
     sensitivity = [+4.92360E+08, +2.20419E+06, +9.84720E+08]
     seismometer_gain = [+2.29145E+03, +1.02583E+01, +2.29145E+03]
     for i, channel in enumerate(['BHZ', 'BLZ', 'LHZ']):
         paz = sp.get_paz(channel)
         self.assertEqual(paz['gain'], gain[i])
         self.assertEqual(paz['zeros'], zeros[i])
         self.assertEqual(paz['poles'], poles[i])
         self.assertEqual(paz['sensitivity'], sensitivity[i])
         self.assertEqual(paz['seismometer_gain'], seismometer_gain[i])
     sp = Parser(os.path.join(self.path, 'dataless.seed.BW_RJOB'))
     paz = sp.get_paz("BW.RJOB..EHZ", UTCDateTime("2007-01-01"))
     result = {
         'gain': 1.0,
         'poles': [(-4.444 + 4.444j), (-4.444 - 4.444j), (-1.083 + 0j)],
         'seismometer_gain': 400.0,
         'sensitivity': 671140000.0,
         'zeros': [0j, 0j, 0j],
         'digitizer_gain': 1677850.0
     }
     self.assertEqual(paz, result)
     paz = sp.get_paz("BW.RJOB..EHZ", UTCDateTime("2010-01-01"))
     result = {
         'gain':
         60077000.0,
         'poles': [(-0.037004000000000002 + 0.037016j),
                   (-0.037004000000000002 - 0.037016j),
                   (-251.33000000000001 + 0j),
                   (-131.03999999999999 - 467.29000000000002j),
                   (-131.03999999999999 + 467.29000000000002j)],
         'seismometer_gain':
         1500.0,
         'sensitivity':
         2516800000.0,
         'zeros': [0j, 0j],
         'digitizer_gain':
         1677850.0
     }
     self.assertEqual(sorted(paz.items()), sorted(result.items()))
     # check arg name changed in [3722]
     result = {
         'gain':
         60077000.0,
         'poles': [(-0.037004000000000002 + 0.037016j),
                   (-0.037004000000000002 - 0.037016j),
                   (-251.33000000000001 + 0j),
                   (-131.03999999999999 - 467.29000000000002j),
                   (-131.03999999999999 + 467.29000000000002j)],
         'seismometer_gain':
         1500.0,
         'sensitivity':
         2516800000.0,
         'zeros': [0j, 0j],
         'digitizer_gain':
         1677850.0
     }
     paz = sp.get_paz(seed_id="BW.RJOB..EHZ",
                      datetime=UTCDateTime("2010-01-01"))
     self.assertEqual(sorted(paz.items()), sorted(result.items()))
     # test for multiple blockette 53s using II dataless
     sp = Parser(os.path.join(self.path, 'dataless.seed.II_COCO'))
     paz = sp.get_paz("II.COCO.00.BHZ", UTCDateTime("2013-01-01"))
     result = {
         'gain':
         1057.5083723679224,
         'poles': [(-0.004799989149937387 + 0j),
                   (-0.07341022385496342 + 0j),
                   (-21.852101684280665 + 23.497667916231002j),
                   (-21.852101684280665 - 23.497667916231002j)],
         'seismometer_gain':
         2164.8,
         'sensitivity':
         3598470000.0,
         'zeros': [0j, 0j],
         'digitizer_gain':
         1662150.0
     }
     self.assertEqual(sorted(paz.items()), sorted(result.items()))