Skip to content

Commit

Permalink
Merge pull request #140 from Hazboun6/linting
Browse files Browse the repository at this point in the history
Merging these changes which fixed @paulthebaker concerns.
  • Loading branch information
Hazboun6 authored Oct 1, 2021
2 parents c06bd58 + 589aaeb commit cca7d23
Show file tree
Hide file tree
Showing 34 changed files with 1,034 additions and 990 deletions.
22 changes: 22 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[flake8]
max-line-length = 120
max-complexity = 45
ignore =
E203
E225 # missing whitespace around operator
E226 # missing whitespace around arithmetic operator
W503 # line break before binary operator; conflicts with black
W504 # Don't want to change with code frozen...
E722 # bare except ok
E731 # lambda expressions ok
E266 # block comments
E741 # ambiguous variable names
E501 # lines
exclude =
.git
.tox
__pycache__
build
dist
docs/*
.enterprise_extensions/*
6 changes: 3 additions & 3 deletions .github/workflows/ci_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ jobs:
- name: Install dependencies and package
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install flake8 pytest black pytest-cov
python -m pip install flake8 pytest pytest-cov
NO_MKL=1 python -m pip install -e .
- name: Display Python, pip, setuptools, and all installed versions
run: |
python -c "import sys; print(f'Python {sys.version}')"
python -c "import pip; print(f'pip {pip.__version__}')"
python -c "import setuptools; print(f'setuptools {setuptools.__version__}')"
python -m pip freeze
#- name: Run lint
# run: make lint
- name: Run lint
run: make lint
- name: Test with pytest
run: make test
- name: Codecov
Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: "3.7.7"
hooks:
- id: flake8
args: ["--config=.flake8"]
- repo: https://github.com/timothycrosley/isort
rev: 5.6.1
hooks:
- id: isort
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
=======
History
=======
2.3.1 (2021-09-30)
Fix bugs associated with recent function additions. Added linting and mild PEP8
rules. Also removed older Python functionality which is no longer supported.

2.3.0 (2021-09-15)*
Functionality added for NANOGrav 15yr dataset analyses.
Outlier analysis software moved into separate package.
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@ init:
@./.enterprise_extensions/bin/python3 -m pip install -U pip setuptools wheel
@./.enterprise_extensions/bin/python3 -m pip install -r requirements.txt -U
@./.enterprise_extensions/bin/python3 -m pip install -r requirements_dev.txt -U
@./.enterprise_extensions/bin/python3 -m pre_commit install --install-hooks --overwrite
@./.enterprise_extensions/bin/python3 -m pip install -e .
@echo "run source .enterprise_extensions/bin/activate to activate environment"


format:
black .

lint:
black --check .
flake8 .

clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ You can also install it by cloning the repo and running `pip install .` in the `
Did you use `enterprise_extensions`?
Remember to cite it as:

>Taylor, S. R., Baker, P. T., Hazboun, J. S., Simon, J., & Vigeland, S. J. (2021). enterprise_extensions v0.9.2. https://github.com/nanograv/enterprise_extensions
>Taylor, S. R., Baker, P. T., Hazboun, J. S., Simon, J., & Vigeland, S. J. (2021). enterprise_extensions v2.3.1. https://github.com/nanograv/enterprise_extensions
```latex
@misc{enterprise,
author = {Stephen R. Taylor and Paul T. Baker and Jeffrey S. Hazboun and Joseph Simon and Sarah J. Vigeland},
title = {enterprise_extensions},
year = {2021},
url = {https://github.com/nanograv/enterprise_extensions},
note = {v2.2.0}
note = {v2.3.1}
}
```

Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#
import os
import sys

sys.path.insert(0, os.path.abspath('..'))

import enterprise_extensions
Expand Down
2 changes: 1 addition & 1 deletion enterprise_extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.3.0"
__version__ = "2.3.1"
100 changes: 48 additions & 52 deletions enterprise_extensions/blocks.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)
import numpy as np

import types

from enterprise.signals import parameter
from enterprise.signals import selections
from enterprise.signals import white_signals
from enterprise.signals import gp_signals
from enterprise.signals import utils
import numpy as np
from enterprise import constants as const
from enterprise.signals import deterministic_signals
from enterprise.signals import gp_bases as gpb
from enterprise.signals import gp_priors as gpp
from enterprise.signals import deterministic_signals
from enterprise import constants as const
from . import gp_kernels as gpk
from . import chromatic as chrom
from . import model_orfs
from enterprise.signals import (gp_signals, parameter, selections, utils,
white_signals)

from enterprise_extensions import deterministic as ee_deterministic

from . import chromatic as chrom
from . import gp_kernels as gpk
from . import model_orfs

__all__ = ['white_noise_block',
'red_noise_block',
'bwm_block',
'bwm_sglpsr_block'
'bwm_sglpsr_block',
'dm_noise_block',
'scattering_noise_block',
'chromatic_noise_block',
'common_red_noise_block',
]
Expand Down Expand Up @@ -169,7 +165,7 @@ def red_noise_block(psd='powerlaw', prior='log-uniform', Tspan=None,
alpha_adapt = gpp.InvGamma(df/2, df/2, size=1)
nfreq = parameter.Uniform(-0.5, 10-0.5)
pl = gpp.t_process_adapt(log10_A=log10_A, gamma=gamma,
alphas_adapt=alpha_adapt, nfreq=nfreq)
alphas_adapt=alpha_adapt, nfreq=nfreq)
elif psd == 'infinitepower':
pl = gpp.infinitepower()

Expand Down Expand Up @@ -225,6 +221,7 @@ def red_noise_block(psd='powerlaw', prior='log-uniform', Tspan=None,

return rn


def bwm_block(Tmin, Tmax, amp_prior='log-uniform',
skyloc=None, logmin=-18, logmax=-11,
name='bwm'):
Expand Down Expand Up @@ -272,16 +269,16 @@ def bwm_block(Tmin, Tmax, amp_prior='log-uniform',
costh = parameter.Constant(skyloc[0])(costh_name)
phi = parameter.Constant(skyloc[1])(phi_name)


# BWM signal
bwm_wf = ee_deterministic.bwm_delay(log10_h=log10_A_bwm, t0=t0,
cos_gwtheta=costh, gwphi=phi, gwpol=pol)
cos_gwtheta=costh, gwphi=phi, gwpol=pol)
bwm = deterministic_signals.Deterministic(bwm_wf, name=name)

return bwm


def bwm_sglpsr_block(Tmin, Tmax, amp_prior='log-uniform',
logmin=-17, logmax=-12, name='ramp', fixed_sign=None):
logmin=-17, logmax=-12, name='ramp', fixed_sign=None):

if fixed_sign is None:
sign = parameter.Uniform(-1, 1)("sign")
Expand All @@ -297,12 +294,12 @@ def bwm_sglpsr_block(Tmin, Tmax, amp_prior='log-uniform',
t0_name = '{}_t0'.format(name)
t0 = parameter.Uniform(Tmin, Tmax)(t0_name)


ramp_wf = ee_deterministic.bwm_sglpsr_delay(log10_A=log10_A_ramp, t0=t0, sign = sign)
ramp_wf = ee_deterministic.bwm_sglpsr_delay(log10_A=log10_A_ramp, t0=t0, sign=sign)
ramp = deterministic_signals.Deterministic(ramp_wf, name=name)

return ramp


def dm_noise_block(gp_kernel='diag', psd='powerlaw', nondiag_kernel='periodic',
prior='log-uniform', dt=15, df=200,
Tspan=None, components=30,
Expand Down Expand Up @@ -361,15 +358,15 @@ def dm_noise_block(gp_kernel='diag', psd='powerlaw', nondiag_kernel='periodic',
df = 2
alphas_dm = gpp.InvGamma(df/2, df/2, size=components)
dm_prior = gpp.t_process(log10_A=log10_A_dm, gamma=gamma_dm,
alphas=alphas_dm)
alphas=alphas_dm)
elif psd == 'tprocess_adapt':
df = 2
alpha_adapt_dm = gpp.InvGamma(df/2, df/2, size=1)
nfreq_dm = parameter.Uniform(-0.5, 10-0.5)
dm_prior = gpp.t_process_adapt(log10_A=log10_A_dm,
gamma=gamma_dm,
alphas_adapt=alpha_adapt_dm,
nfreq=nfreq_dm)
gamma=gamma_dm,
alphas_adapt=alpha_adapt_dm,
nfreq=nfreq_dm)

if psd == 'spectrum':
if prior == 'uniform':
Expand Down Expand Up @@ -559,14 +556,14 @@ def chromatic_noise_block(gp_kernel='nondiag', psd='powerlaw',
log10_alpha_wgt = parameter.Uniform(-4, 1)

chm_basis = gpk.get_tf_quantization_matrix(df=df, dt=dt*const.day,
dm=True, dm_idx=idx)
dm=True, dm_idx=idx)
chm_prior = gpk.sf_kernel(log10_sigma=log10_sigma,
log10_ell=log10_ell,
log10_alpha_wgt=log10_alpha_wgt,
log10_ell2=log10_ell2)
log10_ell=log10_ell,
log10_alpha_wgt=log10_alpha_wgt,
log10_ell2=log10_ell2)

cgp = gp_signals.BasisGP(chm_prior, chm_basis, name=name+'_gp',
coefficients=coefficients)
coefficients=coefficients)

if include_quadratic:
# quadratic piece
Expand All @@ -580,8 +577,8 @@ def chromatic_noise_block(gp_kernel='nondiag', psd='powerlaw',

def common_red_noise_block(psd='powerlaw', prior='log-uniform',
Tspan=None, components=30,
log10_A_val = None, gamma_val=None, delta_val=None,
logmin = None, logmax = None,
log10_A_val=None, gamma_val=None, delta_val=None,
logmin=None, logmax=None,
orf=None, orf_ifreq=0, leg_lmax=5,
name='gw', coefficients=False,
pshift=False, pseed=None):
Expand Down Expand Up @@ -632,30 +629,29 @@ def common_red_noise_block(psd='powerlaw', prior='log-uniform',
"""


orfs = {'crn': None, 'hd': model_orfs.hd_orf(),
'gw_monopole': model_orfs.gw_monopole_orf(),
'gw_dipole': model_orfs.gw_dipole_orf(),
'st': model_orfs.st_orf(),
'gt': model_orfs.gt_orf(tau = parameter.Uniform(-1.5,1.5)('tau')),
'gt': model_orfs.gt_orf(tau=parameter.Uniform(-1.5, 1.5)('tau')),
'dipole': model_orfs.dipole_orf(),
'monopole': model_orfs.monopole_orf(),
'param_hd': model_orfs.param_hd_orf(a=parameter.Uniform(-1.5,3.0)('gw_orf_param0'),
b=parameter.Uniform(-1.0,0.5)('gw_orf_param1'),
c=parameter.Uniform(-1.0,1.0)('gw_orf_param2')),
'spline_orf': model_orfs.spline_orf(params=parameter.Uniform(-0.9,0.9,size=7)('gw_orf_spline')),
'bin_orf': model_orfs.bin_orf(params=parameter.Uniform(-1.0,1.0,size=7)('gw_orf_bin')),
'param_hd': model_orfs.param_hd_orf(a=parameter.Uniform(-1.5, 3.0)('gw_orf_param0'),
b=parameter.Uniform(-1.0, 0.5)('gw_orf_param1'),
c=parameter.Uniform(-1.0, 1.0)('gw_orf_param2')),
'spline_orf': model_orfs.spline_orf(params=parameter.Uniform(-0.9, 0.9, size=7)('gw_orf_spline')),
'bin_orf': model_orfs.bin_orf(params=parameter.Uniform(-1.0, 1.0, size=7)('gw_orf_bin')),
'zero_diag_hd': model_orfs.zero_diag_hd(),
'zero_diag_bin_orf': model_orfs.zero_diag_bin_orf(params=parameter.Uniform(
-1.0,1.0,size=7)('gw_orf_bin_zero_diag')),
'freq_hd': model_orfs.freq_hd(params=[components,orf_ifreq]),
-1.0, 1.0, size=7)('gw_orf_bin_zero_diag')),
'freq_hd': model_orfs.freq_hd(params=[components, orf_ifreq]),
'legendre_orf': model_orfs.legendre_orf(params=parameter.Uniform(
-1.0,1.0,size=leg_lmax+1)('gw_orf_legendre')),
-1.0, 1.0, size=leg_lmax+1)('gw_orf_legendre')),
'zero_diag_legendre_orf': model_orfs.zero_diag_legendre_orf(params=parameter.Uniform(
-1.0,1.0,size=leg_lmax+1)('gw_orf_legendre_zero_diag'))}
-1.0, 1.0, size=leg_lmax+1)('gw_orf_legendre_zero_diag'))}

# common red noise parameters
if psd in ['powerlaw', 'turnover', 'turnover_knee','broken_powerlaw']:
if psd in ['powerlaw', 'turnover', 'turnover_knee', 'broken_powerlaw']:
amp_name = '{}_log10_A'.format(name)
if log10_A_val is not None:
log10_Agw = parameter.Constant(log10_A_val)(amp_name)
Expand Down Expand Up @@ -724,8 +720,8 @@ def common_red_noise_block(psd='powerlaw', prior='log-uniform',
delta_gw = parameter.Uniform(-2, 0)(delta_name)
lfk_gw = parameter.Uniform(-8, -7)(lfk_name)
cpl = gpp.turnover_knee(log10_A=log10_Agw, gamma=gamma_gw,
lfb=lfb_gw, lfk=lfk_gw,
kappa=kappa_gw, delta=delta_gw)
lfb=lfb_gw, lfk=lfk_gw,
kappa=kappa_gw, delta=delta_gw)

if psd == 'spectrum':
rho_name = '{}_log10_rho'.format(name)
Expand All @@ -744,14 +740,14 @@ def common_red_noise_block(psd='powerlaw', prior='log-uniform',
elif orf in orfs.keys():
if orf == 'crn':
crn = gp_signals.FourierBasisGP(cpl, coefficients=coefficients,
components=components, Tspan=Tspan,
name=name, pshift=pshift, pseed=pseed)
components=components, Tspan=Tspan,
name=name, pshift=pshift, pseed=pseed)
else:
crn = gp_signals.FourierBasisCommonGP(cpl, orfs[orf],
components=components,
Tspan=Tspan,
name=name, pshift=pshift,
pseed=pseed)
components=components,
Tspan=Tspan,
name=name, pshift=pshift,
pseed=pseed)
elif isinstance(orf, types.FunctionType):
crn = gp_signals.FourierBasisCommonGP(cpl, orf,
components=components,
Expand Down
4 changes: 1 addition & 3 deletions enterprise_extensions/chromatic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division,
print_function, unicode_literals)

from .chromatic import *
from .chromatic import * # noqa: F401, F403
Loading

0 comments on commit cca7d23

Please sign in to comment.