tonik 0.1.11__py3-none-any.whl → 0.1.13__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/api.py CHANGED
@@ -58,16 +58,16 @@ class TonikAPI:
58
58
  dt = dt.replace(tzinfo=None)
59
59
  return dt
60
60
 
61
- def feature(self,
62
- group: str,
63
- name: str,
64
- starttime: Union[str, None],
65
- endtime: Union[str, None],
66
- subdir: SubdirType = None,
67
- resolution: str = 'full',
68
- verticalres: int = 10,
69
- log: bool = False,
70
- normalise: bool = False):
61
+ async def feature(self,
62
+ group: str,
63
+ name: str,
64
+ starttime: Union[str, None],
65
+ endtime: Union[str, None],
66
+ subdir: SubdirType = None,
67
+ resolution: str = 'full',
68
+ verticalres: int = 10,
69
+ log: bool = False,
70
+ normalise: bool = False):
71
71
  _st = self.preprocess_datetime(starttime)
72
72
  _et = self.preprocess_datetime(endtime)
73
73
  g = Storage(group, rootdir=self.rootdir,
@@ -102,22 +102,24 @@ class TonikAPI:
102
102
  dates = np.tile(dates, freq.size)
103
103
  df = pd.DataFrame(
104
104
  {'dates': dates, 'freqs': freqs, 'feature': vals})
105
- df.dates = pd.to_datetime(df.dates.values).tz_localize('UTC')
105
+ df['dates'] = pd.to_datetime(df.dates.values).strftime(
106
+ '%Y-%m-%dT%H:%M:%SZ')
106
107
  output = df.to_csv(index=False,
107
108
  columns=['dates', 'freqs', 'feature'])
108
109
  else:
109
110
  df = pd.DataFrame(data=feat.to_pandas(), columns=[feat.name])
110
- df['dates'] = df.index.tz_localize('UTC')
111
+ df['dates'] = df.index
111
112
  if resolution != 'full':
112
113
  try:
113
114
  current_resolution = pd.Timedelta(
114
115
  df['dates'].diff().mean())
115
116
  if current_resolution < pd.Timedelta(resolution):
116
- df = df.resample(pd.Timedelta(resolution)).mean()
117
+ df = df.resample(pd.Timedelta(resolution)).median()
117
118
  except ValueError:
118
119
  logger.warning(
119
120
  f"Cannot resample {feat.name} to {resolution}: e")
120
121
  df.rename(columns={feat.name: 'feature'}, inplace=True)
122
+ df['dates'] = df['dates'].dt.strftime('%Y-%m-%dT%H:%M:%SZ')
121
123
  output = df.to_csv(index=False, columns=['dates', 'feature'])
122
124
  return StreamingResponse(iter([output]),
123
125
  media_type='text/csv',
@@ -144,7 +146,7 @@ class TonikAPI:
144
146
  d, units='hours since 1970-01-01 00:00:00.0', calendar='gregorian')
145
147
  return freq, dates, spec
146
148
 
147
- def inventory(self, group: str, subdir: SubdirType = None, tree: bool = True) -> InventoryReturnType:
149
+ async def inventory(self, group: str, subdir: SubdirType = None, tree: bool = True) -> InventoryReturnType:
148
150
  sg = Storage(group, rootdir=self.rootdir, create=False)
149
151
  try:
150
152
  c = sg.get_substore(*subdir)
@@ -162,7 +164,7 @@ class TonikAPI:
162
164
  dir_contents.remove('labels.json')
163
165
  return [fn.replace('.nc', '').replace('.zarr', '') for fn in dir_contents]
164
166
 
165
- def labels(self, group: str, subdir: SubdirType = None, starttime: Optional[str] = None, endtime: Optional[str] = None):
167
+ async def labels(self, group: str, subdir: SubdirType = None, starttime: Optional[str] = None, endtime: Optional[str] = None):
166
168
  _st = self.preprocess_datetime(starttime)
167
169
  _et = self.preprocess_datetime(endtime)
168
170
  sg = Storage(group, rootdir=self.rootdir,
tonik/xarray2zarr.py CHANGED
@@ -2,7 +2,11 @@ import logging
2
2
  import os
3
3
 
4
4
  import xarray as xr
5
- from zarr.errors import PathNotFoundError
5
+ try:
6
+ from zarr.errors import PathNotFoundError
7
+ except ImportError:
8
+ class PathNotFoundError(Exception):
9
+ pass
6
10
 
7
11
  from .utils import merge_arrays
8
12
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tonik
3
- Version: 0.1.11
3
+ Version: 0.1.13
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
@@ -9,8 +9,7 @@ License-File: LICENSE
9
9
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
10
10
  Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python :: 3
12
- Requires-Python: >=3.7
13
- Requires-Dist: dask<=2024.10.0
12
+ Requires-Python: >=3.9
14
13
  Requires-Dist: datashader>=0.14
15
14
  Requires-Dist: fastapi>=0.112
16
15
  Requires-Dist: h5netcdf>=1.1
@@ -20,9 +19,12 @@ Requires-Dist: netcdf4>=1.6
20
19
  Requires-Dist: pandas>=2.0
21
20
  Requires-Dist: python-json-logger>=2.0
22
21
  Requires-Dist: uvicorn[standard]>=0.22
23
- Requires-Dist: xarray>=2023.4
24
- Requires-Dist: zarr
22
+ Requires-Dist: xarray[accel,io,parallel]
23
+ Requires-Dist: zarr<3; python_version < '3.11'
24
+ Requires-Dist: zarr>=3.0.3; python_version >= '3.11'
25
25
  Provides-Extra: dev
26
+ Requires-Dist: httpx; extra == 'dev'
27
+ Requires-Dist: ipykernel; extra == 'dev'
26
28
  Requires-Dist: mkdocs; extra == 'dev'
27
29
  Requires-Dist: mkdocs-jupyter; extra == 'dev'
28
30
  Requires-Dist: mkdocstrings[python]; extra == 'dev'
@@ -1,12 +1,12 @@
1
1
  tonik/__init__.py,sha256=dov-nMeGFBzLspmj4rWKjC4r736vmaPDgMEkHSUfP98,523
2
- tonik/api.py,sha256=xUH-fr-xUwc_a21QYz11Dk3YjB2nRuCclmALvU64UJM,7592
2
+ tonik/api.py,sha256=XDKiz1AzYNBOwYfaRxpMgqGRDAPJEE6wWJyBxuYPRLc,7751
3
3
  tonik/storage.py,sha256=IklM_atZD4rebUsnXsUj5JldSHU2LqmuqME03PHp_UI,10441
4
4
  tonik/utils.py,sha256=9eSVKIbs8TIZlJCz_-B7FrvOUQCQHO3K52v4Heus-uE,6135
5
5
  tonik/xarray2netcdf.py,sha256=gDNT6nxnRbXPeRqZ3URW5oXY3Nfh3TCrfueE-eUrIoY,5181
6
- tonik/xarray2zarr.py,sha256=xJjKcFZF0oz6gw47apuCiXFtW5HgWqnZgiIuEVQHhBI,2363
6
+ tonik/xarray2zarr.py,sha256=RhCnS6g3yqe8mrEXhD_4PCN0EI3QPhp5X7ui_wvb_jY,2445
7
7
  tonik/package_data/index.html,sha256=GKDClUhIam_fAYbNfzAolORhSCG3ae1wW3VjWCg4PMk,2732
8
- tonik-0.1.11.dist-info/METADATA,sha256=xEhlRUeS79ZRxwL_-ksmf5do2OrOapKBealQRPUSFpE,2005
9
- tonik-0.1.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- tonik-0.1.11.dist-info/entry_points.txt,sha256=mT3B4eBE8SHlAeMhFnZGor9-YkVtoWM1NVHVuypJ-uY,74
11
- tonik-0.1.11.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
- tonik-0.1.11.dist-info/RECORD,,
8
+ tonik-0.1.13.dist-info/METADATA,sha256=MNuL04Q7howEYqs_HbnLxQtIXLAoLhN5nEC9GcE3uk4,2143
9
+ tonik-0.1.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ tonik-0.1.13.dist-info/entry_points.txt,sha256=mT3B4eBE8SHlAeMhFnZGor9-YkVtoWM1NVHVuypJ-uY,74
11
+ tonik-0.1.13.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
+ tonik-0.1.13.dist-info/RECORD,,
File without changes