Skip to content

Commit

Permalink
hooked up the interpolation and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielaBreitman committed May 9, 2024
1 parent 74d2cb3 commit 2156c2b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/powerbox/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ def _field_average_interpolate(coords, field, bins, weights, angular_resolution=
[
np.round(2 * np.pi * bins / angular_resolution),
np.ones_like(bins) / angular_resolution,
]
],
axis=0,
),
dtype=int,
)
Expand Down Expand Up @@ -307,6 +308,7 @@ def angular_average_nd(
get_variance=False,
log_bins=False,
interpolation_method=None,
angular_resolution=0.1,
):
"""
Average the first n dimensions of a given field within radial bins.
Expand All @@ -326,7 +328,7 @@ def angular_average_nd(
An array of arbitrary dimension specifying the field to be angularly averaged.
coords : list of n arrays
A list of 1D arrays specifying the co-ordinates in each dimension *to be average*.
A list of 1D arrays specifying the co-ordinates in each dimension *to be averaged*.
bins : int or array.
Specifies the radial bins for the averaged dimensions. Can be an int or array specifying radial bin edges.
Expand Down Expand Up @@ -394,7 +396,7 @@ def angular_average_nd(
if len(coords) != len(field.shape):
raise ValueError("coords should be a list of arrays, one for each dimension.")

if n == len(coords):
if n == len(coords) and interpolation_method is None:
return angular_average(
field,
coords,
Expand All @@ -406,10 +408,10 @@ def angular_average_nd(
log_bins=log_bins,
)

coords = _magnitude_grid([c for i, c in enumerate(coords) if i < n])
coords_grid = _magnitude_grid([c for i, c in enumerate(coords) if i < n])

indx, bins, sumweights = _get_binweights(
coords, weights, bins, average, bin_ave=bin_ave, log_bins=log_bins
coords_grid, weights, bins, average, bin_ave=bin_ave, log_bins=log_bins
)

n1 = np.prod(field.shape[:n])
Expand All @@ -429,7 +431,13 @@ def angular_average_nd(
if get_variance:
var[:, i] = _field_variance(indx, fld, res[:, i], w, sumweights)
elif interpolation_method == "linear":
res[:, i], sumweights = _field_average_interpolate(coords, fld, bins, w)
res[:, i], sumweights = _field_average_interpolate(

Check warning on line 434 in src/powerbox/tools.py

View check run for this annotation

Codecov / codecov/patch

src/powerbox/tools.py#L433-L434

Added lines #L433 - L434 were not covered by tests
np.array(coords)[:n, ...],
fld.reshape(field.shape[:n]),
bins,
w,
angular_resolution=angular_resolution,
)
if get_variance:

Check warning on line 441 in src/powerbox/tools.py

View check run for this annotation

Codecov / codecov/patch

src/powerbox/tools.py#L441

Added line #L441 was not covered by tests
# TODO: Implement variance calculation for interpolation
var[:, i] = np.zeros_like(res[:, i])

Check warning on line 443 in src/powerbox/tools.py

View check run for this annotation

Codecov / codecov/patch

src/powerbox/tools.py#L443

Added line #L443 was not covered by tests
Expand Down

0 comments on commit 2156c2b

Please sign in to comment.