ugants package#
UG-ANTS: A library for generating ancillary files targeting unstructured grids.
Subpackages#
- ugants.analysis package
- ugants.filter package
- ugants.io package
- Submodules
- ugants.io.applications module
- ugants.io.load module
- ugants.io.save module
- ugants.io.xios_command_line module
ConvertToXIOSConvertToXIOS.__init__()ConvertToXIOS.sourcesConvertToXIOS.cast_to_singleConvertToXIOS.resultsConvertToXIOS.outputConvertToXIOS.run()ConvertToXIOS.apply_long_name_workaround()ConvertToXIOS.apply_online_operation_workaround()ConvertToXIOS.apply_dimension_order_workaround()ConvertToXIOS.get_fill_values()ConvertToXIOS.save()
reorder_cube_dimensions()cast_to_single_precision()
- ugants.mask package
- ugants.regrid package
- ugants.utils package
Submodules#
ugants.abc module#
Abstract base classes for UG-ANTS.
- class ugants.abc.Application(*args, **kwargs)[source]#
Bases:
ABCAbstract base class for creating UG-ANTS applications.
The
Applicationbase class provides a common interface for writing applications for generating unstructured grid ancillaries, providing functionality common to most applications:A standardised command line interface is automatically generated from the application signature
Load and save methods are provided by the base class. These are intended to provide a sensible default, but can be overridden in specific applications if necessary.
The
__init__()andrun()methods must be provided when subclassingApplication. See the documentation for these methods for more detail.- results: CubeList = None#
A
CubeListcontaining the results from running the application. This attribute is set when therun()method is called.
- output: str = None#
Filepath to which the
resultswill be written upon callingsave(). If the application has been instantiated using thefrom_command_line()method, then this attribute will be set to theoutputcommand line argument.
- abstract __init__(*args, **kwargs)[source]#
Initialise an instance of the class.
Subclasses of
Applicationmust provide an__init__method.The
__init__must be appropriately type hinted in order for the command line argument parser to be constructed correctly.For example:
from iris.cube import CubeList class ApplicationClass: def __init__(self, source: CubeList, scheme: str, number: int = 0): self.source = source self.scheme = scheme self.number = number
See also
from_command_line()for more information about how the type hints are used to construct the command line argument parser.
- abstract run()[source]#
Run the application.
Subclasses of
ugants.abc.Applicationmust provide arunmethod.This method should make use of the inputs specified in the
__init__()method, and assign the resultsCubeListtoresults.
- save()[source]#
Save results to UGrid netcdf.
Saves the
resultsto the file location specfied byoutput.outputshould have been set from the command line, if the application instance has been created using thefrom_command_line()method, or by explicitly settingoutputon the application instance.
- Raises:
ValueError – If no output file location is specified at
output.ValueError – If no results are specified at
results.
- classmethod from_command_line(args: Sequence[str] | None = None)[source]#
Create an application instance from the command line.
The parameter names and type hints from the
__init__method are used to construct a command line argument parser. The command line arguments are then parsed and passed to the__init__method to create an instance of the class. Anoutputcommand line argument is also added, which is mapped to theoutputattribute when instantiating an application via thefrom_command_line()method.- Returns:
An instance of the class initialised with the command line arguments.
Notes
Some parameter type hints have special effects on how the parser is constructed and the class instantiated:
Type hint
Interpretation
Add a command line positional argument representing the path to the UGrid data to be loaded. The loaded data will be passed to the
__init__method to create an instance of the class. For example,source_data: CubeListadds a positional command line argumentsource_data.Add command line arguments representing the path to the mesh file to be loaded and the name of the mesh to extract. The loaded mesh will be passed to the
__init__method to create an instance of the class. For example,target_mesh: Meshadds two command line arguments:--target-mesh(the path to the mesh file) and--target-mesh-name(the name of the mesh to extract).Add a command line argument with a limited set of choices. For example,
regrid_scheme: Literal["conservative", "bilinear"]adds a command line argument--regrid-schemewith choices{conservative, bilinear}.Add a command line flag that stores True if provided, or False if not provided. For example,
a_flag: booladds a command line flag--a-flagwhich setsa_flagto True if provided, or False if not provided.Parameter with default argument
Add an optional command line argument with a default value. For example,
number: int = 0adds an optional command line argument--numberwith default value0.
ugants.exceptions module#
Exceptions specific to UG-ANTS.
- exception ugants.exceptions.ProvisionalWarning[source]#
Bases:
UserWarningA warning to inform users that results are provisional.