Skip to content

Commit 719b3e4

Browse files
authored
Merge pull request #23 from cedadev/poetry2
Poetry 2 + Logs
2 parents 791bc6e + 0b10346 commit 719b3e4

File tree

17 files changed

+1178
-800
lines changed

17 files changed

+1178
-800
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ jobs:
3030
python3 -m pip install --upgrade pip
3131
pip3 install poetry
3232
poetry install
33-
- name: Run isort
34-
run: |
35-
poetry run isort --check --diff cfapyx
33+
#- name: Run isort
34+
# run: |
35+
# poetry run isort --check --diff cfapyx
3636
# Test with pytest
3737
- name: Run pytest
3838
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CFAPyX.egg-info/
99
.vscode/
1010
testing/
1111
build/
12+
dist/
1213
.DS_Store
1314
docs/.DS_Store
1415
docs/source/.DS_Store

cfapyx/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .backend import CFANetCDFBackendEntrypoint
22
from .creator import CFANetCDF
3+
from .utils import set_verbose

cfapyx/backend.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@
1111

1212
from cfapyx.datastore import CFADataStore
1313

14+
from cfapyx.utils import logstream
15+
1416
logger = logging.getLogger(__name__)
1517

18+
logger.addHandler(logstream)
19+
logger.propagate = False
20+
1621
def open_cfa_dataset(
1722
filename_or_obj,
1823
drop_variables=None,
@@ -22,11 +27,13 @@ def open_cfa_dataset(
2227
decode_coords=None,
2328
use_cftime=None,
2429
decode_timedelta=None,
25-
cfa_options: dict=None,
30+
cfa_options: dict = None,
2631
group=None,
2732
):
2833
"""
29-
Top-level function which opens a CFA dataset using Xarray. Creates a CFA Datastore
34+
Top-level function which opens a CFA dataset using Xarray.
35+
36+
Creates a CFA Datastore
3037
from the ``filename_or_obj`` provided, then passes this to a CFA StoreBackendEntrypoint
3138
to create an Xarray Dataset. Most parameters are not handled by CFA, so only the
3239
CFA-relevant ones are described here.
@@ -52,11 +59,7 @@ def open_cfa_dataset(
5259
store = CFADataStore.open(filename_or_obj, group=group)
5360

5461
# 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
62+
store.cfa_options = cfa_options
6063

6164
# Xarray makes use of StoreBackendEntrypoints to provide the Dataset 'ds'
6265
store_entrypoint = CFAStoreBackendEntrypoint()
@@ -68,13 +71,13 @@ def open_cfa_dataset(
6871
decode_coords=decode_coords,
6972
drop_variables=drop_variables,
7073
use_cftime=use_cftime,
71-
decode_timedelta=decode_timedelta,
72-
use_active=use_active
74+
decode_timedelta=decode_timedelta
7375
)
7476

7577
return ds
7678

7779
class CFANetCDFBackendEntrypoint(BackendEntrypoint):
80+
"""Open CFA-netCDF files (.nca) using 'cfapyx' in Xarray"""
7881

7982
description = 'Open CFA-netCDF files (.nca) using "cfapyx" in Xarray'
8083
url = "https://cedadev.github.io/CFAPyX/"
@@ -115,6 +118,8 @@ def open_dataset(
115118
group=group)
116119

117120
class CFAStoreBackendEntrypoint(StoreBackendEntrypoint):
121+
"""Open CFA-based Abstract Data Store"""
122+
118123
description = "Open CFA-based Abstract Data Store"
119124
url = "https://cedadev.github.io/CFAPyX/"
120125

@@ -128,7 +133,6 @@ def open_dataset(
128133
drop_variables=None,
129134
use_cftime=None,
130135
decode_timedelta=None,
131-
use_active=False,
132136
) -> Dataset:
133137
"""
134138
Takes cfa_xarray_store of type AbstractDataStore and creates an xarray.Dataset object.
@@ -162,18 +166,7 @@ def open_dataset(
162166
)
163167

164168
# 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)
169+
ds = Dataset(vars, attrs=attrs)
177170

178171
ds = ds.set_coords(coord_names.intersection(vars))
179172
ds.set_close(cfa_xarray_store.close)

cfapyx/creator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
import netCDF4
1010
import numpy as np
1111

12+
from cfapyx.utils import logstream
13+
1214
logger = logging.getLogger(__name__)
1315

16+
logger.addHandler(logstream)
17+
logger.propagate = False
18+
1419
CONCAT_MSG = 'See individual datasets for more information.'
1520

1621
class CFACreateMixin:
@@ -93,7 +98,6 @@ def _first_pass(self, agg_dims: list = None) -> tuple:
9398
f'Files contain differing numbers of dimensions. "{d}"'
9499
'appears to not be present in all files.'
95100
)
96-
97101
new_info, arr_components = self._collect_dim_info(
98102
ds, d, pure_dimensions, coord_variables,
99103
agg_dims=agg_dims, first_time=first_time)
@@ -305,7 +309,7 @@ def _arrange_dimensions(
305309
sort = np.argsort(arr)
306310

307311
cdimarr = None
308-
nds = []
312+
nds, nstarts = [],[]
309313
for s in sort:
310314

311315
if cdimarr is None:
@@ -314,21 +318,25 @@ def _arrange_dimensions(
314318
cdimarr = np.concatenate((cdimarr, np.array(arrays[s])))
315319

316320
nds.append(sizes[s])
321+
nstarts.append(starts[s])
317322

318323
ndimsizes = tuple(nds) # Removed np.array here
319324

320325
info['size'] = cdimarr.size
321326
info['array'] = cdimarr
322327
info['sizes'] = ndimsizes
323328

329+
# Reorder starts like with sizes
330+
info['starts'] = nstarts
331+
324332
if agg_dims is not None:
325333
if len(agg_dims) != len(aggregation_dims):
326334
raise ValueError(
327335
'Found fewer aggregation dims than user provided value.'
328336
f'User defined: ({list(agg_dims)})'
329337
f'Derived: ({list(aggregation_dims)})'
330338
)
331-
339+
332340
return dim_info, aggregation_dims
333341

334342
def _assemble_location(

cfapyx/datastore.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
from cfapyx.group import CFAGroupWrapper
1818
from cfapyx.wrappers import FragmentArrayWrapper
1919

20+
from cfapyx.utils import logstream
21+
2022
logger = logging.getLogger(__name__)
2123

24+
logger.addHandler(logstream)
25+
logger.propagate = False
26+
2227

2328
xarray_subs = {
2429
'file:///':'/'
@@ -34,6 +39,8 @@ class CFADataStore(NetCDF4DataStore):
3439
that may be un-set at time of use.
3540
"""
3641

42+
wrapper = FragmentArrayWrapper
43+
3744
@property
3845
def chunks(self):
3946
if hasattr(self,'_cfa_chunks'):
@@ -55,8 +62,7 @@ def cfa_options(self):
5562
'substitutions': self._substitutions,
5663
'decode_cfa': self._decode_cfa,
5764
'chunks': self.chunks,
58-
'chunk_limits': self._chunk_limits,
59-
'use_active': self.use_active
65+
'chunk_limits': self._chunk_limits
6066
}
6167

6268
@cfa_options.setter
@@ -69,7 +75,6 @@ def _set_cfa_options(
6975
decode_cfa=True,
7076
chunks={},
7177
chunk_limits=True,
72-
use_active=False,
7378
):
7479
"""
7580
Method to set cfa options.
@@ -80,8 +85,6 @@ def _set_cfa_options(
8085
:param decode_cfa: (bool) Optional setting to disable CFA decoding
8186
in some cases, default is True.
8287
83-
:param use_active: (bool) Enable for use with XarrayActive.
84-
8588
:param chunks: (dict) Not implemented in 2024.9.0
8689
8790
:param chunk_limits: (dict) Not implemented in 2024.9.0
@@ -91,7 +94,6 @@ def _set_cfa_options(
9194
self._substitutions = substitutions
9295
self._decode_cfa = decode_cfa
9396
self._chunk_limits = chunk_limits
94-
self.use_active = use_active
9597

9698
def _acquire(self, needs_lock=True):
9799
"""
@@ -360,7 +362,7 @@ def open_variable(self, name: str, var):
360362
:returns: The variable object opened as either a standard store variable
361363
or CFA aggregated variable.
362364
"""
363-
if type(var) == tuple:
365+
if isinstance(var, tuple):
364366
if var[1] and self._decode_cfa:
365367
variable = self.open_cfa_variable(name, var[0])
366368
else:
@@ -412,7 +414,7 @@ def open_cfa_variable(self, name: str, var):
412414

413415
## Array-like object
414416
data = indexing.LazilyIndexedArray(
415-
FragmentArrayWrapper(
417+
self.wrapper(
416418
fragment_info,
417419
fragment_space,
418420
shape=array_shape,

cfapyx/decoder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
import logging
66
from itertools import accumulate, product
77

8+
from cfapyx.utils import logstream
9+
810
logger = logging.getLogger(__name__)
911

12+
logger.addHandler(logstream)
13+
logger.propagate = False
14+
1015
def get_fragment_positions(fragment_size_per_dim):
1116
"""
1217
Get the positions in index space for each fragment.

cfapyx/group.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
import logging
66

7+
from cfapyx.utils import logstream
8+
79
logger = logging.getLogger(__name__)
810

11+
logger.addHandler(logstream)
12+
logger.propagate = False
13+
914
class VariableWrapper:
1015
"""
1116
Wrapper object for the ``ds.variables`` and ``ds.attributes`` objects which can handle

cfapyx/tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ def pytest_collection_modifyitems(items):
44
CLASS_ORDER = [
55
"TestPath"
66
"TestCFAWrite",
7-
"TestCFARead",
8-
"TestCleanup"
7+
"TestCFARead"
98
]
109

1110
sorted_items = items.copy()

cfapyx/tests/test_basic.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,4 @@
77
class TestPath:
88
def testpath(self, tests=TESTDIR):
99
logger.error(os.getcwd())
10-
logger.error(tests)
11-
12-
class TestCleanup:
13-
def test_cleanup(self, testdir=TESTDIR):
14-
os.system(f'rm {testdir}/testrain.nca')
15-
print('Integration tests: Cleanup - complete')
10+
logger.error(tests)

0 commit comments

Comments
 (0)