Skip to content

Commit 492d424

Browse files
committed
dev
1 parent 7552ff4 commit 492d424

File tree

7 files changed

+63
-36
lines changed

7 files changed

+63
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ of its array manipulation and can:
8787
* read field constructs from netCDF, CDL, PP and UM datasets,
8888
* create new field constructs in memory,
8989
* write and append field and domain constructs to netCDF datasets on disk,
90-
* read, write, and manipulate UGRID mesh topologies
90+
* read, create, and manipulate UGRID mesh topologies,
9191
* read, write, and create coordinates defined by geometry cells,
9292
* read netCDF and CDL datasets containing hierarchical groups,
9393
* inspect field constructs,

cf/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575

7676
__Conventions__ = "CF-1.11"
7777
__date__ = "2023-??-??"
78-
__version__ = "3.16.0"
78+
__version__ = "3.16.0b1"
7979

8080
_requires = (
8181
"numpy",
@@ -193,7 +193,7 @@
193193
)
194194

195195
# Check the version of cfdm
196-
_minimum_vn = "1.11.0.0"
196+
_minimum_vn = "1.11.0.0b1"
197197
_maximum_vn = "1.11.1.0"
198198
_cfdm_version = Version(cfdm.__version__)
199199
if not Version(_minimum_vn) <= _cfdm_version < Version(_maximum_vn):

cf/field.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@
165165
"standard_deviation",
166166
"var",
167167
"variance",
168-
# 'sum_of_weights',
169-
# 'sum_of_weights2',
168+
"sum",
169+
'sum_of_weights',
170+
'sum_of_weights2',
170171
"integral",
171172
"root_mean_square",
172173
)
@@ -3765,7 +3766,7 @@ def weights(
37653766
# ----------------------------------------------------
37663767
for key, w in comp.items():
37673768
comp[key] = Weights.scale(w, scale)
3768-
3769+
37693770
if components or methods:
37703771
# --------------------------------------------------------
37713772
# Return a dictionary of component weights, which may be
@@ -4956,6 +4957,7 @@ def collapse(
49564957
great_circle=False,
49574958
verbose=None,
49584959
remove_vertical_crs=True,
4960+
allow_negative_weights=False,
49594961
_create_zero_size_cell_bounds=False,
49604962
_update_cell_methods=True,
49614963
i=False,
@@ -6400,6 +6402,12 @@ def collapse(
64006402

64016403
.. versionadded:: 3.14.1
64026404

6405+
allow_negative_weights: `bool`, optional
6406+
6407+
If true then allow weights provided
6408+
6409+
.. versionadded:: UGRIDVER
6410+
64036411
{{inplace: `bool`, optional}}
64046412

64056413
{{i: deprecated at version 3.0.0}}
@@ -6767,6 +6775,7 @@ def collapse(
67676775
weights = None
67686776

67696777
d_kwargs = {}
6778+
print (11, repr(weights))
67706779
if weights is not None:
67716780
if measure:
67726781
# Never scale weights that are cell measures
@@ -6785,10 +6794,18 @@ def collapse(
67856794
radius=radius,
67866795
great_circle=great_circle,
67876796
)
6788-
6797+
print (9999)
67896798
if d_weights:
67906799
d_kwargs["weights"] = d_weights
6791-
6800+
if not allow_negative_weights:
6801+
for w in d_weights.values():
6802+
w_min= w.min()
6803+
if w_min < 0:
6804+
raise ValueError(
6805+
"All weights must be non-negative. "
6806+
f"Got a weight of {w_min!r}"
6807+
)
6808+
67926809
if debug:
67936810
logger.debug(
67946811
f" Output weights = {d_weights!r}"

cf/test/create_test_files.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
faulthandler.enable() # to debug seg faults and timeouts
99

10-
import cfdm
1110
import netCDF4
1211

12+
import cfdm
13+
1314
VN = cfdm.CF()
1415

1516

@@ -5374,7 +5375,7 @@ def _make_ugrid_2(filename):
53745375
"""Create a UGRID file with a 2-d mesh topology."""
53755376
n = netCDF4.Dataset(filename, "w")
53765377

5377-
n.Conventions = f"CF-{VN} UGRID-1.0"
5378+
n.Conventions = f"CF-{VN}"
53785379

53795380
n.createDimension("time", 2)
53805381
n.createDimension("nMesh2_node", 7)

cf/test/test_Field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ def test_Field_collapse(self):
548548
)
549549
self.assertEqual(len(u.coordinate_references()), 2)
550550
self.assertEqual(len(u.domain_ancillaries()), 2)
551-
551+
552552
def test_Field_all(self):
553553
f = self.f.copy()
554554

cf/test/test_collapse.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datetime
22
import faulthandler
3-
import inspect
43
import os
54
import unittest
65

@@ -25,9 +24,6 @@ def setUp(self):
2524
# self.test_only = ['test_Field_collapse_GROUPS']
2625

2726
def test_Field_collapse_CLIMATOLOGICAL_TIME(self):
28-
if self.test_only and inspect.stack()[0][3] not in self.test_only:
29-
return
30-
3127
verbose = False
3228

3329
f = cf.example_field(2)
@@ -258,9 +254,6 @@ def test_Field_collapse_CLIMATOLOGICAL_TIME(self):
258254
self.assertEqual(list(g.shape), expected_shape)
259255

260256
def test_Field_collapse(self):
261-
if self.test_only and inspect.stack()[0][3] not in self.test_only:
262-
return
263-
264257
verbose = False
265258

266259
f = cf.read(self.filename2)[0]
@@ -393,9 +386,6 @@ def test_Field_collapse(self):
393386
# )
394387

395388
def test_Field_collapse_WEIGHTS(self):
396-
if self.test_only and inspect.stack()[0][3] not in self.test_only:
397-
return
398-
399389
verbose = False
400390

401391
f = cf.example_field(2)
@@ -414,10 +404,40 @@ def test_Field_collapse_WEIGHTS(self):
414404
i = cf.example_field(4)
415405
i.collapse("area: maximum")
416406

407+
# Zero weights
408+
g = cf.example_field(0)
409+
w = g.weights('area')
410+
w.hardmask = False
411+
412+
for method in ('variance', 'sum_of_weights'):
413+
f = g.copy()
414+
weights = w.copy()
415+
416+
weights[0, 0] = 0
417+
m0 = f.collapse(axes='area', method=method, weights=weights)
418+
weights[0, 0] = cf.masked
419+
m1 = f.collapse(axes='area', method=method, weights=weights)
420+
self.assertTrue(m0.equals(m1))
421+
422+
f[0, 0] = cf.masked
423+
m = f.collapse(axes='area', method=method, weights=weights)
424+
self.assertTrue(m.equals(m0))
425+
426+
weights[0, 0] = 0
427+
m0 = f.collapse(axes='area', method=method, weights=weights)
428+
self.assertTrue(m0.equals(m))
429+
430+
weights[0, 0] = cf.masked
431+
m0 = f.collapse(axes='area', method=method, weights=weights)
432+
self.assertTrue(m0.equals(m))
433+
434+
# Negative weights
435+
weights[0, 0] = -3.14
436+
g.collapse('area: mean', weights=weights, allow_negative_weights=True)
437+
with self.assertRaises(ValueError):
438+
g.collapse('area: mean', weights=weights)
439+
417440
def test_Field_collapse_GROUPS(self):
418-
if self.test_only and inspect.stack()[0][3] not in self.test_only:
419-
return
420-
421441
verbose = False
422442

423443
f = cf.example_field(2)
@@ -695,17 +715,6 @@ def test_Field_collapse_GROUPS(self):
695715
print(g.constructs)
696716
self.assertEqual(list(g.shape), expected_shape, g.shape)
697717

698-
699-
# g = f[::2].collapse('T: mean', group=cf.M(5, month=12),
700-
# group_span=cf.M(5),group_contiguous=1)
701-
# g = f.collapse('T: mean', group=cf.M(5, month= 3),
702-
# group_contiguous=1)
703-
# g = f.collapse('T: mean', group=cf.M(5, month=12),
704-
# group_contiguous=2)
705-
# g = f.collapse('T: mean', group=cf.M(5, month= 3),
706-
# group_contiguous=2)
707-
708-
709718
if __name__ == "__main__":
710719
print("Run date:", datetime.datetime.now())
711720
cf.environment()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
netCDF4>=1.5.4
22
cftime>=1.6.2
33
numpy>=1.22
4-
cfdm>=1.11.0.0, <1.11.1.0
4+
cfdm>=1.11.0.0b1, <1.11.1.0
55
psutil>=0.6.0
66
cfunits>=3.3.6
77
dask>=2022.12.1

0 commit comments

Comments
 (0)