pygplates.GmlDataBlock

class pygplates.GmlDataBlock(scalar_type_to_values_mapping)

Bases: pygplates.PropertyValue

A data block that associates each scalar type with a sequence of floating-point scalar values.

This is typically used to store one or more scalar values for each point in a geometry where each scalar value (stored at a point) has a different scalar type.

The following operations are supported:

Operation Result
len(d) number of scalar types in the data block d
for s in d iterates over the scalar type s in data block d
s in d True if s is a scalar type in data block d
s not in d False if s is a scalar type in data block d

For example:

for scalar_type in data_block:
    scalar_values = data_block.get_scalar_values(scalar_type)

The following methods support getting, setting and removing scalar values in a data block:

__init__(scalar_type_to_values_mapping)

Create a data block containing one or more scalar types and their associated scalar values.

Parameters:scalar_type_to_values_mapping (dict mapping each ScalarType to a sequence of float, or a sequence of (ScalarType, sequence of float) tuples) – maps each scalar type to a sequence of scalar values
Raises:ValueError if scalar_type_to_values_mapping is empty, or if each scalar type is not mapped to the same number of scalar values.

To create gpml:VelocityColat and gpml:VelocityLon scalar values:

data_block = pygplates.GmlDataBlock(
    [
        (pygplates.ScalarType.create_gpml('VelocityColat'), [-1.5, -1.6, -1.55]),
        (pygplates.ScalarType.create_gpml('VelocityLon'), [0.36, 0.37, 0.376])])

To do the same thing using a dict:

data_block = pygplates.GmlDataBlock(
    {
        pygplates.ScalarType.create_gpml('VelocityColat') : [-1.5, -1.6, -1.55],
        pygplates.ScalarType.create_gpml('VelocityLon') : [0.36, 0.37, 0.376]})

Methods

__init__(scalar_type_to_values_mapping) Create a data block containing one or more scalar types and their associated scalar values.
accept_visitor(visitor) Accept a property value visitor so that it can visit this property value.
clone() Create a duplicate of this property value (derived) instance, including a recursive copy of any nested property values that this instance might contain.
get_geometry() Extracts the geometry if this property value contains a geometry.
get_scalar_values(scalar_type) Returns the list of scalar values associated with a scalar type.
get_value([time=0]) Extracts the value, of this possibly time-dependent property value, at the reconstruction time.
remove(scalar_type) Removes the list of scalar values associated with a scalar type.
set(scalar_type, scalar_values) Sets the scalar values of the data block associated with a scalar type.
accept_visitor(visitor)

Accept a property value visitor so that it can visit this property value. As part of the visitor pattern, this enables the visitor instance to discover the derived class type of this property. Note that there is no common interface shared by all property value types, hence the visitor pattern provides one way to find out which type of property value is being visited.

Parameters:visitor (PropertyValueVisitor) – the visitor instance visiting this property value
clone()

Create a duplicate of this property value (derived) instance, including a recursive copy of any nested property values that this instance might contain.

Return type:PropertyValue
get_geometry()

Extracts the geometry if this property value contains a geometry.

Return type:GeometryOnSphere or None

This function searches for a geometry in the following standard geometry property value types:

If this property value does not contain a geometry then None is returned.

Time-dependent geometry properties are not yet supported, so the only time-dependent property value wrapper currently supported by this function is GpmlConstantValue.

To extract geometry from a specific feature property:

property_value = feature.get_value(pygplates.PropertyName.gpml_pole_position)
if property_value:
    geometry = property_value.get_geometry()

...however Feature.get_geometry() provides an easier way to extract geometry from a feature with:

geometry = feature.get_geometry(pygplates.PropertyName.gpml_pole_position)

To extract all geometries from a feature (regardless of which properties they came from):

all_geometries = []
for property in feature:
    property_value = property.get_value()
    if property_value:
        geometry = property_value.get_geometry()
        if geometry:
            all_geometries.append(geometry)

...however again Feature.get_geometry() does this more easily with:

all_geometries = feature.get_geometry(lambda property: True, pygplates.PropertyReturn.all)
get_scalar_values(scalar_type)

Returns the list of scalar values associated with a scalar type.

Parameters:scalar_type (ScalarType) – the type of the scalars
Returns:the scalar values associated with scalar_type, otherwise None if scalar_type does not exist
Return type:list of float, or None

To test if a scalar type is present and retrieve its list of scalar values:

velocity_colat_scalar_type = pygplates.ScalarType.create_gpml('VelocityColat')
velocity_colat_scalar_values = data_block.get_scalar_values(velocity_colat_scalar_type)
if velocity_colat_scalar_values:
    for scalar_value in velocity_colat_scalar_values:
        ...
# ...or a less efficient approach...
if velocity_colat_scalar_type in data_block:
    velocity_colat_scalar_values = data_block.get_scalar_values(velocity_colat_scalar_type)
get_value([time=0])

Extracts the value, of this possibly time-dependent property value, at the reconstruction time.

Parameters:time (float or GeoTimeInstant) – the time to extract value (defaults to present day)
Return type:PropertyValue or None

If this property value is a time-dependent property (GpmlConstantValue, GpmlIrregularSampling or GpmlPiecewiseAggregation) then a nested property value is extracted at the reconstruction time and returned. Otherwise this property value instance is simply returned as is (since it’s not a time-dependent property value).

Returns None if this property value is a time-dependent property (GpmlConstantValue, GpmlIrregularSampling or GpmlPiecewiseAggregation) and time is outside its time range (of time samples or time windows).

Note that if this property value is a GpmlIrregularSampling instance then the extracted property value is interpolated (at reconstruction time) if property value can be interpolated (currently only GpmlFiniteRotation and XsDouble), otherwise None is returned.

The following example demonstrates extracting an interpolated finite rotation from a total reconstruction pole at time 20Ma:

gpml_finite_rotation_20Ma = total_reconstruction_pole.get_value(20)
if gpml_finite_rotation_20Ma:
  print 'Interpolated finite rotation at 20Ma: %s' % gpml_finite_rotation_20Ma.get_finite_rotation()
remove(scalar_type)

Removes the list of scalar values associated with a scalar type.

Parameters:scalar_type (ScalarType) – the type of the scalars

To remove the scalar values associated with gpml:VelocityColat:

gml_data_block.remove(pygplates.ScalarType.create_gpml('VelocityColat'))

Note

If scalar_type does not exist in the data block then it is ignored and nothing is done.

set(scalar_type, scalar_values)

Sets the scalar values of the data block associated with a scalar type.

Parameters:
  • scalar_type (ScalarType) – the type of the scalars
  • scalar_values (sequence (eg, list or tuple) of float) – the scalar values associated with scalar_type
Raises:

ValueError if the length of scalar_values does not match the length of existing scalar values for other scalar types.

To set (or replace) the scalar values associated with gpml:VelocityColat:

gml_data_block.set(
    pygplates.ScalarType.create_gpml('VelocityColat'),
    [-1.5, -1.6, -1.55])

Note

If there is no list of scalar values associated with scalar_type then a new list is added, otherwise the existing list is replaced.

Previous topic

pygplates.Enumeration

Next topic

pygplates.GmlLineString

This Page