Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
include README.md LICENSE
include tessreduce/tess_straps.csv
include tessreduce/calspec_mags.npy
include tessreduce/Tonry_splines.txt
include tessreduce/SMspline.txt
include tessreduce/sector_mjd.csv
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![DOI](https://img.shields.io/badge/DOI-10.3847%2F1538--3881%2Fac2c2e-blue.svg)](https://doi.org/10.3847/1538-3881/ac2c2e)

![plot](./figs/header.png)
![plot](https://raw.githubusercontent.com/CheerfulUser/TESSreduce/main/figs/header.png)

With this package that builds on lightkurve, you can reduce TESS data while preserving transient signals. You can supply a TPF or give coordinates and sector to construct a TPF with TESScut. The background subtraction accounts for the smooth background and
detector straps. Alongisde background subtraction TESSreduce also aligns images, performs difference imaging, and can even detect transient events!
Expand All @@ -29,7 +29,7 @@ obs = tr.sn_lookup('sn2018fub')
```python
tess = tr.tessreduce(obs_list=obs)
```
![plot](./figs/fub.png)
![plot](https://raw.githubusercontent.com/CheerfulUser/TESSreduce/main/figs/fub.png)

**OR**
```python
Expand Down Expand Up @@ -75,7 +75,7 @@ Several options are available for flux and are interchangeable, however, mag is
```python
tess.plotter()
```
![plot](./figs/fub_cal.png)
![plot](https://raw.githubusercontent.com/CheerfulUser/TESSreduce/main/figs/fub_cal.png)


# Extracting key variables
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
'sep',
'tqdm',
'alerce',
'tess-point',
'tesswcs>=1.8',
'tabulate',
'TESS_PRF']

Expand Down Expand Up @@ -137,9 +137,11 @@ def run(self):
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy'
],
# $ setup.py publish support.
cmdclass={
Expand Down
1 change: 0 additions & 1 deletion tessreduce/#__init__.py#

This file was deleted.

88 changes: 71 additions & 17 deletions tessreduce/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from photutils.detection import StarFinder

from PRF import TESS_PRF
from tess_stars2px import tess_stars2px_function_entry as focal_plane
import tesswcs
from tabulate import tabulate

package_directory = os.path.dirname(os.path.abspath(__file__)) + '/'
Expand Down Expand Up @@ -520,6 +520,62 @@ def grad_flux_rad(flux):
return rad


def _tess_pointing_table():
"""
Sector start/end times (MJD), sourced from tesswcs.pointings so the table
stays current with tesswcs releases rather than a file pinned in this repo.

Returns
-------
sec_times : pd.DataFrame
Indexed by Sector, with mjd_start and mjd_end columns.
"""
pointings = tesswcs.pointings.to_pandas()[['Sector','Start','End']]
pointings = pointings.rename(columns={'Start':'mjd_start','End':'mjd_end'})
pointings['mjd_start'] = Time(pointings['mjd_start'].values,format='jd').mjd
pointings['mjd_end'] = Time(pointings['mjd_end'].values,format='jd').mjd
return pointings.set_index('Sector').sort_index()


def _target_sectors(ra,dec):
"""
Find which TESS sectors, cameras and CCDs observe a given coordinate.
Replaces tess_stars2px_function_entry (tess-point) with tesswcs, which
covers both archived and predicted sector pointings.

Returns
-------
outSecs, outCam, outCcd, outColPix, outRowPix : np.array
Sector number, camera, CCD, and pixel column/row for each match,
sorted by sector.
"""
import logging
coord = SkyCoord(ra,dec,unit='deg')

level = tesswcs.log.level
tesswcs.log.setLevel(logging.ERROR)
secs, cams, ccds, cols, rows = [], [], [], [], []
try:
for sector in tesswcs.pointings['Sector']:
sector = int(sector)
for camera in range(1,5):
for ccd in range(1,5):
try:
wcs = tesswcs.WCS.from_sector(sector,camera,ccd)
except ValueError:
continue
if wcs.footprint_contains(coord):
col, row = wcs.world_to_pixel(coord)
secs += [sector]; cams += [camera]; ccds += [ccd]
cols += [float(col)]; rows += [float(row)]
finally:
tesswcs.log.setLevel(level)

order = np.argsort(secs)
return (np.array(secs)[order], np.array(cams)[order], np.array(ccds)[order],
np.array(cols)[order], np.array(rows)[order])


def sn_lookup(name,time='disc',buffer=0,print_table=True, df = False):
"""
Check for overlapping TESS ovservations for a transient. Uses the Open SNe Catalog for
Expand Down Expand Up @@ -589,16 +645,15 @@ def sn_lookup(name,time='disc',buffer=0,print_table=True, df = False):
ra = c.ra.deg
dec = c.dec.deg

outID, outEclipLong, outEclipLat, outSecs, outCam, outCcd, outColPix, \
outRowPix, scinfo = focal_plane(0, ra, dec)

sec_times = pd.read_csv(package_directory + 'sector_mjd.csv')
if len(outSecs) > 0:
ind = outSecs - 1
outSecs, outCam, outCcd, outColPix, outRowPix = _target_sectors(ra, dec)

new_ind = [i for i in ind if i < len(sec_times)]
sec_times = _tess_pointing_table()
if len(outSecs) > 0:
keep = np.isin(outSecs, sec_times.index)
outSecs, outCam, outCcd, outColPix, outRowPix = \
outSecs[keep], outCam[keep], outCcd[keep], outColPix[keep], outRowPix[keep]

secs = sec_times.iloc[new_ind]
secs = sec_times.loc[outSecs].reset_index()
if type(time) == str:
if (time.lower() == 'disc') | (time.lower() == 'discovery'):
disc_start = secs['mjd_start'].values - disc_t.mjd
Expand Down Expand Up @@ -679,16 +734,15 @@ def spacetime_lookup(ra,dec,time=None,buffer=0,print_table=True, df = False, pri
ra = c.ra.deg
dec = c.dec.deg

outID, outEclipLong, outEclipLat, outSecs, outCam, outCcd, outColPix, \
outRowPix, scinfo = focal_plane(0, ra, dec)

sec_times = pd.read_csv(package_directory + 'sector_mjd.csv')
if len(outSecs) > 0:
ind = outSecs - 1
outSecs, outCam, outCcd, outColPix, outRowPix = _target_sectors(ra, dec)

new_ind = [i for i in ind if i < len(sec_times)]
sec_times = _tess_pointing_table()
if len(outSecs) > 0:
keep = np.isin(outSecs, sec_times.index)
outSecs, outCam, outCcd, outColPix, outRowPix = \
outSecs[keep], outCam[keep], outCcd[keep], outColPix[keep], outRowPix[keep]

secs = sec_times.iloc[new_ind]
secs = sec_times.loc[outSecs].reset_index()
disc_start = secs['mjd_start'].values - time
disc_end = secs['mjd_end'].values - time

Expand Down
108 changes: 0 additions & 108 deletions tessreduce/sector_mjd.csv

This file was deleted.

2 changes: 0 additions & 2 deletions tessreduce/web path

This file was deleted.

40 changes: 40 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
smooth_zp,
Smooth_bkg,
regional_stats_mask,
_tess_pointing_table,
_target_sectors,
)


Expand Down Expand Up @@ -315,5 +317,43 @@ def test_outlier_masked(self):
self.assertTrue(mask[15, 15])


class TestTessPointingTable(unittest.TestCase):

def test_indexed_by_sector_with_expected_columns(self):
table = _tess_pointing_table()
self.assertEqual(table.index.name, 'Sector')
self.assertIn('mjd_start', table.columns)
self.assertIn('mjd_end', table.columns)

def test_end_after_start(self):
table = _tess_pointing_table()
self.assertTrue((table['mjd_end'] > table['mjd_start']).all())

def test_known_sector_one_start_time(self):
# Sector 1 start is 2018-07-25 19:00 UT, JD 2458324.5 -> MJD 58324.0
table = _tess_pointing_table()
self.assertAlmostEqual(table.loc[1, 'mjd_start'], 58324.0, places=3)


class TestTargetSectors(unittest.TestCase):

def test_known_target_returns_expected_sectors(self):
# Reference target cross-checked against tess_stars2px_function_entry
# (tess-point) output: sectors 2, 29, 69, 96, 103, 104, 105, 106.
outSecs, outCam, outCcd, outColPix, outRowPix = _target_sectors(10.127, -50.687)
expected = {2, 29, 69, 96, 103, 104, 105, 106}
self.assertTrue(expected.issubset(set(outSecs.tolist())))

def test_arrays_aligned_and_sorted(self):
outSecs, outCam, outCcd, outColPix, outRowPix = _target_sectors(10.127, -50.687)
lengths = {len(outSecs), len(outCam), len(outCcd), len(outColPix), len(outRowPix)}
self.assertEqual(len(lengths), 1)
assert_array_equal(outSecs, np.sort(outSecs))

def test_pixel_coordinates_within_ccd_bounds(self):
outSecs, outCam, outCcd, outColPix, outRowPix = _target_sectors(10.127, -50.687)
self.assertTrue(np.all((outColPix >= 0) & (outColPix <= 2136)))
self.assertTrue(np.all((outRowPix >= 0) & (outRowPix <= 2078)))

if __name__ == '__main__':
unittest.main()
Loading