Пример #1
0
 def _readFixedHeader(self):
     """
     Reads the fixed header of the Mini-SEED file and writes all entries to
     self.fixed_header, a dictionary.
     """
     # Init empty fixed header dictionary. Use an ordered dictionary to
     # achieve the same order as in the Mini-SEED manual.
     self.fixed_header = OrderedDict()
     # Read and unpack.
     self.file.seek(self.record_offset, 0)
     fixed_header = self.file.read(48)
     encoding = native_str('%s20c2H3Bx4H4Bl2H' % self.endian)
     header_item = unpack(encoding, fixed_header)
     # Write values to dictionary.
     self.fixed_header['Sequence number'] = \
         int(''.join(x.decode('ascii') for x in header_item[:6]))
     self.fixed_header['Data header/quality indicator'] = \
         header_item[6].decode('ascii')
     self.fixed_header['Station identifier code'] = \
         ''.join(x.decode('ascii') for x in header_item[8:13]).strip()
     self.fixed_header['Location identifier'] = \
         ''.join(x.decode('ascii') for x in header_item[13:15]).strip()
     self.fixed_header['Channel identifier'] = \
         ''.join(x.decode('ascii') for x in header_item[15:18]).strip()
     self.fixed_header['Network code'] = \
         ''.join(x.decode('ascii') for x in header_item[18:20]).strip()
     # Construct the starttime. This is only the starttime in the fixed
     # header without any offset. See page 31 of the SEED manual for the
     # time definition.
     self.fixed_header['Record start time'] = \
         UTCDateTime(year=header_item[20], julday=header_item[21],
                     hour=header_item[22], minute=header_item[23],
                     second=header_item[24], microsecond=header_item[25] *
                     100)
     self.fixed_header['Number of samples'] = int(header_item[26])
     self.fixed_header['Sample rate factor'] = int(header_item[27])
     self.fixed_header['Sample rate multiplier'] = int(header_item[28])
     self.fixed_header['Activity flags'] = int(header_item[29])
     self.fixed_header['I/O and clock flags'] = int(header_item[30])
     self.fixed_header['Data quality flags'] = int(header_item[31])
     self.fixed_header['Number of blockettes that follow'] = \
         int(header_item[32])
     self.fixed_header['Time correction'] = int(header_item[33])
     self.fixed_header['Beginning of data'] = int(header_item[34])
     self.fixed_header['First blockette'] = int(header_item[35])
Пример #2
0
 def _parseBlockette(self, blkt_type):
     """
     Parses the blockette blkt_type. If nothing is known about the blockette
     is will just return an empty dictionary.
     """
     blkt_dict = OrderedDict()
     # Check the blockette number.
     if blkt_type == 100:
         unpack_values = unpack('%sfxxxx' % self.endian, self.file.read(8))
         blkt_dict['Sampling Rate'] = float(unpack_values[0])
     elif blkt_type == 1000:
         unpack_values = unpack('%sBBBx' % self.endian, self.file.read(4))
         blkt_dict['Encoding Format'] = int(unpack_values[0])
         blkt_dict['Word Order'] = int(unpack_values[1])
         blkt_dict['Data Record Length'] = int(unpack_values[2])
     elif blkt_type == 1001:
         unpack_values = unpack('%sBBxB' % self.endian, self.file.read(4))
         blkt_dict['Timing quality'] = int(unpack_values[0])
         blkt_dict['mu_sec'] = int(unpack_values[1])
         blkt_dict['Frame count'] = int(unpack_values[2])
     return blkt_dict
Пример #3
0
 def _getBlockettes(self):
     """
     Loop over header and try to extract all header values!
     """
     self.blockettes = OrderedDict()
     cur_blkt_offset = self.fixed_header['First blockette']
     # Loop until the beginning of the data is reached.
     while True:
         if cur_blkt_offset >= self.fixed_header['Beginning of data']:
             break
         # Seek to the offset.
         self.file.seek(cur_blkt_offset, 0)
         # Unpack the first two values. This is always the blockette type
         # and the beginning of the next blockette.
         encoding = native_str('%s2H' % self.endian)
         blkt_type, next_blockette = unpack(encoding, self.file.read(4))
         blkt_type = int(blkt_type)
         next_blockette = int(next_blockette)
         cur_blkt_offset = next_blockette
         self.blockettes[blkt_type] = self._parseBlockette(blkt_type)
         # Also break the loop if next_blockette is zero.
         if next_blockette == 0:
             break