Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhassell committed Oct 23, 2023
1 parent 3ba860a commit 4b1f7bd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 57 deletions.
26 changes: 5 additions & 21 deletions cf/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
"var",
"variance",
"sum",
'sum_of_weights',
'sum_of_weights2',
"sum_of_weights",
"sum_of_weights2",
"integral",
"root_mean_square",
)
Expand Down Expand Up @@ -3766,7 +3766,7 @@ def weights(
# ----------------------------------------------------
for key, w in comp.items():
comp[key] = Weights.scale(w, scale)

if components or methods:
# --------------------------------------------------------
# Return a dictionary of component weights, which may be
Expand Down Expand Up @@ -4957,7 +4957,6 @@ def collapse(
great_circle=False,
verbose=None,
remove_vertical_crs=True,
allow_negative_weights=False,
_create_zero_size_cell_bounds=False,
_update_cell_methods=True,
i=False,
Expand Down Expand Up @@ -6402,12 +6401,6 @@ def collapse(

.. versionadded:: 3.14.1

allow_negative_weights: `bool`, optional

If true then allow weights provided

.. versionadded:: UGRIDVER

{{inplace: `bool`, optional}}

{{i: deprecated at version 3.0.0}}
Expand Down Expand Up @@ -6775,7 +6768,6 @@ def collapse(
weights = None

d_kwargs = {}
print (11, repr(weights))
if weights is not None:
if measure:
# Never scale weights that are cell measures
Expand All @@ -6794,18 +6786,10 @@ def collapse(
radius=radius,
great_circle=great_circle,
)
print (9999)

if d_weights:
d_kwargs["weights"] = d_weights
if not allow_negative_weights:
for w in d_weights.values():
w_min= w.min()
if w_min < 0:
raise ValueError(
"All weights must be non-negative. "
f"Got a weight of {w_min!r}"
)


if debug:
logger.debug(
f" Output weights = {d_weights!r}"
Expand Down
3 changes: 1 addition & 2 deletions cf/test/create_test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

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

import netCDF4

import cfdm
import netCDF4

VN = cfdm.CF()

Expand Down
2 changes: 1 addition & 1 deletion cf/test/test_Field.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def test_Field_collapse(self):
)
self.assertEqual(len(u.coordinate_references()), 2)
self.assertEqual(len(u.domain_ancillaries()), 2)

def test_Field_all(self):
f = self.f.copy()

Expand Down
34 changes: 1 addition & 33 deletions cf/test/test_collapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,39 +404,6 @@ def test_Field_collapse_WEIGHTS(self):
i = cf.example_field(4)
i.collapse("area: maximum")

# Zero weights
g = cf.example_field(0)
w = g.weights('area')
w.hardmask = False

for method in ('variance', 'sum_of_weights'):
f = g.copy()
weights = w.copy()

weights[0, 0] = 0
m0 = f.collapse(axes='area', method=method, weights=weights)
weights[0, 0] = cf.masked
m1 = f.collapse(axes='area', method=method, weights=weights)
self.assertTrue(m0.equals(m1))

f[0, 0] = cf.masked
m = f.collapse(axes='area', method=method, weights=weights)
self.assertTrue(m.equals(m0))

weights[0, 0] = 0
m0 = f.collapse(axes='area', method=method, weights=weights)
self.assertTrue(m0.equals(m))

weights[0, 0] = cf.masked
m0 = f.collapse(axes='area', method=method, weights=weights)
self.assertTrue(m0.equals(m))

# Negative weights
weights[0, 0] = -3.14
g.collapse('area: mean', weights=weights, allow_negative_weights=True)
with self.assertRaises(ValueError):
g.collapse('area: mean', weights=weights)

def test_Field_collapse_GROUPS(self):
verbose = False

Expand Down Expand Up @@ -715,6 +682,7 @@ def test_Field_collapse_GROUPS(self):
print(g.constructs)
self.assertEqual(list(g.shape), expected_shape, g.shape)


if __name__ == "__main__":
print("Run date:", datetime.datetime.now())
cf.environment()
Expand Down

0 comments on commit 4b1f7bd

Please sign in to comment.