File tree Expand file tree Collapse file tree 6 files changed +36
-10
lines changed Expand file tree Collapse file tree 6 files changed +36
-10
lines changed Original file line number Diff line number Diff line change 1
-
2
- version NEXTRELEASE
1
+ version NEXTVERSION
3
2
-------------------
4
3
5
4
**2024-??-?? **
6
5
6
+ * Include the UM version as a field property when reading UM files
7
+ (https://github.com/NCAS-CMS/cf-python/issues/777)
7
8
* Fix bug where `cf.example_fields ` returned a `list `
8
9
of Fields rather than a `Fieldlist `
9
10
(https://github.com/NCAS-CMS/cf-python/issues/725)
Original file line number Diff line number Diff line change @@ -10479,9 +10479,9 @@ def convolution_filter(
10479
10479
new_bounds[0 : length - lower_offset, 1:] = old_bounds[
10480
10480
lower_offset:length, 1:
10481
10481
]
10482
- new_bounds[length - lower_offset : length, 1:] = (
10483
- old_bounds[ length - 1 , 1:]
10484
- )
10482
+ new_bounds[
10483
+ length - lower_offset : length , 1:
10484
+ ] = old_bounds[length - 1, 1:]
10485
10485
10486
10486
coord.set_bounds(self._Bounds(data=new_bounds))
10487
10487
Original file line number Diff line number Diff line change @@ -1040,6 +1040,22 @@ def __init__(
1040
1040
cf_properties ["stash_code" ] = str (stash )
1041
1041
cf_properties ["submodel" ] = str (submodel )
1042
1042
1043
+ # Convert the UM version to a string and provide it as a
1044
+ # CF property. E.g. 405 -> '4.5', 606.3 -> '6.6.3', 1002
1045
+ # -> '10.2'
1046
+ #
1047
+ # Note: We don't just do `divmod(self.um_version, 100)`
1048
+ # because if self.um_version has a fractional part
1049
+ # then it would likely get altered in the divmod
1050
+ # calculation.
1051
+ a , b = divmod (int (self .um_version ), 100 )
1052
+ fraction = str (self .um_version ).split ("." )[- 1 ]
1053
+ um = f"{ a } .{ b } "
1054
+ if fraction != "0" and fraction != str (self .um_version ):
1055
+ um += f".{ fraction } "
1056
+
1057
+ cf_properties ["um_version" ] = um
1058
+
1043
1059
# --------------------------------------------------------
1044
1060
# Set the data and extra data
1045
1061
# --------------------------------------------------------
Original file line number Diff line number Diff line change @@ -2389,7 +2389,9 @@ def test_Data_BINARY_AND_UNARY_OPERATORS(self):
2389
2389
except Exception :
2390
2390
pass
2391
2391
else :
2392
- self .assertTrue ((x ** d ).all (), "{}**{}" .format (x , repr (d )))
2392
+ self .assertTrue (
2393
+ (x ** d ).all (), "{}**{}" .format (x , repr (d ))
2394
+ )
2393
2395
2394
2396
self .assertTrue (
2395
2397
d .__truediv__ (x ).equals (
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ def test_PP_read_um(self):
57
57
g = cf .read (self .ppextradata , um = {"fmt" : "pp" })[0 ]
58
58
self .assertTrue (f .equals (g ))
59
59
60
- for vn in (4.5 , 405 , "4.5" , None ):
60
+ for vn in (4.5 , 405 , "4.5" ):
61
61
g = cf .read (self .ppextradata , um = {"fmt" : "pp" , "version" : vn })[0 ]
62
62
self .assertTrue (f .equals (g ))
63
63
@@ -138,6 +138,13 @@ def test_PP_extra_data(self):
138
138
self .assertTrue (f .dimension_coordinate ("time" , default = False ))
139
139
self .assertTrue (f .auxiliary_coordinate ("longitude" , default = False ))
140
140
141
+ def test_PP_um_version (self ):
142
+ f = cf .read (self .ppfile )[0 ]
143
+ self .assertEqual (f .get_property ("um_version" ), "11.0" )
144
+
145
+ f = cf .read (self .ppfile , um = {"version" : "6.6.3" })[0 ]
146
+ self .assertEqual (f .get_property ("um_version" ), "6.6.3" )
147
+
141
148
142
149
if __name__ == "__main__" :
143
150
print ("Run date:" , datetime .datetime .now ())
Original file line number Diff line number Diff line change @@ -1461,9 +1461,9 @@ def linear(
1461
1461
else :
1462
1462
# Bounds exist
1463
1463
if methods :
1464
- weights [( da_key ,)] = (
1465
- f"linear { f . constructs . domain_axis_identity (da_key ) } "
1466
- )
1464
+ weights [
1465
+ (da_key ,)
1466
+ ] = f"linear { f . constructs . domain_axis_identity ( da_key ) } "
1467
1467
else :
1468
1468
weights [(da_key ,)] = dim .cellsize
1469
1469
You can’t perform that action at this time.
0 commit comments