pymt.portprinter package

Submodules

pymt.portprinter.port_printer module

class pymt.portprinter.port_printer.NcPortPrinter(port, var_name, filename=None)[source]

Bases: PortPrinter

class pymt.portprinter.port_printer.PortPrinter(port, var_name, filename=None)[source]

Bases: object

close()[source]
property format
classmethod from_dict(d)[source]
classmethod from_path(path, prefix='print')[source]
classmethod from_string(source, prefix='print')[source]
open(clobber=False)[source]
resync_field_to_port()[source]
property var_name
write()[source]

pymt.portprinter.utils module

exception pymt.portprinter.utils.BadFileFormatError(fmt)[source]

Bases: Error

exception pymt.portprinter.utils.DimensionError(msg)[source]

Bases: Error

exception pymt.portprinter.utils.Error[source]

Bases: Exception

pymt.portprinter.utils.construct_file_name(var_name, template='${var}', fmt=None, prefix='')[source]
pymt.portprinter.utils.construct_port_as_field(port, var_name)[source]

Create a field object from a port.

Parameters:
  • port (port_like) – A port.

  • var_name (str) – Name of the variable field.

Returns:

A newly created field that contains the data for var_name.

Return type:

field_like

pymt.portprinter.utils.data_is_centered_on_cells(field, data)[source]
pymt.portprinter.utils.data_is_centered_on_points(field, data)[source]
pymt.portprinter.utils.find_unknown_dimension(shape)[source]

Find unlimited dimensions.

If a dimension is negative, it’s thought to be unknown or unlimited Find that dimension. Raise an error if there are multiple unknown dimensions.

Parameters:

shape (ndarray of int) – Array shape.

Returns:

Dimension that is unknown or None if all dimensions are known.

Return type:

int

Raises:

DimensionError – There are multiple unknown dimensions.

pymt.portprinter.utils.fix_unknown_shape(shape, size)[source]

Determine shape with an unknown dimension.

Parameters:
  • shape (ndarray of int) – Array shape (with a possible unknown dimension).

  • size (int) – Sive of the array.

Returns:

Shape of the array with any unknown dimension fixed.

Return type:

tuple of int

Examples

>>> from pymt.portprinter.utils import fix_unknown_shape
>>> fix_unknown_shape((4, 3), 12)
(4, 3)
>>> fix_unknown_shape((4, -1), 12)
(4, 3)
pymt.portprinter.utils.format_to_file_extension(fmt)[source]
pymt.portprinter.utils.get_data_centering(field, data_array)[source]
pymt.portprinter.utils.is_rectilinear_port(port, grid_id)[source]
pymt.portprinter.utils.is_structured_port(port, grid_id)[source]
pymt.portprinter.utils.mesh_size_has_changed(field, data)[source]
pymt.portprinter.utils.next_unique_file_name(file_name)[source]
pymt.portprinter.utils.normalize_format_name(fmt)[source]
pymt.portprinter.utils.port_is_one_point(port, grid_id)[source]
pymt.portprinter.utils.positive_dimensions(shape)[source]

Check if all dimensions are positive.

Parameters:

shape (ndarray of int) – Array shape.

Returns:

True if dimensions are positive non-zero. Otherwise, False.

Return type:

boolean

pymt.portprinter.utils.reconstruct_port_as_field(port, field)[source]

Recreate a field object from a port.

Add data from port to field. If the mesh of the port is no longer the same as that of field, create a new field object and add the data to it. Where possible, the new data is added to the existing field. Only the data that does not fit on the existing field is added to the new one.

Parameters:
  • port (port_like) – A port.

  • field (field_like) – An existing field with new data.

Returns:

A (possibley) newly created field that contains the data for var_name.

Return type:

field_like

Module contents