Skip to content

Commit

Permalink
* New attribure for Updatables: parameter_prefix.
Browse files Browse the repository at this point in the history
* Added the necessary calls to make the current Updatable implementation to pass sacc_tracer as the default parameter_prefix.
  • Loading branch information
vitenti committed Sep 20, 2023
1 parent e773e79 commit 8e83525
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 100 deletions.
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
88 changes: 46 additions & 42 deletions firecrown/likelihood/gauss_family/statistic/source/number_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,20 @@ 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.
"""

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 +108,20 @@ class PTNonLinearBiasSystematic(NumberCountsSystematic):
"""Non-linear bias systematic.
This systematic adds a linear bias model which varies with redshift and
Parameters
----------
b_2: float
b_s: float
the growth function.
"""

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 @@ -147,31 +143,22 @@ 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
"""

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 +194,19 @@ 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.
"""

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 @@ -234,10 +224,14 @@ class PhotoZShift(NumberCountsSystematic):
"""

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 +262,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
70 changes: 31 additions & 39 deletions firecrown/likelihood/gauss_family/statistic/source/weak_lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,17 @@ class MultiplicativeShearBias(WeakLensingSystematic):
"""Multiplicative shear bias systematic.
This systematic adjusts the `scale_` of a source by `(1 + m)`.
"""

def __init__(self, sacc_tracer: str) -> None:
"""Create a MultiplicativeShearBias object that uses the named tracer.
Parameters
----------
sacc_tracer : The name of the multiplicative bias parameter.
:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.
"""
super().__init__()
super().__init__(parameter_prefix=sacc_tracer)

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

def apply(
self, tools: ModelingTools, tracer_arg: WeakLensingArgs
Expand All @@ -93,36 +91,23 @@ class LinearAlignmentSystematic(WeakLensingSystematic):
This systematic adds a linear intrinsic alignment model systematic
which varies with redshift and the growth function.
Methods
-------
apply : apply the systematic to a source
"""

def __init__(self, sacc_tracer: Optional[str] = None, alphag=1.0):
"""Create a LinearAlignmentSystematic object, using the specified
tracer name.
Instance data are:
alphaz : The redshift dependence parameter of the intrinsic alignment
signal.
alphag : The growth dependence parameter of the intrinsic alignment
signal.
:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.
z_piv : The pivot redshift parameter for the intrinsic alignment
parameter.
"""
super().__init__()
super().__init__(parameter_prefix=sacc_tracer)

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

self.sacc_tracer = sacc_tracer

def apply(
self, tools: ModelingTools, tracer_arg: WeakLensingArgs
) -> WeakLensingArgs:
Expand All @@ -148,26 +133,20 @@ class TattAlignmentSystematic(WeakLensingSystematic):
"""TATT alignment systematic.
This systematic adds a TATT (nonlinear) intrinsic alignment model systematic.
Parameters
----------
ia_a_1: float
ia_a_2: float
ia_a_d: float
Methods
-------
apply : apply the systematic to a source
"""

def __init__(self, sacc_tracer: Optional[str] = None):
super().__init__()
"""Create a TattAlignmentSystematic 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.ia_a_1 = parameters.create()
self.ia_a_2 = parameters.create()
self.ia_a_d = parameters.create()

self.sacc_tracer = sacc_tracer

def apply(
self, tools: ModelingTools, tracer_arg: WeakLensingArgs
) -> WeakLensingArgs:
Expand Down Expand Up @@ -201,10 +180,14 @@ class PhotoZShift(WeakLensingSystematic):
"""

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: WeakLensingArgs):
"""Apply a shift to the photo-z distribution of a source."""
Expand Down Expand Up @@ -233,8 +216,17 @@ def __init__(
scale: float = 1.0,
systematics: Optional[List[WeakLensingSystematic]] = None,
):
"""Initialize the WeakLensing object."""
super().__init__()
"""Initialize the WeakLensing object.
:param sacc_tracer: the name of the tracer in the SACC file. This is used
as a prefix for its parameters.
:param scale: the scale of the source. This is used to scale the shear
power spectrum.
:param systematics: a list of WeakLensingSystematic objects to apply to
this source.
"""
super().__init__(sacc_tracer)

self.sacc_tracer = sacc_tracer
self.scale = scale
Expand Down
4 changes: 2 additions & 2 deletions firecrown/likelihood/gauss_family/statistic/statistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ class Statistic(Updatable):
Statistics represent things like two-point functions and mass functions.
"""

def __init__(self):
super().__init__()
def __init__(self, parameter_prefix: Optional[str] = None):
super().__init__(parameter_prefix=parameter_prefix)
self.sacc_indices: Optional[npt.NDArray[np.int64]]
self.ready = False

Expand Down
2 changes: 1 addition & 1 deletion firecrown/likelihood/gauss_family/statistic/supernova.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Supernova(Statistic):

def __init__(self, sacc_tracer) -> None:
"""Initialize this statistic."""
super().__init__()
super().__init__(parameter_prefix=sacc_tracer)

self.sacc_tracer = sacc_tracer
self.data_vector: Optional[DataVector] = None
Expand Down
Loading

0 comments on commit 8e83525

Please sign in to comment.