Skip to content

Commit

Permalink
redshift trend as diagnostic plot option
Browse files Browse the repository at this point in the history
  • Loading branch information
sibirrer committed Mar 11, 2021
1 parent 56fc46c commit b4771d9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
24 changes: 20 additions & 4 deletions hierarc/Diagnostics/goodness_of_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def __init__(self, kwargs_likelihood_list):
self._kwargs_likelihood_list = kwargs_likelihood_list
self._sample_likelihood = LensSampleLikelihood(kwargs_likelihood_list)

def plot_ddt_fit(self, cosmo, kwargs_lens, kwargs_kin, color_measurement=None, color_prediction=None):
def plot_ddt_fit(self, cosmo, kwargs_lens, kwargs_kin, color_measurement=None, color_prediction=None,
redshift_trend=False):
"""
plots the prediction and the uncorrelated error bars on the individual lenses
currently works for likelihood classes 'TDKinGaussian', 'KinGaussian'
Expand All @@ -26,6 +27,7 @@ def plot_ddt_fit(self, cosmo, kwargs_lens, kwargs_kin, color_measurement=None, c
:param kwargs_kin: kinematics model keyword arguments
:param color_measurement: color of measurement
:param color_prediction: color of model prediction
:param redshift_trend: boolean, if True, plots as a function of redshift
:return: fig, axes of matplotlib instance
"""
logL = self._sample_likelihood.log_likelihood(cosmo, kwargs_lens, kwargs_kin)
Expand All @@ -39,6 +41,7 @@ def plot_ddt_fit(self, cosmo, kwargs_lens, kwargs_kin, color_measurement=None, c

ddt_data_mean_list = []
ddt_data_sigma_list = []
z_list = []

for i, kwargs_likelihood in enumerate(self._kwargs_likelihood_list):
name = kwargs_likelihood.get('name', 'lens ' + str(i))
Expand All @@ -53,21 +56,34 @@ def plot_ddt_fit(self, cosmo, kwargs_lens, kwargs_kin, color_measurement=None, c
ddt_model_sigma_list.append(ddt_model_sigma)
ddt_data_mean_list.append(ddt_mean_measurement)
ddt_data_sigma_list.append(ddt_sigma_measurement)
z_list.append(likelihood.z_lens)
if redshift_trend:
x = z_list
else:
x = np.arange(len(ddt_name_list))

f, ax = plt.subplots(1, 1, figsize=(len(ddt_name_list)/1.5, 4))
ax.errorbar(np.arange(len(ddt_name_list)), ddt_data_mean_list, yerr=ddt_data_sigma_list,
ax.errorbar(x, ddt_data_mean_list, yerr=ddt_data_sigma_list,
color=color_measurement,
xerr=None, fmt='o', ecolor=None, elinewidth=None,
capsize=None, barsabove=False, lolims=False, uplims=False,
xlolims=False, xuplims=False, errorevery=1, capthick=None, data=None, label='measurement')

ax.errorbar(np.arange(len(ddt_name_list)), ddt_model_mean_list, yerr=ddt_model_sigma_list,
ax.errorbar(x, ddt_model_mean_list, yerr=ddt_model_sigma_list,
color=color_prediction,
xerr=None, fmt='o', ecolor=None, elinewidth=None,
capsize=None, barsabove=False, lolims=False, uplims=False,
xlolims=False, xuplims=False, errorevery=1, capthick=None, data=None, label='prediction')

ax.set_xticks(ticks=np.arange(len(ddt_name_list)))
if redshift_trend:
# put redshift ticks on top of plot
ax2 = ax.twiny()
ax2.set_xlim(ax.get_xlim())
#ax2.set_xticks(z_list)
#ax2.set_xticklabels(labels=ddt_name_list, rotation='vertical')
ax2.set_xlabel('lens redshift', fontsize=15)

ax.set_xticks(ticks=x)
ax.set_xticklabels(labels=ddt_name_list, rotation='vertical')
ax.set_ylabel(r'$D_{\Delta t}$ [Mpc]', fontsize=15)
ax.legend()
Expand Down
6 changes: 4 additions & 2 deletions hierarc/Likelihood/LensLikelihood/base_lens_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def __init__(self, z_lens, z_source, likelihood_type, name='name', **kwargs_like
see individual classes for their use
"""
self._name = name
self._z_lens = z_lens
self._z_source = z_source
self.z_lens = z_lens
self.z_source = z_source
self.likelihood_type = likelihood_type
if likelihood_type in ['DdtGaussian']:
from hierarc.Likelihood.LensLikelihood.ddt_gauss_likelihood import DdtGaussianLikelihood
Expand Down Expand Up @@ -98,6 +98,8 @@ def log_likelihood(self, ddt, dd, aniso_scaling=None, sigma_v_sys_error=None, mu

def ddt_measurement(self):
"""
Inferred Ddt from a lens model (i.e. power-law fit) and time-delay, without lambda correction (excludes also the
external convergence contribution)
:return: ddt measurement median, 1-sigma (without lambda correction factor)
"""
Expand Down
4 changes: 3 additions & 1 deletion test/test_Diagnostics/test_goodness_of_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def setup(self):
def test_plot_ddt_fit(self):
kwargs_lens = {'lambda_mst': 1}
kwargs_kin = {}
f, ax = self.goodnessofFit.plot_ddt_fit(self.cosmo, kwargs_lens, kwargs_kin)
f, ax = self.goodnessofFit.plot_ddt_fit(self.cosmo, kwargs_lens, kwargs_kin, redshift_trend=False)
plt.close()
f, ax = self.goodnessofFit.plot_ddt_fit(self.cosmo, kwargs_lens, kwargs_kin, redshift_trend=True)
plt.close()

def test_plot_kin_fit(self):
Expand Down

0 comments on commit b4771d9

Please sign in to comment.