Skip to content

Commit

Permalink
Editing utils.py to patch py27 functionality (#193)
Browse files Browse the repository at this point in the history
* adding ability to have user-defined modes in CommonGP

* fixing lint issues

* adding dynamic partial files

* adding code for dynamic BayesEphem

* fixing ephemeris tests

* fixing ephemeris tests

* fixing ephemeris tests

* fixing to allow py27 support

* running travis tests on py2 and py3

* changing numpy requirements

* changing python requirements

* patching to avoid crashing when python2 is used with gp coefficients

* final lint corrections
  • Loading branch information
stevertaylor authored May 30, 2019
1 parent b6808ad commit 1a1c9d9
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 199 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: python
cache: pip

python:
- "2.7.15"
- "3.6"

before_install:
Expand Down
21 changes: 16 additions & 5 deletions enterprise/signals/gp_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import math
import itertools
import functools
import platform
import logging

import numpy as np

Expand All @@ -21,6 +23,12 @@
from enterprise.signals.selections import Selection
from enterprise.signals.utils import KernelMatrix

pyv3 = platform.python_version().split('.')[0] == '3'

logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)


def BasisGP(priorFunction, basisFunction, coefficients=False, combine=True,
selection=Selection(selections.no_selection),
Expand All @@ -39,6 +47,9 @@ def __init__(self, psr):
self.name = self.psrname + '_' + self.signal_id
self._do_selection(psr, priorFunction, basisFunction,
coefficients, selection)
if coefficients and not pyv3:
msg = 'GP coefficients compatible only with Python 3'
logger.warning(msg)

def _do_selection(self, psr, priorfn, basisfn, coefficients,
selection):
Expand All @@ -60,7 +71,7 @@ def _do_selection(self, psr, priorfn, basisfn, coefficients,
self._bases[key]._params.values()):
self._params[par.name] = par

if coefficients:
if coefficients and pyv3:
# we can only create GPCoefficients parameters if the basis
# can be constructed with default arguments
# (and does not change size)
Expand Down Expand Up @@ -116,7 +127,7 @@ def _construct_basis(self, params={}):
# this class does different things (and gets different method
# definitions) if the user wants it to model GP coefficients
# (e.g., for a hierarchical likelihood) or if they do not
if coefficients:
if coefficients and pyv3:
def _get_coefficient_logprior(self, key, c, **params):
self._construct_basis(params)

Expand Down Expand Up @@ -230,7 +241,7 @@ class TimingModel(BaseClass):
signal_name = 'linear timing model'
signal_id = name + '_svd' if use_svd else name

if coefficients:
if coefficients and pyv3:
def _get_coefficient_logprior(self, key, c, **params):
# MV: probably better to avoid this altogether
# than to use 1e40 as in get_phi
Expand Down Expand Up @@ -296,7 +307,7 @@ def __init__(self, psr):

self._psrpos = psr.pos

if coefficients:
if coefficients and pyv3:
self._construct_basis()

chain = itertools.chain(self._prior._params.values(),
Expand Down Expand Up @@ -326,7 +337,7 @@ def basis_params(self):
def _construct_basis(self, params={}):
self._basis, self._labels = self._bases(params=params)

if coefficients:
if coefficients and pyv3:
def _get_coefficient_logprior(self, c, **params):
# MV: for correlated GPs, the prior needs to use
# the coefficients for all GPs together;
Expand Down
7 changes: 6 additions & 1 deletion enterprise/signals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,13 @@ def createfourierdesignmatrix_physicalephem(toas, planetssb, pos_t,
c = np.zeros(6)
c[i] = dpar

#Fl.append(physical_ephem_delay(toas, planetssb, pos_t,
# **{parname: c}, **oa)/dpar)
kwarg_dict = {parname: c}
kwarg_dict.update(oa)
Fl.append(physical_ephem_delay(toas, planetssb, pos_t,
**{parname: c}, **oa)/dpar)
**kwarg_dict)/dpar)

Phil.append(ppar)

return np.array(Fl).T.copy(), np.array(Phil)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy==1.16.0
numpy==1.16.3
scipy==1.2.0
ephem>=3.7.6.0
Cython==0.28.5
Expand Down
Loading

0 comments on commit 1a1c9d9

Please sign in to comment.