|
9 | 9 | import numpy as np |
10 | 10 | import pytest |
11 | 11 | import xarray as xr |
12 | | -from iris.coords import DimCoord |
| 12 | +from iris.coords import AncillaryVariable, CellMeasure, DimCoord |
13 | 13 | from iris.cube import Cube, CubeList |
14 | 14 |
|
15 | 15 | from esmvalcore.exceptions import ESMValCoreLoadWarning |
@@ -39,6 +39,39 @@ def test_load(tmp_path, sample_cube): |
39 | 39 | assert_array_equal(sample_cube.coord("latitude").points, [1, 2]) |
40 | 40 |
|
41 | 41 |
|
| 42 | +def test_load_with_range_attrs(tmp_path: Path, sample_cube: Cube) -> None: |
| 43 | + """Test loading multiple files.""" |
| 44 | + sample_cube.attributes["valid_max"] = 1 |
| 45 | + ancillary_var = AncillaryVariable( |
| 46 | + [0, 1.1], |
| 47 | + standard_name="land_area_fraction", |
| 48 | + units="%", |
| 49 | + ) |
| 50 | + ancillary_var.attributes["valid_max"] = 1 |
| 51 | + sample_cube.add_ancillary_variable(ancillary_var, data_dims=[0]) |
| 52 | + cell_measure = CellMeasure([1, 1], standard_name="cell_area", units="m2") |
| 53 | + cell_measure.attributes["valid_min"] = 1 |
| 54 | + sample_cube.add_cell_measure(cell_measure, data_dims=[0]) |
| 55 | + temp_file = tmp_path / "cube.nc" |
| 56 | + iris.save(sample_cube, temp_file) |
| 57 | + |
| 58 | + cubes = load(temp_file) |
| 59 | + |
| 60 | + assert len(cubes) == 1 |
| 61 | + sample_cube = cubes[0] |
| 62 | + assert "valid_max" not in sample_cube.attributes |
| 63 | + assert_array_equal( |
| 64 | + sample_cube.data, |
| 65 | + np.ma.array([1, 2], mask=[False, True]), |
| 66 | + ) |
| 67 | + assert "valid_max" not in sample_cube.ancillary_variables()[0].attributes |
| 68 | + assert_array_equal( |
| 69 | + sample_cube.ancillary_variables()[0].data, |
| 70 | + np.ma.array([0, 1.1], mask=[False, True]), |
| 71 | + ) |
| 72 | + assert "valid_min" not in sample_cube.cell_measures()[0].attributes |
| 73 | + |
| 74 | + |
42 | 75 | def test_load_grib(): |
43 | 76 | """Test loading a grib file.""" |
44 | 77 | grib_path = ( |
|
0 commit comments