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

New functions for fft_ops #869

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7969bed
added masking and binning function
May 23, 2024
5e88252
hwp_angle can be declared
May 23, 2024
3fc19ae
Modified not to use Numpy.MaskedArray
17-sugiyama Jun 3, 2024
307ab16
modified binning and fitting function
17-sugiyama Jul 8, 2024
3c96965
Reflected Tomoki's comments
17-sugiyama Jul 8, 2024
9575bf9
Modified fit_binned_noise_model
17-sugiyama Jul 16, 2024
81fbde8
Minor debug
17-sugiyama Jul 17, 2024
5bbde3d
Merge branch 'master' into fft_ops_hwpss_mask
tterasaki Aug 1, 2024
8116be2
moved get_hwp_freq to sotodlib.hwp.hwp
tterasaki Aug 1, 2024
f5673c8
small bug fix
tterasaki Aug 1, 2024
912ac2e
improved calc_psd merging style
tterasaki Aug 1, 2024
97d2127
from capital PSD_mask to psd_mask
tterasaki Aug 1, 2024
63b9608
binning_psd can accept 2d array
tterasaki Aug 1, 2024
c946071
binning_psd can accept 2d array
tterasaki Aug 1, 2024
65f4125
log_binning modification
tterasaki Aug 1, 2024
f138b70
integrated fit_noise_model and fit_binned_noise_model
17-sugiyama Aug 8, 2024
15a83a9
fit_noise_model can have a constant fixed parameter's value
17-sugiyama Aug 8, 2024
d3eaabd
put nan in covout where the parameter is fixed
17-sugiyama Aug 8, 2024
b57326e
changed some function's name
17-sugiyama Aug 8, 2024
57f5c24
minor bug fix
17-sugiyama Aug 8, 2024
3d02df5
give initial estimates of parameters for fit_noise_model
17-sugiyama Aug 8, 2024
91c4381
reflected Tomoki's comments
17-sugiyama Sep 12, 2024
f10e0f0
add unittest
17-sugiyama Sep 24, 2024
db40980
Merge branch 'master' into fft_ops_hwpss_mask
tterasaki Sep 26, 2024
95844f4
Merge branch 'master' into fft_ops_hwpss_mask
earosenberg Jan 13, 2025
fe6d5be
fft_ops cleanups and subscan merge fixes
earosenberg Jan 13, 2025
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
2 changes: 1 addition & 1 deletion sotodlib/hwp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"""
from .g3thwp import G3tHWP
from .hwp import (get_hwpss, subtract_hwpss, demod_tod)
from .hwp import (get_hwpss, subtract_hwpss, demod_tod, get_hwp_freq)
from .sim_hwp import I_to_P_param
from .sim_hwp import sim_hwpss
from .sim_hwp import sim_hwpss_2f4f
27 changes: 21 additions & 6 deletions sotodlib/hwp/hwp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from scipy.optimize import curve_fit
from sotodlib import core, tod_ops
from sotodlib.tod_ops import bin_signal, filters
from sotodlib.tod_ops import filters
import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -210,7 +210,7 @@ def get_binned_hwpss(aman, signal=None, hwp_angle=None,
if hwp_angle is None:
hwp_angle = aman['hwp_angle']

binning_dict = bin_signal(aman, bin_by=hwp_angle, range=[0, 2*np.pi],
binning_dict = tod_ops.bin_signal(aman, bin_by=hwp_angle, range=[0, 2*np.pi],
bins=bins, signal=signal, flags=flags)

bin_centers = binning_dict['bin_centers']
Expand Down Expand Up @@ -491,8 +491,22 @@ def subtract_hwpss(aman, signal=None, hwpss_template=None,
aman.wrap(subtract_name, np.subtract(
signal, hwpss_template), [(0, 'dets'), (1, 'samps')])

def get_hwp_freq(timestamps, hwp_angle):
"""
Calculate the frequency of HWP rotation.

Parameters:
timestamps (array-like): An array of timestamps.
hwp_angle (array-like): An array of HWP angles in radian

Returns:
float: The frequency of the HWP rotation in Hz.
"""
hwp_freq = (np.sum(np.abs(np.diff(np.unwrap(hwp_angle)))) /
(timestamps[-1] - timestamps[0])) / (2 * np.pi)
return hwp_freq

def demod_tod(aman, signal_name='signal', demod_mode=4,
def demod_tod(aman, signal_name='signal', hwp_angle=None, demod_mode=4,
bpf_cfg=None, lpf_cfg=None):
"""
Demodulate TOD based on HWP angle
Expand Down Expand Up @@ -527,9 +541,10 @@ def demod_tod(aman, signal_name='signal', demod_mode=4,
the demodulated signal imaginary component filtered with `lpf` and multiplied by 2.

"""
if hwp_angle is None:
hwp_angle = aman.hwp_angle
# HWP speed in Hz
speed = (np.sum(np.abs(np.diff(np.unwrap(aman.hwp_angle)))) /
(aman.timestamps[-1] - aman.timestamps[0])) / (2 * np.pi)
speed = get_hwp_freq(timestamps=aman.timestamps, hwp_angle=hwp_angle)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you implement below and use here and elsewhere?

def get_hwp_freq(timestamps=None, hwp_angle=None):
    hwp_freq = (np.sum(np.abs(np.diff(np.unwrap(hwp_angle)))) /
            (timestamps[-1] - timestamps[0])) / (2 * np.pi)
    return hwp_freq

if bpf_cfg is None:
bpf_center = demod_mode * speed
Expand All @@ -547,7 +562,7 @@ def demod_tod(aman, signal_name='signal', demod_mode=4,
'trans_width': 0.1}
lpf = filters.get_lpf(lpf_cfg)

phasor = np.exp(demod_mode * 1.j * aman.hwp_angle)
phasor = np.exp(demod_mode * 1.j * hwp_angle)
demod = tod_ops.fourier_filter(aman, bpf, detrend=None,
signal_name=signal_name) * phasor

Expand Down
Loading