Skip to content

Commit 6ad9042

Browse files
committed
handle boundary case
1 parent 011be17 commit 6ad9042

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

hat/station_mapping/station_mapping.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ def conduct_mapping(
7373
best_error_1d_index = np.nanargmin(error)
7474
min_index = np.unravel_index(best_error_1d_index, shape)
7575
best_error = error[best_error_1d_index]
76-
# 1d equivalent to [self.max_search_distance, self.max_search_distance]
77-
closest_1d_index = (
78-
self.max_search_distance * (2 * self.max_search_distance + 1) + self.max_search_distance
79-
)
76+
77+
center_offset_x = closest_idx - searchbox_min_x
78+
center_offset_y = closest_idy - searchbox_min_y
79+
subset_width = searchbox_max_y - searchbox_min_y
80+
closest_1d_index = center_offset_x * subset_width + center_offset_y
8081

8182
closest_error = error[closest_1d_index]
8283

@@ -92,9 +93,10 @@ def conduct_mapping(
9293
indy = closest_idy
9394
best_error = closest_error
9495
except ValueError:
95-
closest_1d_index = (
96-
self.max_search_distance * (2 * self.max_search_distance + 1) + self.max_search_distance
97-
)
96+
center_offset_x = closest_idx - searchbox_min_x
97+
center_offset_y = closest_idy - searchbox_min_y
98+
subset_width = searchbox_max_y - searchbox_min_y
99+
closest_1d_index = center_offset_x * subset_width + center_offset_y
98100

99101
closest_error = error[closest_1d_index]
100102
indx = closest_idx

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ dependencies = [
7272
[project.scripts]
7373
hat-extract-timeseries = "hat.cli:extractor_cli"
7474
hat-hydrostats = "hat.cli:stat_calc_cli"
75-
hat-stations-mapping = "hat.cli:mapper_cli"
75+
hat-station-mapping = "hat.cli:mapper_cli"
7676

7777
# Linting settings
7878
[tool.ruff]

0 commit comments

Comments
 (0)