Skip to content
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

Issue in little_h homogeneity when using grouping.spherical_average #361

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 26 additions & 14 deletions hera_pspec/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,15 +664,20 @@ def spherical_average(uvp_in, kbins, bin_widths, blpair_groups=None, time_avg=Fa
if isinstance(bin_widths, (float, int)):
bin_widths = np.ones_like(kbins) * bin_widths

# copy input
uvp = copy.deepcopy(uvp_in)

# transform kgrid to little_h units
if not little_h:
kbins = kbins / uvp.cosmo.h
bin_widths = bin_widths / uvp.cosmo.h

# ensure bins don't overlap
assert len(kbins) == len(bin_widths)
kbin_left = kbins - bin_widths / 2
kbin_right = kbins + bin_widths / 2
assert np.all(kbin_left[1:] >= kbin_right[:-1] - 1e-6), "kbins must not overlap"

# copy input
uvp = copy.deepcopy(uvp_in)

# perform time and cylindrical averaging upfront if requested
if not uvp.exact_windows and (blpair_groups is not None or time_avg):
uvp.average_spectra(blpair_groups=blpair_groups, time_avg=time_avg,
Expand All @@ -695,10 +700,6 @@ def spherical_average(uvp_in, kbins, bin_widths, blpair_groups=None, time_avg=Fa
if store_window:
window_function_array = odict()

# transform kgrid to little_h units
if not little_h:
kbins = kbins / uvp.cosmo.h
bin_widths = bin_widths / uvp.cosmo.h

# iterate over spectral windows
spw_ranges = uvp.get_spw_ranges()
Expand Down Expand Up @@ -887,7 +888,7 @@ def spherical_average(uvp_in, kbins, bin_widths, blpair_groups=None, time_avg=Fa
time_avg=time_avg,
error_weights=error_weights,
spw_array=spw,
little_h=little_h,
little_h=True,
verbose=True)[spw]

# handle data arrays
Expand Down Expand Up @@ -986,7 +987,8 @@ def spherical_wf_from_uvp(uvp_in, kbins, bin_widths,

little_h : bool, optional
If True, kgrid is in h Mpc^-1 units, otherwise just Mpc^-1 units.
If False, user must ensure adopted h is consistent with uvp_in.cosmo
The code ensures adopted h is consistent with uvp_in.cosmo. If not,
it modifies the unit of kbins.

verbose : bool, optional
If True, print progress, warnings and debugging info to stdout.
Expand All @@ -1004,6 +1006,21 @@ def spherical_wf_from_uvp(uvp_in, kbins, bin_widths,

if isinstance(bin_widths, (float, int)):
bin_widths = np.ones_like(kbins) * bin_widths

# if window functions have been computed without little h
# it is not possible to re adjust so kbins need to be in Mpc-1
# and reciprocally
if little_h != ('h^-3' in uvp_in.norm_units):
warnings.warn('Changed little_h units to make kbins consistent ' \
'with uvp.window_function_array. Might be inconsistent ' \
'with the power spectrum units.')
if little_h:
kbins *= uvp_in.cosmo.h
bin_widths *= uvp_in.cosmo.h
else:
kbins /= uvp_in.cosmo.h
bin_widths /= uvp_in.cosmo.h
little_h = 'h^-3' in uvp_in.norm_units

# ensure bins don't overlap
assert len(kbins) == len(bin_widths)
Expand Down Expand Up @@ -1063,11 +1080,6 @@ def spherical_wf_from_uvp(uvp_in, kbins, bin_widths,
time_avg=time_avg,
inplace=True)

# transform kgrid to little_h units
if not little_h:
kbins = kbins / uvp.cosmo.h
bin_widths = bin_widths / uvp.cosmo.h

# initialize blank arrays and dicts
window_function_array = odict()

Expand Down