tonik 0.1.0__py3-none-any.whl → 0.1.2__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
@@ -76,6 +76,7 @@ class Path(object):
76
76
  self.name = name
77
77
  self.create = create
78
78
  self.backend = backend
79
+ self.engine = 'h5netcdf' if self.backend == 'netcdf' else self.backend
79
80
  self.path = os.path.join(parentdir, name)
80
81
  if create:
81
82
  try:
@@ -154,8 +155,7 @@ class Path(object):
154
155
  format(stack_length, interval, num_periods))
155
156
 
156
157
  xd_index = dict(datetime=slice(self.starttime, self.endtime))
157
- engine = 'h5netcdf' if self.backend == 'netcdf' else self.backend
158
- with xr.open_dataset(filename, group='original', engine=engine) as ds:
158
+ with xr.open_dataset(filename, group='original', engine=self.engine) as ds:
159
159
  rq = ds.loc[xd_index].load()
160
160
 
161
161
  # Stack features
@@ -193,6 +193,14 @@ class Path(object):
193
193
  elif self.backend == 'zarr':
194
194
  xarray2zarr(data, self.path, **kwargs)
195
195
 
196
+ def shape(self, feature):
197
+ """
198
+ Get shape of a feature on disk
199
+ """
200
+ filename = self.feature_path(feature)
201
+ with xr.open_dataset(filename, group='original', engine=self.engine) as ds:
202
+ return ds[feature].sizes
203
+
196
204
 
197
205
  class Storage(Path):
198
206
  """
tonik/xarray2netcdf.py CHANGED
@@ -12,7 +12,8 @@ from .utils import merge_arrays
12
12
 
13
13
 
14
14
  def xarray2netcdf(xArray, fdir, rootGroupName="original", timedim="datetime",
15
- archive_starttime=datetime(2000, 1, 1), resolution=None):
15
+ archive_starttime=datetime(2000, 1, 1), resolution=None,
16
+ mode='a'):
16
17
  """
17
18
  Store an xarray dataset as an HDF5 file.
18
19
 
@@ -44,8 +45,8 @@ def xarray2netcdf(xArray, fdir, rootGroupName="original", timedim="datetime",
44
45
 
45
46
  for featureName in list(xArray.data_vars.keys()):
46
47
  h5file = os.path.join(fdir, featureName + '.nc')
47
- mode = 'w'
48
- if os.path.isfile(h5file):
48
+ _mode = 'w'
49
+ if os.path.isfile(h5file) and mode == 'a':
49
50
  if archive_starttime > data_starttime:
50
51
  xds_existing = xr.open_dataset(
51
52
  h5file, group='original', engine='h5netcdf')
@@ -56,9 +57,9 @@ def xarray2netcdf(xArray, fdir, rootGroupName="original", timedim="datetime",
56
57
  xda_new.to_netcdf(h5file, group='original',
57
58
  mode='w', engine='h5netcdf')
58
59
  continue
59
- mode = 'a'
60
+ _mode = 'a'
60
61
 
61
- with h5netcdf.File(h5file, mode) as h5f:
62
+ with h5netcdf.File(h5file, _mode) as h5f:
62
63
  try:
63
64
  rootGrp = _create_h5_Structure(rootGroupName, featureName,
64
65
  h5f, xArray, starttime, timedim)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: tonik
3
- Version: 0.1.0
3
+ Version: 0.1.2
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=zn-Nn6A9wIfkvivQOm9pdGqLH1TGx6CtHX7nbq2tLQE,11508
4
+ tonik/utils.py,sha256=3nSRU_GnV6arP4e63YHn4oEV8XbqzVAW8FCvQVIwGdg,2757
5
+ tonik/xarray2netcdf.py,sha256=aZSSMADmS0DpnprT5TBqERGxrycZTPTNuQhxm1rOsh0,5135
6
+ tonik/xarray2zarr.py,sha256=jTrHFpjN3lEDIJEI6RyPvvbW2jZsfYwGE_LQaZ6dwx8,2099
7
+ tonik/package_data/index.html,sha256=GKDClUhIam_fAYbNfzAolORhSCG3ae1wW3VjWCg4PMk,2732
8
+ tonik-0.1.2.dist-info/METADATA,sha256=0TAmD3zLolBMyGYJpsCUA5ffUfA6yfX09rEqqgFekzE,1938
9
+ tonik-0.1.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
+ tonik-0.1.2.dist-info/entry_points.txt,sha256=VnGfC5qAzpntEHAb5pooUEpYABSgOfQoNhCEtLDJyf8,45
11
+ tonik-0.1.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
+ tonik-0.1.2.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=Oh3BBQL13yLYHlgk8-a-wstmlUC2vNJ0yi_fnyETK_g,11237
4
- tonik/utils.py,sha256=3nSRU_GnV6arP4e63YHn4oEV8XbqzVAW8FCvQVIwGdg,2757
5
- tonik/xarray2netcdf.py,sha256=ey7lY4czlMREUt56SzE3quXNzeqXxV0Ru_EatsJpynA,5088
6
- tonik/xarray2zarr.py,sha256=jTrHFpjN3lEDIJEI6RyPvvbW2jZsfYwGE_LQaZ6dwx8,2099
7
- tonik/package_data/index.html,sha256=GKDClUhIam_fAYbNfzAolORhSCG3ae1wW3VjWCg4PMk,2732
8
- tonik-0.1.0.dist-info/METADATA,sha256=VtdNFXyUplO5s_TmR8xEgW0NdMtKgI4Zl2rWLhxpnK0,1938
9
- tonik-0.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
- tonik-0.1.0.dist-info/entry_points.txt,sha256=VnGfC5qAzpntEHAb5pooUEpYABSgOfQoNhCEtLDJyf8,45
11
- tonik-0.1.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
- tonik-0.1.0.dist-info/RECORD,,
File without changes