Skip to content

Commit e2fac2c

Browse files
committed
dev
2 parents 6545ae0 + a44f7ba commit e2fac2c

File tree

12 files changed

+1139
-95
lines changed

12 files changed

+1139
-95
lines changed

cf/data/collapse/dask_collapse.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from operator import mul
1111

1212
import numpy as np
13-
from cfdm.data.dask_utils import cfdm_asanyarray
13+
from cfdm.data.dask_utils import cfdm_to_memory
1414
from dask.array import chunk
1515
from dask.array.core import _concatenate2
1616
from dask.array.reductions import divide, numel
@@ -276,9 +276,9 @@ def cf_mean_chunk(
276276
if computing_meta:
277277
return x
278278

279-
x = cfdm_asanyarray(x)
279+
x = cfdm_to_memory(x)
280280
if weights is not None:
281-
weights = cfdm_asanyarray(weights)
281+
weights = cfdm_to_memory(weights)
282282

283283
# N, sum
284284
d = cf_sum_chunk(x, weights=weights, dtype=dtype, **kwargs)
@@ -401,7 +401,7 @@ def cf_max_chunk(x, dtype=None, computing_meta=False, **kwargs):
401401
if computing_meta:
402402
return x
403403

404-
x = cfdm_asanyarray(x)
404+
x = cfdm_to_memory(x)
405405

406406
return {
407407
"max": chunk.max(x, **kwargs),
@@ -555,7 +555,7 @@ def cf_min_chunk(x, dtype=None, computing_meta=False, **kwargs):
555555
if computing_meta:
556556
return x
557557

558-
x = cfdm_asanyarray(x)
558+
x = cfdm_to_memory(x)
559559

560560
return {
561561
"min": chunk.min(x, **kwargs),
@@ -662,7 +662,7 @@ def cf_range_chunk(x, dtype=None, computing_meta=False, **kwargs):
662662
if computing_meta:
663663
return x
664664

665-
x = cfdm_asanyarray(x)
665+
x = cfdm_to_memory(x)
666666

667667
# N, max
668668
d = cf_max_chunk(x, **kwargs)
@@ -779,7 +779,7 @@ def cf_rms_chunk(x, weights=None, dtype="f8", computing_meta=False, **kwargs):
779779
if computing_meta:
780780
return x
781781

782-
x = cfdm_asanyarray(x)
782+
x = cfdm_to_memory(x)
783783

784784
return cf_mean_chunk(
785785
np.multiply(x, x, dtype=dtype), weights=weights, dtype=dtype, **kwargs
@@ -857,7 +857,7 @@ def cf_sample_size_chunk(x, dtype="i8", computing_meta=False, **kwargs):
857857
if computing_meta:
858858
return x
859859

860-
x = cfdm_asanyarray(x)
860+
x = cfdm_to_memory(x)
861861

862862
if np.ma.isMA(x):
863863
N = chunk.sum(np.ones_like(x, dtype=dtype), **kwargs)
@@ -985,10 +985,10 @@ def cf_sum_chunk(
985985
if computing_meta:
986986
return x
987987

988-
x = cfdm_asanyarray(x)
988+
x = cfdm_to_memory(x)
989989

990990
if weights is not None:
991-
weights = cfdm_asanyarray(weights)
991+
weights = cfdm_to_memory(weights)
992992
if check_weights:
993993
w_min = weights.min()
994994
if w_min <= 0:
@@ -1107,9 +1107,9 @@ def cf_sum_of_weights_chunk(
11071107
if computing_meta:
11081108
return x
11091109

1110-
x = cfdm_asanyarray(x)
1110+
x = cfdm_to_memory(x)
11111111
if weights is not None:
1112-
weights = cfdm_asanyarray(weights)
1112+
weights = cfdm_to_memory(weights)
11131113

11141114
# N
11151115
d = cf_sample_size_chunk(x, **kwargs)
@@ -1152,9 +1152,9 @@ def cf_sum_of_weights2_chunk(
11521152
if computing_meta:
11531153
return x
11541154

1155-
x = cfdm_asanyarray(x)
1155+
x = cfdm_to_memory(x)
11561156
if weights is not None:
1157-
weights = cfdm_asanyarray(weights)
1157+
weights = cfdm_to_memory(weights)
11581158

11591159
# N
11601160
d = cf_sample_size_chunk(x, **kwargs)
@@ -1193,7 +1193,7 @@ def cf_unique_chunk(x, dtype=None, computing_meta=False, **kwargs):
11931193
if computing_meta:
11941194
return x
11951195

1196-
x = cfdm_asanyarray(x)
1196+
x = cfdm_to_memory(x)
11971197

11981198
return {"unique": np.unique(x)}
11991199

@@ -1298,11 +1298,11 @@ def cf_var_chunk(
12981298
if computing_meta:
12991299
return x
13001300

1301-
x = cfdm_asanyarray(x)
1301+
x = cfdm_to_memory(x)
13021302

13031303
weighted = weights is not None
13041304
if weighted:
1305-
weights = cfdm_asanyarray(weights)
1305+
weights = cfdm_to_memory(weights)
13061306

13071307
# N, V1, sum
13081308
d = cf_mean_chunk(x, weights=weights, dtype=dtype, **kwargs)

cf/data/dask_regrid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Regridding functions used within a dask graph."""
22

33
import numpy as np
4-
from cfdm.data.dask_utils import cfdm_asanyarray
4+
from cfdm.data.dask_utils import cfdm_to_memory
55

66

77
def regrid(
@@ -175,12 +175,12 @@ def regrid(
175175
"""
176176
weights, dst_mask = weights_dst_mask
177177

178-
a = cfdm_asanyarray(a)
178+
a = cfdm_to_memory(a)
179179
if dst_mask is not None:
180-
dst_mask = cfdm_asanyarray(dst_mask)
180+
dst_mask = cfdm_to_memory(dst_mask)
181181

182182
if ref_src_mask is not None:
183-
ref_src_mask = cfdm_asanyarray(ref_src_mask)
183+
ref_src_mask = cfdm_to_memory(ref_src_mask)
184184

185185
# ----------------------------------------------------------------
186186
# Reshape the array into a form suitable for the regridding dot

cf/data/dask_utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from functools import partial
99

1010
import numpy as np
11-
from cfdm.data.dask_utils import cfdm_asanyarray
11+
from cfdm.data.dask_utils import cfdm_to_memory
1212
from scipy.ndimage import convolve1d
1313

1414
from ..cfdatetime import dt, dt2rt, rt2dt
@@ -38,8 +38,8 @@ def cf_contains(a, value):
3838
value.
3939
4040
"""
41-
a = cfdm_asanyarray(a)
42-
value = cfdm_asanyarray(value)
41+
a = cfdm_to_memory(a)
42+
value = cfdm_to_memory(value)
4343
return np.array(value in a).reshape((1,) * a.ndim)
4444

4545

@@ -73,7 +73,7 @@ def cf_convolve1d(a, window=None, axis=-1, origin=0):
7373
Convolved float array with same shape as input.
7474
7575
"""
76-
a = cfdm_asanyarray(a)
76+
a = cfdm_to_memory(a)
7777

7878
# Cast to float to ensure that NaNs can be stored
7979
if a.dtype != float:
@@ -155,7 +155,7 @@ def cf_percentile(a, q, axis, method, keepdims=False, mtol=1):
155155
"""
156156
from math import prod
157157

158-
a = cfdm_asanyarray(a)
158+
a = cfdm_to_memory(a)
159159

160160
if np.ma.isMA(a) and not np.ma.is_masked(a):
161161
# Masked array with no masked elements
@@ -274,7 +274,7 @@ def cf_YMDhms(a, attr):
274274
array([1, 2])
275275
276276
"""
277-
a = cfdm_asanyarray(a)
277+
a = cfdm_to_memory(a)
278278
return _array_getattr(a, attr=attr)
279279

280280

@@ -307,7 +307,7 @@ def cf_rt2dt(a, units):
307307
cftime.DatetimeGregorian(2000, 1, 2, 0, 0, 0, 0, has_year_zero=False)]
308308
309309
"""
310-
a = cfdm_asanyarray(a)
310+
a = cfdm_to_memory(a)
311311

312312
if not units.iscalendartime:
313313
return rt2dt(a, units_in=units)
@@ -363,7 +363,7 @@ def cf_dt2rt(a, units):
363363
[365 366]
364364
365365
"""
366-
a = cfdm_asanyarray(a)
366+
a = cfdm_to_memory(a)
367367
return dt2rt(a, units_out=units, units_in=None)
368368

369369

@@ -404,7 +404,7 @@ def cf_units(a, from_units, to_units):
404404
[1000. 2000.]
405405
406406
"""
407-
a = cfdm_asanyarray(a)
407+
a = cfdm_to_memory(a)
408408
return Units.conform(
409409
a, from_units=from_units, to_units=to_units, inplace=False
410410
)
@@ -428,7 +428,7 @@ def cf_is_masked(a):
428428
values.
429429
430430
"""
431-
a = cfdm_asanyarray(a)
431+
a = cfdm_to_memory(a)
432432
out = np.ma.is_masked(a)
433433
return np.array(out).reshape((1,) * a.ndim)
434434

@@ -461,5 +461,5 @@ def cf_filled(a, fill_value=None):
461461
[[-999 2 3]]
462462
463463
"""
464-
a = cfdm_asanyarray(a)
464+
a = cfdm_to_memory(a)
465465
return np.ma.filled(a, fill_value=fill_value)

0 commit comments

Comments
 (0)