Skip to content

Commit

Permalink
pep8 changes made by atom
Browse files Browse the repository at this point in the history
  • Loading branch information
aphearin committed Sep 18, 2020
1 parent e851791 commit de727d3
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from .....sim_manager import sim_defaults


__author__ = ['Andrew Hearin']
__all__ = ['TrivialPhaseSpace']
__author__ = ["Andrew Hearin"]
__all__ = ["TrivialPhaseSpace"]


class TrivialPhaseSpace(object):
Expand All @@ -22,11 +22,13 @@ class TrivialPhaseSpace(object):
:math:`P(\vec{x}_{\rm cen}, \vec{v}_{\rm cen}) = \delta^{(6)}(\vec{x}_{\rm halo}, \vec{v}_{\rm halo})`.
"""

def __init__(self,
cosmology=sim_defaults.default_cosmology,
redshift=sim_defaults.default_redshift,
mdef=model_defaults.halo_mass_definition,
**kwargs):
def __init__(
self,
cosmology=sim_defaults.default_cosmology,
redshift=sim_defaults.default_redshift,
mdef=model_defaults.halo_mass_definition,
**kwargs
):
"""
Parameters
----------
Expand All @@ -40,11 +42,17 @@ def __init__(self,
String specifying the halo mass definition, e.g., 'vir' or '200m'.
Default is set in `~halotools.empirical_models.model_defaults`.
"""
self._mock_generation_calling_sequence = ['assign_phase_space']
self._galprop_dtypes_to_allocate = np.dtype([
('x', 'f8'), ('y', 'f8'), ('z', 'f8'),
('vx', 'f8'), ('vy', 'f8'), ('vz', 'f8'),
])
self._mock_generation_calling_sequence = ["assign_phase_space"]
self._galprop_dtypes_to_allocate = np.dtype(
[
("x", "f8"),
("y", "f8"),
("z", "f8"),
("vx", "f8"),
("vy", "f8"),
("vz", "f8"),
]
)

self.param_dict = {}

Expand All @@ -56,6 +64,6 @@ def __init__(self,
def assign_phase_space(self, table, **kwargs):
r"""
"""
phase_space_keys = ['x', 'y', 'z', 'vx', 'vy', 'vz']
phase_space_keys = ["x", "y", "z", "vx", "vy", "vz"]
for key in phase_space_keys:
table[key][:] = table['halo_'+key][:]
table[key][:] = table["halo_" + key][:]
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

from ... import model_defaults

newtonG = G.to(u.km*u.km*u.Mpc/(u.Msun*u.s*u.s))
newtonG = G.to(u.km * u.km * u.Mpc / (u.Msun * u.s * u.s))

__author__ = ['Andrew Hearin', 'Benedikt Diemer']
__author__ = ["Andrew Hearin", "Benedikt Diemer"]

__all__ = ['AnalyticDensityProf']
__all__ = ["AnalyticDensityProf"]


@six.add_metaclass(ABCMeta)
Expand Down Expand Up @@ -63,8 +63,8 @@ def __init__(self, cosmology, redshift, mdef, **kwargs):
# The following four attributes are derived quantities from the above,
# so that self-consistency between them is ensured
self.density_threshold = halo_boundary_functions.density_threshold(
cosmology=self.cosmology,
redshift=self.redshift, mdef=self.mdef)
cosmology=self.cosmology, redshift=self.redshift, mdef=self.mdef
)
self.halo_boundary_key = model_defaults.get_halo_boundary_key(self.mdef)
self.prim_haloprop_key = model_defaults.get_halo_mass_key(self.mdef)

Expand Down Expand Up @@ -157,11 +157,13 @@ def mass_density(self, radius, mass, *prof_params):
"""
halo_radius = self.halo_mass_to_halo_radius(mass)
scaled_radius = radius/halo_radius
scaled_radius = radius / halo_radius

dimensionless_mass = self.dimensionless_mass_density(scaled_radius, *prof_params)
dimensionless_mass = self.dimensionless_mass_density(
scaled_radius, *prof_params
)

density = self.density_threshold*dimensionless_mass
density = self.density_threshold * dimensionless_mass
return density

def _enclosed_dimensionless_mass_integrand(self, scaled_radius, *prof_params):
Expand All @@ -183,8 +185,10 @@ def _enclosed_dimensionless_mass_integrand(self, scaled_radius, *prof_params):
integrand: array_like
function to be integrated to yield the amount of enclosed mass.
"""
dimensionless_density = self.dimensionless_mass_density(scaled_radius, *prof_params)
return dimensionless_density*4*np.pi*scaled_radius**2
dimensionless_density = self.dimensionless_mass_density(
scaled_radius, *prof_params
)
return dimensionless_density * 4 * np.pi * scaled_radius ** 2

def cumulative_mass_PDF(self, scaled_radius, *prof_params):
r"""
Expand Down Expand Up @@ -219,12 +223,20 @@ def cumulative_mass_PDF(self, scaled_radius, *prof_params):

for i in range(len(x)):
enclosed_mass[i], _ = quad_integration(
self._enclosed_dimensionless_mass_integrand, 0., x[i], epsrel=1e-5,
args=prof_params)
self._enclosed_dimensionless_mass_integrand,
0.0,
x[i],
epsrel=1e-5,
args=prof_params,
)

total, _ = quad_integration(
self._enclosed_dimensionless_mass_integrand, 0., 1.0, epsrel=1e-5,
args=prof_params)
self._enclosed_dimensionless_mass_integrand,
0.0,
1.0,
epsrel=1e-5,
args=prof_params,
)

return enclosed_mass / total

Expand Down Expand Up @@ -259,7 +271,7 @@ def enclosed_mass(self, radius, total_mass, *prof_params):
"""
radius = np.atleast_1d(radius).astype(np.float64)
scaled_radius = radius / self.halo_mass_to_halo_radius(total_mass)
mass = self.cumulative_mass_PDF(scaled_radius, *prof_params)*total_mass
mass = self.cumulative_mass_PDF(scaled_radius, *prof_params) * total_mass

return mass

Expand Down Expand Up @@ -289,7 +301,9 @@ def dimensionless_circular_velocity(self, scaled_radius, *prof_params):
See :ref:`halo_profile_definitions` for derivations and implementation details.
"""
return np.sqrt(self.cumulative_mass_PDF(scaled_radius, *prof_params)/scaled_radius)
return np.sqrt(
self.cumulative_mass_PDF(scaled_radius, *prof_params) / scaled_radius
)

def virial_velocity(self, total_mass):
r""" The circular velocity evaluated at the halo boundary,
Expand All @@ -310,8 +324,9 @@ def virial_velocity(self, total_mass):
See :ref:`halo_profile_definitions` for derivations and implementation details.
"""
return halo_boundary_functions.halo_mass_to_virial_velocity(total_mass,
self.cosmology, self.redshift, self.mdef)
return halo_boundary_functions.halo_mass_to_virial_velocity(
total_mass, self.cosmology, self.redshift, self.mdef
)

def circular_velocity(self, radius, total_mass, *prof_params):
r"""
Expand Down Expand Up @@ -344,13 +359,14 @@ def circular_velocity(self, radius, total_mass, *prof_params):
halo_radius = self.halo_mass_to_halo_radius(total_mass)
scaled_radius = np.atleast_1d(radius) / halo_radius
return self.dimensionless_circular_velocity(
scaled_radius, *prof_params)*self.virial_velocity(total_mass)
scaled_radius, *prof_params
) * self.virial_velocity(total_mass)

def _vmax_helper(self, scaled_radius, *prof_params):
""" Helper function used to calculate `vmax` and `rmax`.
"""
encl = self.cumulative_mass_PDF(scaled_radius, *prof_params)
return -1.*encl/scaled_radius
return -1.0 * encl / scaled_radius

def rmax(self, total_mass, *prof_params):
r""" Radius at which the halo attains its maximum circular velocity.
Expand Down Expand Up @@ -380,7 +396,7 @@ def rmax(self, total_mass, *prof_params):

result = scipy_minimize(self._vmax_helper, guess, args=prof_params)

return result.x[0]*halo_radius
return result.x[0] * halo_radius

def vmax(self, total_mass, *prof_params):
r""" Maximum circular velocity of the halo profile.
Expand Down Expand Up @@ -408,7 +424,9 @@ def vmax(self, total_mass, *prof_params):
result = scipy_minimize(self._vmax_helper, guess, args=prof_params)
halo_radius = self.halo_mass_to_halo_radius(total_mass)

return self.circular_velocity(result.x[0]*halo_radius, total_mass, *prof_params)
return self.circular_velocity(
result.x[0] * halo_radius, total_mass, *prof_params
)

def halo_mass_to_halo_radius(self, total_mass):
r"""
Expand All @@ -434,8 +452,8 @@ def halo_mass_to_halo_radius(self, total_mass):
"""
return halo_boundary_functions.halo_mass_to_halo_radius(
total_mass, cosmology=self.cosmology,
redshift=self.redshift, mdef=self.mdef)
total_mass, cosmology=self.cosmology, redshift=self.redshift, mdef=self.mdef
)

def halo_radius_to_halo_mass(self, radius):
r"""
Expand All @@ -461,5 +479,5 @@ def halo_radius_to_halo_mass(self, radius):
"""
return halo_boundary_functions.halo_radius_to_halo_mass(
radius, cosmology=self.cosmology,
redshift=self.redshift, mdef=self.mdef)
radius, cosmology=self.cosmology, redshift=self.redshift, mdef=self.mdef
)
Loading

0 comments on commit de727d3

Please sign in to comment.