Skip to content

Commit 4ea3997

Browse files
committed
Updated all code, removed active storage dependencies, attempt poetry 2 upgrade
1 parent 5e45752 commit 4ea3997

File tree

5 files changed

+778
-835
lines changed

5 files changed

+778
-835
lines changed

cfapyx/backend.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ def open_cfa_dataset(
2222
decode_coords=None,
2323
use_cftime=None,
2424
decode_timedelta=None,
25-
cfa_options: dict=None,
25+
cfa_options: dict = None,
2626
group=None,
2727
):
2828
"""
29-
Top-level function which opens a CFA dataset using Xarray. Creates a CFA Datastore
29+
Top-level function which opens a CFA dataset using Xarray.
30+
31+
Creates a CFA Datastore
3032
from the ``filename_or_obj`` provided, then passes this to a CFA StoreBackendEntrypoint
3133
to create an Xarray Dataset. Most parameters are not handled by CFA, so only the
3234
CFA-relevant ones are described here.
@@ -52,11 +54,7 @@ def open_cfa_dataset(
5254
store = CFADataStore.open(filename_or_obj, group=group)
5355

5456
# Expands cfa_options into individual kwargs for the store.
55-
store.cfa_options = cfa_options
56-
57-
use_active = False
58-
if hasattr(store, 'use_active'):
59-
use_active = store.use_active
57+
store.cfa_options = cfa_options
6058

6159
# Xarray makes use of StoreBackendEntrypoints to provide the Dataset 'ds'
6260
store_entrypoint = CFAStoreBackendEntrypoint()
@@ -68,13 +66,13 @@ def open_cfa_dataset(
6866
decode_coords=decode_coords,
6967
drop_variables=drop_variables,
7068
use_cftime=use_cftime,
71-
decode_timedelta=decode_timedelta,
72-
use_active=use_active
69+
decode_timedelta=decode_timedelta
7370
)
7471

7572
return ds
7673

7774
class CFANetCDFBackendEntrypoint(BackendEntrypoint):
75+
"""Open CFA-netCDF files (.nca) using 'cfapyx' in Xarray"""
7876

7977
description = 'Open CFA-netCDF files (.nca) using "cfapyx" in Xarray'
8078
url = "https://cedadev.github.io/CFAPyX/"
@@ -115,6 +113,8 @@ def open_dataset(
115113
group=group)
116114

117115
class CFAStoreBackendEntrypoint(StoreBackendEntrypoint):
116+
"""Open CFA-based Abstract Data Store"""
117+
118118
description = "Open CFA-based Abstract Data Store"
119119
url = "https://cedadev.github.io/CFAPyX/"
120120

@@ -128,7 +128,6 @@ def open_dataset(
128128
drop_variables=None,
129129
use_cftime=None,
130130
decode_timedelta=None,
131-
use_active=False,
132131
) -> Dataset:
133132
"""
134133
Takes cfa_xarray_store of type AbstractDataStore and creates an xarray.Dataset object.
@@ -162,18 +161,7 @@ def open_dataset(
162161
)
163162

164163
# Create the xarray.Dataset object here.
165-
if use_active:
166-
try:
167-
from XarrayActive import ActiveDataset
168-
169-
ds = ActiveDataset(vars, attrs=attrs)
170-
except ImportError:
171-
raise ImportError(
172-
'"ActiveDataset" from XarrayActive failed to import - please '
173-
'ensure you have the XarrayActive package installed.'
174-
)
175-
else:
176-
ds = Dataset(vars, attrs=attrs)
164+
ds = Dataset(vars, attrs=attrs)
177165

178166
ds = ds.set_coords(coord_names.intersection(vars))
179167
ds.set_close(cfa_xarray_store.close)

cfapyx/datastore.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class CFADataStore(NetCDF4DataStore):
3434
that may be un-set at time of use.
3535
"""
3636

37+
wrapper = FragmentArrayWrapper
38+
3739
@property
3840
def chunks(self):
3941
if hasattr(self,'_cfa_chunks'):
@@ -55,8 +57,7 @@ def cfa_options(self):
5557
'substitutions': self._substitutions,
5658
'decode_cfa': self._decode_cfa,
5759
'chunks': self.chunks,
58-
'chunk_limits': self._chunk_limits,
59-
'use_active': self.use_active
60+
'chunk_limits': self._chunk_limits
6061
}
6162

6263
@cfa_options.setter
@@ -69,7 +70,6 @@ def _set_cfa_options(
6970
decode_cfa=True,
7071
chunks={},
7172
chunk_limits=True,
72-
use_active=False,
7373
):
7474
"""
7575
Method to set cfa options.
@@ -80,8 +80,6 @@ def _set_cfa_options(
8080
:param decode_cfa: (bool) Optional setting to disable CFA decoding
8181
in some cases, default is True.
8282
83-
:param use_active: (bool) Enable for use with XarrayActive.
84-
8583
:param chunks: (dict) Not implemented in 2024.9.0
8684
8785
:param chunk_limits: (dict) Not implemented in 2024.9.0
@@ -91,7 +89,6 @@ def _set_cfa_options(
9189
self._substitutions = substitutions
9290
self._decode_cfa = decode_cfa
9391
self._chunk_limits = chunk_limits
94-
self.use_active = use_active
9592

9693
def _acquire(self, needs_lock=True):
9794
"""
@@ -360,7 +357,7 @@ def open_variable(self, name: str, var):
360357
:returns: The variable object opened as either a standard store variable
361358
or CFA aggregated variable.
362359
"""
363-
if type(var) == tuple:
360+
if isinstance(var, tuple):
364361
if var[1] and self._decode_cfa:
365362
variable = self.open_cfa_variable(name, var[0])
366363
else:
@@ -412,7 +409,7 @@ def open_cfa_variable(self, name: str, var):
412409

413410
## Array-like object
414411
data = indexing.LazilyIndexedArray(
415-
FragmentArrayWrapper(
412+
self.wrapper(
416413
fragment_info,
417414
fragment_space,
418415
shape=array_shape,

0 commit comments

Comments
 (0)