Пример #1
0
def read_channel_header(f, npad=4):
    x = f.read(npad)
    if len(x) == 0:
        raise EOF()

    d = f.read(1040)
    f.read(npad)

    sta, cha1, loc1, cha2, ear, loc2, doy, net1, mon, net2, day, hr, min, \
        tflag, secs, rate, nsamples, lat, lon, elevation, gain_flag, \
        sample_bytes, response_flag1, response_flag2 = unpack_fixed(
            'a5,a2,a1,a1,i3,a1,i3,a1,i2,a1,i2,x1,i2,x1,i2,a1,f6,x1,f7,i7,x1,'
            'f8?,x1,f9?,x1,f5?,a1,i1,a1,a1', d[:79])

    gain = 1
    if gain_flag:
        gain = unpack_fixed('f12', d[147:159])

    cha = cha1+cha2
    loc = loc1+loc2
    net = net1+net2
    tmin = calendar.timegm((1900+ear, mon, day, hr, min, secs))
    deltat = 1./rate

    return (net, sta, loc, cha, tmin, tflag, deltat, nsamples, sample_bytes,
            lat, lon, elevation, gain)
Пример #2
0
def read_file_header(f, npad=4):

    header_infos = []

    nlines = 12
    iline = 0
    while iline < nlines:
        f.read(npad)
        d = f.read(80)
        f.read(npad)

        if iline == 0:
            net_name, nchannels, ear, doy, mon, day, hr, min, secs, tlen = unpack_fixed(
                'x1,a29,i3,i3,x1,i3,x1,i2,x1,i2,x1,i2,x1,i2,x1,f6,x1,f9', d)
            year = 1900 + ear
            tmin = calendar.timegm((year, mon, day, hr, min, secs))
            header_infos.append((net_name, nchannels, util.time_to_str(tmin)))

            if nchannels > 24:
                nlines += (nchannels - 25) / 3 + 1

        if iline >= 2:
            for j in range(3):
                s = d[j * 26:(j + 1) * 26]
                if s.strip():
                    sta1, cha1, cha2, sta2, toffset, tlen = unpack_fixed(
                        'x1,a4,a2,x1,a1,a1,f7,x1,f8', s)
                    sta = sta1 + sta2
                    cha = cha1 + cha2
                    header_infos.append((sta, cha, toffset, tlen))

        iline += 1

    return header_infos
Пример #3
0
def read_file_header(f, npad=4):
    
    header_infos = []

    nlines = 12
    iline = 0
    while iline < nlines:
        f.read(npad)
        d = f.read(80)
        f.read(npad)
        
        if iline == 0:
            net_name, nchannels, ear, doy, mon, day, hr, min, secs, tlen = unpack_fixed('x1,a29,i3,i3,x1,i3,x1,i2,x1,i2,x1,i2,x1,i2,x1,f6,x1,f9', d)
            year = 1900 + ear
            tmin = calendar.timegm((year,mon,day,hr,min,secs))
            header_infos.append( (net_name, nchannels, util.time_to_str(tmin)) )

            if nchannels > 30:
                nlines += (nchannels - 31)/3 + 1

        if iline >= 2:
            for j in range(3):
                s = d[j*26:(j+1)*26]
                if s.strip():
                    sta1, cha1, cha2, sta2, toffset, tlen = unpack_fixed('x1,a4,a2,x1,a1,a1,f7,x1,f8', s)
                    sta = sta1 + sta2
                    cha = cha1 + cha2
                    header_infos.append( (sta, cha, toffset, tlen) )
        
        iline += 1

    return header_infos
Пример #4
0
def read_channel_header(f, npad=4):
    x = f.read(npad)
    if len(x) == 0:
        raise EOF()

    d = f.read(1040)
    d = str(d.decode('ascii'))
    f.read(npad)

    sta, cha1, loc1, cha2, ear, loc2, doy, net1, mon, net2, day, hr, min, \
        tflag, secs, rate, nsamples, lat, lon, elevation, gain_flag, \
        sample_bytes, response_flag1, response_flag2 = unpack_fixed(
            'a5,a2,a1,a1,i3,a1,i3,a1,i2,a1,i2,x1,i2,x1,i2,a1,f6,x1,f7,i7,x1,'
            'f8?,x1,f9?,x1,f5?,a1,i1,a1,a1', d[:79])

    gain = 1
    if gain_flag:
        gain = unpack_fixed('f12', d[147:159])

    cha = cha1 + cha2
    loc = loc1 + loc2
    net = net1 + net2
    tmin = calendar.timegm((1900 + ear, mon, day, hr, min, secs))
    deltat = 1. / rate

    return (net, sta, loc, cha, tmin, tflag, deltat, nsamples, sample_bytes,
            lat, lon, elevation, gain)
Пример #5
0
def read_wid1(f):
    line = f.readline()
    if not line.strip():
        raise EOF()

    (wid1, stmin, imilli, nsamples, sta, channel_id, channel_name, sample_rate,
     system_type, data_format, diff_flag) = util.unpack_fixed(
         'a4,x1,a17,x1,i3,x1,i8,x1,a6,x1,a8,x1,a2,x1,f11,x1,a6,x1,a4,x1,i1',
         line[:80])

    if wid1 != 'WID1':
        raise GSE1LoadError('"WID1" marker expected but not found.')

    tmin = util.str_to_time(stmin, format='%Y%j %H %M %S') + 0.001 * imilli

    line = f.readline()
    (gain, units, calib_period, lat, lon, elevation, depth, beam_azimuth,
     beam_slowness, horizontal_orientation) = util.unpack_fixed(
         'f9,i1,f7,x1,f9,x1,f9,x1,f9,x1,f9,x1,f7,x1,f7,x1,f6', line[:80])

    return (tmin, nsamples, sta, channel_id, channel_name, sample_rate,
            system_type, data_format, diff_flag, gain, units, calib_period,
            lat, lon, elevation, depth, beam_azimuth, beam_slowness,
            horizontal_orientation)
Пример #6
0
def read_wid1(f):
    line = f.readline()
    if not line.strip():
        raise EOF()

    (wid1, stmin, imilli, nsamples, sta, channel_id, channel_name, sample_rate,
        system_type, data_format, diff_flag) = util.unpack_fixed(
        'a4,x1,a17,x1,i3,x1,i8,x1,a6,x1,a8,x1,a2,x1,f11,x1,a6,x1,a4,x1,i1',
        line[:80])

    if wid1 != 'WID1':
        raise GSE1LoadError('"WID1" marker expected but not found.')

    tmin = util.str_to_time(stmin, format='%Y%j %H %M %S') + 0.001*imilli

    line = f.readline()
    (gain, units, calib_period, lat, lon, elevation, depth, beam_azimuth,
        beam_slowness, horizontal_orientation) = util.unpack_fixed(
        'f9,i1,f7,x1,f9,x1,f9,x1,f9,x1,f9,x1,f7,x1,f7,x1,f6', line[:80])

    return (tmin, nsamples, sta, channel_id, channel_name, sample_rate,
            system_type, data_format, diff_flag, gain, units, calib_period,
            lat, lon, elevation, depth, beam_azimuth, beam_slowness,
            horizontal_orientation)