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.