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

Modify reduce pipeline to simulate noise and foregrounds without CMB #4

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Changes from all commits
Commits
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
89 changes: 53 additions & 36 deletions pipelines/toast_planck_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ def add_sim_params(parser):
action="store_true",
help="Simulate and add noise to signal.",
)
parser.add_argument(
"--simulate_signal",
dest="simulate_signal",
default=False,
action="store_true",
help="Simulate signal and overwrite data.",
)
# Decalibration
parser.add_argument(
"--decalibrate",
Expand Down Expand Up @@ -2026,7 +2033,7 @@ def run_noisesim(args, data, fsample, mc, mpiworld):
return
timer = Timer()
timer.start()
if not args.cmb_alm:
if not args.simulate_signal:
# zero the local signal for noise
for obs in data.obs:
tod = obs["tod"]
Expand Down Expand Up @@ -2151,16 +2158,29 @@ def check_files(data, args, mc):


def run_signalsim(args, data, mc, outdir, rimo, mpiworld):
if not args.cmb_alm:
if not args.simulate_signal:
return None
if data.comm.comm_world.rank == 0:
print("Simulating signal ...", flush=True)
memreport("Before signalsim", mpiworld)
fwhm = tp.utilities.freq_to_fwhm(args.freq)

almfile = args.cmb_alm.format(mc)
if data.comm.comm_world.rank == 0:
print("Simulating CMB from {}".format(almfile), flush=True)
# Optionally run a CMB simulation
if args.cmb_alm:
almfile = args.cmb_alm.format(mc)
if data.comm.comm_world.rank == 0:
print("Simulating CMB from {}".format(almfile), flush=True)
if args.conviqt_beamfile and not args.tfmode:
run_conviqt(args, data, almfile, args.conviqt_beamfile, rimo, mpiworld)
almfile = None
add = True
else:
add = False
else:
almfile = None
add = False

# Draw center frequencies
if args.freq_sigma is None:
if data.comm.comm_world.rank == 0:
print("WARNING: not simulating bandpass mismatch", flush=True)
Expand Down Expand Up @@ -2190,12 +2210,6 @@ def run_signalsim(args, data, mc, outdir, rimo, mpiworld):
freqs[det] = freq
if data.comm.comm_world.rank == 0:
print("MC {:4} Det {:8} center freq = {:10.3f}".format(mc, det, freq))
if args.conviqt_beamfile and not args.tfmode:
run_conviqt(args, data, almfile, args.conviqt_beamfile, rimo, mpiworld)
almfile = None
add = True
else:
add = False

timer = Timer()
timer.start()
Expand Down Expand Up @@ -2237,30 +2251,33 @@ def run_signalsim(args, data, mc, outdir, rimo, mpiworld):
del signalsim
memreport("after deleting tp.OpSignalSim", mpiworld)

fn_cmb = os.path.join(
CMBCACHE,
"{}_nside{:04}_quickpol.fits".format(
os.path.basename(args.cmb_alm.format(mc)).replace(".fits", ""),
args.sim_nside,
),
)
if data.comm.comm_world.rank == 0:
if not os.path.isfile(fn_cmb):
print(
"ERROR: Even when using Conviqt, there must also be a cached version "
'of the CMB map. File not found: "{}"'.format(fn_cmb),
flush=True,
)
data.comm.comm_world.Abort("No cached CMB map")
print("Loading pre-computed CMB map from {}".format(fn_cmb), flush=True)
cmb = MapSampler(
fn_cmb,
pol=True,
comm=data.comm.comm_world,
nest=True,
nside=args.reproc_nside_bandpass,
plug_holes=False,
)
if args.cmb_alm:
fn_cmb = os.path.join(
CMBCACHE,
"{}_nside{:04}_quickpol.fits".format(
os.path.basename(args.cmb_alm.format(mc)).replace(".fits", ""),
args.sim_nside,
),
)
if data.comm.comm_world.rank == 0:
if not os.path.isfile(fn_cmb):
print(
"ERROR: Even when using Conviqt, there must also be a cached version "
'of the CMB map. File not found: "{}"'.format(fn_cmb),
flush=True,
)
data.comm.comm_world.Abort("No cached CMB map")
print("Loading pre-computed CMB map from {}".format(fn_cmb), flush=True)
cmb = MapSampler(
fn_cmb,
pol=True,
comm=data.comm.comm_world,
nest=True,
nside=args.reproc_nside_bandpass,
plug_holes=False,
)
else:
cmb = None

if args.sim_tf is not None:
if data.comm.comm_world.rank == 0:
Expand Down Expand Up @@ -2408,7 +2425,7 @@ def main():
continue
mctimer = Timer()
mctimer.start()
if args.cmb_alm or args.simulate_noise:
if args.simulate_signal or args.simulate_noise:
outdir = os.path.join(args.out, "{:04}".format(mc))
if comm.world_rank == 0:
os.makedirs(outdir, exist_ok=True)
Expand Down