Skip to content

Commit

Permalink
Merge pull request #280 from ecmwf/develop
Browse files Browse the repository at this point in the history
merge develop into main
  • Loading branch information
mathleur authored Dec 11, 2024
2 parents 0da4c4d + c1af2a2 commit e97e06f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
30 changes: 17 additions & 13 deletions polytope_feature/datacube/backends/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,23 @@ def _create_axes(self, name, values, transformation_type_key, transformation_opt
for axis_name in final_axis_names:
self.fake_axes.append(axis_name)
# if axis does not yet exist, create it

# first need to change the values so that we have right type
values = transformation.change_val_type(axis_name, values)
if self._axes is None or axis_name not in self._axes.keys():
DatacubeAxis.create_standard(axis_name, values, self)
# add transformation tag to axis, as well as transformation options for later
setattr(self._axes[axis_name], has_transform[transformation_type_key.name], True) # where has_transform is
# a factory inside datacube_transformations to set the has_transform, is_cyclic etc axis properties
# add the specific transformation handled here to the relevant axes
# Modify the axis to update with the tag

if transformation not in self._axes[axis_name].transformations: # Avoids duplicates being stored
self._axes[axis_name].transformations.append(transformation)
if transformation.change_val_type(axis_name, values) is not None:
# first need to change the values so that we have right type
values = transformation.change_val_type(axis_name, values)
if self._axes is None or axis_name not in self._axes.keys():
DatacubeAxis.create_standard(axis_name, values, self)
# add transformation tag to axis, as well as transformation options for later
setattr(self._axes[axis_name], has_transform[transformation_type_key.name], True)
# where has_transform is a factory inside datacube_transformations to set the has_transform, is_cyclic
# etc axis properties add the specific transformation handled here to the relevant axes
# Modify the axis to update with the tag

if transformation not in self._axes[axis_name].transformations: # Avoids duplicates being stored
self._axes[axis_name].transformations.append(transformation)
else:
# Means we have an unsliceable axis since we couln't transform values to desired type
if self._axes is None or axis_name not in self._axes.keys():
DatacubeAxis.create_standard(axis_name, values, self)

def _add_all_transformation_axes(self, options, name, values):
for transformation_type_key in options.transformations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def transformation_axes_final(self):

def change_val_type(self, axis_name, values):
return_idx = [self._final_transformation.transform_type(val) for val in values]
if None in return_idx:
return None
return_idx.sort()
return return_idx

Expand Down Expand Up @@ -61,7 +63,10 @@ def __init__(self, axis_name, new_type):
self._new_type = new_type

def transform_type(self, value):
return int(value)
try:
return int(value)
except ValueError:
return None

def make_str(self, value):
values = []
Expand Down

0 comments on commit e97e06f

Please sign in to comment.