pymt.framework package

Submodules

pymt.framework.bmi_bridge module

Bridge between BMI and a PyMT component.

class pymt.framework.bmi_bridge.BmiCap[source]

Bases: GridMapperMixIn, _BmiCap, BmiTimeInterpolator, SetupMixIn

class pymt.framework.bmi_bridge.DataValues(bmi, name)[source]

Bases: object

property data
property grid
property intent
property location
property name
property size
property type
property units
values(**kwds)[source]
class pymt.framework.bmi_bridge.DeprecatedMethods[source]

Bases: object

get_grid_dim(grid, dim)[source]
get_grid_face_node_connectivity(grid, out=None)[source]
get_grid_face_node_offset(grid, out=None)[source]
get_grid_face_nodes(grid, out=None)[source]
get_grid_ndim(grid)[source]
get_grid_nodes_per_face(grid, out=None)[source]
get_grid_number_of_edges(grid)[source]
get_grid_number_of_faces(grid)[source]
get_grid_number_of_nodes(grid)[source]
get_grid_number_of_vertices(grid)[source]
get_grid_origin(grid, out=None)[source]
get_grid_rank(grid)[source]
get_grid_shape(grid, out=None)[source]
get_grid_size(grid)[source]
get_grid_spacing(grid, out=None)[source]
get_grid_type(grid)[source]
get_grid_x(grid, out=None)[source]
get_grid_y(grid, out=None)[source]
get_grid_z(grid, out=None)[source]
get_var_grid(name)[source]
get_var_grid_loc(name)[source]
get_var_intent(name)[source]
get_var_itemsize(name)[source]
get_var_location(name)[source]
get_var_nbytes(name)[source]
get_var_type(name)[source]
get_var_units(name)[source]
pymt.framework.bmi_bridge.bmi_factory(cls)[source]

pymt.framework.bmi_docstring module

pymt.framework.bmi_docstring.bmi_docstring(plugin, author=None, version=None, license=None, doi=None, url=None, parameters=None, summary=None, cite_as=None, email=None)[source]

Build the docstring for a BMI model.

Parameters:
  • name (str) – Name of a BMI component.

  • author (str, optional) – Name of author or authors.

  • version (str, optional) – Version string for the component.

  • license (str, optional) – Name of the license of the component.

  • doi (str, optional) – A DOI for the component.

  • url (str, optional) – URL of the component’s location on the internet.

  • parameters (iterable, optional) – List of input parameters for the component. Each parameter object must have attributes for name, type, value, units, and desc.

  • cite_as (iterable of str, optional) – List of citations for this component.

  • email (str, optional) – Contact email address.

Returns:

The docstring.

Return type:

str

Examples

>>> from pymt.framework.bmi_docstring import bmi_docstring
>>> print(bmi_docstring('Model', author='Walt Disney')) 
Basic Model Interface for Model.
...

pymt.framework.bmi_mapper module

class pymt.framework.bmi_mapper.GridMapperMixIn[source]

Bases: object

map_to(name, **kwds)[source]

Map values to another grid.

Parameters:

name (str) – Name of values to push.

map_value(name, **kwds)[source]

Map values from another grid.

Parameters:
  • name (str) – Name of values to map to.

  • mapfrom (tuple or bmi_like, optional) – BMI object from which values are mapped from. This can also be a tuple of (name, bmi), where name is the variable of the source grid and bmi is the bmi-like source. If not provided, use self.

  • nomap (narray of bool, optional) – Values in the destination grid to not map.

regrid(name, **kwds)[source]

Regrid values from one grid to another.

Parameters:
  • name (str) – Name of the values to regrid.

  • to (bmi_like, optional) – BMI object onto which to map values. If not provided, map values onto one of the object’s own grids.

  • to_name (str, optional) – Name of the value to map onto. If not provided, use name.

Returns:

The regridded values.

Return type:

ndarray

set_value(name, *args, **kwds)[source]

Set values for a variable. set_value(name, value) set_value(name, mapfrom=self, nomap=None)

Parameters:

name (str) – Name of the destination values.

pymt.framework.bmi_mapper.as_esmf_field(mesh, field_name, data=None, at='node')[source]
pymt.framework.bmi_mapper.as_esmf_mesh(xy_of_node, nodes_at_patch=None, nodes_per_patch=None)[source]
pymt.framework.bmi_mapper.bmi_as_esmf_mesh(bmi_grid)[source]
pymt.framework.bmi_mapper.graph_as_esmf(graph, field_name, data=None, at='node')[source]
pymt.framework.bmi_mapper.ravel_jaggedarray(array)[source]
pymt.framework.bmi_mapper.run_regridding(source_field, destination_field, method=ESMP_REGRIDMETHOD_CONSERVE, unmapped=ESMP_UNMAPPEDACTION_ERROR)[source]
PRECONDITIONS:

Two ESMP_Fields have been created and a regridding operation is desired from ‘srcfield’ to ‘dstfield’.

POSTCONDITIONS:

An ESMP regridding operation has set the data on ‘dstfield’.

pymt.framework.bmi_plot module

pymt.framework.bmi_plot.quick_plot(bmi, name, **kwds)[source]

pymt.framework.bmi_setup module

class pymt.framework.bmi_setup.GitHubSetupMixIn[source]

Bases: object

setup(case='default', name=None, path=None)[source]
class pymt.framework.bmi_setup.SetupMixIn[source]

Bases: object

property author
property cite_as
property contact
property datadir
property defaults
property doi
property email
property license
property parameters
setup(*args, **kwds)[source]

Set up a simulation.

Parameters:

path (str, optional) – Path to a folder to set up the simulation. If not given, use a temporary folder.

Returns:

Path to the folder that contains the set up simulation.

Return type:

str

property summary
property url
property version
pymt.framework.bmi_setup.fetch_input(name, path=None)[source]

Fetch input for a BMI component.

Parameters:
  • name (str) – Component name.

  • path (str, optional) – Directory to extract into.

Returns:

Path to input files for various cases.

Return type:

str

pymt.framework.bmi_setup.get_initialize_arg(dir_)[source]

Get the BMI initialize argument for a set of input files.

Parameters:

dir (str) – Path to a folder that contains input files.

Returns:

Argument that can be passed to a BMI initialize method.

Return type:

str

pymt.framework.bmi_setup.url_to_input_file_repo(name)[source]

URL to a repo of input files for a component.

Parameters:

name (str) – Component name.

Returns:

URL of input-file repository.

Return type:

str

pymt.framework.bmi_setup.url_to_input_file_zip(name)[source]

URL of zip file on input files.

Parameters:

name (str) – Component name.

Returns:

URL of zip file of input files.

Return type:

str

pymt.framework.bmi_timeinterp module

class pymt.framework.bmi_timeinterp.BmiTimeInterpolator(*args, **kwds)[source]

Bases: object

add_data()[source]
interpolate(name, at)[source]
reset(method='linear')[source]
update_until(then, method=None, units=None)[source]

pymt.framework.bmi_ugrid module

class pymt.framework.bmi_ugrid.Points(*args)[source]

Bases: _Base

class pymt.framework.bmi_ugrid.Rectilinear(*args)[source]

Bases: _Base

class pymt.framework.bmi_ugrid.Scalar(*args)[source]

Bases: _Base

class pymt.framework.bmi_ugrid.StructuredQuadrilateral(*args)[source]

Bases: _Base

class pymt.framework.bmi_ugrid.UniformRectilinear(*args)[source]

Bases: _Base

class pymt.framework.bmi_ugrid.Unstructured(*args)[source]

Bases: _Base

class pymt.framework.bmi_ugrid.Vector(*args)[source]

Bases: _Base

pymt.framework.bmi_ugrid.coordinate_names(rank)[source]
pymt.framework.bmi_ugrid.dataset_from_bmi_grid(bmi, grid_id)[source]
pymt.framework.bmi_ugrid.index_names(rank)[source]

pymt.framework.services module

Access to framework services.

pymt.framework.services.del_component_instance(name)[source]

Remove an instance by name.

Parameters:

name (str) – Component instance.

pymt.framework.services.del_component_instances(names)[source]

Remove a list of instances by name.

Parameters:

names (list) – Component instance names.

pymt.framework.services.del_services()[source]
pymt.framework.services.get_component_class(name)[source]

Get a registered component class by name.

Parameters:

name (str) – Name of the registered class.

Returns:

The registered class.

Return type:

class

Raises:

KeyError – If the name is not registered with the framework.

pymt.framework.services.get_component_instance(name)[source]

Get a registered instance from the framework.

Parameters:

name (str) – Name of the registered instance.

Returns:

The registered instance.

Return type:

object

Raises:

KeyError – If name is not registered with the framework.

pymt.framework.services.get_component_instance_names()[source]

Names of all instances.

Returns:

Names of all the instanciated components.

Return type:

list

pymt.framework.services.instantiate_component(cls_name, instance_name)[source]

Instantiate a registered component class.

Instantiate a registered class and register that instance with the framework as instance_name.

Parameters:
  • cls_name (str) – Name of the registered class.

  • instance_name (str) – Name of the new instance.

Returns:

An instance of the registered class.

Return type:

object

Examples

>>> from pymt.framework.services import (
...     del_services,
...     register_component_class,
...     instantiate_component,
...     get_component_instance
... )
>>> del_services()
>>> register_component_class('pymt.testing.services.AirPort')
>>> air_port = instantiate_component('AirPort', 'air_port')
>>> air_port is get_component_instance('air_port')
True
pymt.framework.services.register_component_class(name, if_exists='raise')[source]

Register a component with the framework.

Add the component class, name, to the list of framework services. The component name should be the fully-qualified name of a Python class.

Parameters:
  • name (str) – Name of component to register.

  • if_exists ({'raise', 'warn', 'pass', 'clobber'}, optional) – What to do if the class is already registered.

Raises:
  • ValueError – If the class is already registered with the framework.

  • ImportError – If there is a problem importing any part of name.

Notes

This function will try to import name as though it were a fully-qualified name of a Python class. That is, if name were foo.bar.Baz, try the following:

from foo.bar import Baz

Examples

>>> from pymt.framework.services import (
...     del_services,
...     register_component_class,
...     get_component_class
... )
>>> del_services()
>>> register_component_class('pymt.testing.services.AirPort')
>>> get_component_class('AirPort')
<class 'pymt.testing.services.AirPort'>

Raise an ImportError if the component class could not be loaded.

>>> register_component_class('pymt.testing.services.NotAClass') # doctest : +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ImportError: cannot import component NotAClass from pymt.testing.services
>>> register_component_class('pymt.not.a.module.AirPort') # doctest : +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
ValueError: component class exists (AirPort)
pymt.framework.services.register_component_classes(components, **kwds)[source]

Register a list of components with the framework.

Parameters:
  • components (list) – Component names to register.

  • if_exists ({'raise', 'warn', 'pass', 'clobber'}, optional) – What to do if the class is already registered.

See also

register_component_class()

Register just a single component.

pymt.framework.services.register_component_instance(name, instance)[source]

Register a component instance with the framework.

Parameters:
  • name (str) – Name of the component instance.

  • instance (object) – Component instance.

Raises:

ValueError – If name is already registered with the framework.

Examples

>>> from pymt.framework.services import (
...     del_services,
...     register_component_class,
...     get_component_instance
... )
>>> del_services()
>>> from pymt.testing.services import AirPort
>>> air_port = AirPort()
>>> register_component_instance('air_port', air_port)
>>> air_port is get_component_instance('air_port')
True

pymt.framework.timeinterp module

class pymt.framework.timeinterp.TimeInterpolator(data=(), method='linear', fill_value='extrapolate', maxsize=None)[source]

Bases: object

METHODS = ('linear', 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'previous', 'next')
__call__(time)[source]

Interpolate the data at a given time.

__init__(data=(), method='linear', fill_value='extrapolate', maxsize=None)[source]

Interpolate data based on an evolving time series of data values.

Parameters:
  • data (iterable of (time, data), optional) – The data to use for the interpolation as an iterable of (time, data). data can either be scalars or numpy arrays.

  • method (str, optional) – The interpolation method to use.

  • fill_value (str or float, optional) – The value to use if trying to interpolate values that are outside the stored times. The default is to extrapolate to the given time.

  • maxsize (int, optional) – The maximum size of the buffer that holds the interpolation times. When the buffer reaches this size, the oldest times will be popped off a the stack.

add_data(time_and_data)[source]

Add new data points to the interpolator.

Parameters:
  • time (float or iterable of float) – Time values

  • data (float or iterable) – Data values to interpolate.

property fill_value

Value to use when interpolating values outside of the data.

interpolate(time)[source]

Interpolate the data at a given time.

property maxsize

The maximum number of times to be stored.

property method

The method used for interpolating time.

Module contents