Skip to content

Commit

Permalink
217 more pylint cleanup (#218)
Browse files Browse the repository at this point in the history
* Simplify flow of control re: pylint

* Improve variable naming re: pylint

* Add documentation to functions

* Fix error in name of descriptor

* Remove use of warnings.UserWarning

The name warnings.UserWarning does not exist. The default exception
type used by `warn` is just UserWarning. Since this is the default,
there is no actual need to specify it.

* Simply control flow re: pylint

* Add type annotation for mypy
  • Loading branch information
marcpaterno authored Dec 16, 2022
1 parent 69665dc commit 15142ca
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
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)

0 comments on commit 15142ca

Please sign in to comment.