Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nschanche committed Mar 28, 2024
1 parent 0d05ac5 commit 4ea3566
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
12 changes: 7 additions & 5 deletions src/newlk_search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def __init__(self,
sequence=sector)
if(table is None):
self._add_ffi_products()
self.sortTESS()
self.sort_TESS()

def _add_ffi_products(self):
#get the ffi info for the targets
Expand Down Expand Up @@ -854,16 +854,18 @@ def _sector2ffiexptime(self, sector):
return 200


def sortTESS(self):
def sort_TESS(self):
# base sort + TESS HLSP handling?
sort_priority = {"SPOC": 1,
"TESS-SPOC": 2,
"TESScut": 3,
}

self.table["sort_order"] = self.table['pipeline'].map(sort_priority).fillna(9)
self.table.sort_values(by=["distance", "project", "sort_order", "sequence_number", "exptime"], ignore_index=True, inplace=True)

df = self.table
df["sort_order"] = df['pipeline'].map(sort_priority).fillna(9)
df = df.sort_values(by=["distance", "sort_order", "start_time", "exptime"], ignore_index=True)
self.table = df
def download_ffi():
raise NotImplementedError

Expand Down Expand Up @@ -954,7 +956,7 @@ def get_sequence_number(self):
self.table['sequence_number'] = seq_num

# Update 'mission' with the sequence number
self.table["mission"] = [f" {proj} - Campaign {seq}"
self.table["mission"] = [f" {proj} - Quarter {seq}"
for proj, seq in zip(
self.table['mission'].values.astype(str),
seq_num)]
Expand Down
39 changes: 20 additions & 19 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from lightkurve.utils import LightkurveWarning, LightkurveError
from src.newlk_search.search import (
MASTSearch,
KeplerSearch,
TESSSearch,
K2Search
Expand Down Expand Up @@ -127,27 +128,29 @@ def test_search_timeseries(caplog):
# The name Kepler-10 somehow no longer works on MAST. So we use 2MASS instead:
# https://simbad.cds.unistra.fr/simbad/sim-id?Ident=%405506010&Name=Kepler-10
assert (
len(KeplerSearch('2MASS J19024305+5014286', author='Kepler', exptime='long').timeseries.table)
len(KeplerSearch('2MASS J19024305+5014286', pipeline='Kepler', exptime='long').timeseries.table)
== 15
)
# An invalid KIC/EPIC ID or target name should be dealt with gracefully
search_timeseries(-999)
KeplerSearch((-999).timeseries)
#assert "disambiguate" in caplog.text
assert "Target must" in caplog.text

# TODO: This tries to search, should probs add a check before it gets to that point.
# Or just check there is a NameResolveError?
search_timeseries("DOES_NOT_EXIST (UNIT TEST)")
assert "disambiguate" in caplog.text

# If we ask for all cadence types, there should be four Kepler files given
assert len(KeplerSearch("KIC 4914423", quarter=6, exptime='any', author="Kepler").timeseries.table) == 4
assert len(KeplerSearch("KIC 4914423", quarter=6, exptime='any', pipeline="Kepler").timeseries.table) == 4

# ...and only one should have long cadence
assert len(KeplerSearch('KIC 4914423', quarter=6, exptime='long', author='Kepler').timeseries.table) == 1
assert len(KeplerSearch('KIC 4914423', quarter=6, exptime='long', pipeline='Kepler').timeseries.table) == 1
# Should be able to resolve an ra/dec
assert len(KeplerSearch("297.5835, 40.98339", quarter=6, author="Kepler").timeseries.table) == 1
assert len(KeplerSearch("297.5835, 40.98339", quarter=6, pipeline="Kepler").timeseries.table) == 1
# Should be able to resolve a SkyCoord
c = SkyCoord("297.5835 40.98339", unit=(u.deg, u.deg))
search = KeplerSearch(c, quarter=6, author="Kepler").timeseries
search = KeplerSearch(c, quarter=6, pipeline="Kepler").timeseries
assert len(search.table) == 1
assert len(search) == 1

Expand All @@ -163,12 +166,12 @@ def test_search_timeseries(caplog):
assert len(TESSSearch(tic).timeseries.table) > 1
assert (
len(
TESSSearch(tic, author="spoc", sector=1, search_radius=100).timeseries.table
TESSSearch(tic, pipeline="spoc", sector=1, search_radius=100).timeseries.table
)
== 2
)
# TODO: search_timeseries(tic, mission="TESS", author="SPOC", sector=1).download()
assert len(TESSSearch("pi Mensae", author="SPOC", sector=1).timeseries.table) == 1
assert len(TESSSearch("pi Mensae", pipeline="SPOC", sector=1).timeseries.table) == 1


#@pytest.mark.remote_data
Expand Down Expand Up @@ -241,7 +244,7 @@ def test_search_timeseries(caplog):
#@pytest.mark.remote_data
def test_search_with_skycoord():
"""Can we pass both names, SkyCoord objects, and coordinate strings?"""
sr_name = search.KeplerSearch("KIC 11904151", exptime='long').cubedata
sr_name = KeplerSearch("KIC 11904151", exptime='long').cubedata
assert (
len(sr_name) == 15
) # Kepler-10 as observed during 15 quarters in long cadence
Expand All @@ -264,11 +267,11 @@ def test_search_with_skycoord():
assert_array_equal(
sr_name.table["productFilename"], sr_sexagesimal.table["productFilename"]
)
'''# Can we search using the KIC ID?

sr_kic = KeplerSearch("KIC 11904151", exptime='long').cubedata
assert_array_equal(
sr_name.table["productFilename"], sr_kic.table["productFilename"]
)'''
)


#@pytest.mark.remote_data
Expand Down Expand Up @@ -302,28 +305,26 @@ def test_collections():
# TODO: get download working
assert (
len(
search_timeseries(
"EPIC 205998445", mission="K2", radius=900, limit=3, author="K2"
).download_all()
MASTSearch("EPIC 205998445", mission="K2", search_radius=900, pipeline="K2").limit_results(3).download()
)
== 3
)
# if fewer targets are found than targetlimit, should still download all available
assert (
len(K2Search("EPIC 205998445", search_radius=900, author="K2").cubedata.limit_results(6).table)
len(K2Search("EPIC 205998445", search_radius=900, pipeline="K2").cubedata.limit_results(6).table)
== 4
)
# if download() is used when multiple files are available, should only download 1
# TODO: deal with downloads later
with pytest.warns(LightkurveWarning, match="4 files available to download"):
assert isinstance(
search_cubedata(
"EPIC 205998445", mission="K2", radius=900, author="K2"
).download(),
MASTSearch(
"EPIC 205998445", mission="K2", radius=900, pipeline="K2"
).cubedata.download(),
KeplerTargetPixelFile,
)


# NS got to here!
#@pytest.mark.remote_data
def test_properties():
c = SkyCoord("297.5835 40.98339", unit=(u.deg, u.deg))
Expand Down

0 comments on commit 4ea3566

Please sign in to comment.