Skip to content

Commit 1afb34a

Browse files
committed
dev
1 parent 6009f36 commit 1afb34a

File tree

10 files changed

+300
-345
lines changed

10 files changed

+300
-345
lines changed

cf/aggregate.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,11 @@ def __init__(
807807
self.msr = {}
808808
info_msr = {}
809809
for key, msr in f.cell_measures(todict=True).items():
810-
if not (
811-
self.has_measure(msr)
812-
and self.has_data(msr)
813-
and self.has_units(msr)
810+
if not self.has_measure(msr):
811+
return
812+
813+
if not msr.nc_get_external() and not (
814+
self.has_data(msr) and self.has_units(msr)
814815
):
815816
return
816817

@@ -2972,7 +2973,7 @@ def aggregate(
29722973
output_meta_append(meta)
29732974

29742975
continue
2975-
2976+
29762977
# ------------------------------------------------------------
29772978
# This field has a structural signature, so append it to the
29782979
# list of fields with the same structural signature.
@@ -3601,7 +3602,6 @@ def _create_hash_and_first_values(
36013602
canonical_direction = {}
36023603

36033604
for m in meta:
3604-
print(777)
36053605
field = m.field
36063606
constructs = field.constructs.todict()
36073607

@@ -3669,11 +3669,11 @@ def _create_hash_and_first_values(
36693669
sort_indices = slice(None, None, -1)
36703670
else:
36713671
sort_indices = slice(None)
3672-
elif identity in m.domain_topology:
3672+
elif identity in m.domain_topology:
36733673
# ... or which doesn't have a dimension coordinate but
36743674
# does have a domain topology ...
36753675
sort_indices = slice(None)
3676-
needs_sorting = False
3676+
needs_sorting = False
36773677
else:
36783678
# ... or which doesn't have a dimension coordinate but
36793679
# does have one or more 1-d auxiliary coordinates
@@ -3753,7 +3753,7 @@ def _create_hash_and_first_values(
37533753
m_hash_values[identity] = hash_values
37543754
m_first_values[identity] = first_values
37553755
m_last_values[identity] = last_values
3756-
3756+
37573757
# ------------------------------------------------------------
37583758
# N-d auxiliary coordinates
37593759
# ------------------------------------------------------------
@@ -3882,7 +3882,6 @@ def _create_hash_and_first_values(
38823882
hash_values.append((h,))
38833883

38843884
topology["hash_values"] = hash_values
3885-
print('done domain_top',topology)
38863885

38873886
# ------------------------------------------------------------
38883887
# Cell connectivities
@@ -3920,7 +3919,6 @@ def _create_hash_and_first_values(
39203919

39213920
connectivity["hash_values"] = hash_values
39223921

3923-
print('done cell_conn', connectivity)
39243922
# ------------------------------------------------------------
39253923
# Field ancillaries
39263924
# ------------------------------------------------------------
@@ -4039,7 +4037,6 @@ def _sort_indices(m, canonical_axes):
40394037
"""
40404038
canonical_axes = [m.id_to_axis[identity] for identity in canonical_axes]
40414039
sort_indices = tuple([m.sort_indices[axis] for axis in canonical_axes])
4042-
print (m.sort_indices, sort_indices, (slice(None),) * len(sort_indices))
40434040
needs_sorting = sort_indices != (slice(None),) * len(sort_indices)
40444041
return sort_indices, needs_sorting
40454042

@@ -4554,39 +4551,51 @@ def _ok_coordinate_arrays(
45544551
f"contiguous={bool(contiguous)} and "
45554552
f"{m.axis[axis]['ids'][dim_coord_index]!r} "
45564553
"dimension coordinate cells do not match "
4557-
"the cell spacing condition between fields "
4558-
f"({data1!r} - {data0!r} = {dim_diff!r}) "
4554+
"the cell spacing condition between fields: "
4555+
f"{data1!r} - {data0!r} = {dim_diff!r} "
45594556
f"!= {diff!r}"
45604557
)
45614558

45624559
return False
45634560
else:
45644561
# ------------------------------------------------------------
4565-
# The aggregating axis does not have a dimension coordinate,
4566-
# but it does have at least one 1-d auxiliary coordinate.
4562+
# The aggregating axis does not have a dimension coordinate
45674563
# ------------------------------------------------------------
4568-
# Check for duplicate auxiliary coordinate values
4569-
for i, identity in enumerate(meta[0].axis[axis]["ids"]):
4570-
set_of_1d_aux_coord_values = set()
4571-
number_of_1d_aux_coord_values = 0
4572-
for m in meta:
4573-
aux = m.axis[axis]["keys"][i]
4574-
# '.data.compute()' is faster than '.array'
4575-
array = m.field.constructs[aux].data.compute()
4576-
set_of_1d_aux_coord_values.update(array)
4577-
number_of_1d_aux_coord_values += array.size
4578-
if (
4579-
len(set_of_1d_aux_coord_values)
4580-
!= number_of_1d_aux_coord_values
4581-
):
4582-
if info:
4583-
meta[0].message = (
4584-
f"no {identity!r} dimension coordinates and "
4585-
f"{identity!r} auxiliary coordinates have "
4586-
"duplicate values"
4587-
)
4564+
if axis in m.domain_topology or axis in m.cell_connectivity:
4565+
if info:
4566+
meta[0].message = (
4567+
f"can't aggregate along the {axis!r} mesh topology "
4568+
"discrete axis"
4569+
)
45884570

4589-
return False
4571+
return False
4572+
# else:
4573+
# ------------------------------------------------------------
4574+
# The aggregating axis does not have a dimension coordinate,
4575+
# but it does have at least one 1-d auxiliary coordinate.
4576+
# ------------------------------------------------------------
4577+
# Check for duplicate auxiliary coordinate values
4578+
# for i, identity in enumerate(meta[0].axis[axis]["ids"]):
4579+
# set_of_1d_aux_coord_values = set()
4580+
# number_of_1d_aux_coord_values = 0
4581+
# for m in meta:
4582+
# aux = m.axis[axis]["keys"][i]
4583+
# # Note: '.data.compute()' is faster than '.array'
4584+
# array = m.field.constructs[aux].data.compute()
4585+
# set_of_1d_aux_coord_values.update(array.tolist())
4586+
# number_of_1d_aux_coord_values += array.size
4587+
# if (
4588+
# len(set_of_1d_aux_coord_values)
4589+
# != number_of_1d_aux_coord_values
4590+
# ):
4591+
# if info:
4592+
# meta[0].message = (
4593+
# f"no {identity!r} dimension coordinates and "
4594+
# f"{identity!r} auxiliary coordinates have "
4595+
# "duplicate values"
4596+
# )
4597+
#
4598+
# return False
45904599

45914600
# ----------------------------------------------------------------
45924601
# Still here? Then the aggregating axis does not overlap between

cf/data/array/mixin/raggedarraymixin.py

Lines changed: 0 additions & 103 deletions
This file was deleted.

cf/data/data.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10006,6 +10006,60 @@ def masked_all(
1000610006
d._set_dask(dx)
1000710007
return d
1000810008

10009+
@_inplace_enabled(default=False)
10010+
def masked_values(self, value, rtol=None, atol=None, inplace=False):
10011+
"""Mask using floating point equality.
10012+
10013+
Masks the data where elements are approximately equal to the
10014+
given value. For integer types, exact equality is used.
10015+
10016+
.. versionadded:: UGRIDVER
10017+
10018+
.. seealso:: `mask`
10019+
10020+
:Parameters:
10021+
10022+
value: number
10023+
Masking value.
10024+
10025+
{{rtol: number, optional}}
10026+
10027+
{{atol: number, optional}}
10028+
10029+
{{inplace: `bool`, optional}}
10030+
10031+
:Returns:
10032+
10033+
`{{class}}` or `None`
10034+
The result of masking the data where approximately
10035+
equal to *value*, or `None` if the operation was
10036+
in-place.
10037+
10038+
**Examples**
10039+
10040+
>>> d = {{package}}.{{class}}([1, 1.1, 2, 1.1, 3])
10041+
>>> e = d.masked_values(1.1)
10042+
>>> print(e.array)
10043+
[1.0 -- 2.0 -- 3.0]
10044+
10045+
"""
10046+
d = _inplace_enabled_define_and_cleanup(self)
10047+
10048+
if rtol is None:
10049+
rtol = self._rtol
10050+
else:
10051+
rtol = float(rtol)
10052+
10053+
if atol is None:
10054+
atol = self._atol
10055+
else:
10056+
atol = float(atol)
10057+
10058+
dx = d.to_dask_array()
10059+
dx = da.ma.masked_values(dx, value, rtol=rtol, atol=atol)
10060+
d._set_dask(dx)
10061+
return d
10062+
1000910063
@_inplace_enabled(default=False)
1001010064
@_deprecated_kwarg_check("i", version="3.0.0", removed_at="4.0.0")
1001110065
def mid_range(

cf/field.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,13 +3786,14 @@ def weights(
37863786
for key, w in comp.items():
37873787
comp[key] = weights_scale(w, scale)
37883788

3789-
for w in comp.values():
3790-
mn = w.minimum()
3791-
if mn <= 0:
3792-
raise ValueError(
3793-
"All weights must be positive. "
3794-
f"Got a weight of {mn}"
3795-
)
3789+
# Don't do this - too much lazy doom!
3790+
# for w in comp.values():
3791+
# mn = w.min()
3792+
# if mn <= 0:
3793+
# raise ValueError(
3794+
# "All weights must be positive. "
3795+
# f"Got a weight of {mn}"
3796+
# )
37963797

37973798
if components or methods:
37983799
# --------------------------------------------------------
@@ -6693,6 +6694,8 @@ def collapse(
66936694
"simultaneously"
66946695
)
66956696

6697+
axis = [a for a in collapse_axes][0]
6698+
66966699
# ------------------------------------------------------------
66976700
# Grouped collapse: Calculate weights
66986701
# ------------------------------------------------------------
@@ -6718,10 +6721,17 @@ def collapse(
67186721
great_circle=great_circle,
67196722
)
67206723

6724+
# For grouped collapses, bring the weights into
6725+
# memory. This is to prevent lazy operations being
6726+
# run on the entire weights array for every group.
67216727
if not g_weights:
67226728
g_weights = None
6723-
6724-
axis = [a for a in collapse_axes][0]
6729+
elif isinstance(g_weights, dict):
6730+
iaxes = (self.get_data_axes().index(axis),)
6731+
if iaxes in g_weights:
6732+
g_weights[iaxes] = np.asanyarray(g_weights[iaxes])
6733+
else:
6734+
g_weights = np.asanyarray(g_weights)
67256735

67266736
f = f._collapse_grouped(
67276737
method,

cf/mixin/propertiesdata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3282,7 +3282,7 @@ def equivalent(self, other, rtol=None, atol=None, traceback=False):
32823282
return True
32833283

32843284
# Check that each instance is the same type
3285-
if type(self) != type(other):
3285+
if type(self) is type(other):
32863286
print(
32873287
f"{self.__class__.__name__}: Different types: "
32883288
f"{self.__class__.__name__}, {other.__class__.__name__}"

cf/mixin/propertiesdatabounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ def equivalent(self, other, rtol=None, atol=None, traceback=False):
17341734
return True
17351735

17361736
# Check that each instance is the same type
1737-
if type(self) != type(other):
1737+
if type(self) is type(other):
17381738
print(
17391739
f"{self.__class__.__name__}: Different types: "
17401740
f"{self.__class__.__name__}, {other.__class__.__name__}"

0 commit comments

Comments
 (0)