Skip to content

Commit c8e0305

Browse files
authored
Merge pull request #303 from ecmwf/feature/avoid_duplicate_merging
fix duplicate merging
2 parents e9ce437 + 68732e3 commit c8e0305

File tree

7 files changed

+15
-16
lines changed

7 files changed

+15
-16
lines changed

polytope_feature/datacube/backends/datacube.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ def validate(self, axes):
4848
def _create_axes(self, name, values, transformation_type_key, transformation_options):
4949
# first check what the final axes are for this axis name given transformations
5050
transformation_options = transformation_type_key
51-
final_axis_names = DatacubeAxisTransformation.get_final_axes(
52-
name, transformation_type_key.name, transformation_options
53-
)
54-
transformation = DatacubeAxisTransformation.create_transform(
55-
name, transformation_type_key.name, transformation_options
51+
(final_axis_names, transformation) = DatacubeAxisTransformation.get_final_axes(
52+
name, transformation_type_key.name, transformation_options, self
5653
)
5754

5855
# do not compress merged axes

polytope_feature/datacube/transformations/datacube_cyclic/datacube_cyclic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class DatacubeAxisCyclic(DatacubeAxisTransformation):
99
# The transformation here will be to point the old axes to the new cyclic axes
1010

11-
def __init__(self, name, cyclic_options):
11+
def __init__(self, name, cyclic_options, datacube=None):
1212
self.name = name
1313
self.transformation_options = cyclic_options
1414
self.range = cyclic_options.range

polytope_feature/datacube/transformations/datacube_mappers/datacube_mappers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class DatacubeMapper(DatacubeAxisTransformation):
88
# Needs to implements DatacubeAxisTransformation methods
99

10-
def __init__(self, name, mapper_options):
10+
def __init__(self, name, mapper_options, datacube=None):
1111
self.transformation_options = mapper_options
1212
self.grid_type = mapper_options.type
1313
self.grid_resolution = mapper_options.resolution

polytope_feature/datacube/transformations/datacube_merger/datacube_merger.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88

99
class DatacubeAxisMerger(DatacubeAxisTransformation):
10-
def __init__(self, name, merge_options):
10+
def __init__(self, name, merge_options, datacube=None):
1111
self.transformation_options = merge_options
1212
self.name = name
1313
self._first_axis = name
1414
self._second_axis = merge_options.other_axis
1515
self._linkers = merge_options.linkers
16+
self._merged_values = self.merged_values(datacube)
1617

1718
def blocked_axes(self):
1819
return [self._second_axis]
@@ -34,6 +35,7 @@ def merged_values(self, datacube):
3435
)
3536
merged_values = pd.to_datetime(combined_strings).to_numpy().astype("datetime64[s]")
3637
merged_values = np.array(merged_values)
38+
merged_values.sort()
3739
logging.info(
3840
f"Merged values {first_ax_vals} on axis {self.name} and \
3941
values {second_ax_vals} on axis {second_ax_name} to values {merged_values}"
@@ -74,7 +76,7 @@ def change_val_type(self, axis_name, values):
7476

7577
def find_modified_indexes(self, indexes, path, datacube, axis):
7678
if axis.name == self._first_axis:
77-
return self.merged_values(datacube)
79+
return self._merged_values
7880

7981
def unmap_path_key(self, key_value_path, leaf_path, unwanted_path, axis):
8082
new_key_value_path = {}

polytope_feature/datacube/transformations/datacube_reverse/datacube_reverse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class DatacubeAxisReverse(DatacubeAxisTransformation):
6-
def __init__(self, name, mapper_options):
6+
def __init__(self, name, mapper_options, datacube=None):
77
self.name = name
88
self.transformation_options = mapper_options
99

polytope_feature/datacube/transformations/datacube_transformations.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ def __init__(self):
88
self.parent = None
99

1010
@staticmethod
11-
def create_transform(name, transformation_type_key, transformation_options):
11+
def create_transform(name, transformation_type_key, transformation_options, datacube):
1212
transformation_type = _type_to_datacube_transformation_lookup[transformation_type_key]
1313
transformation_file_name = _type_to_transformation_file_lookup[transformation_type_key]
1414
file_name = ".datacube_" + transformation_file_name
1515
module = import_module("polytope_feature.datacube.transformations" + file_name + file_name)
1616
constructor = getattr(module, transformation_type)
1717
transformation_type_option = transformation_options
18-
new_transformation = deepcopy(constructor(name, transformation_type_option))
18+
new_transformation = deepcopy(constructor(name, transformation_type_option, datacube))
1919

2020
new_transformation.name = name
2121
return new_transformation
2222

2323
@staticmethod
24-
def get_final_axes(name, transformation_type_key, transformation_options):
24+
def get_final_axes(name, transformation_type_key, transformation_options, datacube):
2525
new_transformation = DatacubeAxisTransformation.create_transform(
26-
name, transformation_type_key, transformation_options
26+
name, transformation_type_key, transformation_options, datacube
2727
)
2828
transformation_axis_names = new_transformation.transformation_axes_final()
29-
return transformation_axis_names
29+
return (transformation_axis_names, new_transformation)
3030

3131
def name(self):
3232
pass

polytope_feature/datacube/transformations/datacube_type_change/datacube_type_change.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class DatacubeAxisTypeChange(DatacubeAxisTransformation):
88
# The transformation here will be to point the old axes to the new cyclic axes
99

10-
def __init__(self, name, type_options):
10+
def __init__(self, name, type_options, datacube=None):
1111
self.name = name
1212
self.transformation_options = type_options
1313
self.new_type = type_options.type

0 commit comments

Comments
 (0)