pygplates.GmlDataBlock

class pygplates.GmlDataBlock

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.

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)
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.