tonik 0.0.11__tar.gz → 0.0.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tonik-0.0.11 → tonik-0.0.12}/PKG-INFO +1 -1
- {tonik-0.0.11 → tonik-0.0.12}/pyproject.toml +1 -1
- {tonik-0.0.11 → tonik-0.0.12}/src/tonik/xarray2zarr.py +44 -8
- {tonik-0.0.11 → tonik-0.0.12}/.devcontainer/devcontainer.json +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/.gitignore +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/HOW_TO_RELEASE.md +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/LICENSE +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/README.md +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/docs/index.md +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/docs/tonik_example.ipynb +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/mkdocs.yml +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/src/tonik/__init__.py +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/src/tonik/api.py +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/src/tonik/package_data/index.html +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/src/tonik/storage.py +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/src/tonik/utils.py +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/src/tonik/xarray2hdf5.py +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/tests/backend_speed_test.py +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/tests/conftest.py +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/tests/test_api.py +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/tests/test_group.py +0 -0
- {tonik-0.0.11 → tonik-0.0.12}/tests/test_save.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: tonik
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.12
|
|
4
4
|
Summary: Store time series data as HDF5 files and access them through an API.
|
|
5
5
|
Project-URL: Homepage, https://tsc-tools.github.io/tonik
|
|
6
6
|
Project-URL: Issues, https://github.com/tsc-tools/tonik/issues
|
|
@@ -6,7 +6,47 @@ import xarray as xr
|
|
|
6
6
|
logger = logging.getLogger(__name__)
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
def
|
|
9
|
+
def merge_arrays(xds_old: xr.DataArray, xds_new: xr.DataArray) -> xr.DataArray:
|
|
10
|
+
"""
|
|
11
|
+
Merge two xarray datasets with the same datetime index.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
xds_old : xr.DataArray
|
|
16
|
+
Old array.
|
|
17
|
+
xds_new : xr.DataArray
|
|
18
|
+
New array.
|
|
19
|
+
|
|
20
|
+
Returns
|
|
21
|
+
-------
|
|
22
|
+
xr.DataArray
|
|
23
|
+
Merged array.
|
|
24
|
+
"""
|
|
25
|
+
xda_old = xds_old.drop_duplicates(
|
|
26
|
+
'datetime', keep='last')
|
|
27
|
+
xda_new = xds_new.drop_duplicates(
|
|
28
|
+
'datetime', keep='last')
|
|
29
|
+
xda_new = xda_new.combine_first(xda_old)
|
|
30
|
+
return xda_new
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def xarray2zarr(xds: xr.Dataset, path: str, mode: str = 'a'):
|
|
34
|
+
"""
|
|
35
|
+
Write xarray dataset to zarr files.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
xds : xr.Dataset
|
|
40
|
+
Dataset to write.
|
|
41
|
+
path : str
|
|
42
|
+
Path to write the dataset.
|
|
43
|
+
mode : str, optional
|
|
44
|
+
Write mode, by default 'a'.
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
None
|
|
49
|
+
"""
|
|
10
50
|
for feature in xds.data_vars.keys():
|
|
11
51
|
fout = os.path.join(path, feature + '.zarr')
|
|
12
52
|
if not os.path.exists(fout) or mode == 'w':
|
|
@@ -15,8 +55,8 @@ def xarray2zarr(xds, path, mode='a'):
|
|
|
15
55
|
else:
|
|
16
56
|
xds_existing = xr.open_zarr(fout, group='original')
|
|
17
57
|
if xds_existing.datetime[0] > xds.datetime[0] or xds_existing.datetime[-1] > xds.datetime[-1]:
|
|
18
|
-
|
|
19
|
-
|
|
58
|
+
xda_new = merge_arrays(xds_existing[feature], xds[feature])
|
|
59
|
+
xda_new.to_zarr(fout, group='original', mode='w')
|
|
20
60
|
else:
|
|
21
61
|
try:
|
|
22
62
|
overlap = xds_existing.datetime.where(
|
|
@@ -34,9 +74,5 @@ def xarray2zarr(xds, path, mode='a'):
|
|
|
34
74
|
msg += "Attempting to merge the two datasets."
|
|
35
75
|
logger.error(msg)
|
|
36
76
|
# remove duplicate datetime entries
|
|
37
|
-
|
|
38
|
-
'datetime', keep='last')
|
|
39
|
-
xda_new = xds[feature].drop_duplicates(
|
|
40
|
-
'datetime', keep='last')
|
|
41
|
-
xda_new = xda_new.combine_first(xda_existing)
|
|
77
|
+
xda_new = merge_arrays(xds_existing[feature], xds[feature])
|
|
42
78
|
xda_new.to_zarr(fout, group='original', mode='w')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|