Пример #1
0
 def test_create_resp_from_xseed(self):
     """
     Tests RESP file creation from XML-SEED.
     """
     # 1
     # parse Dataless SEED
     filename = os.path.join(self.path, 'dataless.seed.BW_FURT')
     sp1 = Parser(filename)
     # write XML-SEED
     with NamedTemporaryFile() as fh:
         tempfile = fh.name
         sp1.write_xseed(tempfile)
         # parse XML-SEED
         sp2 = Parser(tempfile)
         # create RESP files
         sp2.get_resp()
     # 2
     # parse Dataless SEED
     filename = os.path.join(self.path, 'arclink_full.seed')
     sp1 = Parser(filename)
     # write XML-SEED
     with NamedTemporaryFile() as fh:
         tempfile = fh.name
         sp1.write_xseed(tempfile)
         # parse XML-SEED
         sp2 = Parser(tempfile)
         # create RESP files
         sp2.get_resp()
Пример #2
0
 def test_create_resp_from_xseed(self):
     """
     Tests RESP file creation from XML-SEED.
     """
     # 1
     # parse Dataless SEED
     filename = os.path.join(self.path, 'dataless.seed.BW_FURT')
     sp1 = Parser(filename)
     # write XML-SEED
     with NamedTemporaryFile() as fh:
         tempfile = fh.name
         sp1.write_xseed(tempfile)
         # parse XML-SEED
         sp2 = Parser(tempfile)
         # create RESP files
         sp2.get_resp()
     # 2
     # parse Dataless SEED
     filename = os.path.join(self.path, 'arclink_full.seed')
     sp1 = Parser(filename)
     # write XML-SEED
     with NamedTemporaryFile() as fh:
         tempfile = fh.name
         sp1.write_xseed(tempfile)
         # parse XML-SEED
         sp2 = Parser(tempfile)
         # create RESP files
         sp2.get_resp()
Пример #3
0
def dataless2xseed(filename, options):
    files = []
    for item in filename:
        files.extend(glob(item))
    outdir = False
    outfile = False
    if options.output:
        if os.path.isdir(options.output):
            outdir = options.output
        elif len(files) > 1:
            msg = 'More than one filename is given.' + os.linesep
            msg += '\t--output argument will not be used.\n'
            sys.stdout.write(msg)
        else:
            outfile = options.output
    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:] != b'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 outdir:
            output = os.path.join(outdir,
                                  os.path.basename(file) + os.extsep + 'xml')
        elif outfile:
            output = outfile
        else:
            output = os.path.basename(file) + os.extsep + 'xml'
        if options.verbose:
            msg = 'Parsing file %s' % file + os.linesep
            sys.stdout.write(msg)
        try:
            parser = Parser(file, debug=options.debug)
            parser.write_xseed(output,
                               version=str(options.version),
                               split_stations=options.split_stations)
        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)
Пример #4
0
 def test_split_stations_dataless_to_xseed(self):
     """
     Test case for writing dataless to XSEED with multiple entries.
     """
     filename = os.path.join(self.path, 'dataless.seed.BW_DHFO')
     parser = Parser()
     parser.read(filename)
     with NamedTemporaryFile() as fh:
         tempfile = fh.name
         # this will create two files due to two entries in dataless
         parser.write_xseed(tempfile, split_stations=True)
         # the second file name is appended with the timestamp of start
         # period
         os.remove(tempfile + '.1301529600.0.xml')
Пример #5
0
def dataless2xseed(filename, options):
    files = []
    for item in filename:
        files.extend(glob(item))
    outdir = False
    outfile = False
    if options.output:
        if os.path.isdir(options.output):
            outdir = options.output
        elif len(files) > 1:
            msg = 'More than one filename is given.' + os.linesep
            msg += '\t--output argument will not be used.\n'
            sys.stdout.write(msg)
        else:
            outfile = options.output
    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:] != b'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 outdir:
            output = os.path.join(outdir,
                                  os.path.basename(file) + os.extsep + 'xml')
        elif outfile:
            output = outfile
        else:
            output = os.path.basename(file) + os.extsep + 'xml'
        if options.verbose:
            msg = 'Parsing file %s' % file + os.linesep
            sys.stdout.write(msg)
        try:
            parser = Parser(file, debug=options.debug)
            parser.write_xseed(output, version=str(options.version),
                               split_stations=options.split_stations)
        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)
Пример #6
0
 def test_split_stations_dataless_to_xseed(self):
     """
     Test case for writing dataless to XSEED with multiple entries.
     """
     filename = os.path.join(self.path, 'dataless.seed.BW_DHFO')
     parser = Parser()
     parser.read(filename)
     with NamedTemporaryFile() as fh:
         tempfile = fh.name
         # this will create two files due to two entries in dataless
         parser.write_xseed(tempfile, split_stations=True)
         # the second file name is appended with the timestamp of start
         # period
         os.remove(tempfile + '.1301529600.0.xml')
Пример #7
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)
Пример #8
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)