tonik 0.1.2__tar.gz → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: tonik
3
- Version: 0.1.2
3
+ Version: 0.1.3
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
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "tonik"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  authors = [
9
9
  { name="Yannik Behr", email="y.behr@gns.cri.nz" },
10
10
  { name="Christof Mueller", email="c.mueller@gns.cri.nz" }
@@ -156,15 +156,16 @@ class Path(object):
156
156
 
157
157
  xd_index = dict(datetime=slice(self.starttime, self.endtime))
158
158
  with xr.open_dataset(filename, group='original', engine=self.engine) as ds:
159
- rq = ds.loc[xd_index].load()
159
+ rq = ds[feature].loc[xd_index].load()
160
+ rq.attrs = ds.attrs
160
161
 
161
162
  # Stack features
162
163
  if stack_length is not None:
163
164
  logger.debug("Stacking feature...")
164
165
  try:
165
- xdf = rq[feature].rolling(datetime=int(num_periods),
166
- center=False,
167
- min_periods=1).mean()
166
+ xdf = rq.rolling(datetime=int(num_periods),
167
+ center=False,
168
+ min_periods=1).mean()
168
169
  # Return requested timeframe to that defined in initialisation
169
170
  self.starttime += pd.to_timedelta(stack_length)
170
171
  xdf_new = xdf.loc[self.starttime:self.endtime]
@@ -175,8 +176,7 @@ class Path(object):
175
176
  format(stack_length, feature))
176
177
  else:
177
178
  return xdf_new
178
-
179
- return rq[feature]
179
+ return rq
180
180
 
181
181
  def load(self, *args, **kwargs):
182
182
  """
@@ -88,6 +88,8 @@ def xarray2netcdf(xArray, fdir, rootGroupName="original", timedim="datetime",
88
88
  data[indices] = xArray[featureName].values
89
89
  rootGrp.attrs['endtime'] = str(num2date(times[-1], units=rootGrp[timedim].attrs['units'],
90
90
  calendar=rootGrp[timedim].attrs['calendar']))
91
+ rootGrp.attrs['resolution'] = resolution
92
+ rootGrp.attrs['resolution_units'] = 'h'
91
93
  try:
92
94
  _setMetaInfo(featureName, h5f, xArray)
93
95
  except KeyError as e:
@@ -102,7 +104,7 @@ def _create_h5_Structure(defaultGroupName, featureName, h5f, xArray, starttime,
102
104
  coordinates.attrs['units'] = 'hours since 1970-01-01 00:00:00.0'
103
105
  coordinates.attrs['calendar'] = 'gregorian'
104
106
  rootGrp.attrs['starttime'] = str(starttime)
105
- for label, size in xArray.dims.items():
107
+ for label, size in xArray.sizes.items():
106
108
  if not np.issubdtype(xArray[label].dtype, np.datetime64):
107
109
  rootGrp.dimensions[label] = size
108
110
  coordinates = rootGrp.create_variable(label, (label,), float)
@@ -18,7 +18,10 @@ def write_read(backend):
18
18
  test_dir = tempfile.mkdtemp()
19
19
  sg = Storage('speed_test', test_dir, starttime=tstart, endtime=tend,
20
20
  backend=backend)
21
- sg.save(spec)
21
+ kwargs = {}
22
+ if backend == 'netcdf':
23
+ kwargs['archive_starttime'] = tstart
24
+ sg.save(spec, **kwargs)
22
25
  spec_test = sg('ssam')
23
26
 
24
27
 
@@ -85,6 +85,8 @@ def test_xarray2netcdf_resolution(tmp_path_factory):
85
85
  xdf_test = c('rsam')
86
86
  assert xdf_test.loc['2022-07-18T00:12:00'] == xdf['rsam'].loc['2022-07-18T00:10:00']
87
87
  assert np.isnan(xdf_test.loc['2022-07-18T00:06:00'].data)
88
+ assert xdf_test.attrs['resolution'] == 0.1
89
+ assert xdf_test.attrs['resolution_units'] == 'h'
88
90
 
89
91
 
90
92
  def test_xarray2netcdf_with_gaps(tmp_path_factory):
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