polytope-python 1.0.25__tar.gz → 1.0.26__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.
Files changed (57) hide show
  1. {polytope-python-1.0.25/polytope_python.egg-info → polytope-python-1.0.26}/PKG-INFO +1 -1
  2. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/datacube_axis.py +29 -8
  3. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_type_change/datacube_type_change.py +47 -1
  4. polytope-python-1.0.26/polytope_feature/version.py +1 -0
  5. {polytope-python-1.0.25 → polytope-python-1.0.26/polytope_python.egg-info}/PKG-INFO +1 -1
  6. polytope-python-1.0.25/polytope_feature/version.py +0 -1
  7. {polytope-python-1.0.25 → polytope-python-1.0.26}/LICENSE +0 -0
  8. {polytope-python-1.0.25 → polytope-python-1.0.26}/MANIFEST.in +0 -0
  9. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/__init__.py +0 -0
  10. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/__init__.py +0 -0
  11. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/backends/__init__.py +0 -0
  12. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/backends/datacube.py +0 -0
  13. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/backends/fdb.py +0 -0
  14. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/backends/mock.py +0 -0
  15. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/backends/xarray.py +0 -0
  16. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/index_tree_pb2.py +0 -0
  17. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/tensor_index_tree.py +0 -0
  18. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/__init__.py +0 -0
  19. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_cyclic/__init__.py +0 -0
  20. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_cyclic/datacube_cyclic.py +0 -0
  21. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_mappers/__init__.py +0 -0
  22. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_mappers/datacube_mappers.py +0 -0
  23. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_mappers/mapper_types/__init__.py +0 -0
  24. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_mappers/mapper_types/healpix.py +0 -0
  25. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_mappers/mapper_types/healpix_nested.py +0 -0
  26. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_mappers/mapper_types/local_regular.py +0 -0
  27. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_mappers/mapper_types/octahedral.py +0 -0
  28. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_mappers/mapper_types/reduced_ll.py +0 -0
  29. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_mappers/mapper_types/regular.py +0 -0
  30. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_merger/__init__.py +0 -0
  31. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_merger/datacube_merger.py +0 -0
  32. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_reverse/__init__.py +0 -0
  33. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_reverse/datacube_reverse.py +0 -0
  34. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_transformations.py +0 -0
  35. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/transformations/datacube_type_change/__init__.py +0 -0
  36. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/datacube/tree_encoding.py +0 -0
  37. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/engine/__init__.py +0 -0
  38. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/engine/engine.py +0 -0
  39. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/engine/hullslicer.py +0 -0
  40. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/options.py +0 -0
  41. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/polytope.py +0 -0
  42. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/shapes.py +0 -0
  43. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/utility/__init__.py +0 -0
  44. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/utility/combinatorics.py +0 -0
  45. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/utility/exceptions.py +0 -0
  46. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/utility/geometry.py +0 -0
  47. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/utility/list_tools.py +0 -0
  48. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_feature/utility/profiling.py +0 -0
  49. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_python.egg-info/SOURCES.txt +0 -0
  50. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_python.egg-info/dependency_links.txt +0 -0
  51. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_python.egg-info/not-zip-safe +0 -0
  52. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_python.egg-info/requires.txt +0 -0
  53. {polytope-python-1.0.25 → polytope-python-1.0.26}/polytope_python.egg-info/top_level.txt +0 -0
  54. {polytope-python-1.0.25 → polytope-python-1.0.26}/pyproject.toml +0 -0
  55. {polytope-python-1.0.25 → polytope-python-1.0.26}/requirements.txt +0 -0
  56. {polytope-python-1.0.25 → polytope-python-1.0.26}/setup.cfg +0 -0
  57. {polytope-python-1.0.25 → polytope-python-1.0.26}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: polytope-python
3
- Version: 1.0.25
3
+ Version: 1.0.26
4
4
  Summary: Polytope datacube feature extraction library
5
5
  Home-page: https://github.com/ecmwf/polytope
6
6
  Author: ECMWF
@@ -5,6 +5,7 @@ from typing import Any, List
5
5
 
6
6
  import numpy as np
7
7
  import pandas as pd
8
+ import xarray as xr
8
9
 
9
10
  from .transformations.datacube_cyclic.datacube_cyclic import DatacubeAxisCyclic
10
11
  from .transformations.datacube_mappers.datacube_mappers import DatacubeMapper
@@ -142,22 +143,39 @@ class DatacubeAxis(ABC):
142
143
  )
143
144
  return indexes_between_ranges
144
145
 
146
+ @staticmethod
147
+ def values_type(values):
148
+ type_ = None
149
+ if isinstance(values, xr.core.variable.IndexVariable) or isinstance(values, xr.core.variable.Variable):
150
+ # If we have some xarray variable, transform them to actual variable type
151
+ values = np.array(values)
152
+ type_ = values.dtype.type
153
+ else:
154
+ if len(values) == 0:
155
+ # If we have no values (newly created axis), default to a float
156
+ values = np.array(values)
157
+ type_ = values.dtype.type
158
+ else:
159
+ type_ = type(values[0])
160
+ return type_
161
+
145
162
  @staticmethod
146
163
  def create_standard(name, values, datacube):
147
- values = np.array(values)
148
- DatacubeAxis.check_axis_type(name, values)
164
+ val_type = DatacubeAxis.values_type(values)
165
+
166
+ DatacubeAxis.check_axis_type(name, val_type)
149
167
  if datacube._axes is None:
150
- datacube._axes = {name: deepcopy(_type_to_axis_lookup[values.dtype.type])}
168
+ datacube._axes = {name: deepcopy(_type_to_axis_lookup[val_type])}
151
169
  else:
152
- datacube._axes[name] = deepcopy(_type_to_axis_lookup[values.dtype.type])
170
+ datacube._axes[name] = deepcopy(_type_to_axis_lookup[val_type])
171
+
153
172
  datacube._axes[name].name = name
154
173
  datacube.axis_counter += 1
155
174
 
156
175
  @staticmethod
157
- def check_axis_type(name, values):
158
- # NOTE: The values here need to be a numpy array which has a dtype attribute
159
- if values.dtype.type not in _type_to_axis_lookup:
160
- raise ValueError(f"Could not create a mapper for index type {values.dtype.type} for axis {name}")
176
+ def check_axis_type(name, val_type):
177
+ if val_type not in _type_to_axis_lookup:
178
+ raise ValueError(f"Could not create a mapper for index type {val_type} for axis {name}")
161
179
 
162
180
 
163
181
  transformations_order = [
@@ -302,10 +320,13 @@ _type_to_axis_lookup = {
302
320
  np.int64: IntDatacubeAxis(),
303
321
  np.datetime64: PandasTimestampDatacubeAxis(),
304
322
  np.timedelta64: PandasTimedeltaDatacubeAxis(),
323
+ pd.Timedelta: PandasTimedeltaDatacubeAxis(),
305
324
  np.float64: FloatDatacubeAxis(),
306
325
  np.float32: FloatDatacubeAxis(),
307
326
  np.int32: IntDatacubeAxis(),
308
327
  np.str_: UnsliceableDatacubeAxis(),
309
328
  str: UnsliceableDatacubeAxis(),
310
329
  np.object_: UnsliceableDatacubeAxis(),
330
+ int: IntDatacubeAxis(),
331
+ float: FloatDatacubeAxis(),
311
332
  }
@@ -1,6 +1,8 @@
1
1
  from copy import deepcopy
2
2
  from importlib import import_module
3
3
 
4
+ import pandas as pd
5
+
4
6
  from ..datacube_transformations import DatacubeAxisTransformation
5
7
 
6
8
 
@@ -75,4 +77,48 @@ class TypeChangeStrToInt(DatacubeAxisTypeChange):
75
77
  return tuple(values)
76
78
 
77
79
 
78
- _type_to_datacube_type_change_lookup = {"int": "TypeChangeStrToInt"}
80
+ class TypeChangeStrToTimestamp(DatacubeAxisTypeChange):
81
+ def __init__(self, axis_name, new_type):
82
+ self.axis_name = axis_name
83
+ self._new_type = new_type
84
+
85
+ def transform_type(self, value):
86
+ try:
87
+ return pd.Timestamp(value)
88
+ except ValueError:
89
+ return None
90
+
91
+ def make_str(self, value):
92
+ values = []
93
+ for val in value:
94
+ values.append(val.strftime("%Y%m%d"))
95
+ return tuple(values)
96
+
97
+
98
+ class TypeChangeStrToTimedelta(DatacubeAxisTypeChange):
99
+ def __init__(self, axis_name, new_type):
100
+ self.axis_name = axis_name
101
+ self._new_type = new_type
102
+
103
+ def transform_type(self, value):
104
+ try:
105
+ hours = int(value[:2])
106
+ mins = int(value[2:])
107
+ return pd.Timedelta(hours=hours, minutes=mins)
108
+ except ValueError:
109
+ return None
110
+
111
+ def make_str(self, value):
112
+ values = []
113
+ for val in value:
114
+ hours = int(val.total_seconds() // 3600)
115
+ mins = int((val.total_seconds() % 3600) // 60)
116
+ values.append(f"{hours:02d}{mins:02d}")
117
+ return tuple(values)
118
+
119
+
120
+ _type_to_datacube_type_change_lookup = {
121
+ "int": "TypeChangeStrToInt",
122
+ "date": "TypeChangeStrToTimestamp",
123
+ "time": "TypeChangeStrToTimedelta",
124
+ }
@@ -0,0 +1 @@
1
+ __version__ = "1.0.26"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: polytope-python
3
- Version: 1.0.25
3
+ Version: 1.0.26
4
4
  Summary: Polytope datacube feature extraction library
5
5
  Home-page: https://github.com/ecmwf/polytope
6
6
  Author: ECMWF
@@ -1 +0,0 @@
1
- __version__ = "1.0.25"