Skip to content

Commit f4e6a35

Browse files
committed
Categorise all Iris warnings.
1 parent 54ebf1f commit f4e6a35

31 files changed

+615
-133
lines changed

lib/iris/_concatenate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import iris.coords
1818
import iris.cube
19+
import iris.exceptions
1920
from iris.util import array_equal, guess_coord_axis
2021

2122
#
@@ -998,7 +999,7 @@ def register(
998999
raise iris.exceptions.ConcatenateError([msg])
9991000
elif not match:
10001001
msg = f"Found cubes with overlap on concatenate axis {candidate_axis}, skipping concatenation for these cubes"
1001-
warnings.warn(msg)
1002+
warnings.warn(msg, category=iris.exceptions.IrisUserWarning)
10021003

10031004
# Check for compatible AuxCoords.
10041005
if match:

lib/iris/analysis/_regrid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
snapshot_grid,
2121
)
2222
from iris.analysis._scipy_interpolate import _RegularGridInterpolator
23+
from iris.exceptions import IrisImpossibleUpdateWarning
2324
from iris.util import _meshgrid, guess_coord_axis
2425

2526

@@ -1136,6 +1137,6 @@ def regrid_reference_surface(
11361137
"Cannot update aux_factory {!r} because of dropped"
11371138
" coordinates.".format(factory.name())
11381139
)
1139-
warnings.warn(msg)
1140+
warnings.warn(msg, category=IrisImpossibleUpdateWarning)
11401141

11411142
return result

lib/iris/analysis/calculus.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import iris.analysis.maths
2525
import iris.coord_systems
2626
import iris.coords
27+
from iris.exceptions import IrisUserWarning
2728
from iris.util import delta
2829

2930
__all__ = ["cube_delta", "curl", "differentiate"]
@@ -85,7 +86,10 @@ def _construct_midpoint_coord(coord, circular=None):
8586
"Construction coordinate midpoints for the '{}' coordinate, "
8687
"though it has the attribute 'circular'={}."
8788
)
88-
warnings.warn(msg.format(circular, coord.circular, coord.name()))
89+
warnings.warn(
90+
msg.format(circular, coord.circular, coord.name()),
91+
category=IrisUserWarning,
92+
)
8993

9094
if coord.ndim != 1:
9195
raise iris.exceptions.CoordinateMultiDimError(coord)

lib/iris/analysis/cartography.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,16 +401,25 @@ def area_weights(cube, normalize=False):
401401
cs = cube.coord_system("CoordSystem")
402402
if isinstance(cs, iris.coord_systems.GeogCS):
403403
if cs.inverse_flattening != 0.0:
404-
warnings.warn("Assuming spherical earth from ellipsoid.")
404+
warnings.warn(
405+
"Assuming spherical earth from ellipsoid.",
406+
category=iris.exceptions.IrisDefaultingWarning,
407+
)
405408
radius_of_earth = cs.semi_major_axis
406409
elif isinstance(cs, iris.coord_systems.RotatedGeogCS) and (
407410
cs.ellipsoid is not None
408411
):
409412
if cs.ellipsoid.inverse_flattening != 0.0:
410-
warnings.warn("Assuming spherical earth from ellipsoid.")
413+
warnings.warn(
414+
"Assuming spherical earth from ellipsoid.",
415+
category=iris.exceptions.IrisDefaultingWarning,
416+
)
411417
radius_of_earth = cs.ellipsoid.semi_major_axis
412418
else:
413-
warnings.warn("Using DEFAULT_SPHERICAL_EARTH_RADIUS.")
419+
warnings.warn(
420+
"Using DEFAULT_SPHERICAL_EARTH_RADIUS.",
421+
category=iris.exceptions.IrisDefaultingWarning,
422+
)
414423
radius_of_earth = DEFAULT_SPHERICAL_EARTH_RADIUS
415424

416425
# Get the lon and lat coords and axes
@@ -551,7 +560,7 @@ def cosine_latitude_weights(cube):
551560
warnings.warn(
552561
"Out of range latitude values will be "
553562
"clipped to the valid range.",
554-
UserWarning,
563+
category=iris.exceptions.IrisDefaultingWarning,
555564
)
556565
points = lat.points
557566
l_weights = np.cos(points).clip(0.0, 1.0)
@@ -665,7 +674,8 @@ def project(cube, target_proj, nx=None, ny=None):
665674
# Assume WGS84 latlon if unspecified
666675
warnings.warn(
667676
"Coordinate system of latitude and longitude "
668-
"coordinates is not specified. Assuming WGS84 Geodetic."
677+
"coordinates is not specified. Assuming WGS84 Geodetic.",
678+
category=iris.exceptions.IrisDefaultingWarning,
669679
)
670680
orig_cs = iris.coord_systems.GeogCS(
671681
semi_major_axis=6378137.0, inverse_flattening=298.257223563
@@ -857,7 +867,8 @@ def project(cube, target_proj, nx=None, ny=None):
857867
lat_coord.name(),
858868
lon_coord.name(),
859869
[coord.name() for coord in discarded_coords],
860-
)
870+
),
871+
category=iris.exceptions.IrisIgnoringWarning,
861872
)
862873

863874
# TODO handle derived coords/aux_factories

lib/iris/analysis/geometry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _extract_relevant_cube_slice(cube, geometry):
7474
except ValueError:
7575
warnings.warn(
7676
"The geometry exceeds the cube's x dimension at the " "lower end.",
77-
UserWarning,
77+
category=iris.exceptions.IrisGeometryExceedWarning,
7878
)
7979
x_min_ix = 0 if x_ascending else x_coord.points.size - 1
8080

@@ -84,7 +84,7 @@ def _extract_relevant_cube_slice(cube, geometry):
8484
except ValueError:
8585
warnings.warn(
8686
"The geometry exceeds the cube's x dimension at the " "upper end.",
87-
UserWarning,
87+
category=iris.exceptions.IrisGeometryExceedWarning,
8888
)
8989
x_max_ix = x_coord.points.size - 1 if x_ascending else 0
9090

@@ -94,7 +94,7 @@ def _extract_relevant_cube_slice(cube, geometry):
9494
except ValueError:
9595
warnings.warn(
9696
"The geometry exceeds the cube's y dimension at the " "lower end.",
97-
UserWarning,
97+
category=iris.exceptions.IrisGeometryExceedWarning,
9898
)
9999
y_min_ix = 0 if y_ascending else y_coord.points.size - 1
100100

@@ -104,7 +104,7 @@ def _extract_relevant_cube_slice(cube, geometry):
104104
except ValueError:
105105
warnings.warn(
106106
"The geometry exceeds the cube's y dimension at the " "upper end.",
107-
UserWarning,
107+
category=iris.exceptions.IrisGeometryExceedWarning,
108108
)
109109
y_max_ix = y_coord.points.size - 1 if y_ascending else 0
110110

lib/iris/analysis/maths.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,8 @@ def _broadcast_cube_coord_data(cube, other, operation_name, dim=None):
988988
if other.has_bounds():
989989
warnings.warn(
990990
"Using {!r} with a bounded coordinate is not well "
991-
"defined; ignoring bounds.".format(operation_name)
991+
"defined; ignoring bounds.".format(operation_name),
992+
category=iris.exceptions.IrisIgnoringBoundsWarning,
992993
)
993994

994995
points = other.points

lib/iris/aux_factory.py

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
metadata_manager_factory,
2222
)
2323
import iris.coords
24+
from iris.exceptions import IrisIgnoringBoundsWarning
2425

2526

2627
class AuxCoordFactory(CFVariableMixin, metaclass=ABCMeta):
@@ -441,7 +442,9 @@ def _check_dependencies(pressure_at_top, sigma, surface_air_pressure):
441442
f"Coordinate '{coord.name()}' has bounds. These will "
442443
"be disregarded"
443444
)
444-
warnings.warn(msg, UserWarning, stacklevel=2)
445+
warnings.warn(
446+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
447+
)
445448

446449
# Check units
447450
if sigma.units.is_unknown():
@@ -522,15 +525,17 @@ def make_coord(self, coord_dims_func):
522525
if pressure_at_top.shape[-1:] not in [(), (1,)]:
523526
warnings.warn(
524527
"Pressure at top coordinate has bounds. These are being "
525-
"disregarded"
528+
"disregarded",
529+
category=IrisIgnoringBoundsWarning,
526530
)
527531
pressure_at_top_pts = nd_points_by_key["pressure_at_top"]
528532
bds_shape = list(pressure_at_top_pts.shape) + [1]
529533
pressure_at_top = pressure_at_top_pts.reshape(bds_shape)
530534
if surface_air_pressure.shape[-1:] not in [(), (1,)]:
531535
warnings.warn(
532536
"Surface pressure coordinate has bounds. These are being "
533-
"disregarded"
537+
"disregarded",
538+
category=IrisIgnoringBoundsWarning,
534539
)
535540
surface_air_pressure_pts = nd_points_by_key[
536541
"surface_air_pressure"
@@ -595,7 +600,9 @@ def __init__(self, delta=None, sigma=None, orography=None):
595600
"Orography coordinate {!r} has bounds."
596601
" These will be disregarded.".format(orography.name())
597602
)
598-
warnings.warn(msg, UserWarning, stacklevel=2)
603+
warnings.warn(
604+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
605+
)
599606

600607
self.delta = delta
601608
self.sigma = sigma
@@ -684,7 +691,7 @@ def make_coord(self, coord_dims_func):
684691
warnings.warn(
685692
"Orography coordinate has bounds. "
686693
"These are being disregarded.",
687-
UserWarning,
694+
category=IrisIgnoringBoundsWarning,
688695
stacklevel=2,
689696
)
690697
orography_pts = nd_points_by_key["orography"]
@@ -739,7 +746,9 @@ def update(self, old_coord, new_coord=None):
739746
"Orography coordinate {!r} has bounds."
740747
" These will be disregarded.".format(new_coord.name())
741748
)
742-
warnings.warn(msg, UserWarning, stacklevel=2)
749+
warnings.warn(
750+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
751+
)
743752
self.orography = new_coord
744753

745754

@@ -806,7 +815,9 @@ def _check_dependencies(delta, sigma, surface_air_pressure):
806815
"Surface pressure coordinate {!r} has bounds. These will"
807816
" be disregarded.".format(surface_air_pressure.name())
808817
)
809-
warnings.warn(msg, UserWarning, stacklevel=2)
818+
warnings.warn(
819+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
820+
)
810821

811822
# Check units.
812823
if sigma is not None and sigma.units.is_unknown():
@@ -898,7 +909,8 @@ def make_coord(self, coord_dims_func):
898909
if surface_air_pressure.shape[-1:] not in [(), (1,)]:
899910
warnings.warn(
900911
"Surface pressure coordinate has bounds. "
901-
"These are being disregarded."
912+
"These are being disregarded.",
913+
category=IrisIgnoringBoundsWarning,
902914
)
903915
surface_air_pressure_pts = nd_points_by_key[
904916
"surface_air_pressure"
@@ -1012,7 +1024,9 @@ def _check_dependencies(sigma, eta, depth, depth_c, nsigma, zlev):
10121024
"The {} coordinate {!r} has bounds. "
10131025
"These are being disregarded.".format(term, coord.name())
10141026
)
1015-
warnings.warn(msg, UserWarning, stacklevel=2)
1027+
warnings.warn(
1028+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1029+
)
10161030

10171031
for coord, term in ((depth_c, "depth_c"), (nsigma, "nsigma")):
10181032
if coord is not None and coord.shape != (1,):
@@ -1187,7 +1201,9 @@ def make_coord(self, coord_dims_func):
11871201
"The {} coordinate {!r} has bounds. "
11881202
"These are being disregarded.".format(key, name)
11891203
)
1190-
warnings.warn(msg, UserWarning, stacklevel=2)
1204+
warnings.warn(
1205+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1206+
)
11911207
# Swap bounds with points.
11921208
bds_shape = list(nd_points_by_key[key].shape) + [1]
11931209
bounds = nd_points_by_key[key].reshape(bds_shape)
@@ -1268,7 +1284,9 @@ def _check_dependencies(sigma, eta, depth):
12681284
"The {} coordinate {!r} has bounds. "
12691285
"These are being disregarded.".format(term, coord.name())
12701286
)
1271-
warnings.warn(msg, UserWarning, stacklevel=2)
1287+
warnings.warn(
1288+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1289+
)
12721290

12731291
# Check units.
12741292
if sigma is not None and sigma.units.is_unknown():
@@ -1349,7 +1367,9 @@ def make_coord(self, coord_dims_func):
13491367
"The {} coordinate {!r} has bounds. "
13501368
"These are being disregarded.".format(key, name)
13511369
)
1352-
warnings.warn(msg, UserWarning, stacklevel=2)
1370+
warnings.warn(
1371+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1372+
)
13531373
# Swap bounds with points.
13541374
bds_shape = list(nd_points_by_key[key].shape) + [1]
13551375
bounds = nd_points_by_key[key].reshape(bds_shape)
@@ -1444,7 +1464,9 @@ def _check_dependencies(s, c, eta, depth, depth_c):
14441464
"The {} coordinate {!r} has bounds. "
14451465
"These are being disregarded.".format(term, coord.name())
14461466
)
1447-
warnings.warn(msg, UserWarning, stacklevel=2)
1467+
warnings.warn(
1468+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1469+
)
14481470

14491471
if depth_c is not None and depth_c.shape != (1,):
14501472
msg = (
@@ -1543,7 +1565,9 @@ def make_coord(self, coord_dims_func):
15431565
"The {} coordinate {!r} has bounds. "
15441566
"These are being disregarded.".format(key, name)
15451567
)
1546-
warnings.warn(msg, UserWarning, stacklevel=2)
1568+
warnings.warn(
1569+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1570+
)
15471571
# Swap bounds with points.
15481572
bds_shape = list(nd_points_by_key[key].shape) + [1]
15491573
bounds = nd_points_by_key[key].reshape(bds_shape)
@@ -1637,7 +1661,9 @@ def _check_dependencies(s, eta, depth, a, b, depth_c):
16371661
"The {} coordinate {!r} has bounds. "
16381662
"These are being disregarded.".format(term, coord.name())
16391663
)
1640-
warnings.warn(msg, UserWarning, stacklevel=2)
1664+
warnings.warn(
1665+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1666+
)
16411667

16421668
coords = ((a, "a"), (b, "b"), (depth_c, "depth_c"))
16431669
for coord, term in coords:
@@ -1740,7 +1766,9 @@ def make_coord(self, coord_dims_func):
17401766
"The {} coordinate {!r} has bounds. "
17411767
"These are being disregarded.".format(key, name)
17421768
)
1743-
warnings.warn(msg, UserWarning, stacklevel=2)
1769+
warnings.warn(
1770+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1771+
)
17441772
# Swap bounds with points.
17451773
bds_shape = list(nd_points_by_key[key].shape) + [1]
17461774
bounds = nd_points_by_key[key].reshape(bds_shape)
@@ -1839,7 +1867,9 @@ def _check_dependencies(s, c, eta, depth, depth_c):
18391867
"The {} coordinate {!r} has bounds. "
18401868
"These are being disregarded.".format(term, coord.name())
18411869
)
1842-
warnings.warn(msg, UserWarning, stacklevel=2)
1870+
warnings.warn(
1871+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1872+
)
18431873

18441874
if depth_c is not None and depth_c.shape != (1,):
18451875
msg = (
@@ -1938,7 +1968,9 @@ def make_coord(self, coord_dims_func):
19381968
"The {} coordinate {!r} has bounds. "
19391969
"These are being disregarded.".format(key, name)
19401970
)
1941-
warnings.warn(msg, UserWarning, stacklevel=2)
1971+
warnings.warn(
1972+
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
1973+
)
19421974
# Swap bounds with points.
19431975
bds_shape = list(nd_points_by_key[key].shape) + [1]
19441976
bounds = nd_points_by_key[key].reshape(bds_shape)

lib/iris/config.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import os.path
3737
import warnings
3838

39+
import iris.exceptions
40+
3941

4042
def get_logger(
4143
name, datefmt=None, fmt=None, level=None, propagate=None, handler=True
@@ -145,7 +147,10 @@ def get_dir_option(section, option, default=None):
145147
"Ignoring config item {!r}:{!r} (section:option) as {!r}"
146148
" is not a valid directory path."
147149
)
148-
warnings.warn(msg.format(section, option, c_path))
150+
warnings.warn(
151+
msg.format(section, option, c_path),
152+
category=iris.exceptions.IrisIgnoringWarning,
153+
)
149154
return path
150155

151156

@@ -251,7 +256,10 @@ def __setattr__(self, name, value):
251256
"Attempting to set invalid value {!r} for "
252257
"attribute {!r}. Defaulting to {!r}."
253258
)
254-
warnings.warn(wmsg.format(value, name, good_value))
259+
warnings.warn(
260+
wmsg.format(value, name, good_value),
261+
category=iris.exceptions.IrisDefaultingWarning,
262+
)
255263
value = good_value
256264
self.__dict__[name] = value
257265

0 commit comments

Comments
 (0)