tonik 0.1.4__tar.gz → 0.1.6__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.4
3
+ Version: 0.1.6
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.4"
7
+ version = "0.1.6"
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" }
@@ -1,8 +1,9 @@
1
1
  import logging
2
2
  import os
3
+ import sys
3
4
  from argparse import ArgumentParser
4
5
  from datetime import datetime
5
- from typing import Annotated
6
+ from typing import Annotated, List, Union
6
7
  from urllib.parse import unquote
7
8
 
8
9
  import datashader as dsh
@@ -19,6 +20,13 @@ from .storage import Storage
19
20
 
20
21
  logger = logging.getLogger(__name__)
21
22
 
23
+ if sys.version_info >= (3, 10):
24
+ # For Python 3.10 and above, use the new union operator '|'
25
+ SubdirType = Annotated[list[str] | None, Query()]
26
+ else:
27
+ # For Python 3.9 and below, use Union from typing
28
+ SubdirType = Annotated[Union[List[str], None], Query()]
29
+
22
30
 
23
31
  class TonikAPI:
24
32
 
@@ -62,7 +70,7 @@ class TonikAPI:
62
70
  verticalres: int = 10,
63
71
  log: bool = False,
64
72
  normalise: bool = False,
65
- subdir: Annotated[list[str] | None, Query()] = None):
73
+ subdir: SubdirType = None):
66
74
  _st = self.preprocess_datetime(starttime)
67
75
  _et = self.preprocess_datetime(endtime)
68
76
  g = Storage(group, rootdir=self.rootdir,
@@ -91,7 +91,7 @@ def xarray2netcdf(xArray, fdir, group="original", timedim="datetime",
91
91
  rootGrp.attrs['resolution'] = resolution
92
92
  rootGrp.attrs['resolution_units'] = 'h'
93
93
  try:
94
- _setMetaInfo(featureName, h5f, xArray)
94
+ _setMetaInfo(featureName, rootGrp, xArray)
95
95
  except KeyError as e:
96
96
  logging.warning(
97
97
  f"Could not set all meta info for {featureName}: {e}")
@@ -117,8 +117,7 @@ def _create_h5_Structure(defaultGroupName, featureName, h5f, xArray, starttime,
117
117
  return rootGrp
118
118
 
119
119
 
120
- def _setMetaInfo(featureName, h5f, xArray):
121
- h5f.attrs['station'] = xArray.attrs['station']
122
- h5f.attrs['latitude'] = -42
123
- h5f.attrs['longitude'] = 168
124
- h5f.attrs['datatype'] = featureName
120
+ def _setMetaInfo(featureName, rootGrp, xArray):
121
+ for key, value in xArray.attrs.items():
122
+ rootGrp.attrs[key] = value
123
+ rootGrp.attrs['feature'] = featureName
@@ -89,6 +89,22 @@ def test_xarray2netcdf_resolution(tmp_path_factory):
89
89
  assert xdf_test.attrs['resolution_units'] == 'h'
90
90
 
91
91
 
92
+ def test_xarray2netcdf_attributes(tmp_path_factory):
93
+ starttime = datetime(2022, 7, 18, 0, 0, 0)
94
+ xdf = generate_test_data(dim=1, ndays=1, tstart=starttime,
95
+ add_nans=False)
96
+ temp_dir = tmp_path_factory.mktemp('test_xarray2netcdf')
97
+ g = Storage('test_experiment', rootdir=temp_dir,
98
+ starttime=datetime(2000, 1, 1),
99
+ endtime=datetime.fromisoformat(xdf.attrs['endtime']),
100
+ backend='netcdf')
101
+ c = g.get_substore('MDR', '00', 'HHZ')
102
+ c.save(xdf, archive_starttime=starttime)
103
+ xdf_test = c('rsam')
104
+ assert xdf_test.attrs['station'] == xdf.attrs['station']
105
+ assert xdf_test.attrs['feature'] == 'rsam'
106
+
107
+
92
108
  def test_xarray2netcdf_with_gaps(tmp_path_factory):
93
109
  """
94
110
  Test writing xarray data to hdf5 with gaps.
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