Skip to content

Commit

Permalink
Merge pull request #622 from aphearin/pep8
Browse files Browse the repository at this point in the history
Pep8 syntax cleanup
  • Loading branch information
aphearin authored Aug 9, 2016
2 parents 50d3dd6 + feb6cb3 commit 72d203a
Show file tree
Hide file tree
Showing 163 changed files with 1,066 additions and 1,080 deletions.
9 changes: 0 additions & 9 deletions halotools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
Halotools is a specialized python package
for building and testing models of the galaxy-halo connection,
and analyzing catalogs of dark matter halos.
"""

# ----------------------------------------------------------------------------
# keep this content at the top.
from ._astropy_init import *

# For egg_info test builds to pass, put package imports here.
if not _ASTROPY_SETUP_:
pass
# ----------------------------------------------------------------------------

from . import custom_exceptions
7 changes: 2 additions & 5 deletions halotools/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# no matter how it is invoked within the source tree.

from astropy.tests.pytest_plugins import *
import os
from . import version

# Uncomment the following line to treat all DeprecationWarnings as
# exceptions
Expand All @@ -18,14 +20,9 @@
except (NameError, KeyError): # NameError is needed to support Astropy < 1.0
pass

# Uncomment the following lines to display the version number of the
# package rather than the version number of Astropy in the top line when
# running the tests.
import os

# This is to figure out the affiliated package version, rather than
# using Astropy's
from . import version

packagename = os.path.basename(os.path.dirname(__file__))
TESTED_VERSIONS[packagename] = version.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
This module contains the `~halotools.empirical_models.HeavisideAssembias` class.
The purpose of this class is to introduce step function-type assembly bias into
Expand Down Expand Up @@ -404,9 +403,9 @@ def assembias_decorator(self, func):
def wrapper(*args, **kwargs):

#################################################################################
### Retrieve the arrays storing prim_haloprop and sec_haloprop
### The control flow below is what permits accepting an input
### table or a directly inputting prim_haloprop and sec_haloprop arrays
# Retrieve the arrays storing prim_haloprop and sec_haloprop
# The control flow below is what permits accepting an input
# table or a directly inputting prim_haloprop and sec_haloprop arrays
_HAS_table = False
if 'table' in kwargs:
try:
Expand Down Expand Up @@ -440,14 +439,14 @@ def wrapper(*args, **kwargs):

#################################################################################

### Compute the fraction of type-2 halos as a function of the input prim_haloprop
# Compute the fraction of type-2 halos as a function of the input prim_haloprop
split = self.percentile_splitting_function(prim_haloprop)

### Compute the baseline, undecorated result
# Compute the baseline, undecorated result
result = func(*args, **kwargs)

# We will only decorate values that are not edge cases,
### so first compute the mask for non-edge cases
# so first compute the mask for non-edge cases
no_edge_mask = (
(split > 0) & (split < 1) &
(result > baseline_lower_bound) & (result < baseline_upper_bound)
Expand Down Expand Up @@ -512,7 +511,7 @@ def wrapper(*args, **kwargs):

frac_type1 = 1 - no_edge_split
frac_type2 = 1 - frac_type1
perturbation[~type1_mask] *= (-frac_type1[~type1_mask]/
perturbation[~type1_mask] *= (-frac_type1[~type1_mask] /
(frac_type2[~type1_mask]))

no_edge_result += perturbation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python

"""
"""
from unittest import TestCase

import numpy as np
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def __init__(self, galprop_abscissa, galprop_ordinates,
except KeyError:
pass

if self._interpol_method=='spline':
if self._interpol_method == 'spline':
if 'input_spline_degree' in list(kwargs.keys()):
self._input_spine_degree = kwargs['input_spline_degree']
else:
Expand Down Expand Up @@ -317,19 +317,19 @@ def _mean_galprop_fraction(self, **kwargs):
self._abscissa = getattr(self, self.galprop_name+'_abscissa')

model_ordinates = [self.param_dict[ordinate_key] for ordinate_key in self._ordinates_keys]
if self._interpol_method=='polynomial':
if self._interpol_method == 'polynomial':
mean_galprop_fraction = model_helpers.polynomial_from_table(
self._abscissa, model_ordinates, prim_haloprop)
elif self._interpol_method=='spline':
elif self._interpol_method == 'spline':
spline_function = model_helpers.custom_spline(
self._abscissa, model_ordinates,
self._abscissa, model_ordinates,
k=self._spline_degree)
mean_galprop_fraction = spline_function(prim_haloprop)
else:
raise HalotoolsError("Input interpol_method must be 'polynomial' or 'spline'.")

# Enforce boundary conditions
mean_galprop_fraction[mean_galprop_fraction<0]=0
mean_galprop_fraction[mean_galprop_fraction>1]=1
mean_galprop_fraction[mean_galprop_fraction < 0] = 0
mean_galprop_fraction[mean_galprop_fraction > 1] = 1

return mean_galprop_fraction
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ def scatter_realization(self, seed=None, **kwargs):

scatter_scale = self.mean_scatter(**kwargs)

#initialize result with zero scatter result
# initialize result with zero scatter result
result = np.zeros(len(scatter_scale))

#only draw from a normal distribution for non-zero values of scatter
# only draw from a normal distribution for non-zero values of scatter
mask = (scatter_scale > 0.0)
with NumpyRNGContext(seed):
result[mask] = np.random.normal(loc=0, scale=scatter_scale[mask])
Expand All @@ -163,7 +163,7 @@ def _update_interpol(self):
def _initialize_param_dict(self):
""" Private method used to initialize ``self.param_dict``.
"""
self.param_dict={}
self.param_dict = {}
for ipar, val in enumerate(self.ordinates):
key = self._get_param_key(ipar)
self.param_dict[key] = val
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
"""
"""
import numpy as np

from astropy.tests.helper import pytest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
"""
"""
import numpy as np
from astropy.table import Table
from unittest import TestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from ....sim_manager import FakeSim

__all__=['test_nonzero_scatter', 'test_zero_scatter']
__all__ = ['test_nonzero_scatter', 'test_zero_scatter']


def test_nonzero_scatter():
Expand All @@ -24,7 +24,7 @@ def test_nonzero_scatter():

scatter = scatter_model.scatter_realization(table=halo_table)

assert len(scatter)==len(halo_table)
assert len(scatter) == len(halo_table)


def test_zero_scatter():
Expand All @@ -36,8 +36,8 @@ def test_zero_scatter():

scatter = scatter_model.scatter_realization(table=halo_table)

assert len(scatter)==len(halo_table)
assert np.all(scatter==0.0)
assert len(scatter) == len(halo_table)
assert np.all(scatter == 0.0)


def test_LogNormalScatterModel_initialization():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# -*- coding: utf-8 -*-
"""
Module containing some commonly used composite HOD models.
"""
from __future__ import (
division, print_function, absolute_import, unicode_literals)
from __future__ import division, print_function, absolute_import, unicode_literals

from ... import factories
from ...occupation_models import leauthaud11_components
Expand Down Expand Up @@ -96,7 +92,7 @@ def hearin15_model_dictionary(central_assembias_strength=1,
"""
##############################
### Build the occupation model
# Build the occupation model
if central_assembias_strength == 0:
centrals_occupation = leauthaud11_components.Leauthaud11Cens(**kwargs)
else:
Expand All @@ -109,7 +105,7 @@ def hearin15_model_dictionary(central_assembias_strength=1,
centrals_profile = TrivialPhaseSpace(**kwargs)

##############################
### Build the occupation model
# Build the occupation model

if satellite_assembias_strength == 0:
satellites_occupation = leauthaud11_components.Leauthaud11Sats(**kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# -*- coding: utf-8 -*-
"""
Module containing the HOD-style composite model based on Leauthaud et al. (2011).
"""
from __future__ import (
division, print_function, absolute_import, unicode_literals)
from __future__ import division, print_function, absolute_import, unicode_literals

from ... import model_defaults
from ...occupation_models import leauthaud11_components
Expand Down Expand Up @@ -83,15 +79,15 @@ def leauthaud11_model_dictionary(threshold=model_defaults.default_stellar_mass_t
>>> model_instance.populate_mock(halocat)
"""
### Build model for centrals
# Build model for centrals
# Build the occupation model
centrals_occupation = leauthaud11_components.Leauthaud11Cens(threshold=threshold, **kwargs)
centrals_occupation._suppress_repeated_param_warning = True
# Build the profile model

centrals_profile = TrivialPhaseSpace(**kwargs)

### Build model for satellites
# Build model for satellites
# Build the occupation model
satellites_occupation = leauthaud11_components.Leauthaud11Sats(threshold=threshold, **kwargs)
# Build the profile model
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python

"""
"""
from unittest import TestCase
from astropy.tests.helper import pytest

from ....factories import PrebuiltHodModelFactory

from .....sim_manager import FakeSim

### Determine whether the machine is mine
# Determine whether the machine is mine
# This will be used to select tests whose
# returned values depend on the configuration
# of my personal cache directory files
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# -*- coding: utf-8 -*-
"""
Module containing some commonly used composite HOD models.
"""
from __future__ import (
division, print_function, absolute_import, unicode_literals)
from __future__ import division, print_function, absolute_import, unicode_literals

from ... import model_defaults
from ...occupation_models import tinker13_components
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
"""
Module containing the HOD-style composite model
published in Zheng et al. (2007), arXiv:0703457.
"""
from __future__ import (
division, print_function, absolute_import, unicode_literals)
from __future__ import division, print_function, absolute_import, unicode_literals

from ... import model_defaults
from ...occupation_models import zheng07_components
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
"""
Module containing a pre-built subhalo-based model
that has a binary quenching feature.
"""
from __future__ import (
division, print_function, absolute_import)
from __future__ import division, print_function, absolute_import

from ... import model_defaults
from ...smhm_models import Behroozi10SmHm
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
"""
Module containing the subhalo-based composite model
based on the Behroozi et al. (2010) stellar-to-halo-mass relation.
"""
from __future__ import (
division, print_function, absolute_import, unicode_literals)
from __future__ import division, print_function, absolute_import, unicode_literals

from ...smhm_models import Behroozi10SmHm

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
"""
"""

from unittest import TestCase
from astropy.tests.helper import pytest
Expand All @@ -8,7 +9,7 @@
from ....sim_manager import CachedHaloCatalog, FakeSim
from ....custom_exceptions import HalotoolsError

### Determine whether the machine is mine
# Determine whether the machine is mine
# This will be used to select tests whose
# returned values depend on the configuration
# of my personal cache directory files
Expand Down
Loading

0 comments on commit 72d203a

Please sign in to comment.