Skip to content

Commit

Permalink
📝 updating docs
Browse files Browse the repository at this point in the history
  • Loading branch information
christinahedges committed Nov 2, 2021
1 parent 7c8f217 commit 0c21244
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .flake8
@@ -0,0 +1,6 @@
[flake8]
max-line-length = 127
max-complexity = 20
count = True
show-source = True
extend-ignore = E203, E741
Binary file modified demo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/epic210957318.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/epic220256496.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/kic5391911.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/kic5866724.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tic13023738.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tic293435336.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "vetting"
version = "0.1.8"
version = "0.1.9"
description = "Simple, stand-alone vetting tools for transiting signals in Keper, K2 and TESS data"
authors = ["Christina Hedges <christina.l.hedges@nasa.gov>"]
license = "MIT"
Expand Down
3 changes: 3 additions & 0 deletions src/vetting/__init__.py
@@ -1,7 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os

from .centroiding import centroid_test

PACKAGEDIR = os.path.abspath(os.path.dirname(__file__))

__all__ = ["centroid_test"]
35 changes: 20 additions & 15 deletions src/vetting/centroiding.py
@@ -1,11 +1,10 @@
import numpy as np
import matplotlib.pyplot as plt
from astropy.convolution import convolve, Gaussian1DKernel
import astropy.units as u
import corner
import lightkurve as lk

import matplotlib.pyplot as plt
import numpy as np
from astropy.convolution import Gaussian1DKernel, convolve
from scipy.stats import ttest_ind
import corner


def _label(tpf):
Expand Down Expand Up @@ -81,8 +80,8 @@ def centroid_test(
r : dict
Dictionary of results, containing 'figs' (a list of matplotlib figures) and 'pvalues', which is a list of tuples.
Each tuple contains the p-value for the input planets. There are as many tuples as input TPFs.
"""

if isinstance(tpfs, lk.targetpixelfile.TargetPixelFile):
tpfs = [tpfs]
if isinstance(tpfs, lk.collections.TargetPixelFileCollection):
Expand Down Expand Up @@ -118,7 +117,6 @@ def centroid_test(
for key in ["1sigma_error"]:
r[key] = []

offsets = np.logspace(-6, np.log10(3), 100)[::-1]
for tpf in tpfs:
if tpf.mission.lower() in ["kepler", "ktwo", "k2"]:
pixel_scale = 4
Expand All @@ -133,7 +131,8 @@ def centroid_test(
if crwd is not None:
if crwd < 0.8:
raise ValueError(
f"Aperture is significantly crowded (CROWDSAP = {crwd}). This method will not work to centroid these cases."
f"Aperture is significantly crowded (CROWDSAP = {crwd}). "
"This method will not work to centroid these cases."
)

aper = tpf._parse_aperture_mask(aperture_mask)
Expand Down Expand Up @@ -167,7 +166,6 @@ def centroid_test(
ycent = np.average(Y, weights=fe, axis=1)
xcent = np.asarray([np.nanmean(xcent, axis=1), np.nanstd(xcent, axis=1)]).T
ycent = np.asarray([np.nanmean(ycent, axis=1), np.nanstd(ycent, axis=1)]).T
import pdb

# If the mission is K2, we need to use SFF to detrend the centroids.
if tpf.mission.lower() in ["ktwo", "k2"]:
Expand Down Expand Up @@ -266,13 +264,23 @@ def centroid_test(
with plt.style.context("seaborn-white"):
xc1 = (xcent[:, 0][k1] - xtr[k1]) * scale
yc1 = (ycent[:, 0][k1] - ytr[k1]) * scale

xrange = np.nanpercentile(xc1, (1, 99))
dx = np.diff(xrange) / 100
xrange[0] -= dx * 15
xrange[1] += dx * 15
yrange = np.nanpercentile(yc1, (1, 99))
dy = np.diff(yrange) / 100
yrange[0] -= dy * 15
yrange[1] += dy * 15

corner.hist2d(
xc1,
yc1,
ax=axs[idx],
range=[
np.nanpercentile(xc1, (1, 99)),
np.nanpercentile(yc1, (1, 99)),
xrange,
yrange,
],
)
axs[idx].errorbar(
Expand All @@ -283,7 +291,7 @@ def centroid_test(
marker=".",
markersize=1,
c=f"C{idx}",
lw=1,
lw=0.5,
ls="",
label=f"Transit {labels[idx]} Cadences",
)
Expand All @@ -304,10 +312,7 @@ def centroid_test(
a2 = weighted_average(xcent[k2, 0] - xtr[k2], 1 / xcent[k2, 1])
b2 = weighted_average(ycent[k2, 0] - ytr[k2], 1 / ycent[k2, 1])
pos_err = np.hypot(np.hypot(a1[1], b1[1]), np.hypot(a2[1], b2[1]))

if transit_depths is not None:
sigma1.append(pixel_scale * pos_err / transit_depths[idx])

if k2.sum() == 0:
pvalue = 1
else:
Expand Down
Binary file added src/vetting/demo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/vetting/version.py
@@ -1,3 +1,3 @@
# It is important to store the version number in a separate file
# so that we can read it from setup.py without importing the package
__version__ = "0.1.8"
__version__ = "0.1.9"
94 changes: 87 additions & 7 deletions tests/test_centroids.py
@@ -1,25 +1,35 @@
import pytest
import os
import matplotlib.pyplot as plt

import lightkurve as lk
import matplotlib.pyplot as plt
import pytest
import numpy as np

from vetting import centroid_test
from vetting import PACKAGEDIR

testdir = "/".join(PACKAGEDIR.split("/")[:-2])

lib_path = os.getcwd()
tpf = lk.KeplerTargetPixelFile(
f"{lib_path}/tests/data/kplr005562784-2011271113734_lpd-targ.fits.gz"
)

def is_action():
try:
return os.environ["GITHUB_ACTIONS"]
except KeyError:
return False


def test_centroid_test():
tpf = lk.KeplerTargetPixelFile(
f"{testdir}/tests/data/kplr005562784-2011271113734_lpd-targ.fits.gz"
)
period, t0, dur = 25.3368592, 192.91552, 8.85 / 24
r = centroid_test(tpf, period, t0, dur, aperture_mask="pipeline", plot=False)
assert r["pvalues"][0][0] < 0.01
assert len(r["pvalues"][0]) == 1

r = centroid_test(tpf, period, t0, dur, aperture_mask="pipeline", plot=True)
assert len(r["figs"]) == 1
r["figs"][0].savefig(f"{lib_path}/demo.png", dpi=200, bbox_inches="tight")
r["figs"][0].savefig(f"{PACKAGEDIR}/demo.png", dpi=200, bbox_inches="tight")

r = centroid_test(
tpf,
Expand Down Expand Up @@ -70,3 +80,73 @@ def test_centroid_test():
transit_depths=0.001499,
labels="c",
)


@pytest.mark.skipif(
is_action(),
reason="Can not run on GitHub actions, because it's a pain to download.",
)
def test_FPs():
"""Produce some figures that show centroid offsets"""
names = [
"KIC 5391911",
"KIC 5866724",
"EPIC 220256496",
"EPIC 210957318",
"TIC 293435336",
"TIC 13023738",
]
kwargs = [
{"quarter": 3},
{"quarter": 3},
{"campaign": 8},
{"campaign": 4},
{},
{"sector": 2},
]

periods = [0.782068488, 2.154911236, 0.669558, 4.098503000, 1.809886, 8.0635]
t0s = [
131.8940201,
133.498613,
2457393.81364 - 2454833,
2457063.80710000 - 2454833,
2456107.85507 - 2457000,
2459104.87232 - 2457000,
]
durs = np.asarray([1.239, 3.1341, 1, 2.3208, 3.694, 3.396]) / 24
depths = [
0.01157 * 0.01,
0.00850 * 0.01,
0.015450 ** 2,
1.603 * 0.01,
1.189 * 0.01,
5180 * 1e-6,
]

for name, period, t0, dur, kwarg, depth in zip(
names, periods, t0s, durs, kwargs, depths
):
tpf = lk.search_targetpixelfile(name, **kwarg).download()
r = centroid_test(
tpf,
period,
t0,
dur,
aperture_mask="pipeline",
plot=True,
transit_depths=depth,
)
r["figs"][0].savefig(
f"{testdir}/docs/{name.replace(' ','').lower()}.png",
dpi=200,
bbox_inches="tight",
)
# nb = int(1 // np.median(np.diff(tpf.time.value)))
# nb = [nb if nb % 2 == 1 else nb + 1][0]
# ax = tpf.to_lightcurve().flatten(nb).fold(period, t0).bin(period / 200).plot()
# plt.savefig(
# f"{testdir}/docs/{name.replace(' ','').lower()}_lc.png",
# dpi=200,
# bbox_inches="tight",
# )

0 comments on commit 0c21244

Please sign in to comment.