Skip to content

Commit

Permalink
fixed postprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Sanchez authored and Javier Sanchez committed Jul 2, 2024
1 parent 0a0a976 commit 3512609
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
4 changes: 3 additions & 1 deletion augur/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,14 @@ def get_derivatives(self, force=False, method='5pt_stencil'):
else:
return self.derivatives

def get_fisher_matrix(self, method='5pt_stencil'):
def get_fisher_matrix(self, method='5pt_stencil', save_txt=True):
# Compute Fisher matrix assuming Gaussian likelihood (around self.x)
if self.derivatives is None:
self.get_derivatives(method=method)
if self.Fij is None:
self.Fij = np.einsum('il, lm, jm', self.derivatives, self.lk.inv_cov, self.derivatives)
if save_txt:
np.savetxt(self.config['output'], self.Fij)
return self.Fij
else:
return self.Fij
Expand Down
25 changes: 12 additions & 13 deletions augur/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from matplotlib.collections import EllipseCollection
import astropy.table
from scipy.stats import norm, chi2
from augur.utils.config_io import parse_config
import os


Expand All @@ -16,16 +17,14 @@ def postprocess(config):
config : dict
The yaml parsed dictional of the input yaml file
"""
config = parse_config(config)
pconfig = config["postprocess"]
outdir = config["analyze"]["cosmosis"]["output_dir"]
fid_params = config["generate"]["parameters"]
var_params = config["analyze"]["cosmosis"]["parameters"]
input = os.path.join(outdir, "chain.txt")
fisher = np.loadtxt(input)
fid_params = config["cosmo"]
var_params = config["fisher"]["var_pars"]
fisher = np.loadtxt(config["fisher"]["output"])
npars = fisher.shape[0]
keys = astropy.table.Table.read(input, format="ascii").keys()
keys = np.array(keys)

keys = np.array(var_params)
outdir = config["postprocess"]["outdir"]
if "labels" not in pconfig.keys():
labels = keys
else:
Expand All @@ -39,7 +38,7 @@ def postprocess(config):
centers = np.zeros(npars)
ind = 0
for key in fid_params.keys():
if key in var_params.keys():
if key in var_params:
centers[ind] = fid_params[key]
ind += 1

Expand Down Expand Up @@ -90,8 +89,8 @@ def postprocess(config):
for i in range(npairplots):
pair0 = pairplots[2*i].split("(")[1]
pair1 = pairplots[2*i+1].split(")")[0]
key1 = f"params--{pair0.lower()}"
key2 = f"params--{pair1.lower()}"
key1 = f"{pair0}"
key2 = f"{pair1}"
if (key1 not in keys) or (key2 not in keys):
# The selected set of parameters is not in the forecast
continue
Expand All @@ -115,8 +114,8 @@ def postprocess(config):
f.savefig(os.path.join(outdir, f"{pair0}--{pair1}.pdf"))

# w0 -- wa plots are always made
iw = np.where(keys == "params--w0")[0][0]
iwa = np.where(keys == "params--wa")[0][0]
iw = np.where(keys == "w0")[0][0]
iwa = np.where(keys == "wa")[0][0]
sig_w0 = np.sqrt(inv_cache[iw, iw])
sig_wa = np.sqrt(inv_cache[iwa, iwa])
FOM, FOM2 = get_FoM_all(fisher, iw, iwa, CL)
Expand Down
11 changes: 8 additions & 3 deletions examples/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ cov_options:
# ------
# Or you can also get it from a file
cov_type : 'SRD'
SRD_cov_path : '../data/Y1_3x2_SRD_cov.npy'
SRD_cov_path : './data/Y1_3x2_SRD_cov.npy'
# Or using TJPCov
#cov_type : 'tjpcov'
#IA : 0.0
Expand All @@ -98,7 +98,7 @@ fisher:
# n_s: [0.9, 0.9645, 1.0]
# #mult_bias: [-0.1 0.0 0.1]
step: 1e-2
output: 'fisher.dat'
output: 'output/fisher.dat'
fisher_bias:
biased_dv: '' # Path to file containing modified data vector with the systematic shift to probe
# If the file is provided it should be a FITS or ASCII file with the same binning as the
Expand All @@ -109,4 +109,9 @@ fisher:
lens0_delta_z: 0.01
src3_delta_z: 0.005


postprocess:
latex_table: output/latex_table.tex
triangle_plot: output/triangle_plot.pdf
pairplots: [(w0, wa), (omega_c, sigma8)]
outdir: 'output/'
CL: 0.68

0 comments on commit 3512609

Please sign in to comment.