Skip to content

Commit b996cc8

Browse files
committed
Merge branch 'develop'
2 parents 5cacfd5 + 5672309 commit b996cc8

File tree

5 files changed

+133
-44
lines changed

5 files changed

+133
-44
lines changed

main.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ def load_config(_config_path):
9898
if 'ipykernel_launcher.py' not in sys.argv[0] and '--show-plots' not in sys.argv:
9999
matplotlib.use('Agg')
100100

101-
# Get the current script's directory
102-
# current_dir = Path(__file__).resolve().parent
103-
# parent_dir = current_dir.parent
104101

105102
warnings.filterwarnings(
106103
'ignore',
@@ -685,7 +682,7 @@ def plot_cls():
685682
fill_value=0,
686683
clip_min=cfg['nz']['clip_zmin'],
687684
clip_max=cfg['nz']['clip_zmax'],
688-
plt_title='$n_i(z)$ sources shifts ',
685+
plt_title='$n_i(z)$ sources shifts',
689686
)
690687
nz_lns = wf_cl_lib.shift_nz(
691688
zgrid_nz_lns,
@@ -698,7 +695,7 @@ def plot_cls():
698695
fill_value=0,
699696
clip_min=cfg['nz']['clip_zmin'],
700697
clip_max=cfg['nz']['clip_zmax'],
701-
plt_title='$n_i(z)$ lenses shifts ',
698+
plt_title='$n_i(z)$ lenses shifts',
702699
)
703700

704701
if cfg['nz']['smooth_nz']:
@@ -877,8 +874,8 @@ def plot_cls():
877874
ccl_obj.wf_galaxy_arr,
878875
]
879876

880-
plt.figure()
881877
for wf_idx in range(len(wf_ccl_list)):
878+
plt.figure()
882879
for zi in range(zbins):
883880
plt.plot(z_grid, wf_ccl_list[wf_idx][:, zi], c=clr[zi], alpha=0.6)
884881
plt.xlabel('$z$')
@@ -1075,8 +1072,10 @@ def plot_cls():
10751072
for ells_in, ells_out in zip(
10761073
[ells_WL_in, ells_XC_in, ells_GC_in],
10771074
[ell_obj.ells_3x2pt_unb, ell_obj.ells_3x2pt_unb, ell_obj.ells_3x2pt_unb],
1075+
strict=True,
10781076
):
1079-
io_obj.check_ells_in(ells_in, ells_out)
1077+
io_handler.check_ells_for_spline(ells_in)
1078+
io_handler.check_ells_for_spline(ells_out)
10801079

10811080
# initialize nmt_cov_obj and set a couple useful attributes
10821081
nmt_cov_obj = cov_partial_sky.NmtCov(
@@ -2104,7 +2103,12 @@ def plot_cls():
21042103
os.makedirs(output_dir, exist_ok=True)
21052104
for i, fig_num in enumerate(plt.get_fignums()):
21062105
fig = plt.figure(fig_num)
2107-
fig.savefig(os.path.join(output_dir, f'fig_{i:03d}.png'))
2106+
fig.savefig(
2107+
os.path.join(output_dir, f'fig_{i:03d}.pdf'),
2108+
bbox_inches='tight',
2109+
pad_inches=0.1,
2110+
)
2111+
print(f'Figures saved in {output_dir}\n')
21082112

21092113

21102114
print(f'Finished in {(time.perf_counter() - script_start_time) / 60:.2f} minutes')

spaceborne/config_checker.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,16 @@ def check_types(self) -> None:
229229
'nz: shift_nz must be a boolean'
230230
)
231231

232-
assert isinstance(nz_cfg.get('dzWL'), list), 'nz: dzWL must be a list'
233-
assert all(isinstance(x, float) for x in nz_cfg['dzWL']), (
234-
'nz: All elements in dzWL must be floats'
235-
)
232+
if nz_cfg['shift_nz']:
233+
assert isinstance(nz_cfg.get('dzWL'), list), 'nz: dzWL must be a list'
234+
assert all(isinstance(x, float) for x in nz_cfg['dzWL']), (
235+
'nz: All elements in dzWL must be floats'
236+
)
236237

237-
assert isinstance(nz_cfg.get('dzGC'), list), 'nz: dzGC must be a list'
238-
assert all(isinstance(x, float) for x in nz_cfg['dzGC']), (
239-
'nz: All elements in dzGC must be floats'
240-
)
238+
assert isinstance(nz_cfg.get('dzGC'), list), 'nz: dzGC must be a list'
239+
assert all(isinstance(x, float) for x in nz_cfg['dzGC']), (
240+
'nz: All elements in dzGC must be floats'
241+
)
241242

242243
assert isinstance(nz_cfg.get('normalize_shifted_nz'), bool), (
243244
'nz: normalize_shifted_nz must be a boolean'
@@ -599,12 +600,12 @@ def check_nz(self) -> None:
599600
assert np.all(np.array(self.cfg['nz']['ngal_lenses']) > 0), (
600601
'ngal_lenses values must be positive'
601602
)
602-
assert np.all(self.cfg['nz']['dzWL'] == self.cfg['nz']['dzGC']), (
603-
'dzWL and dzGC shifts do not match'
604-
)
605603
assert len(self.cfg['nz']['ngal_sources']) == len(self.cfg['nz']['ngal_lenses'])
606604

607605
if self.cfg['nz']['shift_nz']:
606+
assert np.all(self.cfg['nz']['dzWL'] == self.cfg['nz']['dzGC']), (
607+
'dzWL and dzGC shifts do not match'
608+
)
608609
assert len(self.cfg['nz']['dzWL']) == len(self.cfg['nz']['ngal_sources'])
609610
assert len(self.cfg['nz']['dzWL']) == len(self.cfg['nz']['ngal_lenses'])
610611

spaceborne/constants.py

Lines changed: 92 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# HC = Heracles
88

99
DEG2_IN_SPHERE = 4 * np.pi * (180 / np.pi) ** 2
10-
DEG2_TO_SR = (np.pi / 180) ** 2
10+
DEG2_TO_SR = (np.pi / 180) ** 2
1111
SR_TO_ARCMIN2 = (180 / np.pi * 60) ** 2
1212

1313
DR1_DATE = 9191.0
@@ -30,10 +30,10 @@
3030
HS_DIAG_PROBE_COMBS = ['LLLL', 'GLGL', 'GGGG']
3131
RS_DIAG_PROBE_COMBS = ['xipxip', 'ximxim', 'gtgt', 'gggg']
3232
# not used for the moment
33-
HS_DIAG_PROBES = [ 'LL', 'GL', 'GG']
34-
RS_DIAG_PROBES = [ 'xip', 'xim', 'gt', 'gg']
35-
HS_DIAG_PROBES_OC = [ 'mm', 'gm', 'gg']
36-
RS_DIAG_PROBES_OC = [ 'xip', 'xim', 'gm', 'gg']
33+
HS_DIAG_PROBES = ['LL', 'GL', 'GG']
34+
RS_DIAG_PROBES = ['xip', 'xim', 'gt', 'gg']
35+
HS_DIAG_PROBES_OC = ['mm', 'gm', 'gg']
36+
RS_DIAG_PROBES_OC = ['xip', 'xim', 'gm', 'gg']
3737

3838
HS_PROBE_NAME_TO_IX_DICT = {'L': 0, 'G': 1}
3939
HS_PROBE_IX_TO_NAME_DICT = {0: 'L', 1: 'G'}
@@ -113,12 +113,91 @@
113113

114114
RS_PROBE_NAME_TO_LATEX = {
115115
'xip': r'$\xi_{+}$',
116-
'xim': r'$\xi_{-}$',
117-
'gt': r'$\gamma_{t}$',
118-
'gg': r'$w$',
116+
'xim': r'$\xi_{-}$',
117+
'gt': r'$\gamma_{t}$',
118+
'gg': r'$w$',
119+
}
120+
HS_PROBE_NAME_TO_LATEX = {'LL': r'${\rm LL}$', 'GL': r'${\rm GL}$', 'GG': r'${\rm GG}$'}
121+
122+
# adapted from notebook by G. C. Herrera
123+
labels_tex = {
124+
# old
125+
'w': 'w_0',
126+
'omegam': '\\Omega_{\\rm m}',
127+
'omegab': '\\Omega_{\\rm b}',
128+
'HMCode_logT_AGN': '\\log{T_{\\rm AGN}}',
129+
130+
# new
131+
'H0': 'H_0',
132+
'h': 'h',
133+
'ns': 'n_{\\rm s}',
134+
'log10TAGN': '\\log{T_{\\rm AGN}}',
135+
'logA': '\\ln{10^{10}\\,A_{\\rm s}}',
136+
'As': 'A_\\mathrm{s}',
137+
'w0': 'w_0',
138+
'wa': 'w_a',
139+
'Omega_k0': '\\Omega_{\\rm k}',
140+
'Omega_m0': '\\Omega_{\\rm m}',
141+
'Omega_b0': '\\Omega_{\\rm b}',
142+
'Omega_cdm0': '\\Omega_{\\rm c}',
143+
'ombh2': '\\Omega_{{\\rm b}}\\,h^2',
144+
'omch2': '\\Omega_{{\\rm c}}\\,h^2',
145+
'sigma8': '\\sigma_8',
146+
'gamma_MG': '\\gamma_{\\rm g}',
147+
'S8': 'S_8',
148+
'AIA': '\\mathcal{A}_{\\rm IA}',
149+
'EIA': '\\eta_{\\rm IA}',
150+
'CIA': '\\mathcal{C}_{\\rm IA}',
151+
'mnu': '\\Sigma m_\\nu',
152+
'N_mnu': 'N_\\nu',
153+
'b1_photo_poly0': 'b_{{\\rm G},0}',
154+
'b1_photo_poly1': 'b_{{\\rm G},1}',
155+
'b1_photo_poly2': 'b_{{\\rm G},2}',
156+
'b1_photo_poly3': 'b_{{\\rm G},3}',
157+
'magnification_bias_1': 'b_{{\\rm mag},1}',
158+
'magnification_bias_2': 'b_{{\\rm mag},2}',
159+
'magnification_bias_3': 'b_{{\\rm mag},3}',
160+
'magnification_bias_4': 'b_{{\\rm mag},4}',
161+
'magnification_bias_5': 'b_{{\\rm mag},5}',
162+
'magnification_bias_6': 'b_{{\\rm mag},6}',
163+
'dz_pos_1': '\\Delta z_{\\rm G}^{(1)}',
164+
'dz_pos_2': '\\Delta z_{\\rm G}^{(2)}',
165+
'dz_pos_3': '\\Delta z_{\\rm G}^{(3)}',
166+
'dz_pos_4': '\\Delta z_{\\rm G}^{(4)}',
167+
'dz_pos_5': '\\Delta z_{\\rm G}^{(5)}',
168+
'dz_pos_6': '\\Delta z_{\\rm G}^{(6)}',
169+
'dz_pos_7': '\\Delta z_{\\rm G}^{(7)}',
170+
'dz_pos_8': '\\Delta z_{\\rm G}^{(8)}',
171+
'dz_pos_9': '\\Delta z_{\\rm G}^{(9)}',
172+
'dz_pos_10': '\\Delta z_{\\rm G}^{(10)}',
173+
'dz_pos_11': '\\Delta z_{\\rm G}^{(10)}',
174+
'dz_pos_12': '\\Delta z_{\\rm G}^{(10)}',
175+
'dz_pos_13': '\\Delta z_{\\rm G}^{(10)}',
176+
'dz_shear_1': '\\Delta z_{\\rm L}^{(1)}',
177+
'dz_shear_2': '\\Delta z_{\\rm L}^{(2)}',
178+
'dz_shear_3': '\\Delta z_{\\rm L}^{(3)}',
179+
'dz_shear_4': '\\Delta z_{\\rm L}^{(4)}',
180+
'dz_shear_5': '\\Delta z_{\\rm L}^{(5)}',
181+
'dz_shear_6': '\\Delta z_{(6)}^{\\rm L}',
182+
'dz_shear_7': '\\Delta z_{\\rm L}^{(7)}',
183+
'dz_shear_8': '\\Delta z_{\\rm L}^{(8)}',
184+
'dz_shear_9': '\\Delta z_{\\rm L}^{(9)}',
185+
'dz_shear_10': '\\Delta z_{\\rm L}^{(10)}',
186+
'dz_shear_11': '\\Delta z_{\\rm L}^{(11)}',
187+
'dz_shear_12': '\\Delta z_{\\rm L}^{(12)}',
188+
'dz_shear_13': '\\Delta z_{\\rm L}^{(13)}',
189+
'multiplicative_bias_1': 'm_{\\rm L}^{(1)}',
190+
'multiplicative_bias_2': 'm_{\\rm L}^{(2)}',
191+
'multiplicative_bias_3': 'm_{\\rm L}^{(3)}',
192+
'multiplicative_bias_4': 'm_{\\rm L}^{(4)}',
193+
'multiplicative_bias_5': 'm_{\\rm L}^{(5)}',
194+
'multiplicative_bias_6': 'm_{\\rm L}^{(6)}',
195+
'multiplicative_bias_7': 'm_{\\rm L}^{(7)}',
196+
'multiplicative_bias_8': 'm_{\\rm L}^{(8)}',
197+
'multiplicative_bias_9': 'm_{\\rm L}^{(9)}',
198+
'multiplicative_bias_10': 'm_{\\rm L}^{(10)}',
199+
'multiplicative_bias_11': 'm_{\\rm L}^{(11)}',
200+
'multiplicative_bias_12': 'm_{\\rm L}^{(12)}',
201+
'multiplicative_bias_13': 'm_{\\rm L}^{(13)}',
202+
'FoM': '{\\rm FoM}',
119203
}
120-
HS_PROBE_NAME_TO_LATEX = {
121-
'LL': r'${\rm LL}$',
122-
'GL': r'${\rm GL}$',
123-
'GG': r'${\rm GG}$',
124-
}

spaceborne/io_handler.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ def load_cl_euclidlib(filename, key_a, key_b):
7272

7373
is_auto_spectrum = key_a == key_b
7474

75-
# import .fits using el
76-
# cl_dict = el.photo.angular_power_spectra(filename)
77-
cl_dict = el.photo.harmonic_space.angular_power_spectra(filename)
75+
# import .fits using euclidlib
76+
# TODO the bare `except` is horrible but I'm not yet sure what's the definitive
77+
# structure of the euclidlib import
78+
try:
79+
cl_dict = el.photo.harmonic_space.angular_power_spectra(filename)
80+
except:
81+
cl_dict = el.photo.angular_power_spectra(filename)
7882

7983
# extract ells
8084
ells = cl_dict[key_a, key_b, 1, 1].ell
@@ -91,7 +95,7 @@ def load_cl_euclidlib(filename, key_a, key_b):
9195
triu_ix = np.triu_indices(zbins)
9296

9397
idxs = (
94-
zip(*triu_ix)
98+
zip(*triu_ix, strict=True)
9599
if is_auto_spectrum
96100
else itertools.product(range(zbins), range(zbins))
97101
)
@@ -295,6 +299,12 @@ def cov_heracles_dict_to_sb_10d(
295299
return cov_10d
296300

297301

302+
def check_ells_for_spline(ells):
303+
"""Make sure ells are sorted and unique for spline interpolation"""
304+
assert np.all(np.diff(ells) > 0), 'ells are not sorted'
305+
assert len(np.unique(ells)) == len(ells), 'ells are not unique'
306+
307+
298308
class IOHandler:
299309
"""Handles loading of input data (n(z) and Cls) from various file formats.
300310
@@ -443,13 +453,12 @@ def _load_cls_el(self):
443453

444454
def check_ells_in(self, ell_obj):
445455
"""Make sure ells are sorted and unique for spline interpolation"""
446-
for _ells in [ # fmt: skip
456+
for _ells in [
447457
self.ells_WL_in, ell_obj.ells_WL,
448458
self.ells_XC_in, ell_obj.ells_XC,
449459
self.ells_GC_in, ell_obj.ells_GC,
450460
]: # fmt: skip
451-
assert np.all(np.diff(_ells) > 0), 'ells are not sorted'
452-
assert len(np.unique(_ells)) == len(_ells), 'ells are not unique'
461+
check_ells_for_spline(_ells)
453462

454463
def save_cov_euclidlib(self, cov_hs_obj):
455464
"""Helper function to save the covariance in the heracles/cloelikeeuclidlib

spaceborne/plot_lib.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,7 @@ def plot_ell_cuts(
173173

174174
# Add a shared colorbar on the right
175175
cbar = fig.colorbar(cax0, cax=cbar_ax)
176-
cbar.set_label(
177-
'$\\ell^{\\rm max}_{ij}$',
178-
fontsize=15,
179-
loc='center',
180-
)
176+
cbar.set_label('$\\ell^{\\rm max}_{ij}$', fontsize=15, loc='center')
181177
cbar.ax.tick_params(labelsize=15)
182178

183179
plt.tight_layout()

0 commit comments

Comments
 (0)