From f1e35990a9297dbfb780ef589c1f95edab5f4f97 Mon Sep 17 00:00:00 2001 From: Tyler Pritchard Date: Fri, 2 Feb 2024 22:03:19 -0500 Subject: [PATCH 1/3] added tesswcs functionality --- src/newlk_search/search.py | 94 +++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/src/newlk_search/search.py b/src/newlk_search/search.py index 7089f29..d80d4a7 100644 --- a/src/newlk_search/search.py +++ b/src/newlk_search/search.py @@ -923,11 +923,12 @@ def _search_products( # Speed up by restricting the MAST query if we don't want FFI image data # At MAST, non-FFI Kepler pipeline products are known as "cube" products, # and non-FFI TESS pipeline products are listed as "timeseries". + # NEW CHANGE - we're speeding this up by not including TESS FFI images in the search. # We will handle them separately using something else (tesswcs? tesspoint?) # Also the above is written like FFI kepler products exist, but I don't think they do? - #extra_query_criteria["dataproduct_type"] = ["cube", "timeseries"] + extra_query_criteria["dataproduct_type"] = ["cube", "timeseries"] # Query Mast to get a list of observations observations = _query_mast( @@ -1024,41 +1025,51 @@ def _search_products( # Full Frame Images - build this from the querry table if any(['ffi' in ftype.lower() for ftype in filetype]): - # Make sure `search_tesscut` always performs a cone search (i.e. always - # passed a radius value), because strict target name search does not apply. - if radius is None: - radius = 0.0001 * u.arcsec - - cutouts = [] - for idx in np.where(["TESS FFI" in t for t in observations["target_name"]])[0]: - # if target passed in is a SkyCoord object, convert to RA, dec pair - if isinstance(target, SkyCoord): - target = "{}, {}".format(target.ra.deg, target.dec.deg) - # pull sector numbers - s = observations["sequence_number"][idx] - # if the desired sector is available, add a row - if s in np.atleast_1d(sector) or sector is None: - cutouts.append( - { - "description": f"TESS FFI Cutout (sector {s})", - "mission": f"TESS Sector {s:02d}", - "target_name": str(target), - "targetid": str(target), - "t_min": observations["t_min"][idx], - "exptime": observations["exptime"][idx], - "productFilename": "TESScut", - "provenance_name": "TESScut", - "author": "TESScut", - "distance": 0.0, - "sequence_number": s, - "project": "TESS", - "obs_collection": "TESS", - } - ) - if len(cutouts) > 0: - log.debug("Found {} matching cutouts.".format(len(cutouts))) - ffi_result = Table(cutouts) - ffi_result = ffi_result.to_pandas() + from tesswcs import pointings + from tesswcs import WCS + + tesscut_desc=[] + tesscut_mission=[] + tesscut_tmin=[] + tesscut_exptime=[] + tesscut_seqnum=[] + + # Check each sector / camera / ccd for observability + for _, row in pointings.iterrows(): + tess_ra, tess_dec, tess_roll = row['RA', 'Dec', 'Roll'] + for camera in np.arange(1, 5): + for ccd in np.arange(1, 5): + # predict the WCS + wcs = WCS.predict(tess_ra, tess_dec, tess_roll , camera=camera, ccd=ccd) + # check if the target falls inside the CCD + if wcs.footprint_contains(c_targ): + log.debug(f"Target Observable in Sector {sector}, Camera {camera}, CCD {ccd}") + tesscut_desc.append(f"TESS FFI Cutout (sector {s})") + tesscut_mission.append(f"TESS Sector {row['Sector']:02d}") + tesscut_tmin.append([row["Start"]]) + tesscut_exptime.append([observations["exptime"]]) + tesscut_seqnum.append([row['Sector']]) + + # Build the ffi dataframe from the observability + n_results = len(tesscut_seqnum) + ffi_result = pd.DataFrame({"description" : tesscut_desc, + "mission": tesscut_mission, + "target_name" : [str(target)] * n_results, + "targetid" : [str(target)] * n_results, + "t_min" : tesscut_tmin, + "exptime" : _tess_sector2exptime(sector), + "productFilename" : ["TESScut"] * n_results, + "provenance_name" : ["TESScut"] * n_results, + "author" : ["TESScut"] * n_results, + "distance" : [0] * n_results, + "sequence_number" : tesscut_seqnum, + "project" : ["TESS"] * n_results, + "obs_collection" : ["TESS"] * n_results}) + + if len(ffi_result) > 0: + log.debug(f"Found {len(cutouts)} matching cutouts.") + else: + log.debug("Found no matching cutouts.") query_result = pd.concat((masked_result, ffi_result)).sort_values(["distance", @@ -1367,4 +1378,13 @@ def _resolve_object(target): from astroquery.mast import MastClass # Note: `_resolve_object` was renamed `resolve_object` in astroquery 0.3.10 (2019) - return MastClass().resolve_object(target) \ No newline at end of file + return MastClass().resolve_object(target) + +def _tess_sector2exptime(sector): + """Dictionary lookup table for tess sector exposure times""" + if sector < 27: + return 1800 + if (sector >- 27) and (sector < 56): + return 600 + if (sector >= 56): + return 200 \ No newline at end of file From a2538d21ea052d3089da50c3e3b1f511ffcdfa5b Mon Sep 17 00:00:00 2001 From: Tyler Pritchard Date: Fri, 2 Feb 2024 22:31:30 -0500 Subject: [PATCH 2/3] tesswcs implementation --- src/newlk_search/search.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/newlk_search/search.py b/src/newlk_search/search.py index d80d4a7..d9181b0 100644 --- a/src/newlk_search/search.py +++ b/src/newlk_search/search.py @@ -1034,21 +1034,23 @@ def _search_products( tesscut_exptime=[] tesscut_seqnum=[] + coords = _resolve_object(target) # Check each sector / camera / ccd for observability - for _, row in pointings.iterrows(): - tess_ra, tess_dec, tess_roll = row['RA', 'Dec', 'Roll'] + for row in pointings.iterrows(): + tess_ra, tess_dec, tess_roll = row[2:5] for camera in np.arange(1, 5): for ccd in np.arange(1, 5): # predict the WCS wcs = WCS.predict(tess_ra, tess_dec, tess_roll , camera=camera, ccd=ccd) # check if the target falls inside the CCD - if wcs.footprint_contains(c_targ): + if wcs.footprint_contains(coords): + sector = row[0] log.debug(f"Target Observable in Sector {sector}, Camera {camera}, CCD {ccd}") - tesscut_desc.append(f"TESS FFI Cutout (sector {s})") - tesscut_mission.append(f"TESS Sector {row['Sector']:02d}") - tesscut_tmin.append([row["Start"]]) - tesscut_exptime.append([observations["exptime"]]) - tesscut_seqnum.append([row['Sector']]) + tesscut_desc.append(f"TESS FFI Cutout (sector {sector})") + tesscut_mission.append(f"TESS Sector {sector:02d}") + tesscut_tmin.append([row[5]]) + tesscut_exptime.append(_tess_sector2exptime(sector)) + tesscut_seqnum.append([sector]) # Build the ffi dataframe from the observability n_results = len(tesscut_seqnum) @@ -1057,7 +1059,7 @@ def _search_products( "target_name" : [str(target)] * n_results, "targetid" : [str(target)] * n_results, "t_min" : tesscut_tmin, - "exptime" : _tess_sector2exptime(sector), + "exptime" : tesscut_exptime, "productFilename" : ["TESScut"] * n_results, "provenance_name" : ["TESScut"] * n_results, "author" : ["TESScut"] * n_results, @@ -1067,15 +1069,15 @@ def _search_products( "obs_collection" : ["TESS"] * n_results}) if len(ffi_result) > 0: - log.debug(f"Found {len(cutouts)} matching cutouts.") + log.debug(f"Found {n_results} matching cutouts.") else: log.debug("Found no matching cutouts.") query_result = pd.concat((masked_result, - ffi_result)).sort_values(["distance", - "obsid", - "sequence_number"]) - + ffi_result))#.sort_values(["distance", + # "obsid", + # "sequence_number"]) + return query_result # Add in the start and end times for each observation if query_result is not None: print(pd.to_datetime([Time(x + 2400000.5, format="jd").iso for x in query_result['t_min']])) From 2788663e2dda5edae69bed524ff8c8a12a4e4cf4 Mon Sep 17 00:00:00 2001 From: Tyler Pritchard Date: Fri, 2 Feb 2024 22:41:44 -0500 Subject: [PATCH 3/3] updated tesscut t_min, t_max --- src/newlk_search/search.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/newlk_search/search.py b/src/newlk_search/search.py index d9181b0..f87ea38 100644 --- a/src/newlk_search/search.py +++ b/src/newlk_search/search.py @@ -1031,6 +1031,7 @@ def _search_products( tesscut_desc=[] tesscut_mission=[] tesscut_tmin=[] + tesscut_tmax=[] tesscut_exptime=[] tesscut_seqnum=[] @@ -1048,9 +1049,10 @@ def _search_products( log.debug(f"Target Observable in Sector {sector}, Camera {camera}, CCD {ccd}") tesscut_desc.append(f"TESS FFI Cutout (sector {sector})") tesscut_mission.append(f"TESS Sector {sector:02d}") - tesscut_tmin.append([row[5]]) + tesscut_tmin.append(row[5]- 2400000.5) # Time(row[5], format="jd").iso) + tesscut_tmax.append(row[6]- 2400000.5) # Time(row[6], format="jd").iso) tesscut_exptime.append(_tess_sector2exptime(sector)) - tesscut_seqnum.append([sector]) + tesscut_seqnum.append(sector) # Build the ffi dataframe from the observability n_results = len(tesscut_seqnum) @@ -1059,6 +1061,7 @@ def _search_products( "target_name" : [str(target)] * n_results, "targetid" : [str(target)] * n_results, "t_min" : tesscut_tmin, + "t_max" : tesscut_tmax, "exptime" : tesscut_exptime, "productFilename" : ["TESScut"] * n_results, "provenance_name" : ["TESScut"] * n_results, @@ -1077,7 +1080,6 @@ def _search_products( ffi_result))#.sort_values(["distance", # "obsid", # "sequence_number"]) - return query_result # Add in the start and end times for each observation if query_result is not None: print(pd.to_datetime([Time(x + 2400000.5, format="jd").iso for x in query_result['t_min']]))