Skip to content

Commit e43c56d

Browse files
updated get_norm_wtl1_sphere function to make the default behavior use unnormalized L1-norms
1 parent 5d8f0f7 commit e43c56d

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

pycs/astro/wl/hos_peaks_l1.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,14 @@ def get_wtl1(self, nbins=None, Mask=None, min_snr=None, max_snr=None):
582582

583583

584584
def get_norm_wtl1_sphere(
585-
Map, nscales, nbins=None, Mask=None, min_snr=None, max_snr=None, path="/."
585+
Map,
586+
nscales,
587+
nbins=None,
588+
Mask=None,
589+
min_snr=None,
590+
max_snr=None,
591+
path="/.",
592+
normalize_energy=False,
586593
):
587594
"""
588595
Computes L1 norms of wavelet transform coefficients at different scales for a HEALPix map. The wavelet transform is performed using the undecimated wavelet transform.
@@ -598,11 +605,13 @@ def get_norm_wtl1_sphere(
598605
Mask : array_like, optional
599606
Mask indicating where we have observations. Only pixels where Mask != 0 are considered.
600607
min_snr : float, optional
601-
Minimum value for binning. If None, uses the minimum value in the normalized coefficients.
608+
Minimum value for binning. If None, uses the minimum value in the coefficients.
602609
max_snr : float, optional
603-
Maximum value for binning. If None, uses the maximum value in the normalized coefficients.
610+
Maximum value for binning. If None, uses the maximum value in the coefficients.
604611
path : str, optional
605612
Path to the directory for temporary files. Default is "/.".
613+
normalize_energy : bool, optional
614+
If True, normalize wavelet coefficients by their energy. Default is False.
606615
607616
Returns
608617
-------
@@ -617,7 +626,6 @@ def get_norm_wtl1_sphere(
617626
nbins = 40
618627

619628
# Perform undecimated wavelet transform on the spherical map
620-
# WT = mrs_uwttrans(Map, verbose=False, path=path, cxx=True)
621629
WT = mrs_uwttrans(Map, nscale=nscales, verbose=False, path=path, cxx=False)
622630

623631
l1norm_coll = []
@@ -631,26 +639,27 @@ def get_norm_wtl1_sphere(
631639
if Mask is not None:
632640
ScaleCoeffs = ScaleCoeffs[Mask != 0]
633641

634-
# Normalize the wavelet scale to the same energy level
635-
energy = np.sum(ScaleCoeffs**2)
636-
normalization_factor = np.sqrt(energy)
637-
if normalization_factor > 0:
638-
ScaleCoeffs_normalized = ScaleCoeffs / normalization_factor
642+
# Normalize the wavelet scale to the same energy level if requested
643+
if normalize_energy:
644+
energy = np.sum(ScaleCoeffs**2)
645+
normalization_factor = np.sqrt(energy)
646+
if normalization_factor > 0:
647+
ScaleCoeffs = ScaleCoeffs / normalization_factor
639648

640649
# Set the minimum and maximum values based on inputs or defaults
641-
min_val = min_snr if min_snr is not None else np.min(ScaleCoeffs_normalized)
642-
max_val = max_snr if max_snr is not None else np.max(ScaleCoeffs_normalized)
650+
min_val = min_snr if min_snr is not None else np.min(ScaleCoeffs)
651+
max_val = max_snr if max_snr is not None else np.max(ScaleCoeffs)
643652

644653
# Define thresholds and bins
645654
thresholds = np.linspace(min_val, max_val, nbins + 1)
646655
bins = 0.5 * (thresholds[:-1] + thresholds[1:])
647656

648657
# Digitize the values into bins
649-
digitized = np.digitize(ScaleCoeffs_normalized, thresholds)
658+
digitized = np.digitize(ScaleCoeffs, thresholds)
650659

651660
# Calculate the l1 norm for each bin
652661
bin_l1_norm = [
653-
np.sum(np.abs(ScaleCoeffs_normalized[digitized == j]))
662+
np.sum(np.abs(ScaleCoeffs[digitized == j]))
654663
for j in range(1, len(thresholds))
655664
]
656665

0 commit comments

Comments
 (0)