Coverage for /opt/obspy/update-docs/src/obspy/obspy/mseed/headers : 96%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- Defines the libmseed structures and blockettes. """
# Import shared libmseed depending on the platform. # create library names # platform specific library name 'libmseed-%s-%s-py%s' % (platform.system(), platform.architecture()[0], ''.join([str(i) for i in platform.python_version_tuple()[:2]])), # fallback for pre-packaged libraries 'libmseed'] # get default file extension for shared objects # initialize library 'lib', lib_name + lib_extension)) except Exception, e: pass else: msg = 'Could not load shared library for obspy.mseed.\n\n %s' % (e) raise ImportError(msg)
# XXX: Do we still support Python 2.4 ???? # Figure out Py_ssize_t (PEP 353). # # Py_ssize_t is only defined for Python 2.5 and above, so it defaults to # ctypes.c_int for earlier versions. # # http://svn.python.org/projects/ctypes/trunk/ # ctypeslib/ctypeslib/contrib/pythonhdr.py Py_ssize_t = C.c_int else: raise TypeError("Cannot determine type of Py_ssize_t")
# Valid control headers in ASCII numbers.
# expected data types for libmseed id: (numpy, ctypes)
# Valid record lengths for Mini-SEED files. 131072, 262144, 524288, 1048576]
# allowed encodings: # SEED id: SEED name, SEED sampletype a, i, f or d, default numpy type)} 1: ("INT16", "i", np.dtype("int16")), 3: ("INT32", "i", np.dtype("int32")), 4: ("FLOAT32", "f", np.dtype("float32")), 5: ("FLOAT64", "d", np.dtype("float64")), 10: ("STEIM1", "i", np.dtype("int32")), 11: ("STEIM2", "i", np.dtype("int32"))}
# Map the dtype to the samplecode. Redundant information but it is hard coded # for performance reasons. "int16": "i", "int32": "i", "float32": "f", "float64": "d", np.dtype("|S1").type: "a", np.dtype("int16").type: "i", np.dtype("int32").type: "i", np.dtype("float32").type: "f", np.dtype("float64").type: "d"} # as defined in libmseed.h
# SEED binary time ('year', C.c_ushort), ('day', C.c_ushort), ('hour', C.c_ubyte), ('min', C.c_ubyte), ('sec', C.c_ubyte), ('unused', C.c_ubyte), ('fract', C.c_ushort), ]
# Fixed section data of header ('sequence_number', C.c_char * 6), ('dataquality', C.c_char), ('reserved', C.c_char), ('station', C.c_char * 5), ('location', C.c_char * 2), ('channel', C.c_char * 3), ('network', C.c_char * 2), ('start_time', BTime), ('numsamples', C.c_ushort), ('samprate_fact', C.c_short), ('samprate_mult', C.c_short), ('act_flags', C.c_ubyte), ('io_flags', C.c_ubyte), ('dq_flags', C.c_ubyte), ('numblockettes', C.c_ubyte), ('time_correct', C.c_int), ('data_offset', C.c_ushort), ('blockette_offset', C.c_ushort), ]
# Blockette 100, Sample Rate (without header) ('samprate', C.c_float), ('flags', C.c_byte), ('reserved', C.c_ubyte * 3), ]
# Blockette 200, Generic Event Detection (without header) ('amplitude', C.c_float), ('period', C.c_float), ('background_estimate', C.c_float), ('flags', C.c_ubyte), ('reserved', C.c_ubyte), ('time', BTime), ('detector', C.c_char * 24), ]
#Blockette 201, Murdock Event Detection (without header) ('amplitude', C.c_float), ('period', C.c_float), ('background_estimate', C.c_float), ('flags', C.c_ubyte), ('reserved', C.c_ubyte), ('time', BTime), ('snr_values', C.c_ubyte * 6), ('loopback', C.c_ubyte), ('pick_algorithm', C.c_ubyte), ('detector', C.c_char * 24), ]
#Blockette 300, Step Calibration (without header) ('time', BTime), ('numcalibrations', C.c_ubyte), ('flags', C.c_ubyte), ('step_duration', C.c_uint), ('interval_duration', C.c_uint), ('amplitude', C.c_float), ('input_channel', C.c_char * 3), ('reserved', C.c_ubyte), ('reference_amplitude', C.c_uint), ('coupling', C.c_char * 12), ('rolloff', C.c_char * 12), ]
# Blockette 310, Sine Calibration (without header) ('time', BTime), ('reserved1', C.c_ubyte), ('flags', C.c_ubyte), ('duration', C.c_uint), ('period', C.c_float), ('amplitude', C.c_float), ('input_channel', C.c_char * 3), ('reserved2', C.c_ubyte), ('reference_amplitude', C.c_uint), ('coupling', C.c_char * 12), ('rolloff', C.c_char * 12), ]
#Blockette 320, Pseudo-random Calibration (without header) ('time', BTime), ('reserved1', C.c_ubyte), ('flags', C.c_ubyte), ('duration', C.c_uint), ('ptp_amplitude', C.c_float), ('input_channel', C.c_char * 3), ('reserved2', C.c_ubyte), ('reference_amplitude', C.c_uint), ('coupling', C.c_char * 12), ('rolloff', C.c_char * 12), ('noise_type', C.c_char * 8), ]
#Blockette 390, Generic Calibration (without header) ('time', BTime), ('reserved1', C.c_ubyte), ('flags', C.c_ubyte), ('duration', C.c_uint), ('amplitude', C.c_float), ('input_channel', C.c_char * 3), ('reserved2', C.c_ubyte), ]
#Blockette 395, Calibration Abort (without header) ('time', BTime), ('reserved', C.c_ubyte * 2), ]
#Blockette 400, Beam (without header) ('azimuth', C.c_float), ('slowness', C.c_float), ('configuration', C.c_ushort), ('reserved', C.c_ubyte * 2), ]
#Blockette 405, Beam Delay (without header) ('delay_values', C.c_ushort * 1), ]
#Blockette 500, Timing (without header) ('vco_correction', C.c_float), ('time', BTime), ('usec', C.c_byte), ('reception_qual', C.c_ubyte), ('exception_count', C.c_uint), ('exception_type', C.c_char * 16), ('clock_model', C.c_char * 32), ('clock_status', C.c_char * 128), ]
# Blockette 1000, Data Only SEED (without header) ('encoding', C.c_ubyte), ('byteorder', C.c_ubyte), ('reclen', C.c_ubyte), ('reserved', C.c_ubyte), ]
# Blockette 1001, Data Extension (without header) ('timing_qual', C.c_ubyte), ('usec', C.c_byte), ('reserved', C.c_ubyte), ('framecnt', C.c_ubyte), ]
#Blockette 2000, Opaque Data (without header) ('length', C.c_ushort), ('data_offset', C.c_ushort), ('recnum', C.c_uint), ('byteorder', C.c_ubyte), ('flags', C.c_ubyte), ('numheaders', C.c_ubyte), ('payload', C.c_char * 1), ]
# Blockette chain link, generic linkable blockette index
('blktoffset', C.c_ushort), # Blockette offset ('blkt_type', C.c_ushort), # Blockette type ('next_blkt', C.c_ushort), # Offset to next blockette ('blktdata', C.POINTER(None)), # Blockette data ('blktdatalen', C.c_ushort), # Length of blockette data in bytes ('next', C.POINTER(blkt_link_s))]
('packedrecords', C.c_longlong), # Count of packed records ('packedsamples', C.c_longlong), # Count of packed samples ('lastintsample', C.c_int), # Value of last integer sample packed ('comphistory', C.c_byte), # Control use of lastintsample for # compression history ]
('record', C.POINTER(C.c_char)), # Mini-SEED record ('reclen', C.c_int), # Length of Mini-SEED record in bytes # Pointers to SEED data record structures ('fsdh', C.POINTER(fsdh_s)), # Fixed Section of Data Header ('blkts', C.POINTER(BlktLink)), # Root of blockette chain ('Blkt100', C.POINTER(blkt_100_s)), # Blockette 100, if present ('Blkt1000', C.POINTER(blkt_1000_s)), # Blockette 1000, if present ('Blkt1001', C.POINTER(blkt_1001_s)), # Blockette 1001, if present # Common header fields in accessible form ('sequence_number', C.c_int), # SEED record sequence number ('network', C.c_char * 11), # Network designation, NULL terminated ('station', C.c_char * 11), # Station designation, NULL terminated ('location', C.c_char * 11), # Location designation, NULL terminated ('channel', C.c_char * 11), # Channel designation, NULL terminated ('dataquality', C.c_char), # Data quality indicator ('starttime', C.c_longlong), # Record start time, corrected (first # sample) ('samprate', C.c_double), # Nominal sample rate (Hz) ('samplecnt', C.c_int64), # Number of samples in record ('encoding', C.c_byte), # Data encoding format ('byteorder', C.c_byte), # Byte order of record # Data sample fields ('datasamples', C.c_void_p), # Data samples, 'numsamples' of type # 'sampletype' ('numsamples', C.c_int64), # Number of data samples in datasamples ('sampletype', C.c_char), # Sample type code: a, i, f, d # Stream oriented state information ('ststate', C.POINTER(StreamState)), # Stream processing state information ]
('network', C.c_char * 11), # Network designation, NULL terminated ('station', C.c_char * 11), # Station designation, NULL terminated ('location', C.c_char * 11), # Location designation, NULL terminated ('channel', C.c_char * 11), # Channel designation, NULL terminated ('dataquality', C.c_char), # Data quality indicator ('type', C.c_char), # MSTrace type code ('starttime', C.c_longlong), # Time of first sample ('endtime', C.c_longlong), # Time of last sample ('samprate', C.c_double), # Nominal sample rate (Hz) ('samplecnt', C.c_int64), # Number of samples in trace coverage ('datasamples', C.c_void_p), # Data samples, 'numsamples' of type # 'sampletype' ('numsamples', C.c_int64), # Number of data samples in datasamples ('sampletype', C.c_char), # Sample type code: a, i, f, d ('prvtptr', C.c_void_p), # Private pointer for general use ('ststate', C.POINTER(StreamState)), # Stream processing state information ('next', C.POINTER(MSTrace_s)), # Pointer to next trace ]
('numtraces', C.c_int), # Number of MSTraces in the trace chain ('traces', C.POINTER(MSTrace_s)), # Root of the trace chain ]
# Define the high precision time tick interval as 1/modulus seconds */ # Default modulus of 1000000 defines tick interval as a microsecond */
# Reading Mini-SEED records from files
('fp', C.POINTER(Py_ssize_t)), ('filename', C.c_char * 512), ('rawrec', C.c_char_p), ('readlen', C.c_int), ('readoffset', C.c_int), ('packtype', C.c_int), ('packhdroffset', C.c_long), ('filepos', C.c_long), ('filesize', C.c_long), ('recordcount', C.c_int), ]
""" Union for Steim objects. """ ("byte", C.c_int8 * 4), # 4 1-byte differences. ("hw", C.c_int16 * 2), # 2 halfword differences. ("fw", C.c_int32), # 1 fullword difference. ]
""" Frame in a seed data record. """ ("ctrl", C.c_uint32), # control word for frame. ("w", U_DIFF * 14), # compressed data. ]
# Declare function of libmseed library, argument parsing
C.POINTER(C.POINTER(MSFileParam)), C.POINTER(C.POINTER(MSRecord)), C.c_char_p, C.c_int, C.POINTER(Py_ssize_t), C.POINTER(C.c_int), C.c_short, C.c_short, C.c_short]
C.POINTER(C.POINTER(MSTraceGroup)), C.c_char_p, C.c_int, C.c_double, C.c_double, C.c_short, C.c_short, C.c_short, C.c_short]
C.POINTER(C.POINTER(MSTraceGroup)), C.c_char_p, C.c_int, C.c_double, C.c_double, C.c_int64, C.c_int64, C.c_short, C.c_short, C.c_short, C.c_short]
C.c_int, C.c_int, np.ctypeslib.ndpointer(dtype='int32', ndim=1, flags='C_CONTIGUOUS'), np.ctypeslib.ndpointer(dtype='int32', ndim=1, flags='C_CONTIGUOUS'), C.POINTER(C.c_int32), C.POINTER(C.c_int32), C.c_int, C.c_int]
C.c_int, C.c_int, np.ctypeslib.ndpointer(dtype='int32', ndim=1, flags='C_CONTIGUOUS'), np.ctypeslib.ndpointer(dtype='int32', ndim=1, flags='C_CONTIGUOUS'), C.POINTER(C.c_int32), C.POINTER(C.c_int32), C.c_int, C.c_int]
# tricky, C.POINTER(C.c_char) is a pointer to single character fields # this is completely different to C.c_char_p which is a string C.CFUNCTYPE(C.c_void_p, C.POINTER(C.c_char), C.c_int, C.c_void_p), C.c_void_p, C.c_int, C.c_short, C.c_short, C.POINTER(C.c_int), C.c_short, C.c_short, C.POINTER(MSRecord)]
C.POINTER(C.c_char), C.c_int, C.c_int, C.c_int]
C.POINTER(C.POINTER(MSRecord)), C.c_int, C.c_int, C.c_int]
Py_ssize_t, C.c_char_p, C.c_char_p, C.CFUNCTYPE(C.c_int, Py_ssize_t)]
##################################### # Define the C structures. #####################################
# Container for a continuous trace segment, linkable
('starttime', C.c_longlong), # Time of first sample ('endtime', C.c_longlong), # Time of last sample ('samprate', C.c_double), # Nominal sample rate (Hz) ('samplecnt', C.c_int64), # Number of samples in trace coverage ('datasamples', C.c_void_p), # Data samples, 'numsamples' of type # 'sampletype' ('numsamples', C.c_int64), # Number of data samples in datasamples ('sampletype', C.c_char), # Sample type code: a, i, f, d ('prvtptr', C.c_void_p), # Private pointer for general use, unused # by libmseed ('prev', C.POINTER(MSTraceSeg)), # Pointer to previous segment ('next', C.POINTER(MSTraceSeg)) # Pointer to next segment ]
# Container for a trace ID, linkable
('network', C.c_char * 11), # Network designation, NULL terminated ('station', C.c_char * 11), # Station designation, NULL terminated ('location', C.c_char * 11), # Location designation, NULL terminated ('channel', C.c_char * 11), # Channel designation, NULL terminated ('dataquality', C.c_char), # Data quality indicator ('srcname', C.c_char * 45), # Source name (Net_Sta_Loc_Chan_Qual), # NULL terminated ('type', C.c_char), # Trace type code ('earliest', C.c_longlong), # Time of earliest sample ('latest', C.c_longlong), # Time of latest sample ('prvtptr', C.c_void_p), # Private pointer for general use, unused # by libmseed ('numsegments', C.c_int), # Number of segments for this ID ('first', C.POINTER(MSTraceSeg)), # Pointer to first of list of segments ('last', C.POINTER(MSTraceSeg)), # Pointer to last of list of segments ('next', C.POINTER(MSTraceID)) # Pointer to next trace ]
# Container for a continuous trace segment, linkable
('numtraces', C.c_int), # Number of traces in list ('traces', C.POINTER(MSTraceID)), # Pointer to list of traces ('last', C.POINTER(MSTraceID)) # Pointer to last used trace in list ]
# Data selection structure time window definition containers
('starttime', C.c_longlong), # Earliest data for matching channels ('endtime', C.c_longlong), # Latest data for matching channels ('next', C.POINTER(SelectTime)) ]
# Data selection structure definition containers
('srcname', C.c_char * 100), # Matching (globbing) source name: # Net_Sta_Loc_Chan_Qual ('timewindows', C.POINTER(SelectTime)), ('next', C.POINTER(Selections)) ]
# Container for a continuous linked list of records.
('starttime', C.c_longlong), ('endtime', C.c_longlong), ('samprate', C.c_double), ('sampletype', C.c_char), ('hpdelta', C.c_longlong), ('samplecnt', C.c_int64), ('timing_quality', C.c_uint8), ('calibration_type', C.c_int8), ('datasamples', C.c_void_p), # Data samples, 'numsamples' of type # 'sampletype' ('firstRecord', C.c_void_p), ('lastRecord', C.c_void_p), ('next', C.POINTER(ContinuousSegment)), ('previous', C.POINTER(ContinuousSegment)) ]
# A container for continuous segments with the same id
('network', C.c_char * 11), # Network designation, NULL terminated ('station', C.c_char * 11), # Station designation, NULL terminated ('location', C.c_char * 11), # Location designation, NULL terminated ('channel', C.c_char * 11), # Channel designation, NULL terminated ('dataquality', C.c_char), # Data quality indicator ('firstSegment', C.POINTER(ContinuousSegment)), # Pointer to first of list of segments ('lastSegment', C.POINTER(ContinuousSegment)), # Pointer to last of list of segments ('next', C.POINTER(LinkedIDList)), # Pointer to next id ('previous', C.POINTER(LinkedIDList)), # Pointer to previous id ]
######################################## # Done with the C structures defintions. ########################################
# Set the necessary arg- and restypes. np.ctypeslib.ndpointer(dtype='b', ndim=1, flags='C_CONTIGUOUS'), C.c_int, C.POINTER(Selections), C.c_int, C.c_int, C.c_int, C.c_int, C.CFUNCTYPE(C.c_long, C.c_int, C.c_char) ]
# Python callback functions for C return 1 |