Skip to content

Commit

Permalink
Merge branch 'pandas_table' of github.com:tylerapritchard/newlk_searc…
Browse files Browse the repository at this point in the history
…h into pandas_table
  • Loading branch information
tylerapritchard committed Feb 2, 2024
2 parents b8a94e7 + 3d6f5ef commit 1d8a28a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/newlk_search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from requests import HTTPError
import pandas as pd
from IPython.display import HTML
from datetime import datetime, timedelta


from lightkurve import PACKAGEDIR, conf, config
Expand Down Expand Up @@ -177,8 +178,9 @@ def _fix_start_and_end_times(self):
else start_time[idx] + timedelta(days=90)
for idx, filename in enumerate(filenames)
]
self.table.loc[kepler_mask, "start_time"] = start_time
self.table.loc[kepler_mask, "end_time"] = end_time

self.table.loc[kepler_mask, "start_time"] = pd.to_datetime([st.iso for st in start_time])
self.table.loc[kepler_mask, "end_time"] = pd.to_datetime([et.iso for et in end_time])

# We mask KBONUS times because they are invalid for the quarter data
'''if "sequence" in self.table.columns:
Expand Down Expand Up @@ -229,7 +231,7 @@ def __repr__(self, html=False):
out = out.assign(author=out['author'].apply(lambda x: f'<a href="{AUTHOR_LINKS[x]}">{x}</a>' if x in AUTHOR_LINKS.keys() else x))
#out = HTML(out.to_html(escape=False, max_rows=10))

return out.to_string(max_rows=10)
return out.to_string(max_rows=20)


def _repr_html_(self):
Expand Down Expand Up @@ -956,6 +958,7 @@ def _search_products(
from astroquery.mast import Observations

products = Observations.get_product_list(observations)


joint_table = join(
observations,
Expand All @@ -968,6 +971,7 @@ def _search_products(
table_names=["", "_products"],
)


joint_table = joint_table.to_pandas()

# Add the user-friendly 'author' column (synonym for 'provenance_name')
Expand Down Expand Up @@ -1004,17 +1008,17 @@ def _search_products(
joint_table['project'],
joint_table['project'].values.astype(str),
seq_num)]

masked_result = _filter_products(
joint_table,
filetype=filetype,
campaign=campaign,
quarter=quarter,
sector=sector,
exptime=exptime,
project=mission,
provenance_name=provenance_name,
month=month,
sector=sector,
limit=limit,
)
print(masked_result)
Expand Down Expand Up @@ -1249,6 +1253,7 @@ def _filter_products(
products : pandas dataframe object
Masked astropy table containing desired data products
"""

if provenance_name is None: # apply all filters
provenance_lower = ("kepler", "k2", "spoc")
else:
Expand Down Expand Up @@ -1301,18 +1306,19 @@ def _filter_products(
def _mask_kepler_products(products, quarter=None, month=None):
"""Returns a mask flagging the Kepler products that match the criteria."""
#mask = np.array([proj.lower() == "kepler" for proj in products["provenance_name"]])
mask = products['provenance_name'] == 'kepler'
mask = products['provenance_name'].str.lower() == 'kepler'
if sum(mask) == 0:
return mask

# Identify quarter by the description.
# This is necessary because the `sequence_number` field was not populated
# for Kepler prime data at the time of writing this function.
quarter_mask = np.zeros(len(products), dtype=bool)

if quarter is not None:
quarter_mask = np.zeros(len(products), dtype=bool)
for q in np.atleast_1d(quarter):
quarter_mask += products['description'].str.endswith(f"Q{q}")
mask &= quarter_mask
mask &= quarter_mask

# For Kepler short cadence data the month can be specified
if month is not None:
Expand Down

0 comments on commit 1d8a28a

Please sign in to comment.