Skip to content

Commit e8bf585

Browse files
committed
Integrate metal matrix computation in vega
1 parent 9ba6e10 commit e8bf585

File tree

5 files changed

+257
-95
lines changed

5 files changed

+257
-95
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ cachetools
1010
matplotlib
1111
gitpython
1212
getdist
13+
picca

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
scripts = glob.glob('bin/*')
1515

16-
requirements = ['numpy', 'scipy', 'astropy', 'numba', 'iminuit', 'h5py', 'mcfit',
16+
requirements = ['numpy', 'scipy', 'astropy', 'numba', 'iminuit', 'h5py', 'mcfit', 'picca',
1717
'setuptools', 'cachetools', 'matplotlib', 'gitpython', 'getdist']
1818

1919
setup_requirements = ['pytest-runner', ]

vega/correlation_item.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ class CorrelationItem:
1212
_bin_size_rt_model = None
1313
_bin_size_rp_data = None
1414
_bin_size_rt_data = None
15+
cosmo_params = None
16+
rp_min_model = None
17+
rp_max_model = None
18+
rt_max_model = None
19+
num_bins_rp_model = None
20+
num_bins_rt_model = None
1521

1622
def __init__(self, config, model_pk=False):
1723
"""
@@ -40,6 +46,11 @@ def __init__(self, config, model_pk=False):
4046
if 'filename' not in config['data']:
4147
self.has_data = False
4248

49+
self.new_metals = config['model'].getboolean('new_metals', False)
50+
if self.new_metals:
51+
self.tracer1['delta-stack'] = config['data'].get(f'delta_stack_{self.tracer1["name"]}')
52+
self.tracer2['delta-stack'] = config['data'].get(f'delta_stack_{self.tracer2["name"]}')
53+
4354
self.test_flag = config['data'].getboolean('test', False)
4455

4556
self.has_metals = False

vega/data.py

Lines changed: 75 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Data:
2222
_log_cov_det = None
2323
_blind = None
2424
rp_rt_custom_grid = None
25+
cosmo_params = None
2526

2627
def __init__(self, corr_item):
2728
"""
@@ -47,17 +48,31 @@ def __init__(self, corr_item):
4748
self.corr_item.bin_size_rt_model = self.bin_size_rt_model
4849
self.corr_item.bin_size_rp_data = self.bin_size_rp_data
4950
self.corr_item.bin_size_rt_data = self.bin_size_rt_data
51+
self.corr_item.rp_min_model = self.rp_min_model
52+
self.corr_item.rp_max_model = self.rp_max_model
53+
self.corr_item.rt_max_model = self.rt_max_model
54+
self.corr_item.num_bins_rp_model = self.num_bins_rp_model
55+
self.corr_item.num_bins_rt_model = self.num_bins_rt_model
5056

5157
# Read the metal file and init metals in the corr item
5258
if 'metals' in corr_item.config:
53-
tracer_catalog, metal_correlations = self._init_metals(
54-
corr_item.config['metals'])
59+
if not corr_item.new_metals:
60+
tracer_catalog, metal_correlations = self._init_metals(corr_item.config['metals'])
61+
else:
62+
metals_in_tracer1, metals_in_tracer2, tracer_catalog = self._init_metal_tracers(
63+
corr_item.config['metals'])
64+
metal_correlations = self._init_metal_correlations(
65+
corr_item.config['metals'], metals_in_tracer1, metals_in_tracer2)
66+
5567
self.corr_item.init_metals(tracer_catalog, metal_correlations)
5668

5769
# Check if we have broadband
5870
if 'broadband' in corr_item.config:
5971
self.corr_item.init_broadband(self.coeff_binning_model)
6072

73+
if self.cosmo_params is not None:
74+
self.corr_item.cosmo_params = self.cosmo_params
75+
6176
if not self.has_distortion:
6277
self._distortion_mat = np.eye(self.full_data_size)
6378
if not self.has_cov_mat:
@@ -262,6 +277,13 @@ def _read_data(self, data_path, cuts_config, dmat_path=None):
262277
self.num_bins_rp_data = header['NP']
263278
self.num_bins_rt_data = header['NT']
264279

280+
if "OMEGAM" in header:
281+
self.cosmo_params = {}
282+
self.cosmo_params['Omega_m'] = header['OMEGAM']
283+
self.cosmo_params['Omega_k'] = header.get('OMEGAK', 0.)
284+
self.cosmo_params['Omega_r'] = header.get('OMEGAR', 0.)
285+
self.cosmo_params['wl'] = header.get('WL', -1.)
286+
265287
# Get the data bin size
266288
# TODO If RTMIN is ever added to the cf data files this needs modifying
267289
self.bin_size_rp_data = (self.rp_max_data - self.rp_min_data) / self.num_bins_rp_data
@@ -424,22 +446,8 @@ def _build_mask(self, rp_grid, rt_grid, cuts_config, rp_min, bin_size_rp, bin_si
424446
mask &= (bin_center_mu > self.mu_min_cut) & (bin_center_mu < self.mu_max_cut)
425447

426448
return mask
427-
428-
def _init_metals(self, metal_config):
429-
"""Read the metal file and initialize all the metal data.
430-
431-
Parameters
432-
----------
433-
metal_config : ConfigParser
434-
metals section from the config file
435-
436-
Returns
437-
-------
438-
dict
439-
Dictionary containing all tracer objects (metals and the core ones)
440-
list
441-
list of all metal correlations we need to compute
442-
"""
449+
450+
def _init_metal_tracers(self, metal_config):
443451
assert ('in tracer1' in metal_config) or ('in tracer2' in metal_config)
444452

445453
# Read metal tracers
@@ -450,11 +458,6 @@ def _init_metals(self, metal_config):
450458
if 'in tracer2' in metal_config:
451459
metals_in_tracer2 = metal_config.get('in tracer2').split()
452460

453-
self.metal_mats = {}
454-
self.metal_rp_grids = {}
455-
self.metal_rt_grids = {}
456-
self.metal_z_grids = {}
457-
458461
# Build tracer Catalog
459462
tracer_catalog = {}
460463
tracer_catalog[self.tracer1['name']] = self.tracer1
@@ -467,6 +470,55 @@ def _init_metals(self, metal_config):
467470
if metals_in_tracer2 is not None:
468471
for metal in metals_in_tracer2:
469472
tracer_catalog[metal] = {'name': metal, 'type': 'continuous'}
473+
474+
return metals_in_tracer1, metals_in_tracer2, tracer_catalog
475+
476+
def _init_metal_correlations(self, metal_config, metals_in_tracer1, metals_in_tracer2):
477+
metal_correlations = []
478+
if 'in tracer2' in metal_config:
479+
for metal in metals_in_tracer2:
480+
if not self._use_correlation(self.tracer1['name'], metal):
481+
continue
482+
metal_correlations.append((self.tracer1['name'], metal))
483+
484+
if 'in tracer1' in metal_config:
485+
for metal in metals_in_tracer1:
486+
if not self._use_correlation(metal, self.tracer2['name']):
487+
continue
488+
metal_correlations.append((metal, self.tracer2['name']))
489+
490+
if ('in tracer1' in metal_config) and ('in tracer2' in metal_config):
491+
for i, metal1 in enumerate(metals_in_tracer1):
492+
j0 = i if self.tracer1 == self.tracer2 else 0
493+
494+
for metal2 in metals_in_tracer2[j0:]:
495+
if not self._use_correlation(metal1, metal2):
496+
continue
497+
metal_correlations.append((metal1, metal2))
498+
499+
return metal_correlations
500+
501+
def _init_metals(self, metal_config):
502+
"""Read the metal file and initialize all the metal data.
503+
504+
Parameters
505+
----------
506+
metal_config : ConfigParser
507+
metals section from the config file
508+
509+
Returns
510+
-------
511+
dict
512+
Dictionary containing all tracer objects (metals and the core ones)
513+
list
514+
list of all metal correlations we need to compute
515+
"""
516+
metals_in_tracer1, metals_in_tracer2, tracer_catalog = self._init_metal_tracers(metal_config)
517+
518+
self.metal_mats = {}
519+
self.metal_rp_grids = {}
520+
self.metal_rt_grids = {}
521+
self.metal_z_grids = {}
470522

471523
# Read the metal file
472524
metal_hdul = fits.open(find_file(metal_config.get('filename')))

0 commit comments

Comments
 (0)