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

217 more pylint cleanup #218

Merged
merged 7 commits into from
Dec 16, 2022
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 @@ -251,7 +251,7 @@ class NumberCounts(Source):
"""Source class for number counts."""

systematics: UpdatableCollection
tracer_arg: NumberCountsArgs
tracer_args: NumberCountsArgs

def __init__(
self,
Expand All @@ -278,7 +278,7 @@ def __init__(
self.systematics.append(systematic)

self.scale = scale
self.current_tracer_args = None
self.current_tracer_args: Optional[NumberCountsArgs] = None
self.scale_ = None
self.tracer_ = None

Expand Down
12 changes: 5 additions & 7 deletions firecrown/likelihood/gauss_family/statistic/two_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ def read(self, sacc_data):
warnings.warn(
f"Tracers '{tracers}' have 2pt data and you have specified "
"`ell_or_theta` in the configuration. `ell_or_theta` is being ignored!",
warnings.UserWarning,
stacklevel=2,
)

Expand Down Expand Up @@ -315,12 +314,11 @@ def log_interpolator(x, y):
np.log(x), np.log(y), ext=2
)
return lambda x_, intp=intp: np.exp(intp(np.log(x_)))
else:
# only use log for x
intp = scipy.interpolate.InterpolatedUnivariateSpline(
np.log(x), y, ext=2
)
return lambda x_, intp=intp: intp(np.log(x_))
# only use log for x
intp = scipy.interpolate.InterpolatedUnivariateSpline(
np.log(x), y, ext=2
)
return lambda x_, intp=intp: intp(np.log(x_))

theory_interpolator = log_interpolator(self.ell_or_theta_, theory_vector)
ell = self.theory_window_function.values
Expand Down
19 changes: 9 additions & 10 deletions firecrown/likelihood/likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,15 @@ def load_likelihood(
f"Firecrown initialization script {filename} does not define "
f"a `build_likelihood` factory function."
)
else:
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(
"The use of a likelihood variable in Firecrown's initialization "
"script is deprecated. Any parameters passed to the likelihood "
"will be ignored. The script should define a `build_likelihood` "
"factory function.",
category=DeprecationWarning,
)
likelihood = mod.likelihood
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(
"The use of a likelihood variable in Firecrown's initialization "
"script is deprecated. Any parameters passed to the likelihood "
"will be ignored. The script should define a `build_likelihood` "
"factory function.",
category=DeprecationWarning,
)
likelihood = mod.likelihood
else:
if not callable(mod.build_likelihood):
raise TypeError(
Expand Down
22 changes: 20 additions & 2 deletions firecrown/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def __init__(self, *args, **kwargs) -> None:
self.lower_case: bool = False

def use_lower_case_keys(self, enable: bool) -> None:
"""Control whether keys will be translated into lower case.
If `enable` is True, such translation will be done.
This can help make sure code works with CosmoSIS, because such translation
is done inside CosmoSIS itself."""
self.lower_case = enable

def get_from_prefix_param(self, prefix: Optional[str], param: str) -> float:
Expand Down Expand Up @@ -161,8 +165,8 @@ def __init__(self, derived_parameters: List[DerivedParameter]):

self.derived_parameters: Dict[str, DerivedParameter] = {}

for dp in derived_parameters:
self.add_required_parameter(dp)
for parameter in derived_parameters:
self.add_required_parameter(parameter)

def __add__(self, other: Optional[DerivedParameterCollection]):
"""Return a new DerivedParameterCollection with the lists of DerivedParameter
Expand Down Expand Up @@ -230,9 +234,11 @@ def __init__(self):
self.value = None

def set_value(self, value: float):
"""Set the value of this parameter."""
self.value = value

def get_value(self) -> float:
"""Get the current value of this parameter."""
return self.value


Expand All @@ -245,13 +251,25 @@ def __init__(self, value: float):
self.value = value

def set_value(self, value: float):
"""Set the value of this parameter."""
self.value = value

def get_value(self) -> float:
"""Return the current value of this parameter."""
return self.value


def create(value: Optional[float] = None):
"""Create a new parameter.

If `value` is `None`, the result will be a `SamplerParameter`; Firecrown
will expect this value to be supplied by the sampling framwork. If `value`
is a `float` quantity, then Firecrown will expect this parameter to *not*
be supplied by the sampling framework, and instead the provided value will
be used for every sample.

Only `None` or a `float` value is allowed.
"""
if value is None:
return SamplerParameter()
return InternalParameter(value)