Skip to content

Commit

Permalink
Zero out grid points outside of xmin and xmax for pswf_operator (#19)
Browse files Browse the repository at this point in the history
* Truncate pswf if values outside of xmin and xmax

* Add additional test case for pswf

* Add clarifying info to pswf docstring
  • Loading branch information
tyler-a-cox authored Nov 9, 2023
1 parent 1a8b67b commit d5e4f8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions hera_filters/dspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,7 @@ def _normalized_legendre(x, kmax):

def pswf_operator(
x, filter_centers, filter_half_widths, eigenval_cutoff=None, nterms=None,
cache=None, xmin=None, xmax=None, hash_decimal=10,
cache=None, xmin=None, xmax=None, hash_decimal=10
):
"""
Calculates PSWF operator with multiple delay windows to fit data. Frequencies
Expand Down Expand Up @@ -2364,9 +2364,11 @@ def pswf_operator(
nterms: list of integers, optional
integer specifying number of pswf terms to include in each delay fitting block.
xmin: float, optional
Lower bound of the frequency range. If not given, will be calculate from x
Lower bound of the frequency range. If not given, will be calculate from x. If xmin is given and
the range of x is outside of the range, the filters will be set to zero for those values of x.
xmax: float, optional
Upper bound of the frequency range. If not given, will be calculate from x
Upper bound of the frequency range. If not given, will be calculate from x. If xmax is given and
the range of x is outside of the range, the filters will be set to zero for those values of x.
hash_decimal: int
number of decimals to round for floating point dict keys.
Expand Down Expand Up @@ -2453,6 +2455,9 @@ def pswf_operator(
eigvals = (eigvals / eigvals.max()) ** 2
nt = np.max(neven[eigvals > eigenval_cutoff[fn]])

# If x-value is outside of the range, set the filters to zeros
pswf_vectors[(xg < -1) | (xg > 1)] = 0

# Truncate pswf vectors
pswf_vectors = pswf_vectors[:, :nt]
_nterms.append(nt)
Expand Down
3 changes: 3 additions & 0 deletions hera_filters/tests/test_dspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ def test_pswf_operator():
amat1, ncol1 = dspec.pswf_operator(freqs, [0.], [100e-9], eigenval_cutoff=[1e-9])
amat2, ncol2 = dspec.pswf_operator(freqs, [0., 100e-9], [100e-9, 100e-9], eigenval_cutoff=[1e-9, 1e-9])
assert sum(ncol2) == 2 * sum(ncol1)
# Check that values outside of xmin and xmax are set to zero
amat1, ncol1 = dspec.pswf_operator(freqs, [0.], [100e-9], eigenval_cutoff=[1e-9], xmin=1.475e8, xmax=1.5e8)
assert np.isclose(amat1[(freqs < 1.475e8) | (freqs > 1.5e8), :].sum(), 0)

def test_dpss_operator():
#test that an error is thrown when we specify more then one
Expand Down

0 comments on commit d5e4f8d

Please sign in to comment.