Segpy

Segpy is a Python package for reading and writing SEG Y data. The SEG Y file format is one of several standards developed by the Society of Exploration Geophysicists for storing geophysical seismic data. It is an open standard, and is controlled by the SEG Technical Standards Committee, a non-profit organization.

This project aims to implement an open SEG Y module in Python for transporting seismic data between SEG Y files and Python data structures.

Contents

Front Matter

Narrative Documentation

Read this to learn how to use Segpy:

Reference Documentation

Descriptions and examples for every public function, class and method in Segpy.

segpy

segpy package
Submodules
segpy.binary_reel_header module
class segpy.binary_reel_header.AmplitudeRecoveryMethod

Bases: enum.IntEnum

Amplitude recovery method: 1 = none, 2 = spherical divergence, 3 = AGC, 4 = other

AGC = 3
NONE = 1
OTHER = 4
SPHERICAL_DIVERGENCE = 2
UNKNOWN = 0
class segpy.binary_reel_header.AmplitudeRecoveryMethodField

Bases: int

ENUM

alias of AmplitudeRecoveryMethod

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.BinaryGainRecovered

Bases: enum.IntEnum

Binary gain recovered: 1 = no, 2 = yes

NO = 2
UNKNOWN = 0
YES = 1
class segpy.binary_reel_header.BinaryGainRecoveredField

Bases: int

ENUM

alias of BinaryGainRecovered

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.BinaryReelHeader(*args, **kwargs)

Bases: segpy.header.Header

LENGTH_IN_BYTES = 400
START_OFFSET_IN_BYTES = 3201
amplitude_recovery_method = AmplitudeRecoveryMethodField(name='amplitude_recovery_method', value_type='AmplitudeRecoveryMethodField', offset=3253, default=<AmplitudeRecoveryMethod.UNKNOWN: 0>)
auxiliary_traces_per_ensemble = AuxiliaryTracesPerEnsembleField(name='auxiliary_traces_per_ensemble', value_type='NNInt16', offset=3215, default=0)
binary_gain_recovered = BinaryGainRecoveredField(name='binary_gain_recovered', value_type='BinaryGainRecoveredField', offset=3251, default=<BinaryGainRecovered.UNKNOWN: 0>)
correlated_data_traces = CorrelatedDataTracesField(name='correlated_data_traces', value_type='CorrelatedDataTracesField', offset=3249, default=<CorrelatedDataTraces.UNKNOWN: 0>)
data_sample_format = DataSampleFormatField(name='data_sample_format', value_type='DataSampleFormatField', offset=3225, default=<DataSampleFormat.FLOAT32: 5>)
data_traces_per_ensemble = DataTracesPerEnsembleField(name='data_traces_per_ensemble', value_type='NNInt16', offset=3213, default=0)
ensemble_fold = EnsembleFoldField(name='ensemble_fold', value_type='NNInt16', offset=3227, default=0)
fixed_length_trace_flag = FixedLengthTraceFlagField(name='fixed_length_trace_flag', value_type='FixedLengthTraceFlagField', offset=3503, default=<FixedLengthTraceFlag.VARIABLE_LENGTH: 0>)
format_revision_num = FormatRevisionNumField(name='format_revision_num', value_type='FormatRevisionNumField', offset=3501, default=<SegYRevision.REVISION_1: 256>)
impulse_signal_polarity = ImpulseSignalPolarityField(name='impulse_signal_polarity', value_type='ImpulseSignalPolarityField', offset=3257, default=<ImpulseSignalPolarity.UNKNOWN: 0>)
job_id_num = JobIdNumField(name='job_id_num', value_type='Int32', offset=3201, default=0)
line_num = LineNumField(name='line_num', value_type='NNInt32', offset=3205, default=0)
measurement_system = MeasurementSystemField(name='measurement_system', value_type='MeasurementSystemField', offset=3255, default=<MeasurementSystem.UNKNOWN: 0>)
num_extended_textual_headers = NumExtendedTextualHeadersField(name='num_extended_textual_headers', value_type='NumExtendedTextualHeadersField', offset=3505, default=0)
num_samples = NumSamplesField(name='num_samples', value_type='NNInt16', offset=3221, default=0)
original_field_num_samples = OriginalFieldNumSamplesField(name='original_field_num_samples', value_type='NNInt16', offset=3223, default=0)
original_field_sample_interval = OriginalFieldSampleIntervalField(name='original_field_sample_interval', value_type='NNInt16', offset=3219, default=0)
reel_num = ReelNumField(name='reel_num', value_type='Int32', offset=3209, default=0)
sample_interval = SampleIntervalField(name='sample_interval', value_type='NNInt16', offset=3217, default=0)
sweep_frequency_at_end = SweepFrequencyAtEndField(name='sweep_frequency_at_end', value_type='NNInt16', offset=3235, default=0)
sweep_frequency_at_start = SweepFrequencyAtStartField(name='sweep_frequency_at_start', value_type='NNInt16', offset=3233, default=0)
sweep_length = SweepLengthField(name='sweep_length', value_type='NNInt16', offset=3237, default=0)
sweep_trace_number = SweepTraceNumberField(name='sweep_trace_number', value_type='Int16', offset=3241, default=0)
sweep_trace_taper_length_at_end = SweepTraceTaperLengthAtEndField(name='sweep_trace_taper_length_at_end', value_type='NNInt16', offset=3245, default=0)
sweep_trace_taper_length_at_start = SweepTraceTaperLengthAtStartField(name='sweep_trace_taper_length_at_start', value_type='NNInt16', offset=3243, default=0)
sweep_type = SweepTypeField(name='sweep_type', value_type='SweepTypeField', offset=3239, default=<SweepType.UNKNOWN: 0>)
taper_type = TaperTypeField(name='taper_type', value_type='TaperTypeField', offset=3247, default=<TaperType.UNKNOWN: 0>)
trace_sorting = TraceSortingField(name='trace_sorting', value_type='TraceSortingField', offset=3229, default=<TraceSorting.UNKNOWN: 0>)
vertical_sum_code = VerticalSumCodeField(name='vertical_sum_code', value_type='NNInt16', offset=3231, default=0)
vibratory_polarity_code = VibratoryPolarityCodeField(name='vibratory_polarity_code', value_type='VibratoryPolarityCodeField', offset=3259, default=<VibratoryPolarityCode.UNKNOWN: 0>)
class segpy.binary_reel_header.CorrelatedDataTraces

Bases: enum.IntEnum

Correlated data traces: 1 = no, 2 = yes

NO = 1
UNKNOWN = 0
YES = 2
class segpy.binary_reel_header.CorrelatedDataTracesField

Bases: int

ENUM

alias of CorrelatedDataTraces

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.DataSampleFormatField

Bases: int

ENUM

alias of DataSampleFormat

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.FixedLengthTraceFlag

Bases: enum.IntEnum

Fixed length trace flag. A value of one indicates that all traces in this SEG Y file are guaranteed to have the same sample interval and number of samples, as specified in Textual File Header bytes 3217-3218 and 3221-3222. A value of zero indicates that the length of the traces in the file may vary and the number of samples in bytes 115-116 of the Trace Header must be examined to determine the actual length of each trace. This field is mandatory for all versions of SEG Y, although a value of zero indicates “traditional” SEG Y conforming to the 1975 standard.

FIXED_LENGTH = 1
VARIABLE_LENGTH = 0
class segpy.binary_reel_header.FixedLengthTraceFlagField

Bases: int

ENUM

alias of FixedLengthTraceFlag

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.FormatRevisionNumField

Bases: int

ENUM

alias of SegYRevision

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.ImpulseSignalPolarity

Bases: enum.IntEnum

Impulse signal polarity : 1 = Increase in pressure or upward geophone case movement gives negative number on tape, 2 = Increase in pressure or upward geophone case movement gives positive number on tape.

INCREASE_GIVES_NEGATIVE_ON_TAPE = 1
INCREASE_GIVES_POSITIVE_ON_TAPE = 2
UNKNOWN = 0
class segpy.binary_reel_header.ImpulseSignalPolarityField

Bases: int

ENUM

alias of ImpulseSignalPolarity

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.MeasurementSystem

Bases: enum.IntEnum

Measurement system: Highly recommended for all types of data. If Location Data stanzas are included in the file, this entry must agree with the Location Data stanza. If there is a disagreement, the last Location Data stanza is the controlling authority. 1 = Meters, 2 = Feet

FEET = 2
METERS = 1
UNKNOWN = 0
class segpy.binary_reel_header.MeasurementSystemField

Bases: int

ENUM

alias of MeasurementSystem

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.NumExtendedTextualHeadersField

Bases: int

MAXIMUM = 32767
MINIMUM = -1
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.TraceSorting

Bases: enum.IntEnum

Trace sorting code (i.e. type of ensemble) : -1 = Other (should be explained in user Extended Textual File Header stanza, 0 = Unknown, 1 = As recorded (no sorting), 2 = CDP ensemble, 3 = Single fold continuous profile 4 = Horizontally stacked, 5 = Common source point, 6 = Common receiver point, 7 = Common offset point, 8 = Common mid-point, 9 = Common conversion point. Highly recommended for all types of data.

AS_RECORDED = 1
CDP_ENSEMBLE = 2
COMMON_CONVERSION_POINT = 9
COMMON_MIDPOINT = 8
COMMON_OFFSET_POINT = 7
COMMON_RECEIVER_POINT = 6
COMMON_SOURCE_POINT = 5
HORIZONTALLY_STACKED = 4
OTHER = -1
SINGLE_FOLD_CONTINUOUS_PROFILE = 3
UNKNOWN = 0
class segpy.binary_reel_header.TraceSortingField

Bases: int

ENUM

alias of TraceSorting

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.binary_reel_header.VibratoryPolarityCode

Bases: enum.IntEnum

Seismic signal lags pilot signal by: 1 = 337.5° to 22.5°, 2 = 22.5° to 67.5°, 3 = 67.5° to 112.5°, 4 = 112.5° to 157.5°, 5 = 157.5° to 202.5°, 6 = 202.5°to 247.5°, 7 = 247.5° to 292.5°, 8 = 292.5° to 337.5°.

FROM_112_5_TO_157_5 = 4
FROM_157_5_TO_202_5 = 5
FROM_202_5_TO_247_5 = 6
FROM_22_5_TO_67_5 = 2
FROM_247_5_TO_292_5 = 7
FROM_292_5_TO_337_5 = 8
FROM_337_5_TO_22_5 = 1
FROM_67_5_TO_112_5 = 3
UNKNOWN = 0
class segpy.binary_reel_header.VibratoryPolarityCodeField

Bases: int

ENUM

alias of VibratoryPolarityCode

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
segpy.catalog module

Catalogs are immutable mappings useful for building indexes.

This module contains definitions of many different catalog types, all of which implement the interface defined by the Catalog abstract base class, which is itself implements the mapping protocol.

Rather than constructing Catalog subtypes directly, prefer to use the CatalogBuilder class which will analyse the contents of the mapping to find a space and time efficient representation.

class segpy.catalog.Catalog2D(i_range, j_range)

Bases: collections.abc.Mapping

An abstract base class for 2D catalogs.

i_max

Maximum i value

i_min

Minimum i value

i_range
j_max

Maximum j value

j_min

Minimum j value

j_range
key_max()

Maximum (i, j) key

key_min()

Minimum (i, j) key

value_first()

Minimum value at key_min

value_last()

Maximum value at key_max

class segpy.catalog.CatalogBuilder(mapping=None)

Bases: object

Use a catalog builder to construct optimised, immutable mappings.

A CatalogBuilder is useful when, depending on the particular keys and values used, a more compact or efficient representation of the mapping is possible than, say, a regular dictionary. The CatalogBuilder accumulates values and then, once all values have been added, analyzes the keys and values to produce a more optimized representation of the mapping.

add(index, value)

Add an item.

Each index must be unique if create() is to be subsequently called successfully, although duplicate index values will be accepted by this call without complaint.

create()

Create a possibly more optimized representation of the mapping.

In this worst case, this method returns an object which is essentially an immutable dictionary. In the best case, the space savings can be vast.

Returns:A mapping, if a unique mapping from indexes to values is possible, otherwise None.
make_dictionary_catalog_2d()
make_first_index_varies_quickest_catalog_2d()
make_last_index_varies_quickest_catalog_2d()
make_sorted_ranges()
class segpy.catalog.ConstantCatalog(keys, value)

Bases: collections.abc.Mapping

Mapping with arbitrary keys and a single constant value.

class segpy.catalog.DictionaryCatalog(items)

Bases: collections.abc.Mapping

An immutable, ordered, dictionary mapping.

class segpy.catalog.DictionaryCatalog2D(i_range, j_range, items)

Bases: segpy.catalog.Catalog2D

An immutable, ordered, dictionary mapping for 2D keys.

class segpy.catalog.FirstIndexVariesQuickestCatalog2D(i_range, j_range, v_range)

Bases: segpy.catalog.Catalog2D

key(value)

Given a value, get the corresponding key.

Parameters:value – The value for which to find the key.
Returns:A 2-tuple containing the (i, j) values corresponding to the given value.
Raises:ValueError - If there is no corresponding key.
v_range
class segpy.catalog.LastIndexVariesQuickestCatalog2D(i_range, j_range, v_range)

Bases: segpy.catalog.Catalog2D

key(value)

Given a value, get the corresponding key.

Parameters:value – The value for which to find the key.
Returns:A 2-tuple containing the (i, j) values corresponding to the given value.
Raises:ValueError - If there is no corresponding key.
v_range
class segpy.catalog.LinearRegularCatalog(key_min, key_max, key_stride, value_start, value_stop, value_stride)

Bases: collections.abc.Mapping

A mapping which assumes a linear relationship between keys and values.

A LinearRegularCatalog predicts the value v from the key according to the following formula:

v = (value_max - value_min) / (key_max - key_min) * (key - key_min) + value_min
class segpy.catalog.RegularCatalog(key_min, key_max, key_stride, values)

Bases: collections.abc.Mapping

Mapping with keys ordered with regular spacing along the number line.

The values associated with the keys are arbitrary.

class segpy.catalog.RegularConstantCatalog(key_min, key_max, key_stride, value)

Bases: collections.abc.Mapping

Mapping with keys ordered with regular spacing along the number line.

The values associated with the keys are constant.

segpy.cli module
segpy.dataset module
class segpy.dataset.Dataset

Bases: object

binary_reel_header

The binary reel header.

data_sample_format

The data type of the samples in machine-readable form. One of the values from datatypes.DATA_SAMPLE_FORMAT.

data_sample_format_description

A descriptive human-readable description of the data sample format

dimensionality

The spatial dimensionality of the data: 3 for 3D seismic volumes, 2 for 2D seismic lines, 1 for a single trace_samples, otherwise 0.

extended_textual_header
num_traces()

The number of traces.

textual_reel_header

The textual real header as an immutable sequence of forty Unicode strings each 80 characters long.

trace_header(trace_index)

The trace header for a given trace index.

Parameters:trace_index – An integer in the range zero to num_traces() - 1
Returns:A TraceHeader corresponding to the requested trace_samples.
trace_indexes()

An iterator over zero-based trace_samples indexes.

Returns:An iterator which yields integers in the range zero to num_traces - 1
trace_samples(trace_index, start=None, stop=None)

The trace samples for a given trace index.

Parameters:
  • trace_index – An integer in the range zero to num_traces - 1
  • start – Optional zero-based start sample index. The default is to read from the first (i.e. zeroth) sample.
  • stop – Optional zero-based stop sample index. Following Python slice convention this is one beyond the end.
Returns:

A sequence of numeric trace_samples samples.

class segpy.dataset.DelegatingDataset(source_dataset)

Bases: segpy.dataset.Dataset

A Dataset which by default forwards to a source Dataset.

This base class is useful if you only want to override a few methods to perform transformations.

binary_reel_header
dimensionality
encoding
endian
extended_textual_header
num_traces()

The number of traces.

source
textual_reel_header
trace_header(trace_index)
trace_indexes()
trace_samples(trace_index, start=None, stop=None)
segpy.datatypes module

Mappings between the coding systems used for sample types.

class segpy.datatypes.DataSampleFormat

Bases: enum.IntEnum

Data sample format code. Mandatory for all data. 1 = 4-byte IBM floating-point, 2 = 4-byte, two’s complement integer, 3 = 2-byte, two’s complement integer, 4 = 4-byte fixed-point with gain (obsolete), 5 = 4-byte IEEE floating-point, 6 = Not currently used, 7 = Not currently used, 8 = 1-byte, two’s complement integer.

FLOAT32 = 5
IBM = 1
INT16 = 3
INT32 = 2
INT8 = 8
class segpy.datatypes.Limits(min, max)

Bases: tuple

max

Alias for field number 1

min

Alias for field number 0

class segpy.datatypes.SegYType

Bases: str, enum.Enum

An enumeration.

FLOAT32 = 'float32'
IBM = 'ibm'
INT16 = 'int16'
INT32 = 'int32'
INT8 = 'int8'
NNINT16 = 'nnint16'
NNINT32 = 'nnint32'
NNINT8 = 'nnint8'
segpy.datatypes.size_in_bytes(ctype)

The size in bytes of a ctype.

segpy.encoding module

Support for the text encodings used in SEG Y.

SEG Y data can contain textual data encoded in either ASCII or EBCDIC format. This module contains tools for detecting those encodings.

exception segpy.encoding.UnsupportedEncodingError(text, encoding)

Bases: Exception

encoding
segpy.encoding.guess_encoding(bs, threshold=0.5)

Try to determine whether the encoding of byte stream b is an ASCII string or an EBCDIC string.

Parameters:bs – A byte string (Python 2 - str; Python 3 - bytes)
Returns:A string which can be used with the Python encoding functions: ‘cp037’ for EBCDIC, ‘ascii’ for ASCII or None if neither.
segpy.encoding.is_supported_encoding(encoding)
segpy.field_types module
class segpy.field_types.Int16

Bases: int

16-bit signed integer.

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.field_types.Int32

Bases: int

32-bit signed integer.

MAXIMUM = 2147483647
MINIMUM = -2147483648
SEG_Y_TYPE = 'int32'
SIZE = 4
class segpy.field_types.IntEnumFieldMeta(name, bases, namespace, *args, **kwargs)

Bases: segpy.field_types.IntFieldMeta

Metaclass for fields which are defined by an enum.IntEnum.

class_new(*args, **kwargs)
class segpy.field_types.IntFieldMeta(name, bases, namespace, *args, **kwargs)

Bases: type

Metaclass for signed and unsigned int fields.

class_new(*args, **kwargs)
class segpy.field_types.NNInt16

Bases: int

Non-negative 16-bit signed integer.

MAXIMUM = 32767
MINIMUM = 0
SEG_Y_TYPE = 'nnint16'
SIZE = 2
class segpy.field_types.NNInt32

Bases: int

Non-negative 32-bit signed integer.

MAXIMUM = 2147483647
MINIMUM = 0
SEG_Y_TYPE = 'nnint32'
SIZE = 4
segpy.header module
class segpy.header.BaseHeader(*args, **kwargs)

Bases: object

An abstract base class for header format definitions.

Prefer to inherit from Header rather than BaseHeader.

copy(**updates)
classmethod ordered_field_names()

The ordered list of field names.

This is a metamethod which should be called on cls.

Returns:An tuple containing the field names in order.
class segpy.header.FormatMeta

Bases: type

A metaclass for header format classes.

class segpy.header.Header(*args, **kwargs)

Bases: segpy.header.BaseHeader

A base class for header definition classes.

class segpy.header.HeaderFieldDescriptor(value_type, offset, default, documentation)

Bases: object

class segpy.header.NamedField(value_type, offset, default, documentation)

Bases: object

Instances of NamedField can be detected by the NamedDescriptorResolver metaclass.

default

The default value of the field. Must be convertible to value_type.

documentation

A descriptive text string.

name

The field name.

offset

The offset in bytes from the beginning of the header.

value_type

The field value type (e.g. Int32)

class segpy.header.SubFormatMeta(mcs, name, bases, namespace, parent_format, parent_field_names)

Bases: segpy.header.FormatMeta

A metaclass for a format class which has a subset of the fields in an existing format class.

SubFormat classes can be used to reduce storage requirements and increase performance, since they can be used to generate simpler HeaderPackers.

Usage:

class MySubFormat(metaclass=SubFormatMeta,
                  parent_format=MyFormatClass,
                  parent_field_names=[
                     'first_field_name',
                     'second_field_name']):
    pass
segpy.header.are_equal(header_a, header_b)

Compare two headers for equality.

Note

This is not implemented as __eq__() to prevent recursive behaviour in the header descriptor.

segpy.header.field(value_type, offset, default, documentation)

offset: The offset in bytes for this field from the start of the header.

default: The default value for this field.

documentation: A docstring for the field. The first sentence should be usable
as a brief description.
Returns:An instance of a subclass of HeaderFieldDescriptor class.
segpy.header.is_public_non_field_attr(name, attr)
segpy.ibm_float module
class segpy.ibm_float.IBMFloat

Bases: numbers.Real

as_integer_ratio()
exp16

The base 16 exponent.

frexp()

Obtain the fraction and exponent.

Returns:A pair where the first item is the fraction in the range -1.0 and +1.0 and the exponent is an integer such that f = fraction * 2**exponent
classmethod from_bytes(b)
classmethod from_float(f)

Construct an IBMFloat from an IEEE float.

Parameters:

f (float) – The value to be converted.

Returns:

An IBMFloat.

Raises:
  • OverflowError - If f is outside the representable range.
  • ValueError - If f is NaN or infinite.
  • FloatingPointError - If f cannot be represented without total loss of precision.
classmethod from_float_without_underflow(f)

Construct an IBMFloat from an IEEE float.

Parameters:

f (float) – The value to be converted. If the provided IEEE value underflows the smallest representable IBM value, this function returns zero.

Returns:

An IBMFloat.

Raises:
  • OverflowError - If f is outside the representable range.
  • ValueError - If f is NaN or infinite.
classmethod from_real(f)
int_mantissa
is_subnormal()
is_zero()
classmethod ldexp(fraction, exponent)

Make an IBMFloat from fraction and exponent.

The is the inverse function of IBMFloat.frexp()

Parameters:
  • fraction – A Real in the range -1.0 to 1.0.
  • exponent – An integer in the range -256 to 255 inclusive.
normalize()

Normalize the floating point representation.

Returns:A normalized IBMFloat equal in value to this object.
Raises:FloatingPointError - If the number could not be normalized.
signbit

True if the value is negative, otherwise False.

try_normalize()

Normalize if possible.

If it is not possible to normalize the representation, it remains unmodified.

zero_subnormal()
segpy.ibm_float.ibm2ieee(big_endian_bytes)

Interpret a byte string as a big-endian IBM float.

Parameters:big_endian_bytes (bytes) – A byte-string containing at least four bytes.
Returns:The floating point value.
segpy.ibm_float.ieee2ibm(f)

Convert a float to four big-endian bytes representing an IBM float.

Parameters:

f (float) – The value to be converted.

Returns:

A bytes object (Python 3) or a string (Python 2) containing four bytes representing a big-endian IBM float.

Raises:
  • OverflowError - If f is outside the representable range.
  • ValueError - If f is NaN or infinite.
  • FloatingPointError - If f cannot be represented without total loss of precision.
segpy.ibm_float_packer module
segpy.packer module
class segpy.packer.BijectiveHeaderPacker(header_format_class, structure, field_name_allocations)

Bases: segpy.packer.HeaderPacker

One-to-one packing/unpacking of serialised values to header fields.

class segpy.packer.HeaderPacker(header_format_class, structure, field_name_allocations)

Bases: abc.ABC

Packing and unpacking header instances.

header_format_class
pack(header)

Pack a header into a buffer.

unpack(buffer)

Unpack a header into a header object.

Overwrites any existing header field values with new values obtained from the buffer.

Returns:The header object.
class segpy.packer.SurjectiveHeaderPacker(header_format_class, structure, field_name_allocations)

Bases: segpy.packer.HeaderPacker

One-to-many unpacking of serialised values to header fields.

segpy.packer.compile_struct(header_format_class, start_offset=0, length_in_bytes=None, endian='>')

Compile a struct description from a record.

Parameters:
  • header_format_class – A header_format class.
  • start_offset – Optional start offset for the header in bytes. Indicates the position of the start of the header in the same reference frame as which the field offsets are given.
  • length_in_bytes – Optional length in bytes for the header. If the supplied header described a format shorter than this value the returned format will be padded with placeholders for bytes to be discarded. If the value is less than the minimum required for the format described by header_format_class an error will be raised.
  • endian – ‘>’ for big-endian data (the standard and default), ‘<’ for little-endian (non-standard).
Returns:

A two-tuple containing in the zeroth element a format string which can be used with the struct.unpack function, and in the second element containing a list-of-lists for field names. Each item in the outer list corresponds to an element of the tuple of data values returned by struct.unpack(); each name associated with that index is a field to which the unpacked value should be assigned.

Usage:

format, allocations = compile_struct(TraceHeaderFormat)
values = struct.unpack(format)
field_names_to_values = {}
for field_names, value in zip(allocations, values):
    for field_name in field_names:
        field_names_to_values[field_name] = value
header = Header(**field_names_to_values)
Raises:
  • ValueError - If header_format_class defines no fields.
  • ValueError - If header_format_class contains fields which overlap but are not exactly coincident.
  • ValueError - If header_format_class contains coincident fields of different types.
  • ValueError - If header_format_class described a format longer than length_in_bytes.
segpy.packer.make_header_packer(header_format_class, endian='>')
segpy.packer.size_of(t)
segpy.reader module
segpy.reversed_sequence_view module
class segpy.reversed_sequence_view.ReversedSequenceView(sequence)

Bases: collections.abc.Sequence

count(item)
index(item)
segpy.revisions module

SEG Y Revision numbers

From the specification:

SEG Y Format Revision Number. This is a 16-bit unsigned value with a Q- point between the first and second bytes. Thus for SEG Y Revision 1.0, as defined in this document, this will be recorded as 0100 in base 16.
class segpy.revisions.SegYRevision

Bases: enum.IntEnum

An enumeration.

REVISION_0 = 0
REVISION_1 = 256
exception segpy.revisions.SegYRevisionError

Bases: Exception

segpy.revisions.canonicalize_revision(revision)

Canonicalize a SEG Y revision.

Various SEG Y revisions are seen in the wild; this function canonicalizes the supplies revision to either SegYRevision.REVISION_0 or SegYRevision.REVISION_1.

Parameters:revision – Any object representing a SEG Y revision.
Returns:An integer revision - either SegYRevision.REVISION_0 or SegYRevision.REVISION_1.
Raises:SegYRevisionError - If the revision is not known.
segpy.revisions.integer_to_decimal_revision(revision)

Convert a SEG Y revision integer into decimal form.

Parameters:revision – An canonical revision integer e.g. as produced by a call to canonicalize_revision().
Returns:A decimal real number.
segpy.sorted_frozen_set module
class segpy.sorted_frozen_set.SortedFrozenSet

Bases: collections.abc.Sequence, collections.abc.Set

count(item)
difference(iterable)
index(item)
intersection(iterable)
issubset(iterable)
issuperset(iterable)
symmetric_difference(iterable)
union(iterable)
segpy.textual_reel_header module
segpy.toolkit module
segpy.trace_header module
class segpy.trace_header.CoordinateUnits

Bases: enum.IntEnum

Coordinate units: 1 = Length (meters or feet), 2 = Seconds of arc, 3 = Decimal degrees, 4 = Degrees, minutes, seconds (DMS). Note: To encode ±DDDMMSS bytes this value equals ±DDD*104 + MM*102 + SS with xy_scalar set to 1; To encode ±DDDMMSS.ss this value equals ±DDD*106 + MM*104 + SS*102 with xy_scalar set to -100.

DECIMAL_DEGREES = 3
DMS = 4
LENGTH = 1
SECONDS_OF_ARC = 2
UNKNOWN = 0
class segpy.trace_header.CoordinateUnitsField

Bases: int

ENUM

alias of CoordinateUnits

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.Correlated

Bases: enum.IntEnum

Correlated: 1 = no, 2 = yes.

NO = 1
YES = 2
class segpy.trace_header.CorrelatedField

Bases: int

ENUM

alias of Correlated

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.DataUse

Bases: enum.IntEnum

Data use: 1 = Production, 2 = Test

PRODUCTION = 1
TEST = 2
class segpy.trace_header.DataUseField

Bases: int

ENUM

alias of DataUse

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.DayOfYearField

Bases: int

Day of year. (Julian day for GMT and UTC time basis).

Value range based on: https://seg.org/Portals/0/SEG/News%20and%20Resources/Technical%20Standards/seg_y_rev2_0-mar2017.pdf

MAXIMUM = 366
MINIMUM = 0
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.HourOfDayField

Bases: int

Hour of day. (24 hour clock).

MAXIMUM = 24
MINIMUM = 0
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.MinuteOfHourField

Bases: int

Minute of hour.

MAXIMUM = 60
MINIMUM = 0
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.OverTravel

Bases: enum.IntEnum

Over travel associated with taper at beginning or end of line. 1 = down (or behind) 2 = up (or ahead)

DOWN = 1
UNKNOWN = 0
UP = 2
class segpy.trace_header.OverTravelField

Bases: int

ENUM

alias of OverTravel

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.SampleUnit

Bases: enum.IntEnum

-1 = Other (should be described in Data Sample Measurement Units Stanza) 0 = Unknown, 1 = Pascal (Pa), 2 = Volts (v), 3 = Millivolts (mV), 4 = Amperes (A), 5 = Meters (m), 6 = Meters per second (m/s), 7 = Meters per second squared (m/s^2), 8 = Newton (N), 9 = Watt (W)

AMPERES = 4
METERS = 5
METERS_PER_SECOND = 6
METERS_PER_SECOND_SQUARED = 7
MILLIVOLTS = 3
NEWTON = 8
OTHER = -1
PASCAL = 1
UNKNOWN = 0
VOLTS = 2
WATT = 9
class segpy.trace_header.SampleUnitField

Bases: int

ENUM

alias of SampleUnit

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.ScalarFactor

Bases: enum.IntEnum

Scalar to be applied to other fields.

See specific fields (i.e. use of this class) to see the specific fields to which scalars are applied.

Scalar = 1, +10, +100, +1000, or +10,000. If positive, scalar is used as a multiplier; if negative, scalar is used as a divisor.

NEG_1 = -1
NEG_10 = -10
NEG_100 = -100
NEG_1000 = -1000
NEG_10000 = -10000
POS_1 = 1
POS_10 = 10
POS_100 = 100
POS_1000 = 1000
POS_10000 = 10000
UNKNOWN = 0
class segpy.trace_header.ScalarFactorField

Bases: int

ENUM

alias of ScalarFactor

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.SecondOfMinute

Bases: int

Second of minutes.

MAXIMUM = 60
MINIMUM = 0
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.SourceMeasurementUnit

Bases: enum.IntEnum

Source Measurement Unit. The unit used for the source measurement.

-1 = Other (should be described in Source Measurement Unit stanza), 0 = Unknown, 1 = Joule (J), 2 = Kilowatt (kW), 3 = Pascal (Pa), 4 = Bar (Bar), 4 = Bar-meter (Bar-m), 5 = Newton (N), 6 = Kilograms (kg)

BAR = 4
BAR_METER = 4
JOULE = 1
KILOGRAMS = 6
KILOWATT = 2
NEWTON = 5
OTHER = -1
PASCAL = 3
UNKNOWN = 0
class segpy.trace_header.SourceMeasurementUnitField

Bases: int

ENUM

alias of SourceMeasurementUnit

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.SourceTypeField

Bases: int

Source Type/Orientation — Defines the type and the orientation of the energy source. The terms vertical, cross-line and in-line refer to the three axes of an orthogonal coordinate system. The absolute azimuthal orientation of the coordinate system axes can be defined in the Bin Grid Definition Stanza. -1 to -n = Other (should be described in Source Type/Orientation stanza), 0 = Unknown, 1 = Vibratory - Vertical orientation, 2 = Vibratory - Cross-line orientation, 3 = Vibratory - In-line orientation, 4 = Impulsive - Vertical orientation, 5 = Impulsive - Cross-line orientation, 6 = Impulsive - In-line orientation, 7 = Distributed Impulsive - Vertical orientation, 8 = Distributed Impulsive - Cross-line orientation, 9 = Distributed Impulsive - In-line orientation

MAXIMUM = 9
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.SweepType

Bases: enum.IntEnum

Sweep type: 1 = linear, 2 = parabolic, 3 = exponential 4 = other.

EXPONENTIAL = 3
LINEAR = 1
OTHER = 4
PARABOLIC = 2
UNKNOWN = 0
class segpy.trace_header.SweepTypeField

Bases: int

ENUM

alias of SweepType

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.TaperType

Bases: enum.IntEnum

Taper type: 1 = linear, 2 = cos2, 3 = other

COS_SQUARED = 2
LINEAR = 1
OTHER = 3
UNKNOWN = 0
class segpy.trace_header.TaperTypeField

Bases: int

ENUM

alias of TaperType

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.TimeBasisCode

Bases: enum.IntEnum

Time basis code. 1 = Local, 2 = GMT (Greenwich Mean Time), 3 = Other, should be explained in a user defined stanza in the Extended Textual File Header, 4 = UTC (Coordinated Universal Time).

GMT = 2
LOCAL = 1
OTHER = 3
UNKNOWN = 0
UTC = 4
class segpy.trace_header.TimeBasisCodeField

Bases: int

ENUM

alias of TimeBasisCode

MAXIMUM = 32767
MINIMUM = -32768
SEG_Y_TYPE = 'int16'
SIZE = 2
class segpy.trace_header.TraceHeaderRev0(*args, **kwargs)

Bases: segpy.header.Header

LENGTH_IN_BYTES = 240
START_OFFSET_IN_BYTES = 1
alias_filter_frequency = AliasFilterFrequencyField(name='alias_filter_frequency', value_type='NNInt16', offset=141, default=0)
alias_filter_slope = AliasFilterSlopeField(name='alias_filter_slope', value_type='Int16', offset=143, default=0)
coordinate_units = CoordinateUnitsField(name='coordinate_units', value_type='CoordinateUnitsField', offset=89, default=<CoordinateUnits.UNKNOWN: 0>)
correlated = CorrelatedField(name='correlated', value_type='CorrelatedField', offset=125, default=<Correlated.NO: 1>)
data_use = DataUseField(name='data_use', value_type='DataUseField', offset=35, default=<DataUse.PRODUCTION: 1>)
datum_elevation_at_receiver_group = DatumElevationAtReceiverGroupField(name='datum_elevation_at_receiver_group', value_type='NNInt32', offset=53, default=0)
datum_elevation_at_source = DatumElevationAtSourceField(name='datum_elevation_at_source', value_type='Int32', offset=57, default=0)
day_of_year = DayOfYearField(name='day_of_year', value_type='DayOfYearField', offset=159, default=0)
delay_recording_time = DelayRecordingTimeField(name='delay_recording_time', value_type='Int16', offset=109, default=0)
doc_nreceiver_offset = DocNreceiverOffsetField(name='doc_nreceiver_offset', value_type='Int32', offset=37, default=0)
elevation_scalar = ElevationScalarField(name='elevation_scalar', value_type='ScalarFactorField', offset=69, default=<ScalarFactor.POS_1: 1>)
energy_source_point_num = EnergySourcePointNumField(name='energy_source_point_num', value_type='Int32', offset=17, default=0)
ensemble_num = EnsembleNumField(name='ensemble_num', value_type='Int32', offset=21, default=0)
ensemble_trace_num = EnsembleTraceNumField(name='ensemble_trace_num', value_type='NNInt32', offset=25, default=0)
field_record_num = FieldRecordNumField(name='field_record_num', value_type='Int32', offset=9, default=0)
file_sequence_num = FileSequenceNumField(name='file_sequence_num', value_type='Int32', offset=5, default=0)
gain_type_of_field_instruments = GainTypeOfFieldInstrumentsField(name='gain_type_of_field_instruments', value_type='NNInt16', offset=119, default=0)
gap_size = GapSizeField(name='gap_size', value_type='NNInt16', offset=177, default=0)
geophone_group_num_first_trace_original_field = GeophoneGroupNumFirstTraceOriginalFieldField(name='geophone_group_num_first_trace_original_field', value_type='Int16', offset=173, default=0)
geophone_group_num_last_trace_original_field = GeophoneGroupNumLastTraceOriginalFieldField(name='geophone_group_num_last_trace_original_field', value_type='Int16', offset=175, default=0)
geophone_group_num_roll_switch_position_one = GeophoneGroupNumRollSwitchPositionOneField(name='geophone_group_num_roll_switch_position_one', value_type='Int16', offset=171, default=0)
group_static_correction = GroupStaticCorrectionField(name='group_static_correction', value_type='Int16', offset=101, default=0)
group_x = GroupXField(name='group_x', value_type='Int32', offset=81, default=0)
group_y = GroupYField(name='group_y', value_type='Int32', offset=85, default=0)
high_cut_frequency = HighCutFrequencyField(name='high_cut_frequency', value_type='NNInt16', offset=151, default=0)
high_cut_slope = HighCutSlopeField(name='high_cut_slope', value_type='Int16', offset=155, default=0)
hour_of_day = HourOfDayField(name='hour_of_day', value_type='HourOfDayField', offset=161, default=0)
instrument_gain_constant = InstrumentGainConstantField(name='instrument_gain_constant', value_type='Int16', offset=121, default=0)
instrument_initial_gain = InstrumentInitialGainField(name='instrument_initial_gain', value_type='Int16', offset=123, default=0)
lag_time_a = LagTimeAField(name='lag_time_a', value_type='Int16', offset=105, default=0)
lag_time_b = LagTimeBField(name='lag_time_b', value_type='Int16', offset=107, default=0)
line_sequence_num = LineSequenceNumField(name='line_sequence_num', value_type='Int32', offset=1, default=0)
low_cut_frequency = LowCutFrequencyField(name='low_cut_frequency', value_type='NNInt16', offset=149, default=0)
low_cut_slope = LowCutSlopeField(name='low_cut_slope', value_type='Int16', offset=153, default=0)
minute_of_hour = MinuteOfHourField(name='minute_of_hour', value_type='MinuteOfHourField', offset=163, default=0)
mute_end_time = MuteEndTimeField(name='mute_end_time', value_type='NNInt16', offset=113, default=0)
mute_start_time = MuteStartTimeField(name='mute_start_time', value_type='NNInt16', offset=111, default=0)
notch_filter_frequency = NotchFilterFrequencyField(name='notch_filter_frequency', value_type='NNInt16', offset=145, default=0)
notch_filter_slope = NotchFilterSlopeField(name='notch_filter_slope', value_type='Int16', offset=147, default=0)
num_horizontally_stacked_traces = NumHorizontallyStackedTracesField(name='num_horizontally_stacked_traces', value_type='NNInt16', offset=33, default=1)
num_samples = NumSamplesField(name='num_samples', value_type='NNInt16', offset=115, default=0)
num_vertically_summed_traces = NumVerticallySummedTracesField(name='num_vertically_summed_traces', value_type='NNInt16', offset=31, default=1)
over_travel = OverTravelField(name='over_travel', value_type='OverTravelField', offset=179, default=<OverTravel.UNKNOWN: 0>)
receiver_group_elevation = ReceiverGroupElevationField(name='receiver_group_elevation', value_type='Int32', offset=41, default=0)
sample_interval = SampleIntervalField(name='sample_interval', value_type='Int16', offset=117, default=0)
second_of_minute = SecondOfMinuteField(name='second_of_minute', value_type='SecondOfMinute', offset=165, default=0)
source_depth_below_surface = SourceDepthBelowSurfaceField(name='source_depth_below_surface', value_type='NNInt32', offset=49, default=0)
source_static_correction = SourceStaticCorrectionField(name='source_static_correction', value_type='Int16', offset=99, default=0)
source_x = SourceXField(name='source_x', value_type='Int32', offset=73, default=0)
source_y = SourceYField(name='source_y', value_type='Int32', offset=77, default=0)
subweathering_velocity = SubweatheringVelocityField(name='subweathering_velocity', value_type='NNInt16', offset=93, default=0)
surface_elevation_at_source = SurfaceElevationAtSourceField(name='surface_elevation_at_source', value_type='Int32', offset=45, default=0)
sweep_frequency_at_end = SweepFrequencyAtEndField(name='sweep_frequency_at_end', value_type='NNInt16', offset=129, default=0)
sweep_frequency_at_start = SweepFrequencyAtStartField(name='sweep_frequency_at_start', value_type='NNInt16', offset=127, default=0)
sweep_length = SweepLengthField(name='sweep_length', value_type='NNInt16', offset=131, default=0)
sweep_trace_taper_length_at_end = SweepTraceTaperLengthAtEndField(name='sweep_trace_taper_length_at_end', value_type='NNInt16', offset=137, default=0)
sweep_trace_taper_length_at_start = SweepTraceTaperLengthAtStartField(name='sweep_trace_taper_length_at_start', value_type='NNInt16', offset=135, default=0)
sweep_type = SweepTypeField(name='sweep_type', value_type='SweepTypeField', offset=133, default=<SweepType.UNKNOWN: 0>)
taper_type = TaperTypeField(name='taper_type', value_type='TaperTypeField', offset=139, default=<TaperType.UNKNOWN: 0>)
time_basis_code = TimeBasisCodeField(name='time_basis_code', value_type='TimeBasisCodeField', offset=167, default=<TimeBasisCode.UNKNOWN: 0>)
total_static = TotalStaticField(name='total_static', value_type='Int16', offset=103, default=0)
trace_identification_code = TraceIdentificationCodeField(name='trace_identification_code', value_type='Int16', offset=29, default=0)
trace_num = TraceNumField(name='trace_num', value_type='Int32', offset=13, default=0)
trace_weighting_factor = TraceWeightingFactorField(name='trace_weighting_factor', value_type='NNInt16', offset=169, default=0)
uphole_time_at_group = UpholeTimeAtGroupField(name='uphole_time_at_group', value_type='NNInt16', offset=97, default=0)
uphole_time_at_source = UpholeTimeAtSourceField(name='uphole_time_at_source', value_type='NNInt16', offset=95, default=0)
water_depth_at_group = WaterDepthAtGroupField(name='water_depth_at_group', value_type='Int32', offset=65, default=0)
water_depth_at_source = WaterDepthAtSourceField(name='water_depth_at_source', value_type='Int32', offset=61, default=0)
weathering_velocity = WeatheringVelocityField(name='weathering_velocity', value_type='NNInt16', offset=91, default=0)
xy_scalar = XyScalarField(name='xy_scalar', value_type='ScalarFactorField', offset=71, default=<ScalarFactor.POS_1: 1>)
year_recorded = YearRecordedField(name='year_recorded', value_type='Int16', offset=157, default=0)
class segpy.trace_header.TraceHeaderRev1(*args, **kwargs)

Bases: segpy.trace_header.TraceHeaderRev0

cdp_x = CdpXField(name='cdp_x', value_type='Int32', offset=181, default=0)
cdp_y = CdpYField(name='cdp_y', value_type='Int32', offset=185, default=0)
crossline_number = CrosslineNumberField(name='crossline_number', value_type='Int32', offset=193, default=0)
device_trace_identifier = DeviceTraceIdentifierField(name='device_trace_identifier', value_type='Int16', offset=213, default=0)
inline_number = InlineNumberField(name='inline_number', value_type='Int32', offset=189, default=0)
shotpoint_number = ShotpointNumberField(name='shotpoint_number', value_type='Int32', offset=197, default=0)
shotpoint_scalar = ShotpointScalarField(name='shotpoint_scalar', value_type='Int16', offset=201, default=0)
source_energy_direction = SourceEnergyDirectionField(name='source_energy_direction', value_type='Int32', offset=219, default=0)
source_measurement_exponent = SourceMeasurementExponentField(name='source_measurement_exponent', value_type='Int16', offset=229, default=0)
source_measurement_mantissa = SourceMeasurementMantissaField(name='source_measurement_mantissa', value_type='Int32', offset=225, default=0)
source_measurement_unit = SourceMeasurementUnitField(name='source_measurement_unit', value_type='SourceMeasurementUnitField', offset=231, default=<SourceMeasurementUnit.UNKNOWN: 0>)
source_type = SourceTypeField(name='source_type', value_type='SourceTypeField', offset=217, default=0)
time_scalar = TimeScalarField(name='time_scalar', value_type='ScalarFactorField', offset=215, default=<ScalarFactor.UNKNOWN: 0>)
trace_unit = TraceUnitField(name='trace_unit', value_type='SampleUnitField', offset=203, default=<SampleUnit.UNKNOWN: 0>)
transduction_constant_exponent = TransductionConstantExponentField(name='transduction_constant_exponent', value_type='Int16', offset=209, default=0)
transduction_constant_mantissa = TransductionConstantMantissaField(name='transduction_constant_mantissa', value_type='Int32', offset=205, default=0)
transduction_units = TransductionUnitsField(name='transduction_units', value_type='SampleUnitField', offset=211, default=<SampleUnit.UNKNOWN: 0>)
segpy.util module
class segpy.util.SortSense

Bases: enum.Enum

An enumeration.

ascending = 0
descending = 1
segpy.util.all_equal(iterable)

Returns True if all the elements are equal to each other

segpy.util.almost_equal(x, y, epsilon=2.220446049250313e-16)
segpy.util.batched(iterable, batch_size, padding=<object object>)

Batch an iterable series into equal sized batches.

Parameters:
  • iterable – The series to be batched.
  • batch_size – The size of the batch. Must be at least one.
  • padding – Optional value used to pad the final batch to batch_size. If omitted, the final batch may be smaller than batch_size.
Returns:

A series of lists, each containing batch_size items from iterable.

Raises:

ValueError - If batch_size is less than one.

segpy.util.cmp(x, y)

Compare the two objects x and y and return an integer according to the outcome.

Parameters:
  • x – The first number to compare.
  • y – The second number to compare.
Returns:

A negative value if x < y, zero if x == y and positive if x > y.

segpy.util.collect_attributes(derived_class, base_class, predicate)
Returns:A generator of items containing the (class, attribute_name)
segpy.util.complementary_intervals(intervals, start=None, stop=None)

Compute a complementary set of intervals which alternate with given intervals to form a contiguous range.

Given,

Start Stop
[—–) [—–) [—-)

produces,

[–) [—-) [-) [—)
Parameters:
  • intervals – An sequence of at least one existing slices or ranges. The type of the first interval (slice or range) is used as the result type.
  • start – An optional start index, defaults to the start of the first slice.
  • stop – An optional one-beyond-the-end index, defaults to the stop attribute of the last slice.
Returns:

A complementary series of slices which alternate with the supplied slices. The number of returned slices will always be len(slices) + 1 since both leading and trailing slices will always be returned. Note the some of the returned slices may be ‘empty’ (having zero length).

segpy.util.compress_sorted_sequence_to_range(sorted_sequence)

Attempt to represent the supplied sequence as a range.

Useful for reducing the size of large stored integer sequences.

Parameters:sorted_sequence – A sequence of integers which may be ordered in an ascending or descending sense.
Returns:An ordered sequence which may be a range or may be the unaltered argument.
segpy.util.contains_duplicates(sorted_iterable)

Determine if an iterable series contains duplicates.

Parameters:sorted_iterable – Any iterable series which must be sorted in either ascending or descending order.
Returns:True if sorted_iterable contains duplicates, otherwise False.
segpy.util.file_length(fh)

Determine the length of a file-like object in bytes.

Parameters:fh – A seekable file-like-object.
Returns:An integer length in bytes.
segpy.util.filename_from_handle(fh)

Determine the name of the file underlying a file-like object.

Parameters:fh – A file-like object.
Returns:A string containing the file name, or UNKNOWN_FILENAME if it could not be determined.
segpy.util.first(iterable)
segpy.util.first_sentence(s)
segpy.util.four_bytes(byte_str)
segpy.util.hash_for_file(fh, *args)

Compute the SHA1 hash for file combined with any stringified additional args.

The resulting hash is based on both the contents and length of the supplied file- like object.

Parameters:
  • fh – A file-like object opened in binary mode.
  • *args – The stringified values of ny additional arguments with be combined with the file data used to compute the hash.
Returns:

A string containing the hexadecimal digest.

segpy.util.identity(x)
segpy.util.intervals_are_contiguous(intervals)

Determine whether a series of intervals are contiguous.

Parameters:intervals – An iterable series of intervals where each interval is either a range or slice object.
Returns:True if the intervals are in order, contiguous and non-overlapping, otherwise False.
segpy.util.intervals_partially_overlap(interval_a, interval_b)

Determine whether two intervals partially overlap.

Parameters:
  • interval_a – A range or slice object.
  • interval_b – A range or slice object.
Returns:

True if interval_a partially overlaps interval_b, otherwise False if the intervals are either disjoint or exactly coincident.

segpy.util.is_magic_name(name)
segpy.util.is_sorted(iterable, key=None, reverse=False, distinct=False)
segpy.util.last(iterable)
segpy.util.lower_first(s)

Lower case the first character of a string.

segpy.util.make_sorted_distinct_sequence(iterable, sense=<SortSense.ascending: 0>)

Create a sorted immutable sequence from an iterable series.

The resulting collected will be sorted ascending.

Parameters:
  • iterable – An iterable series of comparable values.
  • sense – If None, the any original sense of the data is preserved, so ascending data remains ascending, and descending data remains descending. If the original data was unsorted, the result will be ascending. Force a particular sense by specifying SortSense.ascending or SortSense.descending.
Returns:

An immutable collection which supports the Sized, Iterable, Container and Sequence protocols.

segpy.util.measure_stride(iterable)

Determine whether successive numeric items differ by a constant amount.

Parameters:iterable – An iterable series of numeric values.
Returns:The difference between successive values (e.g. item[1] - item[0]) if that difference is the same between all successive pairs, otherwise None.
segpy.util.minmax(iterable)

Return the minimum and maximum of an iterable series.

This function requires only a single pass over the data.

Parameters:iterable – An iterable series for which to determine the minimum and maximum values.
Returns:A 2-tuple containing the minimum and maximum values.
segpy.util.now_millis()
segpy.util.pad(iterable, padding=None, size=None)
segpy.util.pairwise(iterable)
segpy.util.restored_position_seek(fh, pos)
segpy.util.reversed_range(r)

Given a range object produce the reversed range.

Parameters:r – A range object.
Returns:The reversed range.
segpy.util.round_up(integer, multiple)

Round up to the nearest multiple

segpy.util.roundrobin(*iterables)

Take items from each iterable in turn until all iterables are exhausted.

roundrobin(‘ABC’, ‘D’, ‘EF’) –> A D E B F C

segpy.util.sgn(x)

The sign of a number.

Parameters:x – The number for which to compute the sign.
Returns:+1 is x is positive, -1 if x is negative, 0 if x is zero.
segpy.util.single_item_range(item)

Construct a range object which generates a single value.

segpy.util.super_class(cls)

Return the next class in the MRO of cls, or object.

segpy.util.underscores_to_camelcase(s)

Convert text_in_this_style to TextInThisStyle.

segpy.writer module
Module contents

Change History

Indices and tables