Source code for iris.exceptions

# Copyright Iris contributors
#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Exceptions specific to the Iris package."""


[docs]class IrisError(Exception): """Base class for errors in the Iris package.""" pass
[docs]class CoordinateCollapseError(IrisError): """Raised when a requested coordinate cannot be collapsed.""" pass
[docs]class CoordinateNotFoundError(KeyError): """Raised when a search yields no coordinates.""" pass
[docs]class CellMeasureNotFoundError(KeyError): """Raised when a search yields no cell measures.""" pass
[docs]class AncillaryVariableNotFoundError(KeyError): """Raised when a search yields no ancillary variables.""" pass
[docs]class ConnectivityNotFoundError(KeyError): """Raised when a search yields no connectivities.""" pass
[docs]class CoordinateMultiDimError(ValueError): """Raised when a routine doesn't support multi-dimensional coordinates.""" def __init__(self, msg): # N.B. deferred import to avoid a circular import dependency. import iris.coords if isinstance(msg, iris.coords.Coord): fmt = "Multi-dimensional coordinate not supported: '%s'" msg = fmt % msg.name() ValueError.__init__(self, msg)
[docs]class CoordinateNotRegularError(ValueError): """Raised when a coordinate is unexpectedly irregular.""" pass
[docs]class InvalidCubeError(IrisError): """Raised when a Cube validation check fails.""" pass
[docs]class ConstraintMismatchError(IrisError): """Raised when a constraint operation has failed to find the correct number of results.""" pass
[docs]class NotYetImplementedError(IrisError): """Raised by missing functionality. Different meaning to NotImplementedError, which is for abstract methods. """ pass
[docs]class TranslationError(IrisError): """Raised when Iris is unable to translate format-specific codes.""" pass
[docs]class IgnoreCubeException(IrisError): """Raised from a callback function when a cube should be ignored on load.""" pass
[docs]class ConcatenateError(IrisError): """Raised when concatenate is expected to produce a single cube, but fails to do so.""" def __init__(self, differences): """Create a ConcatenateError with a list of textual descriptions of differences. Create a ConcatenateError with a list of textual descriptions of the differences which prevented a concatenate. Parameters ---------- differences : list of str The list of strings which describe the differences. """ self.differences = differences def __str__(self): return "\n ".join( ["failed to concatenate into a single cube."] + list(self.differences) )
[docs]class MergeError(IrisError): """Raised when merge is expected to produce a single cube, but fails to do so.""" def __init__(self, differences): """Create a MergeError with a list of textual descriptions of the differences. Creates a MergeError with a list of textual descriptions of the differences which prevented a merge. Parameters ---------- differences : list of str The list of strings which describe the differences. """ self.differences = differences def __str__(self): return "\n ".join( ["failed to merge into a single cube."] + list(self.differences) )
[docs]class DuplicateDataError(MergeError): """Raised when merging two or more cubes that have identical metadata.""" def __init__(self, msg): self.differences = [msg]
[docs]class LazyAggregatorError(Exception): pass
[docs]class UnitConversionError(IrisError): """Raised when Iris is unable to convert a unit.""" pass
[docs]class CannotAddError(ValueError): """Raised when an object (e.g. coord) cannot be added to a :class:`~iris.cube.Cube`.""" pass
############################################################################### # WARNINGS # Please namespace all warning objects (i.e. prefix with Iris...).
[docs]class IrisUserWarning(UserWarning): r"""Base class for :class:`UserWarning` generated by Iris.""" pass
[docs]class IrisLoadWarning(IrisUserWarning): """Any warning relating to loading.""" pass
[docs]class IrisSaveWarning(IrisUserWarning): """Any warning relating to saving.""" pass
[docs]class IrisCfWarning(IrisUserWarning): """Any warning relating to :term:`CF Conventions` .""" pass
[docs]class IrisIgnoringWarning(IrisUserWarning): """Any warning that involves an Iris operation not using some information. E.g. :class:`~iris.aux_factory.AuxCoordFactory` generation disregarding bounds. """ pass
[docs]class IrisDefaultingWarning(IrisUserWarning): """Any warning that involves Iris changing invalid/missing information. E.g. creating a :class:`~iris.coords.AuxCoord` from an invalid :class:`~iris.coords.DimCoord` definition. """ pass
[docs]class IrisVagueMetadataWarning(IrisUserWarning): """Warnings where object metadata may not be fully descriptive.""" pass
[docs]class IrisUnsupportedPlottingWarning(IrisUserWarning): """Warnings where support for a plotting module/function is not guaranteed.""" pass
[docs]class IrisImpossibleUpdateWarning(IrisUserWarning): """Warnings where it is not possible to update an object. Mainly generated during regridding where the necessary information for updating an :class:`~iris.aux_factory.AuxCoordFactory` is no longer present. """ pass
[docs]class IrisGeometryExceedWarning(IrisUserWarning): """:mod:`iris.analysis.geometry` warnings about geometry exceeding dimensions.""" pass
[docs]class IrisMaskValueMatchWarning(IrisUserWarning): """Warnings where the value representing masked data is actually present in data.""" pass
########
[docs]class IrisCfLoadWarning(IrisCfWarning, IrisLoadWarning): """Any warning relating to both loading and :term:`CF Conventions` .""" pass
[docs]class IrisCfSaveWarning(IrisCfWarning, IrisSaveWarning): """Any warning relating to both saving and :term:`CF Conventions` .""" pass
[docs]class IrisCfInvalidCoordParamWarning(IrisCfLoadWarning): """Warnings where incorrect information for CF coord construction is in a file.""" pass
[docs]class IrisCfMissingVarWarning(IrisCfLoadWarning): """Warnings where a CF variable references another variable that is not in the file.""" pass
[docs]class IrisCfLabelVarWarning(IrisCfLoadWarning, IrisIgnoringWarning): """Warnings where a CF string/label variable is being used inappropriately.""" pass
[docs]class IrisCfNonSpanningVarWarning(IrisCfLoadWarning, IrisIgnoringWarning): """Warnings where a CF variable is ignored because it does not span the required dimension.""" pass
########
[docs]class IrisIgnoringBoundsWarning(IrisIgnoringWarning): """Warnings where bounds information has not been used by an Iris operation.""" pass
[docs]class IrisCannotAddWarning(IrisIgnoringWarning): """Warnings where a member object cannot be added to a :class:`~iris.cube.Cube` .""" pass
[docs]class IrisGuessBoundsWarning(IrisDefaultingWarning): """Warnings where Iris has filled absent bounds information with a best estimate.""" pass
[docs]class IrisPpClimModifiedWarning(IrisSaveWarning, IrisDefaultingWarning): """Warnings where a climatology has been modified while saving :term:`Post Processing (PP) Format` .""" pass
[docs]class IrisFactoryCoordNotFoundWarning(IrisLoadWarning): """Warnings where a referenced factory coord can not be found when loading a variable in :term:`NetCDF Format`.""" pass
[docs]class IrisNimrodTranslationWarning(IrisLoadWarning): """For unsupported vertical coord types in :mod:`iris.file_formats.nimrod_load_rules`. (Pre-dates the full categorisation of Iris UserWarnings). """ pass
[docs]class IrisUnknownCellMethodWarning(IrisCfLoadWarning): """If a loaded :class:`~iris.coords.CellMethod` is not one the method names known to Iris. (Pre-dates the full categorisation of Iris UserWarnings). """ pass
[docs]class IrisSaverFillValueWarning(IrisMaskValueMatchWarning, IrisSaveWarning): """For fill value complications during Iris file saving :term:`NetCDF Format`. (Pre-dates the full categorisation of Iris UserWarnings). """ pass