Skip to content

Commit

Permalink
Remove some over-redundant hints
Browse files Browse the repository at this point in the history
  • Loading branch information
ggalloni committed Sep 10, 2024
1 parent 3564490 commit 2ddec66
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 69 deletions.
8 changes: 5 additions & 3 deletions soliket/bandpass/bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def initialize_with_params(self):
self.log, "Configuration error in parameters: %r.",
differences)

def must_provide(self, **requirements: dict):
def must_provide(self, **requirements):
# bandint_freqs is required by Foreground
# and requires some params to be computed
# Assign those from Foreground
Expand Down Expand Up @@ -209,7 +209,7 @@ def get_bandint_freqs(self) -> dict:
# Takes care of the bandpass construction. It returns a list of nu-transmittance for
# each frequency or an array with the effective freqs.
def _bandpass_construction(
self, **params: dict
self, **params
) -> Union[np.ndarray, List[np.ndarray]]:
r"""
Builds the bandpass transmission
Expand Down Expand Up @@ -294,7 +294,9 @@ def _init_external_bandpass_construction(self, path: str, exp_ch: List[str]):
nu_ghz, bp = np.loadtxt(path + "/" + expc, usecols=(0, 1), unpack=True)
self.external_bandpass.append([expc, nu_ghz, bp])

def _external_bandpass_construction(self, **params: dict) -> List[np.ndarray]:
def _external_bandpass_construction(
self, **params
) -> Union[np.ndarray, List[np.ndarray]]:
r"""
Builds bandpass transmission
:math:`\frac{\frac{\partial B_{\nu+\Delta \nu}}{\partial T}
Expand Down
12 changes: 6 additions & 6 deletions soliket/bias/bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
function (have a look at the linear bias model for ideas).
"""

from typing import Dict, List, Optional, Set, Tuple, Union
from typing import Any, Dict, List, Optional, Set, Tuple, Union

import numpy as np
from cobaya.theory import Theory
Expand All @@ -47,13 +47,13 @@ class Bias(Theory):
_default_z_sampling = 10 ** _logz
_default_z_sampling[0] = 0

def initialize(self) -> None:
def initialize(self):
self._var_pairs: Set[Tuple[str, str]] = set()

def get_requirements(self) -> Dict[str, dict]:
def get_requirements(self) -> Dict[str, Any]:
return {}

def must_provide(self, **requirements: dict) -> Dict[str, dict]:
def must_provide(self, **requirements) -> Dict[str, Any]:
options = requirements.get("linear_bias") or {}

self.kmax = max(self.kmax, options.get("kmax", self.kmax))
Expand All @@ -62,7 +62,7 @@ def must_provide(self, **requirements: dict) -> Dict[str, dict]:
np.atleast_1d(self.z))))

# Dictionary of the things needed from CAMB/CLASS
needs: Dict[str, dict] = {}
needs = {}

self.nonlinear = self.nonlinear or options.get("nonlinear", False)
self._var_pairs.update(
Expand Down Expand Up @@ -103,7 +103,7 @@ class Linear_bias(Bias):
params: dict

def calculate(self, state: dict, want_derived: bool = True,
**params_values_dict) -> None:
**params_values_dict):
Pk_mm = self._get_Pk_mm()

state["Pk_gg_grid"] = params_values_dict["b_lin"] ** 2. * Pk_mm
Expand Down
6 changes: 3 additions & 3 deletions soliket/cash/cash.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CashCLikelihood(Likelihood):

enforce_types: bool = True

def initialize(self) -> None:
def initialize(self):
x, N = self._get_data()
self.data = CashCData(self.name, N)

Expand All @@ -23,12 +23,12 @@ def _get_data(self) -> Tuple[np.ndarray, np.ndarray]:
x = data[:, :-1]
return x, N

def _get_theory(self, **kwargs: dict) -> np.ndarray:
def _get_theory(self, **kwargs) -> np.ndarray:
if "cash_test_logp" in kwargs:
return np.arange(kwargs["cash_test_logp"])
else:
raise NotImplementedError

def logp(self, **params_values: dict) -> float:
def logp(self, **params_values) -> float:
theory = self._get_theory(**params_values)
return self.data.loglike(theory)
2 changes: 1 addition & 1 deletion soliket/cash/cash_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CashCData:

def __init__(
self, name: str, N: Union[np.ndarray, float], usestirling: bool = True
) -> None:
):
self.name = str(name)
self.data = N
self.usestirling = usestirling
Expand Down
4 changes: 2 additions & 2 deletions soliket/ccl/ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CCL(Theory):
_default_z_sampling[0] = 0
provider: Provider

def initialize(self) -> None:
def initialize(self):
try:
import pyccl as ccl
except ImportError:
Expand Down Expand Up @@ -161,7 +161,7 @@ def get_can_support_params(self) -> Sequence[str]:
return []

def calculate(self, state: dict, want_derived: bool = True,
**params_values_dict) -> None:
**params_values_dict):
# calculate the general CCL cosmo object which likelihoods can then use to get
# what they need (likelihoods should cache results appropriately)
# get our requirements from self.provider
Expand Down
16 changes: 8 additions & 8 deletions soliket/cosmopower/cosmopower.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
information on how SOLikeT infers these values.
"""
import os
from typing import Dict, Iterable, List, Tuple
from typing import Any, Dict, List

import numpy as np
from cobaya.log import LoggedError
Expand All @@ -112,7 +112,7 @@ class CosmoPower(BoltzmannBase):

enforce_types: bool = True

def initialize(self) -> None:
def initialize(self):

super().initialize()

Expand Down Expand Up @@ -283,10 +283,10 @@ def cmb_unit_factor(self, spectra: str,

return res

def get_can_support_parameters(self) -> Iterable[str]:
def get_can_support_parameters(self) -> List[str]:
return self.all_parameters

def get_requirements(self) -> Iterable[Tuple[str, str]]:
def get_requirements(self) -> Dict[str, Any]:
requirements = []
for k in self.all_parameters:
if k in self.renames.values():
Expand All @@ -303,7 +303,7 @@ def get_requirements(self) -> Iterable[Tuple[str, str]]:
class CosmoPowerDerived(Theory):
"""A theory class that can calculate derived parameters from CosmoPower networks."""

def initialize(self) -> None:
def initialize(self):
super().initialize()

if self.network_settings is None:
Expand Down Expand Up @@ -365,10 +365,10 @@ def calculate(self, state: dict, want_derived: bool = True, **params) -> bool:
def get_param(self, p) -> float:
return self.current_state["derived"][self.translate_param(p)]

def get_can_support_parameters(self) -> Iterable[str]:
def get_can_support_parameters(self) -> List[str]:
return self.input_parameters

def get_requirements(self) -> Iterable[Tuple[str, str]]:
def get_requirements(self) -> Dict[str, Any]:
requirements = []
for k in self.input_parameters:
if k in self.renames.values():
Expand All @@ -381,6 +381,6 @@ def get_requirements(self) -> Iterable[Tuple[str, str]]:

return requirements

def get_can_provide(self) -> Iterable[str]:
def get_can_provide(self) -> List[str]:
return set([par for par in self.derived_parameters
if (len(par) > 0 and not par == "_")])
16 changes: 8 additions & 8 deletions soliket/cross_correlation/cross_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def initialize(self):
self._get_sacc_data()
self._check_tracers()

def get_requirements(self) -> Dict[str, dict]:
def get_requirements(self) -> Dict[str, Any]:
return {"CCL": {"kmax": 10, "nonlinear": True}, "zstar": None}

def _get_CCL_results(self) -> Tuple[CCL, dict]:
cosmo_dict = self.provider.get_CCL()
return cosmo_dict["ccl"], cosmo_dict["cosmo"]

def _check_tracers(self) -> None:
def _check_tracers(self):

# check correct tracers
for tracer_comb in self.sacc_data.get_tracer_combinations():
Expand Down Expand Up @@ -72,7 +72,7 @@ def _get_nz(
z: np.ndarray,
tracer: Any,
tracer_name: str,
**params_values: dict
**params_values
) -> np.ndarray:
if self.z_nuisance_mode == 'deltaz':
bias = params_values[f'{tracer_name}_deltaz']
Expand All @@ -82,7 +82,7 @@ def _get_nz(

return nz_biased

def _get_sacc_data(self, **params_values: dict) -> None:
def _get_sacc_data(self, **params_values):
self.sacc_data = sacc.Sacc.load_fits(self.datapath)

if self.use_spectra == 'all':
Expand All @@ -109,7 +109,7 @@ def _construct_ell_bins(self) -> np.ndarray:
return np.concatenate(ell_eff)

def _get_data(
self, **params_values: dict
self, **params_values
) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
data_auto = np.loadtxt(self.auto_file)
data_cross = np.loadtxt(self.cross_file)
Expand Down Expand Up @@ -138,7 +138,7 @@ def get_binning(self, tracer_comb: tuple) -> Tuple[np.ndarray, np.ndarray]:

return ells_theory, w_bins

def logp(self, **params_values: dict) -> float:
def logp(self, **params_values) -> float:
theory = self._get_theory(**params_values)
return self.data.loglike(theory)

Expand All @@ -150,7 +150,7 @@ class GalaxyKappaLikelihood(CrossCorrelationLikelihood):
_allowable_tracers: ClassVar[List[str]] = ['cmb_convergence', 'galaxy_density']
params: dict

def _get_theory(self, **params_values: dict) -> np.ndarray:
def _get_theory(self, **params_values) -> np.ndarray:
ccl, cosmo = self._get_CCL_results()

tracer_comb = self.sacc_data.get_tracer_combinations()
Expand Down Expand Up @@ -194,7 +194,7 @@ class ShearKappaLikelihood(CrossCorrelationLikelihood):
ia_mode: Optional[str]
params: dict

def _get_theory(self, **params_values: dict) -> np.ndarray:
def _get_theory(self, **params_values) -> np.ndarray:
ccl, cosmo = self._get_CCL_results()
cl_binned_list: List[np.ndarray] = []

Expand Down
4 changes: 2 additions & 2 deletions soliket/foreground/foreground.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def _get_foreground_model(
fg_dict[s, "all", f1, f2] += fg_dict[s, comp, f1, f2]
return fg_dict

def must_provide(self, **requirements: dict) -> dict:
def must_provide(self, **requirements) -> dict:
# fg_dict is required by theoryforge
# and requires some params to be computed
# Assign those from theoryforge
Expand All @@ -323,7 +323,7 @@ def must_provide(self, **requirements: dict) -> dict:
return {"bandint_freqs": {"bands": self.bands}}
return {}

def get_bandpasses(self, **params: dict) -> np.ndarray:
def get_bandpasses(self, **params) -> np.ndarray:
"""
Gets bandpass transmissions from the ``BandPass`` class.
"""
Expand Down
14 changes: 7 additions & 7 deletions soliket/gaussian/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GaussianLikelihood(Likelihood):

enforce_types: bool = True

def initialize(self) -> None:
def initialize(self):
x, y = self._get_data()
cov = self._get_cov()
self.data = GaussianData(self.name, x, y, cov, self.ncovsims)
Expand All @@ -34,16 +34,16 @@ def _get_cov(self) -> np.ndarray:
cov = np.loadtxt(self.covpath)
return cov

def _get_theory(self, **kwargs: dict) -> np.ndarray:
def _get_theory(self, **kwargs) -> np.ndarray:
raise NotImplementedError

def logp(self, **params_values: dict) -> float:
def logp(self, **params_values) -> float:
theory = self._get_theory(**params_values)
return self.data.loglike(theory)


class CrossCov(dict):
def save(self, path: str) -> None:
def save(self, path: str):
np.savez(path, **{str(k): v for k, v in self.items()})

@classmethod
Expand All @@ -58,7 +58,7 @@ class MultiGaussianLikelihood(GaussianLikelihood):
options: Optional[Sequence] = None
cross_cov_path: Optional[str] = None

def __init__(self, info: dict = empty_dict, **kwargs) -> None:
def __init__(self, info: dict = empty_dict, **kwargs):

if 'components' in info:
self.likelihoods: List[Likelihood] = [
Expand All @@ -72,15 +72,15 @@ def __init__(self, info: dict = empty_dict, **kwargs) -> None:

super().__init__(info=default_info, **kwargs)

def initialize(self) -> None:
def initialize(self):
self.cross_cov: Optional[CrossCov] = CrossCov.load(self.cross_cov_path)

data_list = [like.data for like in self.likelihoods]
self.data = MultiGaussianData(data_list, self.cross_cov)

self.log.info('Initialized.')

def initialize_with_provider(self, provider: Provider) -> None: # pragma: no cover
def initialize_with_provider(self, provider: Provider): # pragma: no cover
for like in self.likelihoods:
like.initialize_with_provider(provider)
# super().initialize_with_provider(provider)
Expand Down
8 changes: 4 additions & 4 deletions soliket/gaussian/gaussian_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GaussianData:
_fast_chi_squared = staticmethod(functions.chi_squared)

def __init__(self, name: str, x: Sequence[float], y: Sequence[float], cov: np.ndarray,
ncovsims: Optional[int] = None) -> None:
ncovsims: Optional[int] = None):

self.name: str = str(name)
self.ncovsims: Optional[int] = ncovsims
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(
self,
data_list: List[GaussianData],
cross_covs: Optional[Dict[Tuple[str, str], np.ndarray]] = None,
) -> None:
):

if cross_covs is None:
cross_covs = {}
Expand Down Expand Up @@ -148,7 +148,7 @@ def _slice(self, *names: str) -> slice:

return np.s_[tuple(slice(*self._index_range(n)) for n in names)]

def _assemble_data(self) -> None:
def _assemble_data(self):
x = np.concatenate([d.x for d in self.data_list])
y = np.concatenate([d.y for d in self.data_list])

Expand All @@ -161,7 +161,7 @@ def _assemble_data(self) -> None:

self._data = GaussianData(" + ".join(self.names), x, y, cov)

def plot_cov(self, **kwargs) -> None:
def plot_cov(self, **kwargs):
import holoviews as hv

data = [
Expand Down
Loading

0 comments on commit 2ddec66

Please sign in to comment.