tonik 0.0.10__py3-none-any.whl → 0.0.11__py3-none-any.whl

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/storage.py CHANGED
@@ -155,11 +155,7 @@ class Path(object):
155
155
 
156
156
  xd_index = dict(datetime=slice(self.starttime, self.endtime))
157
157
  with xr.open_dataset(filename, group='original', engine=self.backend) as ds:
158
- try:
159
- rq = ds.loc[xd_index].load()
160
- except KeyError:
161
- ds = ds.sortby("datetime")
162
- rq = ds.loc[xd_index].load()
158
+ rq = ds.loc[xd_index].load()
163
159
 
164
160
  # Stack features
165
161
  if stack_length is not None:
tonik/xarray2zarr.py CHANGED
@@ -14,24 +14,29 @@ def xarray2zarr(xds, path, mode='a'):
14
14
  fout, group='original', mode='w')
15
15
  else:
16
16
  xds_existing = xr.open_zarr(fout, group='original')
17
- try:
18
- overlap = xds_existing.datetime.where(
19
- xds_existing.datetime == xds.datetime)
20
- if overlap.size > 0:
21
- xds[feature].loc[dict(datetime=overlap)].to_zarr(
22
- fout, group='original', mode='r+', region='auto')
23
- xds[feature].drop_sel(datetime=overlap).to_zarr(
24
- fout, group='original', mode='a', append_dim="datetime")
25
- else:
26
- xds[feature].to_zarr(
27
- fout, group='original', append_dim='datetime')
28
- except Exception as e:
29
- msg = f"Appending {feature} to {fout} failed: {e}\n"
30
- msg += "Attempting to merge the two datasets."
31
- logger.error(msg)
32
- # remove duplicate datetime entries
33
- xda_existing = xds_existing[feature].drop_duplicates(
34
- 'datetime', keep='last')
35
- xda_new = xds[feature].drop_duplicates('datetime', keep='last')
36
- xda_new = xda_new.combine_first(xda_existing)
37
- xda_new.to_zarr(fout, group='original', mode='w')
17
+ if xds_existing.datetime[0] > xds.datetime[0] or xds_existing.datetime[-1] > xds.datetime[-1]:
18
+ xds_new = xr.merge([xds_existing[feature], xds[feature]])
19
+ xds_new.to_zarr(fout, group='original', mode='w')
20
+ else:
21
+ try:
22
+ overlap = xds_existing.datetime.where(
23
+ xds_existing.datetime == xds.datetime)
24
+ if overlap.size > 0:
25
+ xds[feature].loc[dict(datetime=overlap)].to_zarr(
26
+ fout, group='original', mode='r+', region='auto')
27
+ xds[feature].drop_sel(datetime=overlap).to_zarr(
28
+ fout, group='original', mode='a', append_dim="datetime")
29
+ else:
30
+ xds[feature].to_zarr(
31
+ fout, group='original', append_dim='datetime')
32
+ except Exception as e:
33
+ msg = f"Appending {feature} to {fout} failed: {e}\n"
34
+ msg += "Attempting to merge the two datasets."
35
+ logger.error(msg)
36
+ # remove duplicate datetime entries
37
+ xda_existing = xds_existing[feature].drop_duplicates(
38
+ 'datetime', keep='last')
39
+ xda_new = xds[feature].drop_duplicates(
40
+ 'datetime', keep='last')
41
+ xda_new = xda_new.combine_first(xda_existing)
42
+ xda_new.to_zarr(fout, group='original', mode='w')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: tonik
3
- Version: 0.0.10
3
+ Version: 0.0.11
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
@@ -0,0 +1,12 @@
1
+ tonik/__init__.py,sha256=ZBVGh4dm_l9xwiBGb33O5QV9MfZeNiEd3DBDAm6DiHk,511
2
+ tonik/api.py,sha256=8YS0WCMlm5xs2N6V8n9BiP87ywJC_BUzYsPvWR9KWJk,6499
3
+ tonik/storage.py,sha256=Ts6jKLqwcDQvPIea-swBCpnEjQr_xnAjOl-hkUelTn4,11165
4
+ tonik/utils.py,sha256=_TxXf9o9fOvtuOvGO6-ww9F5m0QelHyfQzQw8RGjTV4,1868
5
+ tonik/xarray2hdf5.py,sha256=cekO9vo9ZRlr0VndswJjPC27CEVD3TpRVKLAJ-aAO0g,4465
6
+ tonik/xarray2zarr.py,sha256=0bWMP_PZ0FLr9AlxKrC5M4aJRh_VGkUfJ-A-BGgKqM8,1979
7
+ tonik/package_data/index.html,sha256=GKDClUhIam_fAYbNfzAolORhSCG3ae1wW3VjWCg4PMk,2732
8
+ tonik-0.0.11.dist-info/METADATA,sha256=cXj6-wI7M6kWVvcffHe3W9BJQVdJfkNigzcrd0s5XlQ,1939
9
+ tonik-0.0.11.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
+ tonik-0.0.11.dist-info/entry_points.txt,sha256=VnGfC5qAzpntEHAb5pooUEpYABSgOfQoNhCEtLDJyf8,45
11
+ tonik-0.0.11.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
+ tonik-0.0.11.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- tonik/__init__.py,sha256=ZBVGh4dm_l9xwiBGb33O5QV9MfZeNiEd3DBDAm6DiHk,511
2
- tonik/api.py,sha256=8YS0WCMlm5xs2N6V8n9BiP87ywJC_BUzYsPvWR9KWJk,6499
3
- tonik/storage.py,sha256=sScIFA4KXURNPwTnV-rvDh6cWCy9sRrErr9BshZpw2I,11303
4
- tonik/utils.py,sha256=_TxXf9o9fOvtuOvGO6-ww9F5m0QelHyfQzQw8RGjTV4,1868
5
- tonik/xarray2hdf5.py,sha256=cekO9vo9ZRlr0VndswJjPC27CEVD3TpRVKLAJ-aAO0g,4465
6
- tonik/xarray2zarr.py,sha256=9gvm7vFnoe-O39-ow2pqK4xoFSg9Tg865qdqKYI-Zy8,1605
7
- tonik/package_data/index.html,sha256=GKDClUhIam_fAYbNfzAolORhSCG3ae1wW3VjWCg4PMk,2732
8
- tonik-0.0.10.dist-info/METADATA,sha256=IN-k1gZOtxQrsVlYDtpiJuBW4gIJCXRsqFO4pNCT_uo,1939
9
- tonik-0.0.10.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
- tonik-0.0.10.dist-info/entry_points.txt,sha256=VnGfC5qAzpntEHAb5pooUEpYABSgOfQoNhCEtLDJyf8,45
11
- tonik-0.0.10.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
- tonik-0.0.10.dist-info/RECORD,,
File without changes