Created
March 12, 2025 14:17
-
-
Save tskisner/d9a517af43f602f725042fb8d482899e to your computer and use it in GitHub Desktop.
Mock code for simulating atmosphere monitoring detectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Pseudocode example as a talking point for discussion. | |
Code similar to this could be dropped into a copy of `toast_so_sim`, or into a notebook where the data is being loaded | |
manually with the LoadContext operator. | |
""" | |
#------------------------------------------------------------------------------------------------------------- | |
# Load data into observations. Either in a notebook with LoadContext directly or in a workflow script calling | |
# `load_or_simulate_observing()`. | |
#------------------------------------------------------------------------------------------------------------- | |
# Now for each observation we are going to: | |
# | |
# 1. Delete any detector data, since this contains the wrong number of detectors. | |
# 2. Add new detectors to the focalplane with a custom bandpass | |
# | |
# Wipe any starting detector data (it will get re-created by the simulation operators). | |
toast.ops.Delete(detdata=[defaults.det_data, defaults.det_flags]).apply(data) | |
# Detectors to add (assuming same names on all wafers) | |
monitor_dets = { | |
"det_atm_01": { | |
"quats": np.array([0, 0, 0, 1]), # Change to the actual boresight offset... | |
"bandcenter": 90.0 * u.GHz, | |
"bandwidth": 5.0 * u.GHz, | |
"psd_net": 0.05 * u.K * np.sqrt(1 * u.second), | |
# Add other properties too... | |
}, | |
"det_atm_02": { # you get the idea... | |
}, | |
} | |
for obs in data.obs: | |
# Note that by default for SO, each observation is a single wafer. | |
# Get the focalplane | |
fp = obs.telescope.focalplane | |
# Get the astropy table of detector properties | |
det_props = fp.detector_data | |
# Add rows for our monitor dets. This modifies the table in place. | |
for mon_name, mon_props in monitor_dets.items(): | |
# Copy an existing row, modify with this current dets properties, then add the new row... | |
det_props.add_row( ... ) | |
# Make a new focalplane with this updated detector table | |
new_fp = toast.Focalplane( | |
detector_data=det_props, | |
field_of_view=fp.field_of_view, | |
sample_rate=fp.sample_rate, | |
thinfp=fp.thinfp, | |
) | |
# Replace the observation focalplane with this new one | |
obs.telescope.focalplane = new_fp | |
#------------------------------------------------------------------------------------------------------------- | |
# Simulate atmosphere for all detectors (including the atmosphere monitor dets). This can be done manually in a | |
# notebook or in a workflow script by calling `wrk.simulate_atmosphere_signal()`. See toast_so_sim for an example | |
#------------------------------------------------------------------------------------------------------------- | |
#------------------------------------------------------------------------------------------------------------- | |
# Simulate instrumental noise for all detectors (including the monitor dets). | |
#------------------------------------------------------------------------------------------------------------- | |
# Now the monitor dets have the desired signal, and we flag them so that the rest of the simulated sky components | |
# do not get added to those dets. | |
for obs in data.obs: | |
obs.set_local_detector_flags( | |
{x: defaults.det_mask_invalid for x in monitor_dets} | |
) | |
#------------------------------------------------------------------------------------------------------------- | |
# Simulate the rest of the sky components... | |
#------------------------------------------------------------------------------------------------------------- | |
# Data reduction. In practice, one would need to calibrate these monitor dets differently... | |
# Then use the monitor dets to build the spatial model of the atmosphere power across the focalplane. This can | |
# then be used as a 2D filter or a destriping template. |
Another note- simulate the AZSS before flagging the dets.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, if the monitor dets are replacing normal detectors, just modify existing rows of the table, rather than adding rows.