Skip to content

Commit 3fdccac

Browse files
Change default units to "unknown" for all DimensionalMetadata (#3713)
1 parent f5feb28 commit 3fdccac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+170
-100
lines changed

docs/iris/example_code/Meteorology/lagged_ensemble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def realization_metadata(cube, field, fname):
4040
import iris.coords
4141

4242
realization_coord = iris.coords.AuxCoord(
43-
np.int32(realization_number), "realization"
43+
np.int32(realization_number), "realization", units="1"
4444
)
4545
cube.add_aux_coord(realization_coord)
4646

docs/iris/src/userguide/navigating_a_cube.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ by field basis *before* they are automatically merged together:
229229
# Add our own realization coordinate if it doesn't already exist.
230230
if not cube.coords('realization'):
231231
realization = np.int32(filename[-6:-3])
232-
ensemble_coord = icoords.AuxCoord(realization, standard_name='realization')
232+
ensemble_coord = icoords.AuxCoord(realization, standard_name='realization', units="1")
233233
cube.add_aux_coord(ensemble_coord)
234234

235235
filename = iris.sample_data_path('GloSea4', '*.pp')

lib/iris/analysis/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,9 @@ def post_process(self, collapsed_cube, data_result, coords, **kwargs):
802802
# order cube.
803803
for point in points:
804804
cube = collapsed_cube.copy()
805-
coord = iris.coords.AuxCoord(point, long_name=coord_name)
805+
coord = iris.coords.AuxCoord(
806+
point, long_name=coord_name, units="percent"
807+
)
806808
cube.add_aux_coord(coord)
807809
cubes.append(cube)
808810

lib/iris/coords.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(
5959
standard_name=None,
6060
long_name=None,
6161
var_name=None,
62-
units="no-unit",
62+
units=None,
6363
attributes=None,
6464
):
6565
"""
@@ -688,7 +688,7 @@ def __init__(
688688
standard_name=None,
689689
long_name=None,
690690
var_name=None,
691-
units="no-unit",
691+
units=None,
692692
attributes=None,
693693
):
694694
"""
@@ -788,7 +788,7 @@ def __init__(
788788
standard_name=None,
789789
long_name=None,
790790
var_name=None,
791-
units="1",
791+
units=None,
792792
attributes=None,
793793
measure=None,
794794
):
@@ -1440,7 +1440,7 @@ def __init__(
14401440
standard_name=None,
14411441
long_name=None,
14421442
var_name=None,
1443-
units="1",
1443+
units=None,
14441444
bounds=None,
14451445
attributes=None,
14461446
coord_system=None,
@@ -2411,7 +2411,7 @@ def from_regular(
24112411
standard_name=None,
24122412
long_name=None,
24132413
var_name=None,
2414-
units="1",
2414+
units=None,
24152415
attributes=None,
24162416
coord_system=None,
24172417
circular=False,
@@ -2474,7 +2474,7 @@ def __init__(
24742474
standard_name=None,
24752475
long_name=None,
24762476
var_name=None,
2477-
units="1",
2477+
units=None,
24782478
bounds=None,
24792479
attributes=None,
24802480
coord_system=None,

lib/iris/fileformats/pp_load_rules.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def _convert_vertical_coords(
147147
model_level_number,
148148
standard_name="model_level_number",
149149
attributes={"positive": "down"},
150+
units="1",
150151
)
151152
coords_and_dims.append((coord, dim))
152153

@@ -197,6 +198,7 @@ def _convert_vertical_coords(
197198
model_level_number,
198199
long_name="soil_model_level_number",
199200
attributes={"positive": "down"},
201+
units="1",
200202
)
201203
coords_and_dims.append((coord, dim))
202204
elif np.any(brsvd1 != brlev):
@@ -235,6 +237,7 @@ def _convert_vertical_coords(
235237
model_level_number,
236238
standard_name="model_level_number",
237239
attributes={"positive": "up"},
240+
units="1",
238241
)
239242
level_pressure = _dim_or_aux(
240243
bhlev,
@@ -243,7 +246,10 @@ def _convert_vertical_coords(
243246
bounds=np.vstack((bhrlev, brsvd2)).T,
244247
)
245248
sigma = AuxCoord(
246-
blev, long_name="sigma", bounds=np.vstack((brlev, brsvd1)).T
249+
blev,
250+
long_name="sigma",
251+
bounds=np.vstack((brlev, brsvd1)).T,
252+
units="1",
247253
)
248254
coords_and_dims.extend(
249255
[(model_level_number, dim), (level_pressure, dim), (sigma, dim)]
@@ -265,6 +271,7 @@ def _convert_vertical_coords(
265271
model_level_number,
266272
standard_name="model_level_number",
267273
attributes={"positive": "up"},
274+
units="1",
268275
)
269276
level_height = _dim_or_aux(
270277
blev,
@@ -274,7 +281,10 @@ def _convert_vertical_coords(
274281
attributes={"positive": "up"},
275282
)
276283
sigma = AuxCoord(
277-
bhlev, long_name="sigma", bounds=np.vstack((bhrlev, brsvd2)).T
284+
bhlev,
285+
long_name="sigma",
286+
bounds=np.vstack((bhrlev, brsvd2)).T,
287+
units="1",
278288
)
279289
coords_and_dims.extend(
280290
[(model_level_number, dim), (level_height, dim), (sigma, dim)]
@@ -846,7 +856,7 @@ def _convert_scalar_realization_coords(lbrsvd4):
846856
coords_and_dims = []
847857
if lbrsvd4 != 0:
848858
coords_and_dims.append(
849-
(DimCoord(lbrsvd4, standard_name="realization"), None)
859+
(DimCoord(lbrsvd4, standard_name="realization", units="1"), None)
850860
)
851861
return coords_and_dims
852862

@@ -1078,7 +1088,7 @@ def _all_other_rules(f):
10781088
and f.lbmon == f.lbmond
10791089
):
10801090
aux_coords_and_dims.append(
1081-
(AuxCoord(f.lbmon, long_name="month_number"), None)
1091+
(AuxCoord(f.lbmon, long_name="month_number", units="1"), None)
10821092
)
10831093
aux_coords_and_dims.append(
10841094
(

lib/iris/tests/integration/test_netcdf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def test_hybrid_height_and_pressure(self):
8181
1200.0, long_name="level_pressure", units="hPa"
8282
)
8383
)
84-
cube.add_aux_coord(iris.coords.DimCoord(0.5, long_name="other sigma"))
84+
cube.add_aux_coord(
85+
iris.coords.DimCoord(0.5, long_name="other sigma", units="1")
86+
)
8587
cube.add_aux_coord(
8688
iris.coords.DimCoord(
8789
1000.0, long_name="surface_air_pressure", units="hPa"

lib/iris/tests/integration/test_pp.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def test_hybrid_height_with_non_standard_coords(self):
299299
delta_lower, delta, delta_upper = 150, 200, 250
300300

301301
cube = Cube(np.zeros((ny, nx)), "air_temperature")
302-
level_coord = AuxCoord(0, "model_level_number")
302+
level_coord = AuxCoord(0, "model_level_number", units="1")
303303
cube.add_aux_coord(level_coord)
304304
delta_coord = AuxCoord(
305305
delta,
@@ -308,7 +308,10 @@ def test_hybrid_height_with_non_standard_coords(self):
308308
units="m",
309309
)
310310
sigma_coord = AuxCoord(
311-
sigma, bounds=[[sigma_lower, sigma_upper]], long_name="mavis"
311+
sigma,
312+
bounds=[[sigma_lower, sigma_upper]],
313+
long_name="mavis",
314+
units="1",
312315
)
313316
surface_altitude_coord = AuxCoord(
314317
np.zeros((ny, nx)), "surface_altitude", units="m"
@@ -343,7 +346,7 @@ def test_hybrid_pressure_with_non_standard_coords(self):
343346
delta_lower, delta, delta_upper = 0.15, 0.2, 0.25
344347

345348
cube = Cube(np.zeros((ny, nx)), "air_temperature")
346-
level_coord = AuxCoord(0, "model_level_number")
349+
level_coord = AuxCoord(0, "model_level_number", units="1")
347350
cube.add_aux_coord(level_coord)
348351
delta_coord = AuxCoord(
349352
delta,
@@ -352,7 +355,10 @@ def test_hybrid_pressure_with_non_standard_coords(self):
352355
units="Pa",
353356
)
354357
sigma_coord = AuxCoord(
355-
sigma, bounds=[[sigma_lower, sigma_upper]], long_name="mavis"
358+
sigma,
359+
bounds=[[sigma_lower, sigma_upper]],
360+
long_name="mavis",
361+
units="1",
356362
)
357363
surface_air_pressure_coord = AuxCoord(
358364
np.zeros((ny, nx)), "surface_air_pressure", units="Pa"

lib/iris/tests/results/analysis/first_quartile_foo_1d.cml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<dimCoord bounds="[[0, 11]]" id="b0d35dcf" long_name="foo" points="[5]" shape="(1,)" units="Unit('1')" value_type="int32"/>
77
</coord>
88
<coord>
9-
<dimCoord id="3d9231d0" long_name="percentile_over_foo" points="[25]" shape="(1,)" units="Unit('1')" value_type="int64"/>
9+
<dimCoord id="f5bc1733" long_name="percentile_over_foo" points="[25]" shape="(1,)" units="Unit('percent')" value_type="int64"/>
1010
</coord>
1111
</coords>
1212
<cellMethods/>

lib/iris/tests/results/analysis/first_quartile_foo_1d_fast_percentile.cml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<dimCoord bounds="[[0, 11]]" id="b0d35dcf" long_name="foo" points="[5]" shape="(1,)" units="Unit('1')" value_type="int32"/>
77
</coord>
88
<coord>
9-
<dimCoord id="3d9231d0" long_name="percentile_over_foo" points="[25]" shape="(1,)" units="Unit('1')" value_type="int64"/>
9+
<dimCoord id="f5bc1733" long_name="percentile_over_foo" points="[25]" shape="(1,)" units="Unit('percent')" value_type="int64"/>
1010
</coord>
1111
</coords>
1212
<cellMethods/>

lib/iris/tests/results/analysis/first_quartile_foo_2d.cml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<dimCoord bounds="[[-15, 45]]" id="b0d35dcf" long_name="foo" points="[15.0]" shape="(1,)" units="Unit('1')" value_type="float64"/>
1212
</coord>
1313
<coord>
14-
<dimCoord id="3d9231d0" long_name="percentile_over_foo" points="[25]" shape="(1,)" units="Unit('1')" value_type="int64"/>
14+
<dimCoord id="f5bc1733" long_name="percentile_over_foo" points="[25]" shape="(1,)" units="Unit('percent')" value_type="int64"/>
1515
</coord>
1616
</coords>
1717
<cellMethods/>

0 commit comments

Comments
 (0)