def load_kps_event_list(filename): elist = [] f = open(filename, 'r') for line in f: toks = line.split() if len(toks) < 7: continue tim = util.ctimegm(toks[0] + ' ' + toks[1]) lat, lon, depth, magnitude = [float(x) for x in toks[2:6]] duration = float(toks[10]) region = toks[-1] name = util.gmctime_fn(tim) e = Event(lat, lon, tim, name=name, depth=depth, magnitude=magnitude, duration=duration, region=region) elist.append(e) f.close() return elist
def loadf(self, file): d = {} try: for line in file: if line.lstrip().startswith('#'): continue toks = line.split(' = ', 1) if len(toks) == 2: k, v = toks[0].strip(), toks[1].strip() if k in ('name', 'region', 'catalog'): d[k] = v if k in ( 'latitude longitude magnitude depth duration mnn mee mdd mne mnd med strike1 dip1 rake1 strike2 dip2 rake2 duration' .split()): d[k] = float(v) if k == 'time': d[k] = util.ctimegm(v[:19]) if line.startswith('---'): d['have_separator'] = True break except Exception, e: raise FileParseError(e)
def loadf(self, file): d = {} try: for line in file: if line.lstrip().startswith("#"): continue toks = line.split(" = ", 1) if len(toks) == 2: k, v = toks[0].strip(), toks[1].strip() if k in ("name", "region", "catalog"): d[k] = v if k in ( "latitude longitude magnitude depth duration mnn mee mdd mne mnd med strike1 dip1 rake1 strike2 dip2 rake2 duration".split() ): d[k] = float(v) if k == "time": d[k] = util.ctimegm(v[:19]) if line.startswith("---"): d["have_separator"] = True break except Exception, e: raise FileParseError(e)
def read(self, filename, get_data=True): '''Read SAC file. filename -- Name of KAN file. get_data -- If True, the data is read, otherwise only read headers. ''' nbh = KanFile.nbytes_header # read in all data f = open(filename, 'rb') if get_data: filedata = f.read() else: filedata = f.read(nbh) f.close() if len(filedata) < nbh: raise KanError('File too short to be a KAN file.') header_records = int(filedata[0:8]) npts = int(filedata[8:20]) leven = int(filedata[20:28]) datatype = int(filedata[28:36]) rate = float(filedata[36:50]) offset = float(filedata[50:64]) byte_sex = ('little', 'big')[int(filedata[382:390])] assert header_records == 1 assert leven == 1 assert datatype == 2 assert offset == 0.0 date = filedata[393:405].strip() tim = filedata[405:415].strip() microseconds = int(filedata[415:423]) ref_time = util.ctimegm('%s %s' % (date, tim)) + microseconds / 1.0e6 stationname = os.path.basename(filename).replace('.kan', '').replace( '.KAN', '') self.npts = npts self.delta = 1.0 / rate self.kstnm = stationname self.ref_time = ref_time if get_data: if byte_sex == 'little': dtype = '<i4' else: dtype = '>i4' self.data = num.fromstring(filedata[nbh:], dtype=dtype) assert self.data.size == self.npts else: self.data = None
def read(self, filename, get_data=True): """Read SAC file. filename -- Name of KAN file. get_data -- If True, the data is read, otherwise only read headers. """ nbh = KanFile.nbytes_header # read in all data f = open(filename, "rb") if get_data: filedata = f.read() else: filedata = f.read(nbh) f.close() if len(filedata) < nbh: raise KanError("File too short to be a KAN file.") header_records = int(filedata[0:8]) npts = int(filedata[8:20]) leven = int(filedata[20:28]) datatype = int(filedata[28:36]) rate = float(filedata[36:50]) offset = float(filedata[50:64]) byte_sex = ("little", "big")[int(filedata[382:390])] assert header_records == 1 assert leven == 1 assert datatype == 2 assert offset == 0.0 date = filedata[393:405].strip() tim = filedata[405:415].strip() microseconds = int(filedata[415:423]) ref_time = util.ctimegm("%s %s" % (date, tim)) + microseconds / 1.0e6 stationname = os.path.basename(filename).replace(".kan", "").replace(".KAN", "") self.npts = npts self.delta = 1.0 / rate self.kstnm = stationname self.ref_time = ref_time if get_data: if byte_sex == "little": dtype = "<i4" else: dtype = ">i4" self.data = num.fromstring(filedata[nbh:], dtype=dtype) assert self.data.size == self.npts else: self.data = None
def read(self, filename, load_data=True): '''Read SAC file. filename -- Name of KAN file. load_data -- If True, the data is read, otherwise only read headers. ''' nbh = KanFile.nbytes_header # read in all data f = open(filename,'rb') if load_data: filedata = f.read() else: filedata = f.read(nbh) f.close() if len(filedata) < nbh: raise KanError('File too short to be a KAN file.') header_records = int(filedata[0:8]) npts = int(filedata[8:20]) leven = int(filedata[20:28]) datatype = int(filedata[28:36]) rate = float(filedata[36:50]) offset = float(filedata[50:64]) byte_sex = ('little', 'big')[int(filedata[382:390])] assert header_records == 1 assert leven == 1 assert datatype == 2 assert offset == 0.0 date = filedata[393:405].strip() tim = filedata[405:415].strip() microseconds = int(filedata[415:423]) ref_time = util.ctimegm('%s %s' % (date,tim)) + microseconds/1.0e6 stationname = os.path.basename(filename).replace('.kan','').replace('.KAN','') self.npts = npts self.delta = 1.0/rate self.kstnm = stationname self.ref_time = ref_time if load_data: if byte_sex == 'little': dtype = '<i4' else: dtype = '>i4' self.data = num.fromstring(filedata[nbh:], dtype=dtype) assert self.data.size == self.npts else: self.data = None
def load_kps_event_list(filename): elist =[] f = open(filename, 'r') for line in f: toks = line.split() if len(toks) < 7: continue tim = util.ctimegm(toks[0]+' '+toks[1]) lat, lon, depth, magnitude = [ float(x) for x in toks[2:6] ] duration = float(toks[10]) region = toks[-1] name = util.gmctime_fn(tim) e = Event(lat, lon, tim, name=name, depth=depth, magnitude=magnitude, duration=duration, region=region) elist.append(e) f.close() return elist
def loadf(self, file): d = {} try: for line in file: if line.lstrip().startswith('#'): continue toks = line.split(' = ',1) if len(toks) == 2: k,v = toks[0].strip(), toks[1].strip() if k in ('name', 'region', 'catalog'): d[k] = v if k in ('latitude longitude magnitude depth duration mnn mee mdd mne mnd med strike1 dip1 rake1 strike2 dip2 rake2 duration'.split()): d[k] = float(v) if k == 'time': d[k] = util.ctimegm(v[:19]) if line.startswith('---'): d['have_separator'] = True break except Exception, e: raise FileParseError(e)