Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent warning repeats #5506

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/iris/_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"""Automatic concatenation of multiple cubes over one or more existing dimensions."""

from collections import defaultdict, namedtuple
import warnings

import dask.array as da
import numpy as np

import iris.coords
import iris.cube
import iris.exceptions
from iris.exceptions import warn_once_at_level
from iris.util import array_equal, guess_coord_axis

#
Expand Down Expand Up @@ -911,7 +911,7 @@ def register(
raise iris.exceptions.ConcatenateError([msg])
elif not match:
msg = f"Found cubes with overlap on concatenate axis {candidate_axis}, skipping concatenation for these cubes"
warnings.warn(msg, category=iris.exceptions.IrisUserWarning)
warn_once_at_level(msg, category=iris.exceptions.IrisUserWarning)

# Check for compatible AuxCoords.
if match:
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# See LICENSE in the root of the repository for full licensing details.
"""Utilities for producing runtime deprecation messages."""

import warnings
from iris.exceptions import warn_once_at_level


class IrisDeprecation(UserWarning):
Expand Down Expand Up @@ -44,7 +44,7 @@ def warn_deprecated(msg, stacklevel=2):
>>>

"""
warnings.warn(msg, category=IrisDeprecation, stacklevel=stacklevel)
warn_once_at_level(msg, category=IrisDeprecation, stacklevel=stacklevel)


# A Mixin for a wrapper class that copies the docstring of the wrapped class
Expand Down
5 changes: 2 additions & 3 deletions lib/iris/analysis/_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import copy
import functools
import warnings

import numpy as np
import numpy.ma as ma
Expand All @@ -19,7 +18,7 @@
snapshot_grid,
)
from iris.analysis._scipy_interpolate import _RegularGridInterpolator
from iris.exceptions import IrisImpossibleUpdateWarning
from iris.exceptions import IrisImpossibleUpdateWarning, warn_once_at_level
from iris.util import _meshgrid, guess_coord_axis


Expand Down Expand Up @@ -1106,6 +1105,6 @@ def regrid_reference_surface(
"Cannot update aux_factory {!r} because of dropped"
" coordinates.".format(factory.name())
)
warnings.warn(msg, category=IrisImpossibleUpdateWarning)
warn_once_at_level(msg, category=IrisImpossibleUpdateWarning)

return result
5 changes: 2 additions & 3 deletions lib/iris/analysis/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

import re
import warnings

import cf_units
import numpy as np
Expand All @@ -22,7 +21,7 @@
import iris.analysis.maths
import iris.coord_systems
import iris.coords
from iris.exceptions import IrisUserWarning
from iris.exceptions import IrisUserWarning, warn_once_at_level
from iris.util import delta

__all__ = ["DIRECTIONAL_NAMES", "cube_delta", "curl", "differentiate"]
Expand Down Expand Up @@ -85,7 +84,7 @@ def _construct_midpoint_coord(coord, circular=None):
"Construction coordinate midpoints for the '{}' coordinate, "
"though it has the attribute 'circular'={}."
)
warnings.warn(
warn_once_at_level(
msg.format(circular, coord.circular, coord.name()),
category=IrisUserWarning,
)
Expand Down
14 changes: 7 additions & 7 deletions lib/iris/analysis/cartography.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from collections import namedtuple
import copy
import warnings

import cartopy.crs as ccrs
import cartopy.img_transform
Expand All @@ -18,6 +17,7 @@
import iris.coord_systems
import iris.coords
import iris.exceptions
from iris.exceptions import warn_once_at_level
from iris.util import _meshgrid

from ._grid_angles import gridcell_angles, rotate_grid_vectors
Expand Down Expand Up @@ -410,7 +410,7 @@ def area_weights(cube, normalize=False):
cs = cube.coord_system("CoordSystem")
if isinstance(cs, iris.coord_systems.GeogCS):
if cs.inverse_flattening != 0.0:
warnings.warn(
warn_once_at_level(
"Assuming spherical earth from ellipsoid.",
category=iris.exceptions.IrisDefaultingWarning,
)
Expand All @@ -419,13 +419,13 @@ def area_weights(cube, normalize=False):
cs.ellipsoid is not None
):
if cs.ellipsoid.inverse_flattening != 0.0:
warnings.warn(
warn_once_at_level(
"Assuming spherical earth from ellipsoid.",
category=iris.exceptions.IrisDefaultingWarning,
)
radius_of_earth = cs.ellipsoid.semi_major_axis
else:
warnings.warn(
warn_once_at_level(
"Using DEFAULT_SPHERICAL_EARTH_RADIUS.",
category=iris.exceptions.IrisDefaultingWarning,
)
Expand Down Expand Up @@ -567,7 +567,7 @@ def cosine_latitude_weights(cube):
if np.any(lat.points < -np.pi / 2.0 - threshold) or np.any(
lat.points > np.pi / 2.0 + threshold
):
warnings.warn(
warn_once_at_level(
"Out of range latitude values will be clipped to the valid range.",
category=iris.exceptions.IrisDefaultingWarning,
)
Expand Down Expand Up @@ -683,7 +683,7 @@ def project(cube, target_proj, nx=None, ny=None):
# Determine source coordinate system
if lat_coord.coord_system is None:
# Assume WGS84 latlon if unspecified
warnings.warn(
warn_once_at_level(
"Coordinate system of latitude and longitude "
"coordinates is not specified. Assuming WGS84 Geodetic.",
category=iris.exceptions.IrisDefaultingWarning,
Expand Down Expand Up @@ -871,7 +871,7 @@ def project(cube, target_proj, nx=None, ny=None):
new_cube.add_aux_coord(coord.copy(), cube.coord_dims(coord))
discarded_coords = coords_to_ignore.difference([lat_coord, lon_coord])
if discarded_coords:
warnings.warn(
warn_once_at_level(
"Discarding coordinates that share dimensions with {} and {}: {}".format(
lat_coord.name(),
lon_coord.name(),
Expand Down
11 changes: 5 additions & 6 deletions lib/iris/analysis/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

"""

import warnings

import numpy as np
from shapely.geometry import Polygon

import iris.exceptions
from iris.exceptions import warn_once_at_level


def _extract_relevant_cube_slice(cube, geometry):
Expand Down Expand Up @@ -69,7 +68,7 @@ def _extract_relevant_cube_slice(cube, geometry):
x_min_ix = np.where(x_bounds_lower <= x_min_geom)[0]
x_min_ix = x_min_ix[np.argmax(x_bounds_lower[x_min_ix])]
except ValueError:
warnings.warn(
warn_once_at_level(
"The geometry exceeds the cube's x dimension at the lower end.",
category=iris.exceptions.IrisGeometryExceedWarning,
)
Expand All @@ -79,7 +78,7 @@ def _extract_relevant_cube_slice(cube, geometry):
x_max_ix = np.where(x_bounds_upper >= x_max_geom)[0]
x_max_ix = x_max_ix[np.argmin(x_bounds_upper[x_max_ix])]
except ValueError:
warnings.warn(
warn_once_at_level(
"The geometry exceeds the cube's x dimension at the upper end.",
category=iris.exceptions.IrisGeometryExceedWarning,
)
Expand All @@ -89,7 +88,7 @@ def _extract_relevant_cube_slice(cube, geometry):
y_min_ix = np.where(y_bounds_lower <= y_min_geom)[0]
y_min_ix = y_min_ix[np.argmax(y_bounds_lower[y_min_ix])]
except ValueError:
warnings.warn(
warn_once_at_level(
"The geometry exceeds the cube's y dimension at the lower end.",
category=iris.exceptions.IrisGeometryExceedWarning,
)
Expand All @@ -99,7 +98,7 @@ def _extract_relevant_cube_slice(cube, geometry):
y_max_ix = np.where(y_bounds_upper >= y_max_geom)[0]
y_max_ix = y_max_ix[np.argmin(y_bounds_upper[y_max_ix])]
except ValueError:
warnings.warn(
warn_once_at_level(
"The geometry exceeds the cube's y dimension at the upper end.",
category=iris.exceptions.IrisGeometryExceedWarning,
)
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/analysis/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import inspect
import math
import operator
import warnings

import cf_units
import dask.array as da
Expand All @@ -22,6 +21,7 @@
from iris.config import get_logger
import iris.coords
import iris.exceptions
from iris.exceptions import warn_once_at_level
import iris.util

# Configure the logger.
Expand Down Expand Up @@ -938,7 +938,7 @@ def _broadcast_cube_coord_data(cube, other, operation_name, dim=None):
raise iris.exceptions.CoordinateMultiDimError(other)

if other.has_bounds():
warnings.warn(
warn_once_at_level(
"Using {!r} with a bounded coordinate is not well "
"defined; ignoring bounds.".format(operation_name),
category=iris.exceptions.IrisIgnoringBoundsWarning,
Expand Down
Loading
Loading