Skip to content

faster merge operation without for loops #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def int_sqrt(self, i):


# md5 grid hash in form {resolution : hash}
_md5_hash = {1024: "cbda19e48d4d7e5e22641154878b9b22",
512: "9533855ee8e38314e19aaa0434c310da",
128: "f3dfeb7a5bbbdd13a20d10fdb3797c71"}
_md5_hash = {
1024: "cbda19e48d4d7e5e22641154878b9b22",
512: "9533855ee8e38314e19aaa0434c310da",
128: "f3dfeb7a5bbbdd13a20d10fdb3797c71",
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ def _mapped_axes(self):
return self._first_axis

def merged_values(self, datacube):
first_ax_vals = datacube.ax_vals(self.name)
first_ax_vals = np.array(datacube.ax_vals(self.name))
second_ax_name = self._second_axis
second_ax_vals = datacube.ax_vals(second_ax_name)
second_ax_vals = np.array(datacube.ax_vals(second_ax_name))
linkers = self._linkers
merged_values = []
for i in range(len(first_ax_vals)):
first_val = first_ax_vals[i]
for j in range(len(second_ax_vals)):
second_val = second_ax_vals[j]
val_to_add = pd.to_datetime("".join([first_val, linkers[0], second_val, linkers[1]]))
val_to_add = val_to_add.to_numpy()
val_to_add = val_to_add.astype("datetime64[s]")
merged_values.append(val_to_add)
first_grid, second_grid = np.meshgrid(first_ax_vals, second_ax_vals, indexing="ij")
combined_strings = np.char.add(
np.char.add(first_grid.ravel(), linkers[0]), np.char.add(second_grid.ravel(), linkers[1])
)
merged_values = pd.to_datetime(combined_strings).to_numpy().astype("datetime64[s]")
merged_values = np.array(merged_values)
logging.info(
f"Merged values {first_ax_vals} on axis {self.name} and \
Expand Down
Loading