<jupyter_start><jupyter_text>This tutorial will demonstrate how to obtain difference images for a planet candidate in TESS data.<jupyter_code>import matplotlib.pyplot as plt
import sys
sys.path.append('../code')<jupyter_output><empty_output><jupyter_text>Provide some basic information on the star and its planet. In this example, we'll look at TIC-25375553, the host star of confirmed planet TOI-143.01 (WASP-111b). There's only one planet in this example, but for multi-planet systems you should list all planets in the same format.<jupyter_code>star = {}
star['id'] = 25375553
star['raDegrees'] = 328.76768
star['decDegrees'] = -22.61258

planet0 = {}
planet0['period'] = 2.31097
planet0['epoch'] = 1325.58249
planet0['durationHours'] = 3.129<jupyter_output><empty_output><jupyter_text>Since TESS works in distinct "sectors" of data (~27 days), decide which sector you would like to use for difference images. TIC-25375553 was observed in both Sectors 1 and 28, but if you aren't sure, you can check with tess-point. For example:<jupyter_code>from tess_stars2px import tess_stars2px_function_entry

outID, outEclipLong, outEclipLat, outSec, outCam, outCcd,\
    outColPix, outRowPix, scinfo = tess_stars2px_function_entry(star['id'], star['raDegrees'], star['decDegrees'])

print(outSec, outCam)<jupyter_output>[ 1 28] [1 1]<jupyter_text>Let's pick the most recently observed sector, Sector 28. This will take about a minute to run, as it downloads the FFI cutout using TESScut, identifies the in-transit datapoints, and calculates the difference image.<jupyter_code>import tessDiffImage

star['sector'] = 28
star['cam'] = 1
star['planetData'] = [planet0]
# If you have quality flags for each cadence in the sector in a file, name the file here; otherwise None
star['qualityFiles'] = None
# If you have quality flags for each cadence in the sector in an array, put the array here; otherwise None
star['qualityFlags'] = None

tdi = tessDiffImage.tessDiffImage(star, spiceFileLocation = "..")

tdi.make_ffi_difference_image(thisPlanet=0)<jupyter_output>Created TAP+ (v1.2.1) - Connection:
	Host: gea.esac.esa.int
	Use HTTPS: True
	Port: 443
	SSL Port: 443
Created TAP+ (v1.2.1) - Connection:
	Host: geadata.esac.esa.int
	Use HTTPS: True
	Port: 443
	SSL Port: 443
loaded de432s.bsp
curl "https://mast.stsci.edu/tesscut/api/v0.1/astrocut?ra=328.76768&dec=-22.61258&y=20&x=20&sector=28" --output tic25375553.zip
['tic25375553/tess-s0028-1-3_328.767680_-22.612580_20x20_astrocut.fits']
no sector quality flags of the same length as FFI quality flags<jupyter_text>The image data was saved in the newly created tic25375553 folder. You'll also find difference image plots saved as pdfs using default the default plotting, and a list of all nearby TICs. You can always load the data back in if you want to manipulate the data on your own:<jupyter_code>import pickle

fname = 'tic25375553/imageData_planet0_sector28_camera1.pickle'
with open(fname, 'rb') as f:
    imageData = pickle.load(f)
diffImageData = imageData[0]
catalogData = imageData[1]

fig, ax = plt.subplots(2,2,figsize=(10,10))
tdi.draw_pix_catalog(diffImageData['diffImage'], catalogData, ax=ax[0,0], fs=14, ss=60, filterStars=True, dMagThreshold=4, annotate=True)
tdi.draw_pix_catalog(diffImageData['diffImage'], catalogData, ax=ax[0,1], fs=14, ss=60, filterStars=True, dMagThreshold=4, annotate=True, close=True)
tdi.draw_pix_catalog(diffImageData['meanOutTransit'], catalogData, ax=ax[1,0], fs=14, ss=60, filterStars=True, dMagThreshold=4, annotate=True)
tdi.draw_pix_catalog(diffImageData['meanOutTransit'], catalogData, ax=ax[1,1], fs=14, ss=60, filterStars=True, dMagThreshold=4, annotate=True, close=True)
ax[0,0].set_title('Difference Image')
ax[0,1].set_title('Difference Image (Close-up)')
ax[1,0].set_title('Direct Image')
ax[1,1].set_title('Direct Image (Close-up)')<jupyter_output>../code/tessDiffImage.py:374: MatplotlibDeprecationWarning: Case-insensitive properties were deprecated in 3.3 and support will be removed two minor releases later
  star_gs = ax.scatter(catalogData["ticColPix"][idx]  - catalogData["dCol"], catalogData["ticRowPix"][idx] - catalogData["dRow"], cmap='BuGn',
../code/tessDiffImage.py:374: MatplotlibDeprecationWarning: Case-insensitive properties were deprecated in 3.3 and support will be removed two minor releases later
  star_gs = ax.scatter(catalogData["ticColPix"][idx]  - catalogData["dCol"], catalogData["ticRowPix"][idx] - catalogData["dRow"], cmap='BuGn',
../code/tessDiffImage.py:374: MatplotlibDeprecationWarning: Case-insensitive properties were deprecated in 3.3 and support will be removed two minor releases later
  star_gs = ax.scatter(catalogData["ticColPix"][idx]  - catalogData["dCol"], catalogData["ticRowPix"][idx] - catalogData["dRow"], cmap='BuGn',
../code/tessDiffImage.py:374: MatplotlibDeprecationWarning: Case-insensitive pr[...]
{'fraction_non_alphanumeric': 0.12003294214535722, 'fraction_numerical': 0.05332509779699403, 'mean_word_length': 6.462365591397849, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '175094', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1663, 'n_words': 457, 'path': 'example/example_diffimages.ipynb', 'repo_name': 'mkunimoto/TESS-plots', 'size': '4857'}