Skip to content

Commit 20af447

Browse files
committed
more proper handling of map.pixel vs pixwin[sv] in get_pseudo2datavec.py and get_spectra_from_maps.py
1 parent 4fdcf63 commit 20af447

File tree

4 files changed

+163
-29
lines changed

4 files changed

+163
-29
lines changed

project/SO/pISO/python/get_mcm_bbl_and_pseudosignal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
raise ValueError("Unkown 'type' value! Must be either 'Dl' or 'Cl'")
4747
binning_file = d["binning_file"]
4848
binned_mcm = d["binned_mcm"]
49-
mk_pseudospectra = False
5049

5150
if d["use_toeplitz_mcm"] == True:
5251
assert args.old, 'can only toeplitz with pspy for now' # FIXME

project/SO/pISO/python/get_pseudo2datavec.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
# being the same survey
5050
templates[sv] = so_map.read_map(d[f"window_kspace_{sv}_{maps[sv][0]}"])
5151

52-
if d[f"pixwin_{sv}"]["pix"] == "CAR":
52+
if templates[sv].pixel == "CAR":
5353
filter_dicts[sv] = d[f"k_filter_{sv}"]
5454
else:
5555
raise NotImplementedError('can only kspace filter CAR maps')
@@ -97,13 +97,15 @@
9797

9898
# need to splice mbl_inv into spectra-ordered arrays
9999
# TODO: consider disk-space, memory (could be sparse)
100+
# FIXME: function assumes TT, TE, TB, ET, BT, EE, EB, BE, BB order
100101
pseudo2datavec = so_mcm.get_spec2spec_array_from_spin2spin_array(mbl_inv, dense=True)
101102

102103
# get the inv_kspace matrix for this array cross, if necessary
103104
if apply_kspace_filter:
104105
inv_kspace_mat = np.linalg.inv(kspace_transfer_matrix[spec_name])
105106

106107
# apply the inv_kspace matrix to mbl_inv to get data operator
108+
# FIXME: assumes inv_kspace_mat in TT, TE, TB, ET, BT, EE, EB, BE, BB order
107109
pseudo2datavec = inv_kspace_mat @ pseudo2datavec
108110

109111
# get the pixwin for healpix, if necessary

project/SO/pISO/python/get_spectra_from_maps.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,23 @@
212212
# FIXME: this will not work for SO LF which has a different template despite
213213
# being the same survey
214214
templates[sv] = so_map.read_map(d[f"window_kspace_{sv}_{maps[sv][0]}"])
215-
216-
if d[f"pixwin_{sv}"]["pix"] == "CAR" and deconvolve_pixwin:
217-
wy, wx = enmap.calc_window(templates[sv].data.shape,
218-
order=d[f"pixwin_{sv}"]["order"])
219-
wy = wy.astype(np.float32)
220-
wx = wx.astype(np.float32)
221-
pixwins[sv] = (wy[:, None] * wx[None, :])
222-
inv_pixwins[sv] = pixwins[sv] ** (-1)
223-
224-
if apply_kspace_filter:
225-
filter_dicts[sv] = d[f"k_filter_{sv}"]
226-
filters[sv] = kspace.get_kspace_filter(templates[sv],
227-
filter_dicts[sv],
228-
dtype=np.float32)
215+
216+
# NOTE: a map may a CAR map but have a HEALPIX pixwin, in which case we may
217+
# kspace filter it, but want to use a HEALPIX pixwin
218+
if templates[sv].pixel == "CAR":
219+
if d[f"pixwin_{sv}"]["pix"] == "CAR" and deconvolve_pixwin:
220+
wy, wx = enmap.calc_window(templates[sv].data.shape,
221+
order=d[f"pixwin_{sv}"]["order"])
222+
wy = wy.astype(np.float32)
223+
wx = wx.astype(np.float32)
224+
pixwins[sv] = (wy[:, None] * wx[None, :])
225+
inv_pixwins[sv] = pixwins[sv] ** (-1)
226+
227+
if apply_kspace_filter:
228+
filter_dicts[sv] = d[f"k_filter_{sv}"]
229+
filters[sv] = kspace.get_kspace_filter(templates[sv],
230+
filter_dicts[sv],
231+
dtype=np.float32)
229232

230233
# get spectrum-level auxiliary data products
231234
spec_name_list = pspipe_list.get_spec_name_list(d, delimiter="_")
@@ -329,14 +332,14 @@
329332

330333
window_tuple = (win_T, win_pol)
331334

332-
if win_T.pixel == "CAR": # FIXME: might not match d[f"pixwin_{sv}"]["pix"], there should only be one
333-
if apply_kspace_filter or deconvolve_pixwin:
335+
if win_T.pixel == "CAR":
336+
if apply_kspace_filter or (deconvolve_pixwin and d[f"pixwin_{sv}"]["pix"] == "CAR"):
334337
win_kspace = so_map.read_map(d[f"window_kspace_{sv}_{m}"])
335338
if apply_kspace_filter:
336339
filter = filters[sv]
337340
weighted_filter = filter_dicts[sv]["weighted"]
338341
if deconvolve_pixwin and d[f"pixwin_{sv}"]["pix"] == "CAR":
339-
inv_pwin = inv_pixwins[sv] # if d[f"pixwin_{sv}"]["pix"] == "CAR" else None # FIXME: see above
342+
inv_pwin = inv_pixwins[sv]
340343

341344
cal, pol_eff = d[f"cal_{sv}_{m}"], d[f"pol_eff_{sv}_{m}"]
342345

@@ -347,11 +350,7 @@
347350
else:
348351
split_idx = k - 1 # we put signal first because it is always correlated, so has biggest memory footprint
349352

350-
if win_T.pixel == "CAR": # FIXME: might not match d[f"pixwin_{sv}"]["pix"], there should only be one
351-
352-
###################################
353-
# INJECT MAPS
354-
###################################
353+
if win_T.pixel == "CAR":
355354

356355
# data injection
357356
if which == 'data':
@@ -385,7 +384,7 @@
385384
else:
386385
split.write_map(f"{sim_map_dir}" + f"noise_sim_map{tag}_{sv}_{m}_set{split_idx}_{iii:05d}.fits")
387386

388-
if apply_kspace_filter and deconvolve_pixwin and d[f"pixwin_{sv}"]["pix"] == "CAR":
387+
if apply_kspace_filter and (deconvolve_pixwin and d[f"pixwin_{sv}"]["pix"] == "CAR"):
389388
if k == 0:
390389
log.info(f"[Rank {so_mpi.rank}, Mapset {iii}] Apply kspace filter and inv pixwin on {sv}, {m}")
391390
split = kspace.filter_map(split,
@@ -404,7 +403,7 @@
404403
weighted_filter=weighted_filter,
405404
use_ducc_rfft=True)
406405

407-
elif deconvolve_pixwin:
406+
elif deconvolve_pixwin and d[f"pixwin_{sv}"]["pix"] == "CAR":
408407
if k == 0:
409408
log.info(f"[Rank {so_mpi.rank}, Mapset {iii}] WARNING: inv pixwin but no kspace filter on {sv}, {m}")
410409
split = so_map.fourier_convolution(split,
@@ -416,9 +415,6 @@
416415
log.info(f"[Rank {so_mpi.rank}, Mapset {iii}] WARNING: no kspace filter and no inv pixwin on {sv}, {m}")
417416

418417
elif win_T.pixel == "HEALPIX":
419-
###################################
420-
# INJECT MAPS
421-
###################################
422418

423419
# data injection
424420
if which == 'data':
@@ -496,11 +492,14 @@
496492

497493
# compute specific cls with higher precision, save memory overall by
498494
# doing this per spectrum. start_at_zero=False to match pspy convention
495+
# TODO: test if speed penalty of alm np.complex128 conversion
496+
# is worth the memory saved (takes ~14s per spectrum)
499497
_, pseudo_dict = so_spectra.get_spectra_pixell(master_alms[sv1, m1, snk1].astype(np.complex128),
500498
master_alms[sv2, m2, snk2].astype(np.complex128),
501499
spectra=spectra,
502500
apply_pspy_cut=True)
503501

502+
# FIXME: assumes pseudo2datavec in spectra order
504503
pseudovec = so_spectra.spec_dict2vec(pseudo_dict, spectra)
505504
datavec = pseudo2datavec @ pseudovec
506505

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
from os.path import join as opj
2+
from henry import Henry
3+
import hippometa as hm
4+
5+
client = Henry()
6+
sim_dir = '/scratch/gpfs/SIMONSOBS/users/zatkins/projects/lat-iso/piso_old/tiger_deep56_sim/sim_factory/sims/maps'
7+
8+
# collection layers:
9+
# Mock LAT ISO-SV1 Sims
10+
# - Mock LAT ISO-SV1 (1000x) Sims
11+
# - Mock LAT ISO-SV1 (1000x) tube freq Sims
12+
# - Mock LAT Deep56 Signal Map (1000x) tube freq {(Tags)}
13+
# - Mock LAT Deep56 Noise Map (1000x) tube freq (Set y)
14+
15+
top_collection = client.new_collection(
16+
name='Mock LAT ISO-SV1 Sims',
17+
description='Mock simulations of the LAT-ISO SV1 data. Each simulation ' \
18+
'includes the four MF tubes i1, i3, i4, and i6, and the two UHF tubes c1 ' \
19+
'and i5. Each tube and frequency band includes variations of signal maps ' \
20+
'(with/without random systematics, with/without map-level lensing) and ' \
21+
'four-way split noise maps.\n\n' \
22+
'See [this page](https://simonsobs.atlassian.net/wiki/spaces/PRO/pages/1452802049/LAT+ISO+Mock+Simulations) ' \
23+
'for more technical information.',
24+
products=[],
25+
)
26+
27+
for sim_num in range(10):
28+
sim_collection = client.new_collection(
29+
name=f'Mock LAT ISO-SV1 (1000{sim_num}) Sims',
30+
description='Mock simulations of the LAT-ISO SV1 data for sim index ' \
31+
f'1000{sim_num}. Each simulation includes the four MF tubes i1, i3, ' \
32+
'i4, and i6, and the two UHF tubes c1 and i5. Each tube and frequency ' \
33+
'band includes variations of signal maps (with/without random ' \
34+
'systematics, with/without map-level lensing) and four-way split noise' \
35+
'maps.\n\n' \
36+
'See [this page](https://simonsobs.atlassian.net/wiki/spaces/PRO/pages/1452802049/LAT+ISO+Mock+Simulations) ' \
37+
'for more technical information.',
38+
products=[],
39+
)
40+
41+
for mapname in ['i1_f090', 'i1_f150', 'i3_f090', 'i3_f150', 'i4_f090',
42+
'i4_f150', 'i6_f090', 'i6_f150', 'c1_f220', 'c1_f280',
43+
'i5_f220', 'i5_f280']:
44+
tube, freq = mapname.split('_')
45+
tube_freq_collection = client.new_collection(
46+
name=f'Mock LAT ISO-SV1 (1000{sim_num}) {tube} {freq} Sims',
47+
description='Mock simulations of the LAT-ISO SV1 data for sim index ' \
48+
f'1000{sim_num}, {tube} {freq} only. Includes variations of signal ' \
49+
'maps (with/without random systematics, with/without map-level ' \
50+
'lensing) and four-way split noise maps.\n\n' \
51+
'See [this page](https://simonsobs.atlassian.net/wiki/spaces/PRO/pages/1452802049/LAT+ISO+Mock+Simulations) ' \
52+
'for more technical information.',
53+
products=[],
54+
)
55+
56+
# signal maps
57+
for tag in ['_', '_syst_', '_lens_', '_syst_lens_']:
58+
map_file = f'signal_sim_map{tag}LAT_{tube}_{freq}_1000{sim_num}.fits'
59+
60+
if map_file == 'signal_sim_map_syst_LAT_i1_f150_10009.fits':
61+
signal_map_set = client.pull_product('69387f74f22a066989fc54e3', realize_sources=False)
62+
else:
63+
nametag = {'_': '',
64+
'_syst_': ' (Systematics)',
65+
'_lens_': ' (Map-level Lensing)',
66+
'_syst_lens_': ' (Systematics, Map-level Lensing)'
67+
}[tag]
68+
69+
desctag = {'_': '',
70+
'_syst_': ' Includes a random systematics realization.',
71+
'_lens_': ' Includes map-level lensing with lenspyx.',
72+
'_syst_lens_': ' Includes a random systematics realization and map-level lensing with lenspyx.'
73+
}[tag]
74+
75+
name = f'Mock LAT Deep56 Signal Map (1000{sim_num}) {tube} {freq}{nametag}'
76+
desc = f'Mock signal simulation of the LAT-ISO SV1 data, for ' \
77+
f'{tube} {freq}. The index of this simulation is 1000{sim_num}. ' \
78+
f'Same map for each of the four-way splits.{desctag} See ' \
79+
'[this page](https://simonsobs.atlassian.net/wiki/spaces/PRO/pages/1452802049/LAT+ISO+Mock+Simulations) ' \
80+
'for more technical information.'
81+
82+
signal_map_set = client.new_product(
83+
name=name,
84+
description=desc,
85+
metadata=hm.MapSet(telescope='lat', instrument=tube,
86+
frequency=freq, release='lat-iso-sv1',
87+
patch='deep56',
88+
polarization_convention='COSMO',
89+
pixelisation='cartesian'),
90+
sources={'map': {'path': opj(sim_dir, map_file),
91+
'description': 'the simulated map'}}
92+
)
93+
94+
tube_freq_collection.append(signal_map_set)
95+
96+
# noise maps
97+
for k in range(4):
98+
map_file = f'noise_sim_map_LAT_{tube}_{freq}_set{k}_1000{sim_num}.fits'
99+
100+
if map_file == 'noise_sim_map_LAT_i1_f150_set0_10009.fits':
101+
noise_map_set = client.pull_product('69387ef3f22a066989fc54dd', realize_sources=False)
102+
else:
103+
desctag = {0: ' first',
104+
1: ' second',
105+
2: ' third',
106+
3: ' fourth'
107+
}[k]
108+
109+
name = f'Mock LAT Deep56 Noise Map (1000{sim_num}) {tube} {freq} (Set {k})'
110+
desc = f'Mock noise simulation of the LAT-ISO SV1 data, for ' \
111+
f'{tube} {freq},{desctag} split of the four-way split. The index ' \
112+
f'of this simulation is 1000{sim_num}. See ' \
113+
'[this page](https://simonsobs.atlassian.net/wiki/spaces/PRO/pages/1452802049/LAT+ISO+Mock+Simulations) ' \
114+
'for more technical information.'
115+
116+
noise_map_set = client.new_product(
117+
name=name,
118+
description=desc,
119+
metadata=hm.MapSet(telescope='lat', instrument=tube,
120+
frequency=freq, release='lat-iso-sv1',
121+
patch='deep56',
122+
polarization_convention='COSMO',
123+
pixelisation='cartesian', split=k),
124+
sources={'map': {'path': opj(sim_dir, map_file),
125+
'description': 'the simulated map'}}
126+
)
127+
128+
tube_freq_collection.append(noise_map_set)
129+
130+
sim_collection.append(tube_freq_collection)
131+
132+
top_collection.append(sim_collection)
133+
134+
client.push(top_collection)

0 commit comments

Comments
 (0)