Skip to content

Commit

Permalink
Merge pull request #28 from CMB-S4/toast3_hwpoint
Browse files Browse the repository at this point in the history
Toast3 hwpoint
  • Loading branch information
tskisner authored Aug 1, 2023
2 parents 88fd545 + 5e97b1c commit 9725175
Show file tree
Hide file tree
Showing 9 changed files with 818 additions and 1,026 deletions.
26 changes: 19 additions & 7 deletions pipelines/s4_hardware_to_toast3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env/python

# Copyright (c) 2020-2020 CMB-S4 Collaboration.
# Copyright (c) 2020-2023 CMB-S4 Collaboration.
# Full license can be found in the top level "LICENSE" file.

"""Translate an S4 hardware map on disk into an HDF5 supported by TOAST3
Expand Down Expand Up @@ -38,7 +38,7 @@ def main():

parser.add_argument(
"--telescope",
required=True,
required=False,
help="Input telescope (LAT0,...,LAT2, or SAT0,...,SAT5). "
"Not used if --hardware is provided.",
)
Expand All @@ -64,8 +64,8 @@ def main():
if args.telescope is None:
raise RuntimeError("Must select a telescope if not providing a hardware file.")
print(f"Simulating hardware for {args.telescope}...", end="", flush=True)
hw = hardware.get_example()
hw.data["detectors"] = hardware.sim_telescope_detectors(hw, args.telescope)
hw = hardware.sim_nominal()
hardware.sim_telescope_detectors(hw, args.telescope)
else:
if args.telescope is not None:
raise RuntimeError("Must not select a telescope if providing a hardware file.")
Expand All @@ -87,6 +87,11 @@ def main():
psi = np.degrees(qa.to_angles(angrot)[2]) % 180
det_data["psi_pol"] = psi
"""
quat = qa.norm(det_data["quat"])
det_data["pol_angle"] = pol_angle = np.arctan2(
2 * quat[3] * quat[2],
quat[3]**2 - quat[2]**2
) % np.pi
if band not in bands:
bands[band] = {"name" : []}
bands[band]["name"].append(det_name)
Expand Down Expand Up @@ -145,7 +150,7 @@ def main():
):
if wafer in wafer_to_FOV_cut:
theta_max = wafer_to_FOV_cut[wafer] / 2
theta, phi = qa.to_position(quat)
theta, phi, _ = qa.to_iso_angles(quat)
if theta > theta_max:
cut[idet] = False
print(f"INFO: FOV_cut rejects {(1 - np.sum(cut) / n_det) * 100:.2f} % pixels")
Expand Down Expand Up @@ -202,12 +207,19 @@ def main():
continue
if key == "fwhm":
unit = u.arcmin
columns.append(Column(name=key, data=np.array(value)[cut], unit=unit))
if key == "quat":
val = np.array(value)[cut, :]
else:
val = np.array(value)[cut]
columns.append(Column(name=key, data=val, unit=unit))

det_table = QTable(columns)

fp = Focalplane(detector_data=det_table, sample_rate=fsample * u.Hz)
fname = f"{args.out}_{args.telescope}_{band_name}.h5"
if args.telescope is None:
fname = f"{args.out}_{band_name}.h5"
else:
fname = f"{args.out}_{args.telescope}_{band_name}.h5"
with toast.io.H5File(fname, "w", comm=None, force_serial=True) as f:
fp.save_hdf5(f.handle)
print(f"Wrote {fname}")
Expand Down
10 changes: 7 additions & 3 deletions s4sim/hardware/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2020 CMB-S4 Collaboration.
# Copyright (c) 2020-2023 CMB-S4 Collaboration.
# Full license can be found in the top level "LICENSE" file.
"""Hardware models for use in analysis.
Expand All @@ -9,8 +9,12 @@

# These are simply namespace imports for convenience.

from .config import Hardware, get_example
from .config import Hardware, sim_nominal

from .sim import sim_wafer_detectors, sim_telescope_detectors
from .sim import (
sim_detectors_toast,
sim_detectors_physical_optics,
sim_telescope_detectors,
)

from .vis import plot_detectors, summary_text
Loading

0 comments on commit 9725175

Please sign in to comment.