Correction of readout delay using bgmap#1645
Conversation
ykyohei
left a comment
There was a problem hiding this comment.
Thank you so much for making this PR! This looks great.
If I understand correctly, this pipeline can be run both on-site and off-site (i.e. nersc), so I suggest dropping the 'run_method' and modifying '_main', as well as renaming 'run_update_obs_site' and 'run_update_bgmap_site'.
Just to confirm, is it correct that this can only correct step delay, and that we cannot measure global delay using bgmap?
| return | ||
|
|
||
| # Transient errors of metadata loading. | ||
| # These can happen when hwpss_subtraction is True, but we can retry. |
| We fit three models: expon, exponbox, exponboxw. | ||
| They are different in the width of the box window. | ||
| """ | ||
| # Normalize not to bee very small value |
| std = chdata.mean_resp[:20].std() | ||
| y = chdata.mean_resp / std | ||
|
|
||
| # Usual BiasStepAnalysis has 20 samples before t=0. |
There was a problem hiding this comment.
I suggest to define a constant at the beginning and use it everywhere, for example
PRE_STEP_SAMPLES = 20 # samples before bias step at t=0
| res.results = aman | ||
| res.success = True | ||
| except Exception as e: | ||
| res.traceback = traceback.format_exc() |
There was a problem hiding this comment.
traceback and fail_msg looks same, and fail_msg is not defined in RunBgmapResult, I suggest to unify these.
| bgmap_ids.append(oid) | ||
| res.bgmap_ids = bgmap_ids | ||
| res.success = True | ||
| except Exception as e: |
There was a problem hiding this comment.
traceback and fail_msg looks same, and fail_msg is not defined in RunObsResult, I suggest to unify these.
| bgmap_ids: Optional[list[str]] = None | ||
|
|
||
|
|
||
| def run_obs_process(cfg: BgmapDelayCfg, obs_id: str) -> RunBgmapResult: |
There was a problem hiding this comment.
| def run_obs_process(cfg: BgmapDelayCfg, obs_id: str) -> RunBgmapResult: | |
| def run_obs_process(cfg: BgmapDelayCfg, obs_id: str) -> RunObsResult: |
| import logging | ||
| from tqdm.auto import tqdm, trange | ||
| from dataclasses import dataclass, astuple, field, fields | ||
| from typing import Optional, Union, Any, Literal, Callable, Self |
There was a problem hiding this comment.
There are some unused imports
dataclasses.astuple, dataclasses.fields, typing.Any, concurrent.futures.Future
| if np.isscalar(dt): | ||
| if invert: | ||
| target *= np.exp(2j * np.pi * freqs * dt) | ||
| else: | ||
| target *= np.exp(-2j * np.pi * freqs * dt) | ||
| return | ||
|
|
||
| assert(len(dt) == len(target)) # safe zip. | ||
| if invert: | ||
| for chdt, dest in zip(dt, target): | ||
| dest *= np.exp(2j * np.pi * freqs * chdt) | ||
| else: | ||
| for chdt, dest in zip(dt, target): | ||
| dest *= np.exp(-2j * np.pi * freqs * chdt) |
There was a problem hiding this comment.
I think this can be simplified as follows
| if np.isscalar(dt): | |
| if invert: | |
| target *= np.exp(2j * np.pi * freqs * dt) | |
| else: | |
| target *= np.exp(-2j * np.pi * freqs * dt) | |
| return | |
| assert(len(dt) == len(target)) # safe zip. | |
| if invert: | |
| for chdt, dest in zip(dt, target): | |
| dest *= np.exp(2j * np.pi * freqs * chdt) | |
| else: | |
| for chdt, dest in zip(dt, target): | |
| dest *= np.exp(-2j * np.pi * freqs * chdt) | |
| if not np.isscalar(dt): | |
| assert(len(dt) == len(target)) # safe zip. | |
| dt = dt[:, None] | |
| if invert: | |
| target *= np.exp(2j * np.pi * freqs * dt) | |
| else: | |
| target *= np.exp(-2j * np.pi * freqs * dt) |
Implement readout delay correction from bgmap data
sotodlib/site_pipeline/update_bgmap_delay.py
sotodlib/tod_ops/filters.py