Skip to content

Commit

Permalink
Merge pull request #33 from pllim/pr26-follow-up
Browse files Browse the repository at this point in the history
Clean up PR 26 etc
  • Loading branch information
pllim authored Nov 24, 2020
2 parents c6cdd65 + e94d964 commit c8b64ef
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 183 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ jobs:
python -m pip install --upgrade pip setuptools
python -m pip install 'numpy<1.19'
python -m pip install -e .[test,all]
- name: Test without optional deps
run: pytest --open-files --remote-data
- name: Test with stable deps and coverage
run: pytest --cov=./ --cov-report=xml --open-files --remote-data
- name: Coverage report
uses: codecov/codecov-action@v1

dev_deps_tests:
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
exovetter: Exoplanet Vetting
----------------------------
============================

.. image:: https://readthedocs.org/projects/exovetter/badge/?version=latest
:target: https://exovetter.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://github.com/spacetelescope/exovetter/workflows/CI/badge.svg
:target: https://github.com/spacetelescope/exovetter/actions
:alt: Github Actions CI Status

.. image:: https://codecov.io/gh/spacetelescope/exovetter/branch/master/graph/badge.svg?token=H3UC4Q0H6R
:target: https://codecov.io/gh/spacetelescope/exovetter
:alt: Coverage report

.. image:: http://img.shields.io/badge/powered%20by-AstroPy-orange.svg?style=flat
:target: http://www.astropy.org
:alt: Powered by Astropy Badge
Expand Down
7 changes: 7 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ Reference/API

.. automodapi:: exovetter.transit_coverage
:no-inheritance-diagram:

.. automodapi:: exovetter.model
:no-inheritance-diagram:

.. automodapi:: exovetter.const
:no-inheritance-diagram:
:include-all-objects:
24 changes: 20 additions & 4 deletions exovetter/const.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
"""Constants and units for exoplanet vetting."""

import astropy.units as u

"""
Useful constants for exoplanet vetting
"""
__all__ = ['bjd', 'bkjd', 'btjd', 'bet', 'ppk', 'ppm', 'frac_amp']

# TODO: Improve docstrings

# Time offset constants

bjd = 0 * u.day
"""BJD"""

bkjd = bjd - 2_454_833 * u.day
"""BKJD"""

btjd = bjd - 2_457_000 * u.day
bet = bjd - 2_451_544.5 * u.day # Barycentric Emphemeris time
"""BTJD"""

bet = bjd - 2_451_544.5 * u.day
"""Barycentric Emphemeris Time (BET)"""

# Handy units to express depth

ppk = 1e-3 * u.dimensionless_unscaled
"""PPK"""

ppm = 1e-3 * ppk
"""PPM"""

frac_amp = u.dimensionless_unscaled
"""Frac amp"""
22 changes: 13 additions & 9 deletions exovetter/lpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import warnings

import numpy as np
from astropy import units as u
from astropy.utils.data import download_file, _is_url
from scipy import io as spio

__all__ = ['compute_lpp_Transitmetric', 'runningMedian', 'foldBinLightCurve',
'computeRawLPPTransitMetric', 'knnDistance_fromKnown',
Expand Down Expand Up @@ -345,16 +348,21 @@ def __init__(self, tce, lc, lc_name="flux", default_snr=10.):

self.check_tce(tce, default_snr)

self.tzero = tce['tzero']
self.dur = tce['duration']
self.period = tce['period']
# FIXME: This looks more correct but fails the test.
# from exovetter import const as exo_const
# self.tzero = tce.get_epoch(
# getattr(exo_const, lc.time_format)).to_value(u.day)

self.tzero = tce['epoch'].to_value(u.day)
self.dur = tce['duration'].to_value(u.hr)
self.period = tce['period'].to_value(u.day)

self.mes = default_snr
if 'snr' in tce.keys():
self.mes = tce['snr']

self.time = lc.time
self.flux = lc.__dict__[lc_name] # TODO: Use getattr?
self.flux = getattr(lc, lc_name)

# make sure flux is zero norm.
if np.round(np.median(self.flux)) != 0:
Expand Down Expand Up @@ -387,13 +395,9 @@ class Loadmap:
If URL is provided, it will be cached using :ref:`astropy:utils-data`
"""
builtin_mat = 'https://stsci.box.com/s/s2jup12rcjn05qll598h33bwycjeym8x'
# builtin_mat = 'https://sourceforge.net/p/lpptransitlikemetric/code/HEAD/tree/data/maps/combMapDR25AugustMapDV_6574.mat?format=raw' # noqa: E501
builtin_mat = 'https://stsci.box.com/shared/static/1ffi1t1fhae82d7xeqexw4ymlhlk0ov4.mat' # noqa

def __init__(self, filename=None):
from astropy.utils.data import download_file, _is_url
from scipy import io as spio

if filename is None:
filename = self.builtin_mat

Expand Down
92 changes: 80 additions & 12 deletions exovetter/model.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
# -*- coding: utf-8 -*-
"""
Repository of transit models.
"""Module to handle transit models.
Available models:
* Boxcar
* Trapezoid (to be added in the future)
Currently, only the box car model is implemented, need a
trapezoid model here too.
Developer notes
===============
For each model type, create 2 functions:
1. ``create_<modelname>_model_for_tce``: Takes a TCE as input.
2. ``create_<modelname>``: Takes more fundamental times
(e.g., numpy arrays, floats).
For each model type create 2 functions, one that takes a TCE as input,
and one that takes more fundamental times (numpy arrays, floats, etc.)
"""
# TODO: See https://github.com/spacetelescope/exovetter/issues/32
# FIXME: Improve docstrings.

import astropy.units as u
import numpy as np
from astropy import units as u

__all__ = ['create_box_model_for_tce', 'create_box_model']


def create_box_model_for_tce(tce, times, time_offset):
"""Create boxcar model for a given TCE.
Parameters
----------
tce : `~exovetter.tce.Tce`
Threshold Crossing Event.
times : `~astropy.units.Quantity`
Times.
time_offset : `~astropy.units.Quantity`
Time offset for :meth:`exovetter.tce.Tce.get_epoch`.
Returns
-------
flux : `~astropy.units.Quantity`
Flux from boxcar model.
Raises
------
ValueError
Invalid input.
See also
--------
create_box_model
"""
if not tce.validate():
raise ValueError("Required quantities missing from TCE")

Expand All @@ -35,22 +74,51 @@ def create_box_model_for_tce(tce, times, time_offset):


def create_box_model(times, period, epoch, duration, depth):
"""Create boxcar model.
Parameters
----------
times : array
Times.
period : float
Period.
epoch : float
Epoch.
duration : float
Duration.
depth : `~astropy.units.Quantity`
Depth.
Returns
-------
flux : `~astropy.units.Quantity`
Flux from boxcar model, in the same unit as ``depth``.
See also
--------
create_box_model_for_tce
"""
# Make epoch the start of the transit, not the midpoint
epoch -= duration / 2.0
epoch -= duration * 0.5

mnT = np.min(times)
mxT = np.max(times)

e0 = int(np.floor((mnT - epoch) / period))
e1 = int(np.floor((mxT - epoch) / period))

flux = 0.0 * times
flux = np.zeros_like(times)
depth_values = depth.to_value()
for i in range(e0, e1 + 1):
t0 = period * i + epoch
t1 = t0 + duration
# print(i, t0, t1)

idx = (t0 <= times) & (times <= t1)
flux[idx] -= depth.to_value()
flux[idx] -= depth_values

return flux * depth.unit
Loading

0 comments on commit c8b64ef

Please sign in to comment.