def test_readHeaderInfo(self): """ Reads and compares header info from the first record. The values can be read from the filename. """ gse2file = os.path.join(self.path, 'loc_RNON20040609200559.z') header = libgse2.readHead(open(gse2file, 'rb')) self.assertEqual('RNON ', header['station']) self.assertEqual(' Z', header['channel']) self.assertEqual(200, header['samp_rate']) self.assertEqual( '20040609200559.850', "%04d%02d%02d%02d%02d%06.3f" % (header['d_year'], header['d_mon'], header['d_day'], header['t_hour'], header['t_min'], header['t_sec']))
def test_readHeaderInfo(self): """ Reads and compares header info from the first record. The values can be read from the filename. """ gse2file = os.path.join(self.path, 'loc_RNON20040609200559.z') header = libgse2.readHead(open(gse2file, 'rb')) self.assertEqual('RNON ', header['station']) self.assertEqual(' Z', header['channel']) self.assertEqual(200, header['samp_rate']) self.assertEqual('20040609200559.850', "%04d%02d%02d%02d%02d%06.3f" % ( header['d_year'], header['d_mon'], header['d_day'], header['t_hour'], header['t_min'], header['t_sec']))
def readGSE2(filename, headonly=False, verify_chksum=True, **kwargs): # @UnusedVariable """ Reads a GSE2 file and returns a Stream object. GSE2 files containing multiple WID2 entries/traces are supported. .. warning:: This function should NOT be called directly, it registers via the ObsPy :func:`~obspy.core.stream.read` function, call this instead. :type filename: string :param filename: GSE2 file to be read. :type headonly: boolean, optional :param headonly: If True read only head of GSE2 file. :type verify_chksum: boolean, optional :param verify_chksum: If True verify Checksum and raise Exception if it is not correct. :rtype: :class:`~obspy.core.stream.Stream` :returns: Stream object containing header and data. .. rubric:: Example >>> from obspy import read >>> st = read("/path/to/loc_RJOB20050831023349.z") """ traces = [] # read GSE2 file with open(filename, "rb") as f: for _k in xrange(10000): # avoid endless loop pos = f.tell() widi = f.readline()[0:4] if widi == "": # end of file break elif widi != "WID2": continue else: # valid gse2 part f.seek(pos) if headonly: header = libgse2.readHead(f) else: header, data = libgse2.read(f, verify_chksum=verify_chksum) # assign all header entries to a new dictionary compatible with # an ObsPy Trace object. new_header = {} for i, j in convert_dict.iteritems(): value = header[i] if isinstance(value, str): value = value.strip() new_header[j] = value # assign gse specific header entries new_header["gse2"] = {} for i in gse2_extra: new_header["gse2"][i] = header[i] # Calculate start time. new_header["starttime"] = ( UTCDateTime( header["d_year"], header["d_mon"], header["d_day"], header["t_hour"], header["t_min"], 0 ) + header["t_sec"] ) if headonly: traces.append(Trace(header=new_header)) else: traces.append(Trace(header=new_header, data=data)) return Stream(traces=traces)