Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 12, 2024
1 parent e48cbb8 commit 7ed47f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 12 additions & 2 deletions appletree/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class Map(Config):
When using log-binning, we will first convert the positions to log space.
"""

def __init__(self, method="IDW", **kwargs):
super().__init__(**kwargs)
self.method = method
Expand Down Expand Up @@ -254,14 +255,22 @@ def build_regbin(self, data):
if self.method == "IDW":
setattr(self, "interpolator", interpolation.map_interpolator_regular_binning_2d)
elif self.method == "NN":
setattr(self, "interpolator", interpolation.map_interpolator_regular_binning_nearest_neighbor_2d)
setattr(
self,
"interpolator",
interpolation.map_interpolator_regular_binning_nearest_neighbor_2d,
)
else:
raise ValueError(f"Unknown method {self.method} for 2D regular binning.")
elif len(self.coordinate_lowers) == 3 and self.method == "IDW":
if self.method == "IDW":
setattr(self, "interpolator", interpolation.map_interpolator_regular_binning_3d)
elif self.method == "NN":
setattr(self, "interpolator", interpolation.map_interpolator_regular_binning_nearest_neighbor_3d)
setattr(
self,
"interpolator",
interpolation.map_interpolator_regular_binning_nearest_neighbor_3d,
)
else:
raise ValueError(f"Unknown method {self.method} for 3D regular binning.")
if self.coordinate_type == "log_regbin":
Expand Down Expand Up @@ -315,6 +324,7 @@ class SigmaMap(Config):
in Component.needed_parameters.
"""

def __init__(self, method="IDW", **kwargs):
super().__init__(**kwargs)
self.method = method
Expand Down
10 changes: 7 additions & 3 deletions appletree/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,11 @@ def find_nearest_indices(x, y):
return indices



@export
@jit
def map_interpolator_regular_binning_nearest_neighbor_2d(pos, ref_pos_lowers, ref_pos_uppers, ref_val):
def map_interpolator_regular_binning_nearest_neighbor_2d(
pos, ref_pos_lowers, ref_pos_uppers, ref_val
):
"""Nearest neighbor 2D interpolation. A uniform mesh grid binning is assumed.
Args:
Expand All @@ -291,9 +292,12 @@ def map_interpolator_regular_binning_nearest_neighbor_2d(pos, ref_pos_lowers, re
val = ref_val[ind0, ind1]
return val


@export
@jit
def map_interpolator_regular_binning_nearest_neighbor_3d(pos, ref_pos_lowers, ref_pos_uppers, ref_val):
def map_interpolator_regular_binning_nearest_neighbor_3d(
pos, ref_pos_lowers, ref_pos_uppers, ref_val
):
"""Nearest neighbor 3D interpolation. A uniform mesh grid binning is assumed.
Args:
Expand Down

0 comments on commit 7ed47f9

Please sign in to comment.