Esempio n. 1
0
 def test_compareBlockettes(self):
     """
     Tests the comparison of two blockettes.
     """
     p = Parser()
     b010_1 = "0100042 2.4082008,001~2038,001~2009,001~~~"
     blockette1 = Blockette010(strict=True,
                               compact=True,
                               xseed_version='1.0')
     blockette1.parseSEED(b010_1)
     blockette2 = Blockette010()
     blockette2.parseSEED(b010_1)
     b010_3 = "0100042 2.4082009,001~2038,001~2009,001~~~"
     blockette3 = Blockette010(strict=True, compact=True)
     blockette3.parseSEED(b010_3)
     blockette4 = Blockette010(xseed_version='1.0')
     blockette4.parseSEED(b010_3)
     self.assertTrue(p._compareBlockettes(blockette1, blockette2))
     self.assertFalse(p._compareBlockettes(blockette1, blockette3))
     self.assertFalse(p._compareBlockettes(blockette2, blockette3))
     self.assertTrue(p._compareBlockettes(blockette3, blockette4))
Esempio n. 2
0
 def test_issue361(self):
     """
     Test case for issue #361.
     """
     filename = os.path.join(self.path, 'G.SPB.dataless')
     parser = Parser()
     parser.read(filename)
     # 1 - G.SPB..BHZ - raises UserWarning - no Laplace transform
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("error", UserWarning)
         self.assertRaises(UserWarning, parser.getPAZ, 'G.SPB..BHZ')
     # 2 - G.SPB.00.BHZ - raises exception because of multiple results
     self.assertRaises(SEEDParserException, parser.getPAZ, 'G.SPB.00.BHZ')
     # 3 - G.SPB.00.BHZ with datetime - again no Laplace transform
     dt = UTCDateTime('2007-01-01')
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("error", UserWarning)
         self.assertRaises(UserWarning, parser.getPAZ, 'G.SPB.00.BHZ', dt)
     # 4 - G.SPB.00.BHZ with later datetime works
     dt = UTCDateTime('2012-01-01')
     parser.getPAZ('G.SPB.00.BHZ', dt)
Esempio n. 3
0
 def test_blocketteStartsAfterRecord(self):
     """
     '... 058003504 1.00000E+00 0.00000E+0000 000006S*0543864 ... '
     ' 0543864' -> results in Blockette 005
     """
     # create a valid blockette 010 with record length 256
     b010 = "0100042 2.4082008,001~2038,001~2009,001~~~"
     blockette = Blockette010(strict=True, compact=True)
     blockette.parseSEED(b010)
     self.assertEquals(b010, blockette.getSEED())
     # create a valid blockette 054
     b054 = "0540240A0400300300000009" + ("+1.58748E-03" * 18)
     blockette = Blockette054(strict=True, compact=True)
     blockette.parseSEED(b054)
     self.assertEquals(b054, blockette.getSEED())
     # combine data
     data = "000001V " + b010 + (' ' * 206)
     data += "000002S " + b054 + (' ' * 8)
     data += "000003S*" + b054 + (' ' * 8)
     # read records
     parser = Parser(strict=True)
     parser.read(data)
Esempio n. 4
0
 def test_get_inventory(self):
     """
     Tests the parser's getInventory() method.
     """
     filename = os.path.join(self.path, 'dataless.seed.BW_FURT')
     p = Parser(filename)
     self.assertEqual(
         p.getInventory(),
         {'networks': [{'network_code': 'BW',
          'network_name': 'BayernNetz'}],
          'stations': [{'station_name': 'Furstenfeldbruck, Bavaria, BW-Net',
                       'station_id': 'BW.FURT'}],
          'channels': [
              {'channel_id': 'BW.FURT..EHZ',
               'start_date': UTCDateTime(2001, 1, 1, 0, 0),
               'instrument': 'Lennartz LE-3D/1 seismometer',
               'elevation_in_m': 565.0,
               'latitude': 48.162899,
               'local_depth_in_m': 0.0,
               'longitude': 11.2752,
               'end_date': '', 'sampling_rate': 200.0},
              {'channel_id': 'BW.FURT..EHN',
               'start_date': UTCDateTime(2001, 1, 1, 0, 0),
               'instrument': 'Lennartz LE-3D/1 seismometer',
               'elevation_in_m': 565.0,
               'latitude': 48.162899,
               'local_depth_in_m': 0.0,
               'longitude': 11.2752,
               'end_date': '',
               'sampling_rate': 200.0},
              {'channel_id': 'BW.FURT..EHE',
               'start_date': UTCDateTime(2001, 1, 1, 0, 0),
               'instrument': 'Lennartz LE-3D/1 seismometer',
               'elevation_in_m': 565.0,
               'latitude': 48.162899,
               'local_depth_in_m': 0.0,
               'longitude': 11.2752,
               'end_date': '',
               'sampling_rate': 200.0}]})
Esempio n. 5
0
def dataless2resp(filename, options):
    if isinstance(filename, list):
        files = []
        for item in filename:
            files.extend(glob(item))
    else:
        files = glob(filename)
    if options.verbose:
        msg = 'Found %s files.' % len(files) + os.linesep
        sys.stdout.write(msg)
    for file in files:
        if not os.path.isfile(file):
            continue
        f = open(file, 'rb')
        if f.read(7)[6] != 'V':
            if options.verbose:
                msg = 'Skipping file %s' % file
                msg += '\t-- not a Dataless SEED file' + os.linesep
                sys.stdout.write(msg)
            f.close()
            continue
        f.close()
        if options.verbose:
            msg = 'Parsing file %s' % file + os.linesep
            sys.stdout.write(msg)
        try:
            parser = Parser(file, debug=options.debug)
            if options.zipped:
                folder = os.path.join(os.path.curdir, os.path.basename(file))
                parser.writeRESP(folder=folder, zipped=True)
            else:
                parser.writeRESP(folder=os.path.curdir, zipped=False)
        except Exception as e:
            if options.debug:
                raise
            msg = '\tError parsing file %s' % file + os.linesep
            msg += '\t' + str(e) + os.linesep
            sys.stderr.write(msg)
Esempio n. 6
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.getPAZ("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)
Esempio n. 7
0
 def test_issue157(self):
     """
     Test case for issue #157: re-using parser object.
     """
     expected = {
         'latitude': 48.162899,
         'elevation': 565.0,
         'longitude': 11.2752
     }
     filename1 = os.path.join(self.path, 'dataless.seed.BW_FURT')
     filename2 = os.path.join(self.path, 'dataless.seed.BW_MANZ')
     t = UTCDateTime("2010-07-01")
     parser = Parser()
     parser.read(filename2)
     # parsing a second time will raise a UserWarning: Clearing parser
     # before every subsequent read()
     with warnings.catch_warnings(record=True):
         warnings.simplefilter("error", UserWarning)
         self.assertRaises(UserWarning, parser.read, filename1)
         warnings.simplefilter("ignore", UserWarning)
         parser.read(filename1)
         result = parser.getCoordinates("BW.FURT..EHZ", t)
         self.assertEqual(expected, result)
Esempio n. 8
0
 def test_getPAZ(self):
     """
     Test extracting poles and zeros information
     """
     filename = os.path.join(self.path, 'arclink_full.seed')
     sp = Parser(filename)
     paz = sp.getPAZ('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.getPAZ, 'EHE')
     #
     # Do the same for another dataless file
     #
     filename = os.path.join(self.path, 'dataless.seed.BW_FURT')
     sp = Parser(filename)
     paz = sp.getPAZ('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.getPAZ, '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.getPAZ, 'EHE')
     #
     # And the same for yet another dataless file
     #
     filename = os.path.join(self.path, 'nied.dataless.gz')
     f = StringIO(gzip.open(filename).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.getPAZ(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.getPAZ("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.getPAZ("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()))
     # last test again, check arg name changed in [3722]
     paz = sp.getPAZ(channel_id="BW.RJOB..EHZ",
                     datetime=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()))