Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a parameter prefix for updatables #316

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def __init__(
:param systematics: A list of the statistics-level systematics to apply to
the statistic. The default of `None` implies no systematics.
"""
super().__init__()
self.sacc_tracer = survey_tracer
super().__init__(parameter_prefix=survey_tracer)
self.survey_tracer = survey_tracer
self.systematics = systematics or []
self.data_vector: Optional[DataVector] = None
self.theory_vector: Optional[TheoryVector] = None
Expand Down Expand Up @@ -84,13 +84,13 @@ def _read_data_type(self, sacc_data, data_type):

cluster_survey_tracers = tracers_combinations[:, 0]

if self.sacc_tracer not in cluster_survey_tracers:
if self.survey_tracer not in cluster_survey_tracers:
raise ValueError(
f"The SACC tracer {self.sacc_tracer} is not "
f"The SACC tracer {self.survey_tracer} is not "
f"present in the SACC file."
)

survey_selection = cluster_survey_tracers == self.sacc_tracer
survey_selection = cluster_survey_tracers == self.survey_tracer

z_tracers = np.unique(tracers_combinations[survey_selection, 1])
logM_tracers = np.unique(tracers_combinations[survey_selection, 2])
Expand Down Expand Up @@ -133,15 +133,15 @@ def read(self, sacc_data: sacc.Sacc):
"""

try:
survey_tracer: SurveyTracer = sacc_data.get_tracer(self.sacc_tracer)
survey_tracer: SurveyTracer = sacc_data.get_tracer(self.survey_tracer)
except KeyError as exc:
raise ValueError(
f"The SACC file does not contain the SurveyTracer "
f"{self.sacc_tracer}."
f"{self.survey_tracer}."
) from exc
if not isinstance(survey_tracer, SurveyTracer):
raise ValueError(
f"The SACC tracer {self.sacc_tracer} is not a SurveyTracer."
f"The SACC tracer {self.survey_tracer} is not a SurveyTracer."
)

self.cluster_abundance.sky_area = survey_tracer.sky_area
Expand Down
117 changes: 79 additions & 38 deletions firecrown/likelihood/gauss_family/statistic/source/number_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,27 @@ class LinearBiasSystematic(NumberCountsSystematic):
This systematic adds a linear bias model which varies with redshift and
the growth function.

Parameters
----------
alphaz : str
The name of redshift dependence parameter of the linear bias.
alphag : str
The name of the growth dependence parameter of the linear bias.
z_piv : str
The name of the pivot redshift parameter for the linear bias.
The following parameters are special Updatable parameters, which means that
they can be updated by the sampler, sacc_tracer is going to be used as a
prefix for the parameters:

:ivar alphaz: the redshift exponent of the bias.
:ivar alphag: the growth function exponent of the bias.
:ivar z_piv: the pivot redshift of the bias.
"""

def __init__(self, sacc_tracer: str):
super().__init__()
"""Initialize the LinearBiasSystematic.

:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.

"""
super().__init__(parameter_prefix=sacc_tracer)

self.alphaz = parameters.create()
self.alphag = parameters.create()
self.z_piv = parameters.create()
self.sacc_tracer = sacc_tracer

def apply(
self, tools: ModelingTools, tracer_arg: NumberCountsArgs
Expand Down Expand Up @@ -113,19 +116,27 @@ class PTNonLinearBiasSystematic(NumberCountsSystematic):
"""Non-linear bias systematic.

This systematic adds a linear bias model which varies with redshift and
the growth function.

The following parameters are special Updatable parameters, which means that
they can be updated by the sampler, sacc_tracer is going to be used as a
prefix for the parameters:

Parameters
----------
b_2: float
b_s: float
:ivar b_2: the quadratic bias.
:ivar b_s: the stochastic bias.
"""

def __init__(self, sacc_tracer: str):
super().__init__()
"""Initialize the PTNonLinearBiasSystematic.

:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.

"""
super().__init__(parameter_prefix=sacc_tracer)

self.b_2 = parameters.create()
self.b_s = parameters.create()
self.sacc_tracer = sacc_tracer

def apply(
self, tools: ModelingTools, tracer_arg: NumberCountsArgs
Expand All @@ -148,30 +159,31 @@ class MagnificationBiasSystematic(NumberCountsSystematic):
This systematic adds a magnification bias model for galaxy number contrast
following Joachimi & Bridle (2010), arXiv:0911.2454.

Parameters
----------
r_lim : float
The name of the limiting magnitude in r band filter.
sig_c, eta, z_c, z_m : float
The name of the fitting parameters in Joachimi & Bridle (2010) equation
(C.1).

Methods
-------
apply : apply the systematic to a source
The following parameters are special Updatable parameters, which means that
they can be updated by the sampler, sacc_tracer is going to be used as a
prefix for the parameters:

:ivar r_lim: the limiting magnitude.
:ivar sig_c: the intrinsic dispersion of the source redshift distribution.
:ivar eta: the slope of the luminosity function.
:ivar z_c: the characteristic redshift of the source distribution.
:ivar z_m: the slope of the source redshift distribution.
"""

def __init__(self, sacc_tracer: str):
super().__init__()
"""Initialize the MagnificationBiasSystematic.

:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.
"""
super().__init__(parameter_prefix=sacc_tracer)

self.r_lim = parameters.create()
self.sig_c = parameters.create()
self.eta = parameters.create()
self.z_c = parameters.create()
self.z_m = parameters.create()

self.sacc_tracer = sacc_tracer

def apply(
self, tools: ModelingTools, tracer_arg: NumberCountsArgs
) -> NumberCountsArgs:
Expand Down Expand Up @@ -207,16 +219,25 @@ def apply(
class ConstantMagnificationBiasSystematic(NumberCountsSystematic):
"""Simple constant magnification bias systematic.

Methods
-------
apply : apply the systematic to a source
This systematic adds a constant magnification bias model for galaxy number
contrast.

The following parameters are special Updatable parameters, which means that
they can be updated by the sampler, sacc_tracer is going to be used as a
prefix for the parameters:

:ivar mag_bias: the magnification bias.
"""

def __init__(self, sacc_tracer: str):
super().__init__()
"""Initialize the ConstantMagnificationBiasSystematic.

:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.
"""
super().__init__(parameter_prefix=sacc_tracer)

self.mag_bias = parameters.create()
self.sacc_tracer = sacc_tracer

def apply(
self, tools: ModelingTools, tracer_arg: NumberCountsArgs
Expand All @@ -231,13 +252,23 @@ class PhotoZShift(NumberCountsSystematic):
"""A photo-z shift bias.

This systematic shifts the photo-z distribution by some ammount `delta_z`.

The following parameters are special Updatable parameters, which means that
they can be updated by the sampler, sacc_tracer is going to be used as a
prefix for the parameters:

:ivar delta_z: the photo-z shift.
"""

def __init__(self, sacc_tracer: str):
super().__init__()
"""Create a PhotoZShift object, using the specified tracer name.

:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.
"""
super().__init__(parameter_prefix=sacc_tracer)

self.delta_z = parameters.create()
self.sacc_tracer = sacc_tracer

def apply(self, tools: ModelingTools, tracer_arg: NumberCountsArgs):
"""Apply a shift to the photo-z distribution of a source."""
Expand Down Expand Up @@ -268,7 +299,17 @@ def __init__(
scale: float = 1.0,
systematics: Optional[List[NumberCountsSystematic]] = None,
):
super().__init__()
"""Initialize the NumberCounts object.

:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.
:param has_rsd: whether to include RSD in the tracer.
:param derived_scale: whether to include a derived parameter for the scale
of the tracer.
:param scale: the initial scale of the tracer.
:param systematics: a list of systematics to apply to the tracer.
"""
super().__init__(sacc_tracer)

self.sacc_tracer = sacc_tracer
self.has_rsd = has_rsd
Expand Down
9 changes: 9 additions & 0 deletions firecrown/likelihood/gauss_family/statistic/source/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ class Source(Updatable):
cosmo_hash: Optional[int]
tracers: Sequence[Tracer]

def __init__(self, sacc_tracer: str) -> None:
"""Create a Source object that uses the named tracer.

:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.
"""
super().__init__(parameter_prefix=sacc_tracer)
self.sacc_tracer = sacc_tracer

@final
def read(self, sacc_data: sacc.Sacc):
"""Read the data for this source from the SACC file."""
Expand Down
Loading
Loading