Skip to content

Commit

Permalink
Merge pull request #8 from jorgemarpa/locator-cloud-rearange
Browse files Browse the repository at this point in the history
Removing `tess-cloud` dependency to make `tess-locator` simpler
  • Loading branch information
jorgemarpa authored Dec 8, 2023
2 parents add23e2 + daba0ce commit 56a9641
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
max-line-length = 127
max-complexity = 13
max-complexity = 15
count = True
show-source = True
extend-ignore = E203, W503
Expand Down
18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tess-locator"
version = "0.6.dev"
version = "0.6.0"
description = "Fast offline queries of TESS FFI positions and filenames."
license = "MIT"
authors = ["Geert Barentsen <[email protected]>",
Expand All @@ -16,14 +16,14 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.7"
astropy = ">= 4.0"
pandas = ">= 1.0"
numpy = ">= 1.19"
tqdm = ">= 4.51"
attrs = ">= 20.3.0"
tess-point = ">= 0.6.1"
tess-cloud = ">=0.3.1"
python = "^3.8"
astropy = "^5.2.0"
pandas = "^1.4.4"
numpy = "^1.23.0"
tqdm = "^4.51.1"
attrs = "^23.1.0"
tess-point = "^0.8"
# tess-cloud = "^0.5"

[tool.poetry.dev-dependencies]
pytest = "^6.0"
Expand Down
2 changes: 1 addition & 1 deletion src/tess_locator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
import tess_stars2px # provided by the `tess-point` package

__version__ = "0.6.dev"
__version__ = "0.6.0"

# Where does this package store its embedded data?
PACKAGEDIR: Path = Path(__file__).parent.absolute()
Expand Down
34 changes: 21 additions & 13 deletions src/tess_locator/locate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,27 @@ def locate(
dec = np.atleast_1d(target.dec.to("deg").value)
result = []
for idx in range(len(ra)):
(
_,
_,
_,
out_sector,
out_camera,
out_ccd,
out_col,
out_row,
scinfo,
) = tess_stars2px_function_entry(
0, ra[idx], dec[idx], trySector=sectors_to_search[idx], aberrate=aberrate
)
# tess_stars2px_function_entry will exit with SystemExit: 1 if trySector < 0
try:
(
_,
_,
_,
out_sector,
out_camera,
out_ccd,
out_col,
out_row,
scinfo,
) = tess_stars2px_function_entry(
0,
ra[idx],
dec[idx],
trySector=sectors_to_search[idx],
aberrate=aberrate,
)
except SystemExit:
continue

for idx_out in range(len(out_sector)):
if out_sector[idx_out] < 0:
Expand Down
119 changes: 60 additions & 59 deletions src/tess_locator/tesscoord.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Defines the TessCoord and TessCoordList classes."""
from collections import UserList
from typing import Union, Optional

# from typing import Union, Optional

import attr
import numpy as np
Expand Down Expand Up @@ -79,41 +80,41 @@ def to_skycoord(self) -> SkyCoord:
crd.obstime = self.time
return crd

def is_observed(self) -> bool:
"""Returns true if this coordinate has been observed."""
return len(self.list_images()) > 0

def list_images(
self,
time: Union[str, Time] = None,
author: str = "spoc",
provider: Optional[str] = None,
):
"""Returns a `TessImageList` detailing the FFI images which include the coordinate.
Parameters
----------
author : str
"spoc" or "tica"
Notes
-----
This feature will use the `tess-cloud` package to query a catalog of
TESS images.
"""
# local import to avoid circular dependency
from tess_cloud import list_images

if time is None:
time = self.time
return list_images(
sector=self.sector,
camera=self.camera,
ccd=self.ccd,
time=time,
author=author,
provider=provider,
)
# def is_observed(self) -> bool:
# """Returns true if this coordinate has been observed."""
# return len(self.list_images()) > 0

# def list_images(
# self,
# time: Union[str, Time] = None,
# author: str = "spoc",
# provider: Optional[str] = None,
# ):
# """Returns a `TessImageList` detailing the FFI images which include the coordinate.
#
# Parameters
# ----------
# author : str
# "spoc" or "tica"
#
# Notes
# -----
# This feature will use the `tess-cloud` package to query a catalog of
# TESS images.
# """
# # local import to avoid circular dependency
# from tess_cloud import list_images
#
# if time is None:
# time = self.time
# return list_images(
# sector=self.sector,
# camera=self.camera,
# ccd=self.ccd,
# time=time,
# author=author,
# provider=provider,
# )


class TessCoordList(UserList):
Expand All @@ -134,29 +135,29 @@ def __eq__(self, obj):
obj.to_pandas()
)

def list_images(
self,
time: Union[str, Time] = None,
author: str = "spoc",
provider: Optional[str] = None,
):
"""Returns a `TessImageList` detailing the FFI images which include the coordinates.
Parameters
----------
author : str
"spoc" or "tica"
"""
# local import to avoid circular dependency
from tess_cloud import TessImageList

if len(self) == 0:
return TessImageList([])

result = self[0].list_images(time=time, author=author, provider=provider).copy()
for img in self[1:]:
result += img.list_images(time=time, author=author, provider=provider)
return result
# def list_images(
# self,
# time: Union[str, Time] = None,
# author: str = "spoc",
# provider: Optional[str] = None,
# ):
# """Returns a `TessImageList` detailing the FFI images which include the coordinates.
#
# Parameters
# ----------
# author : str
# "spoc" or "tica"
# """
# # local import to avoid circular dependency
# from tess_cloud import TessImageList
#
# if len(self) == 0:
# return TessImageList([])
#
# result = self[0].list_images(time=time, author=author, provider=provider).copy()
# for img in self[1:]:
# result += img.list_images(time=time, author=author, provider=provider)
# return result

def to_pandas(self) -> DataFrame:
data = {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_locate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_pi_men():
"""Tests `locate()` against `astroquery.mast.Tesscut.get_sectors()`"""
# Query using Tesscut
crd = SkyCoord(ra=84.291188, dec=-80.46911982, unit="deg")
mast_result = Tesscut.get_sectors(crd)
mast_result = Tesscut.get_sectors(coordinates=crd)
# Query using our tool
our_result = locate(crd)
# Do the sector, camera, and ccd numbers all match?
Expand All @@ -31,7 +31,7 @@ def test_pi_men():
assert our_result_df.iloc[0 : len(mast_result_df)].equals(mast_result_df)
# Can we search by passing a string instead of the coordinates?
our_result2 = locate("Pi Men")
assert our_result.to_pandas().round(2).equals(our_result2.to_pandas().round(2))
assert our_result.to_pandas().round(1).equals(our_result2.to_pandas().round(1))


def test_scalar_vs_nonscalar_coordinate():
Expand Down
66 changes: 33 additions & 33 deletions tests/test_tesscoord.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,36 @@ def test_list_from_pandas():


# @pytest.mark.skip # because TessImage has moved to tess-cloud for now
def test_list_images_twice():
"""Regression test: requesting an image list twice should not change the outcome."""
tcl = TessCoordList(
[
TessCoord(
sector=5,
camera=1,
ccd=4,
column=1553.9,
row=1103.0,
time="2018-11-21 17:35:00",
),
TessCoord(
sector=5,
camera=1,
ccd=4,
column=1553.9,
row=1103.0,
time="2018-11-22 17:35:00",
),
]
)
len1 = len(tcl.list_images())
len2 = len(tcl.list_images())
assert len1 == len2


def test_list_images():
crd = TessCoord(sector=11, camera=2, ccd=2, column=1699, row=1860)
imglist = crd.list_images()
assert len(imglist) == 1248
df = imglist.to_pandas()
assert len(df) == len(imglist)
# def test_list_images_twice():
# """Regression test: requesting an image list twice should not change the outcome."""
# tcl = TessCoordList(
# [
# TessCoord(
# sector=5,
# camera=1,
# ccd=4,
# column=1553.9,
# row=1103.0,
# time="2018-11-21 17:35:00",
# ),
# TessCoord(
# sector=5,
# camera=1,
# ccd=4,
# column=1553.9,
# row=1103.0,
# time="2018-11-22 17:35:00",
# ),
# ]
# )
# len1 = len(tcl.list_images())
# len2 = len(tcl.list_images())
# assert len1 == len2
#
#
# def test_list_images():
# crd = TessCoord(sector=11, camera=2, ccd=2, column=1699, row=1860)
# imglist = crd.list_images()
# assert len(imglist) == 1248
# df = imglist.to_pandas()
# assert len(df) == len(imglist)

0 comments on commit 56a9641

Please sign in to comment.