From cee6cd27990edeee62fee4185e98945d1f05f160 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:21:29 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v4.6.0) - [github.com/psf/black-pre-commit-mirror: 23.12.1 → 24.3.0](https://github.com/psf/black-pre-commit-mirror/compare/23.12.1...24.3.0) - [github.com/asottile/pyupgrade: v3.15.0 → v3.15.2](https://github.com/asottile/pyupgrade/compare/v3.15.0...v3.15.2) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 89bfa66..e31a081 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ exclude: '^docs/conf.py' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: check-added-large-files @@ -33,7 +33,7 @@ repos: - flake8-print # Using this mirror lets us use mypyc-compiled black, which is about 2x faster - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.12.1 + rev: 24.3.0 hooks: - id: black - repo: https://github.com/pre-commit/pygrep-hooks @@ -46,7 +46,7 @@ repos: - id: isort - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.15.2 hooks: - id: pyupgrade args: [--py38-plus] From 0288372f66ae2c2e30a22a8feb4162064cd6c3a9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:24:01 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.py | 1 + src/hmf/__init__.py | 1 + src/hmf/_cli.py | 1 + src/hmf/_internals/__init__.py | 1 + src/hmf/_internals/_cache.py | 7 ++++--- src/hmf/_internals/_framework.py | 1 + src/hmf/alternatives/__init__.py | 1 + src/hmf/cosmology/__init__.py | 1 + src/hmf/cosmology/growth_factor.py | 2 ++ src/hmf/density_field/__init__.py | 1 + src/hmf/density_field/halofit.py | 1 + src/hmf/density_field/transfer.py | 1 + src/hmf/density_field/transfer_models.py | 7 ++++--- src/hmf/halos/mass_definitions.py | 4 ++-- src/hmf/helpers/cfg_utils.py | 1 + src/hmf/helpers/sample.py | 1 + src/hmf/mass_function/__init__.py | 1 + src/hmf/mass_function/fitting_functions.py | 8 +++----- src/hmf/mass_function/integrate_hmf.py | 5 ++--- tests/test_genmf.py | 1 + tests/test_hmf.py | 1 + tests/test_integrate_hmf.py | 4 +--- 22 files changed, 33 insertions(+), 19 deletions(-) diff --git a/setup.py b/setup.py index 87fecd8..c99d4ff 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ """Setup the package.""" + from setuptools import setup setup() diff --git a/src/hmf/__init__.py b/src/hmf/__init__.py index 51b2808..b907edd 100644 --- a/src/hmf/__init__.py +++ b/src/hmf/__init__.py @@ -1,4 +1,5 @@ """A package for producing halo mass functions under Spherical Collapse.""" + try: from importlib.metadata import PackageNotFoundError, version except ImportError: diff --git a/src/hmf/_cli.py b/src/hmf/_cli.py index 65f0c9d..8d95cd1 100644 --- a/src/hmf/_cli.py +++ b/src/hmf/_cli.py @@ -1,4 +1,5 @@ """Module that contains the command line app.""" + import click import importlib import numpy as np diff --git a/src/hmf/_internals/__init__.py b/src/hmf/_internals/__init__.py index 0b77a5f..eac1cae 100644 --- a/src/hmf/_internals/__init__.py +++ b/src/hmf/_internals/__init__.py @@ -2,6 +2,7 @@ These define the structure of the entire library. """ + from ._cache import cached_quantity, parameter from ._framework import ( Component, diff --git a/src/hmf/_internals/_cache.py b/src/hmf/_internals/_cache.py index ec21e0d..4628957 100644 --- a/src/hmf/_internals/_cache.py +++ b/src/hmf/_internals/_cache.py @@ -6,6 +6,7 @@ functionality of being automatically updated when a parent property is updated. """ + import warnings from copy import deepcopy from functools import update_wrapper @@ -104,9 +105,9 @@ def _get_property(self): # if name is already there, can only be because the method has been supered. supered = name in activeq if not supered: - recalc_prpa[ - name - ] = set() # Empty set to which parameter names will be added + recalc_prpa[name] = ( + set() + ) # Empty set to which parameter names will be added activeq.add(name) # Go ahead and calculate the value -- each parameter accessed will add itself to the index. diff --git a/src/hmf/_internals/_framework.py b/src/hmf/_internals/_framework.py index b899bd9..936af19 100644 --- a/src/hmf/_internals/_framework.py +++ b/src/hmf/_internals/_framework.py @@ -1,4 +1,5 @@ """Classes defining the overall structure of the hmf framework.""" + import copy import deprecation import logging diff --git a/src/hmf/alternatives/__init__.py b/src/hmf/alternatives/__init__.py index 97e3ac9..c9212a1 100644 --- a/src/hmf/alternatives/__init__.py +++ b/src/hmf/alternatives/__init__.py @@ -2,4 +2,5 @@ A subpackage dedicated to providing "plugin"-style alternatives to the standard halo mass function, for example Warm Dark Matter cosmologies. """ + from . import wdm diff --git a/src/hmf/cosmology/__init__.py b/src/hmf/cosmology/__init__.py index 756ddc0..6e222ec 100644 --- a/src/hmf/cosmology/__init__.py +++ b/src/hmf/cosmology/__init__.py @@ -1,4 +1,5 @@ """Cosmographic calculations, and other purely cosmological quantities, such as growth factor.""" + from . import cosmo from .cosmo import Cosmology, astropy_to_colossus from .growth_factor import GrowthFactor diff --git a/src/hmf/cosmology/growth_factor.py b/src/hmf/cosmology/growth_factor.py index 9976762..b94f129 100644 --- a/src/hmf/cosmology/growth_factor.py +++ b/src/hmf/cosmology/growth_factor.py @@ -30,6 +30,7 @@ class _GrowthFactor(Cmpt): r""" General class for a growth factor calculation. """ + supported_cosmos = (cosmology.LambdaCDM,) def __init__(self, cosmo, **model_parameters): @@ -64,6 +65,7 @@ class GrowthFactor(_GrowthFactor): ---------- .. [1] Lukic et. al., ApJ, 2007, http://adsabs.harvard.edu/abs/2007ApJ...671.1160L """ + _defaults = {"dlna": 0.01, "amin": 1e-8} def __init__(self, *args, **kwargs): diff --git a/src/hmf/density_field/__init__.py b/src/hmf/density_field/__init__.py index 2fe77aa..30615f8 100644 --- a/src/hmf/density_field/__init__.py +++ b/src/hmf/density_field/__init__.py @@ -2,6 +2,7 @@ A subpackage dedicated to basic measures of the matter density field -- its 2-point structure, cosmological transfer functions, and filter functions which can be applied to it. """ + from . import filters, transfer, transfer_models from .filters import Filter from .halofit import halofit diff --git a/src/hmf/density_field/halofit.py b/src/hmf/density_field/halofit.py index 08cdffa..047ce60 100644 --- a/src/hmf/density_field/halofit.py +++ b/src/hmf/density_field/halofit.py @@ -6,6 +6,7 @@ and Michael Schneider (https://code.google.com/p/chomp/). It has been modified to improve its integration with this package. """ + import numpy as np import warnings from scipy.integrate import simps as _simps diff --git a/src/hmf/density_field/transfer.py b/src/hmf/density_field/transfer.py index 70e2bb9..6010b68 100644 --- a/src/hmf/density_field/transfer.py +++ b/src/hmf/density_field/transfer.py @@ -5,6 +5,7 @@ calculate the transfer function, matter power spectrum and several other related quantities. """ + import numpy as np from .._internals._cache import cached_quantity, parameter diff --git a/src/hmf/density_field/transfer_models.py b/src/hmf/density_field/transfer_models.py index ff116c4..df0e71f 100644 --- a/src/hmf/density_field/transfer_models.py +++ b/src/hmf/density_field/transfer_models.py @@ -4,6 +4,7 @@ Note that these are not transfer function "frameworks". The framework is found in :mod:`hmf.transfer`. """ + import numpy as np import pickle import warnings @@ -462,9 +463,7 @@ def _set_params(self): self.z_eq = 2.5e4 * self.Omh2 * self.theta_cmb ** (-4) # really 1+z self.k_eq = 7.46e-2 * self.Omh2 * self.theta_cmb ** (-2) # units Mpc^-1 (no h!) - self.z_drag_b1 = ( - 0.313 * self.Omh2**-0.419 * (1.0 + 0.607 * self.Omh2**0.674) - ) + self.z_drag_b1 = 0.313 * self.Omh2**-0.419 * (1.0 + 0.607 * self.Omh2**0.674) self.z_drag_b2 = 0.238 * self.Omh2**0.223 self.z_drag = ( 1291.0 @@ -686,6 +685,7 @@ class attribute. .. math:: \Gamma \rightarrow \Gamma \exp\left(-\Omega_{b,0}(1 + \sqrt{2h}/\Omega_{m,0})\right). """ + _defaults = { "a": 2.34, "b": 3.89, @@ -760,6 +760,7 @@ class attribute. .. math:: \alpha = \frac{0.3\times 0.75^2}{\Omega_{m,0} h^2}. """ + _defaults = {"a": 37.1, "b": 21.1, "c": 10.8, "nu": 1.12} def lnt(self, lnk): diff --git a/src/hmf/halos/mass_definitions.py b/src/hmf/halos/mass_definitions.py index 4d4ed1e..44765cf 100644 --- a/src/hmf/halos/mass_definitions.py +++ b/src/hmf/halos/mass_definitions.py @@ -3,6 +3,7 @@ This is primarily inspired by Benedikt Diemer's COLOSSUS code: https://bdiemer.bitbucket.io/colossus/halo_mass_defs.html """ + import astropy.units as u import numpy as np import scipy as sp @@ -366,8 +367,7 @@ def h(x): return np.log(1.0 + x) - x / (1.0 + x) fnc = ( - lambda x, rhos, density_threshold: rhos * h(x) * 3.0 / x**3 - - density_threshold + lambda x, rhos, density_threshold: rhos * h(x) * 3.0 / x**3 - density_threshold ) while x is None and i < len(XDELTA_GUESS_FACTORS): diff --git a/src/hmf/helpers/cfg_utils.py b/src/hmf/helpers/cfg_utils.py index 0d6cbaa..a7b4137 100644 --- a/src/hmf/helpers/cfg_utils.py +++ b/src/hmf/helpers/cfg_utils.py @@ -1,4 +1,5 @@ """Utilities for interacting with hmf TOML configs.""" + from astropy.units import Quantity from datetime import datetime from inspect import signature diff --git a/src/hmf/helpers/sample.py b/src/hmf/helpers/sample.py index b05cc1b..98919e2 100644 --- a/src/hmf/helpers/sample.py +++ b/src/hmf/helpers/sample.py @@ -3,6 +3,7 @@ Provides routines for sampling theoretical functions, and for binning sampled data. """ + import numpy as np from scipy.interpolate import InterpolatedUnivariateSpline as _spline diff --git a/src/hmf/mass_function/__init__.py b/src/hmf/mass_function/__init__.py index 028b591..58a75eb 100644 --- a/src/hmf/mass_function/__init__.py +++ b/src/hmf/mass_function/__init__.py @@ -1,4 +1,5 @@ """Subpackage for determining the halo mass function in Spherical Collapse.""" + from . import fitting_functions, hmf, integrate_hmf from .fitting_functions import PS, SMT, FittingFunction, Tinker08 from .hmf import MassFunction diff --git a/src/hmf/mass_function/fitting_functions.py b/src/hmf/mass_function/fitting_functions.py index b2092a6..5542815 100644 --- a/src/hmf/mass_function/fitting_functions.py +++ b/src/hmf/mass_function/fitting_functions.py @@ -178,6 +178,7 @@ class FittingFunction(_framework.Component): In that example, we did not specify :attr:`cutmask`. """ + _pdocs = r""" Parameters @@ -641,8 +642,7 @@ def fsigma(self): * (1.0 + (1.0 / (a * self.nu**2)) ** p + 0.6 * G_1 + 0.4 * G_2) * self.nu * np.exp( - -c * a * self.nu**2 / 2.0 - - 0.03 * self.nu**0.6 / (self.n_eff + 3) ** 2 + -c * a * self.nu**2 / 2.0 - 0.03 * self.nu**0.6 / (self.n_eff + 3) ** 2 ) ) @@ -1516,9 +1516,7 @@ def normalise(self): * self.beta ** (-2 * self.phi) * self.gamma ** (-0.5 - self.eta) * ( - 2**self.phi - * self.beta ** (2 * self.phi) - * sp.gamma(self.eta + 0.5) + 2**self.phi * self.beta ** (2 * self.phi) * sp.gamma(self.eta + 0.5) + self.gamma**self.phi * sp.gamma(0.5 + self.eta - self.phi) ) ) diff --git a/src/hmf/mass_function/integrate_hmf.py b/src/hmf/mass_function/integrate_hmf.py index 69cded8..de7661c 100644 --- a/src/hmf/mass_function/integrate_hmf.py +++ b/src/hmf/mass_function/integrate_hmf.py @@ -1,6 +1,7 @@ """ A supporting module that provides a routine to integrate the differential hmf in a robust manner. """ + import numpy as np import scipy.integrate as intg from scipy.interpolate import InterpolatedUnivariateSpline as _spline @@ -64,9 +65,7 @@ def hmf_integral_gtm(M, dndm, mass_density=False): # Calculate the mass function (and its integral) from the highest M up to 10**18 if m[-1] < m[0] * 10**18 / m[3]: - m_upper = np.arange( - np.log(m[-1]), np.log(10**18), np.log(m[1]) - np.log(m[0]) - ) + m_upper = np.arange(np.log(m[-1]), np.log(10**18), np.log(m[1]) - np.log(m[0])) mf_func = _spline(np.log(m), np.log(dndlnm), k=1) mf = mf_func(m_upper) diff --git a/tests/test_genmf.py b/tests/test_genmf.py index 0442d1a..08062e5 100644 --- a/tests/test_genmf.py +++ b/tests/test_genmf.py @@ -41,6 +41,7 @@ 'transfer__k_per_logint': 0, 'transfer__kmax':100.0 """ + import pytest import numpy as np diff --git a/tests/test_hmf.py b/tests/test_hmf.py index 029c37e..3a8f1e8 100644 --- a/tests/test_hmf.py +++ b/tests/test_hmf.py @@ -1,4 +1,5 @@ """Tests of HMF.""" + from pytest import raises import numpy as np diff --git a/tests/test_integrate_hmf.py b/tests/test_integrate_hmf.py index de9eee3..1944d68 100644 --- a/tests/test_integrate_hmf.py +++ b/tests/test_integrate_hmf.py @@ -26,9 +26,7 @@ def anl_int(self, m, loghs, alpha, beta): return 10**loghs * gammainc((alpha + 1) / beta, (m / 10**loghs) ** beta) def anl_m_int(self, m, loghs, alpha, beta): - return 10 ** (2 * loghs) * gammainc( - (alpha + 2) / beta, (m / 10**loghs) ** beta - ) + return 10 ** (2 * loghs) * gammainc((alpha + 2) / beta, (m / 10**loghs) ** beta) # def test_basic(self): # m = np.logspace(10,18,500)