pymt.framework package

Submodules

pymt.framework.bmi_bridge module

pymt.framework.bmi_docstring module

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_metadata module

Incorporate CSDMS Model Metadata into PyMT.

PyMT uses the CSDMS model_metadata package, to incorporate CSDMS Model Metadata into BMI-enabled components when they are imported into PyMT. This ensures that:

  • Idenitying model information stays with the component as it appears within the CSDMS Modeling Framework. This ensures that the original author of the model is given appropriate credit and not forgotten in the wrapping of their model. In addition, a citation(s) is clearly displayed for the model. This ensures that a user running the model, either through PyMT or otherwise, will properly cite the original work that describes to model when publishing results that use the model.
  • Model input parameters are properly validated and model input files are properly constructed when preparing a model simulation.
exception pymt.framework.bmi_metadata.MetadataNotFoundError(path_to_metadata)[source]

Bases: Exception

pymt.framework.bmi_metadata.bmi_data_dir(name)[source]

Get a component’s data dir.

Parameters:name (str) – The name of the component.
Returns:The absolute path to the data directory for the component.
Return type:str
pymt.framework.bmi_metadata.find_model_metadata(plugin)[source]

Find the path to a plugin’s metadata.

Parameters:plugin (PyMT plugin) – A PyMT plugin object.
Returns:Path to the folder that contains the plugin’s metadata.
Return type:str

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

author
cite_as
contact
datadir
defaults
doi
email
license
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
summary
url
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

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

Value to use when interpolating values outside of the data.

interpolate(time)[source]

Interpolate the data at a given time.

maxsize

The maximum number of times to be stored.

method

The method used for interpolating time.

Module contents