def get_hash(self): e = self return util.base36encode( abs( hash((util.time_to_str(e.time), str(e.lat), str(e.lon), str(e.depth), str(e.magnitude), e.catalog, e.name, e.region)))).lower()
def get_traces_pyrocko(self, x, z): fns = self.dump_traces(x, z, format='mseed') traces = [] for igm, fn in enumerate(fns): ig = igm + 1 if fn: for tr in io.load(fn): ix = 1 + int(round((x - self.firstx) / self.dx)) iz = 1 + int(round((z - self.firstz) / self.dz)) gridx = self.firstx + (ix - 1) * self.dx gridz = self.firstz + (iz - 1) * self.dz sx = util.base36encode(ix) sz = util.base36encode(iz) tr.meta = {'x': gridx, 'z': gridz, 'ig': ig} tr.set_codes(network=sz, station=sx, channel='%i' % ig) traces.append(tr) return traces
def get_traces_pyrocko(self, x,z): fns = self.dump_traces(x,z, format='mseed') traces = [] for igm, fn in enumerate(fns): ig = igm+1 if fn: for tr in io.load(fn): ix = 1 + int(round((x-self.firstx)/self.dx)) iz = 1 + int(round((z-self.firstz)/self.dz)) gridx = self.firstx + (ix-1)*self.dx gridz = self.firstz + (iz-1)*self.dz sx = util.base36encode(ix) sz = util.base36encode(iz) tr.meta = {'x':gridx, 'z':gridz, 'ig':ig} tr.set_codes(network=sz, station=sx, channel='%i' % ig) traces.append(tr) return traces
def get_hash(self): e = self return util.base36encode(abs(hash((util.time_to_str(e.time), str(e.lat), str(e.lon), str(e.depth), str(e.magnitude), e.catalog, e.name, e.region)))).lower()
def read_header(f, endianness='>'): e = endianness data = read(f, 16, eof_ok=True) isystem_id, istream_id = struct.unpack(e+'II', data[:8]) ex = isystem_id & 0x80000000 if ex: ex2 = isystem_id & (1 << 30) if ex2: system_id = util.base36encode(isystem_id & (2**21 - 1)) else: system_id = util.base36encode(isystem_id & (2**26 - 1)) instrument_type = (isystem_id >> 26) & 0b1 gain = [None, 1, 2, 4, 8, 16, 32, 64][(isystem_id >> 27) & 0b111] else: system_id = util.base36encode(isystem_id) instrument_type = None gain = None stream_id = util.base36encode(istream_id) i_day_second = struct.unpack(e+'I', data[8:12])[0] iday = i_day_second >> 17 isecond = i_day_second & 0x1ffff time = (iday*24*60*60) + guralp_zero + isecond ittl, israte, compression, nrecords = struct.unpack(e+'BBBB', data[12:]) if nrecords > 250: raise FileLoadError('Header indicates too many records in block.') if israte == 0: if compression == 4 and stream_id[-2:] == '00': block_type = 'status_block' elif compression == 4 and stream_id[-2:] == '01': block_type = 'unified_status_block' elif compression == 4 and stream_id[-2:] == 'SM': block_type = 'strong_motion_block' elif stream_id[-2:] == 'CD': block_type = 'cd_status_block' elif compression == 4 and stream_id[-2:] == 'BP': block_type = 'byte_pipe_block' elif stream_id[-2:] == 'IB': block_type = 'information_block' else: raise FileLoadError('Unexpected block type found.') return Header(block_type, system_id, stream_id, instrument_type, time, gain, ittl, 0.0, compression, nrecords) else: block_type = 'data_block' if not re.match(r'^([ZNEXC][0-9A-CG-S]|M[0-9A-F])$', stream_id[-2:]): raise FileLoadError('Unexpected data stream ID') sample_rate_tab = { 157: (0.1, None), 161: (0.125, None), 162: (0.2, None), 164: (0.25, None), 167: (0.5, None), 171: (400., 8), 174: (500., 2), 176: (1000., 4), 179: (2000., 8), 181: (4000., 16)} if israte in sample_rate_tab: sample_rate, tfod = sample_rate_tab[israte] else: sample_rate = float(israte) tfod = None if tfod is not None: toff = (compression >> 4) / tfod compression = compression & 0b1111 time += toff if compression not in (1, 2, 4): raise GCFLoadError( 'Unsupported compression code: %i' % compression) return Header(block_type, system_id, stream_id, instrument_type, time, gain, ittl, sample_rate, compression, nrecords)
def read_header(f, endianness='>'): e = endianness data = read(f, 16, eof_ok=True) isystem_id, istream_id = struct.unpack(e + 'II', data[:8]) ex = isystem_id & 0x80000000 if ex: ex2 = isystem_id & (1 << 30) if ex2: system_id = util.base36encode(isystem_id & (2**21 - 1)) else: system_id = util.base36encode(isystem_id & (2**26 - 1)) instrument_type = (isystem_id >> 26) & 0b1 gain = [None, 1, 2, 4, 8, 16, 32, 64][(isystem_id >> 27) & 0b111] else: system_id = util.base36encode(isystem_id) instrument_type = None gain = None stream_id = util.base36encode(istream_id) i_day_second = struct.unpack(e + 'I', data[8:12])[0] iday = i_day_second >> 17 isecond = i_day_second & 0x1ffff time = (iday * 24 * 60 * 60) + guralp_zero + isecond ittl, israte, compression, nrecords = struct.unpack(e + 'BBBB', data[12:]) if nrecords > 250: raise FileLoadError('Header indicates too many records in block.') if israte == 0: if compression == 4 and stream_id[-2:] == '00': block_type = 'status_block' elif compression == 4 and stream_id[-2:] == '01': block_type = 'unified_status_block' elif compression == 4 and stream_id[-2:] == 'SM': block_type = 'strong_motion_block' elif stream_id[-2:] == 'CD': block_type = 'cd_status_block' elif compression == 4 and stream_id[-2:] == 'BP': block_type = 'byte_pipe_block' elif stream_id[-2:] == 'IB': block_type = 'information_block' else: raise FileLoadError('Unexpected block type found.') return Header(block_type, system_id, stream_id, instrument_type, time, gain, ittl, 0.0, compression, nrecords) else: block_type = 'data_block' if not re.match(r'^([ZNEXC][0-9A-CG-S]|M[0-9A-F])$', stream_id[-2:]): raise FileLoadError('Unexpected data stream ID') sample_rate_tab = { 157: (0.1, None), 161: (0.125, None), 162: (0.2, None), 164: (0.25, None), 167: (0.5, None), 171: (400., 8), 174: (500., 2), 176: (1000., 4), 179: (2000., 8), 181: (4000., 16) } if israte in sample_rate_tab: sample_rate, tfod = sample_rate_tab[israte] else: sample_rate = float(israte) tfod = None if tfod is not None: toff = (compression >> 4) / tfod compression = compression & 0b1111 time += toff if compression not in (1, 2, 4): raise GCFLoadError('Unsupported compression code: %i' % compression) return Header(block_type, system_id, stream_id, instrument_type, time, gain, ittl, sample_rate, compression, nrecords)