tglc 0.6.4__tar.gz → 0.6.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tglc
3
- Version: 0.6.4
3
+ Version: 0.6.5
4
4
  Summary: TESS-Gaia Light Curve
5
5
  Home-page: https://github.com/TeHanHunter/TESS_Gaia_Light_Curve
6
6
  Author: Te Han
@@ -11,6 +11,17 @@ Classifier: Operating System :: OS Independent
11
11
  Requires-Python: >=3.8
12
12
  Description-Content-Type: text/x-rst
13
13
  License-File: LICENSE
14
+ Requires-Dist: astropy>=5.1
15
+ Requires-Dist: astroquery
16
+ Requires-Dist: matplotlib
17
+ Requires-Dist: numpy
18
+ Requires-Dist: oauthlib
19
+ Requires-Dist: requests
20
+ Requires-Dist: scipy
21
+ Requires-Dist: threadpoolctl
22
+ Requires-Dist: tqdm
23
+ Requires-Dist: wheel
24
+ Requires-Dist: wotan
14
25
 
15
26
  ==================================
16
27
  Introduction
@@ -6,7 +6,7 @@ with open("README.rst", "r", encoding="utf-8") as fh:
6
6
  long_description = fh.read()
7
7
  setuptools.setup(
8
8
  name="tglc",
9
- version='0.6.4',
9
+ version='0.6.5',
10
10
  author="Te Han",
11
11
  author_email="tehanhunter@gmail.com",
12
12
  description="TESS-Gaia Light Curve",
@@ -0,0 +1,3 @@
1
+ __version__ = "0.6.5"
2
+ __author__ = 'Te Han, Timothy Brandt'
3
+ __credits__ = 'University of California, Santa Barbara'
@@ -19,7 +19,8 @@ from astroquery.mast import Tesscut
19
19
  # warnings.simplefilter('ignore', UserWarning)
20
20
  from threadpoolctl import ThreadpoolController, threadpool_limits
21
21
  import numpy as np
22
-
22
+ import seaborn as sns
23
+ import itertools
23
24
  controller = ThreadpoolController()
24
25
 
25
26
 
@@ -40,10 +41,6 @@ def tglc_lc(target='TIC 264468702', local_directory='', size=90, save_aper=True,
40
41
  os.makedirs(local_directory + f'lc/', exist_ok=True)
41
42
  os.makedirs(local_directory + f'epsf/', exist_ok=True)
42
43
  os.makedirs(local_directory + f'source/', exist_ok=True)
43
- if first_sector_only:
44
- sector = 'first'
45
- elif last_sector_only:
46
- sector = 'last'
47
44
  print(f'Target: {target}')
48
45
  target_ = Catalogs.query_object(target, radius=42 * 0.707 / 3600, catalog="Gaia", version=2)
49
46
  if len(target_) == 0:
@@ -77,7 +74,7 @@ def tglc_lc(target='TIC 264468702', local_directory='', size=90, save_aper=True,
77
74
  elif first_sector_only:
78
75
  print(f'Only processing the first sector the target is observed in: Sector {sector_table["sector"][0]}.')
79
76
  print('Downloading Data from MAST and Gaia ...')
80
-
77
+ sector = sector_table["sector"][0]
81
78
  source = ffi_cut(target=target, size=size, local_directory=local_directory, sector=sector,
82
79
  limit_mag=limit_mag, transient=transient) # sector
83
80
  source.select_sector(sector=source.sector_table['sector'][0])
@@ -86,6 +83,7 @@ def tglc_lc(target='TIC 264468702', local_directory='', size=90, save_aper=True,
86
83
  elif last_sector_only:
87
84
  print(f'Only processing the last sector the target is observed in: Sector {sector_table["sector"][-1]}.')
88
85
  print('Downloading Data from MAST and Gaia ...')
86
+ sector = sector_table["sector"][-1]
89
87
  source = ffi_cut(target=target, size=size, local_directory=local_directory, sector=sector,
90
88
  limit_mag=limit_mag, transient=transient) # sector
91
89
  source.select_sector(sector=source.sector_table['sector'][-1])
@@ -296,47 +294,59 @@ def plot_pf_lc(local_directory=None, period=None, mid_transit_tbjd=None, kind='c
296
294
  plt.close(fig)
297
295
 
298
296
 
299
- def plot_contamination(local_directory=None, gaia_dr3=None):
300
- files = glob(f'{local_directory}lc/*.fits')
297
+ def plot_contamination(local_directory=None, gaia_dr3=None, ymin=None, ymax=None, pm_years=3000):
298
+ sns.set(rc={'font.family': 'serif', 'font.serif': 'DejaVu Serif', 'font.size': 12,
299
+ 'axes.edgecolor': '0.2', 'axes.labelcolor': '0.', 'xtick.color': '0.', 'ytick.color': '0.',
300
+ 'axes.facecolor': '0.95', "axes.grid": False})
301
+
302
+ files = glob(f'{local_directory}lc/*{gaia_dr3}*.fits')
301
303
  os.makedirs(f'{local_directory}plots/', exist_ok=True)
302
304
  for i in range(len(files)):
303
305
  with fits.open(files[i], mode='denywrite') as hdul:
304
306
  sector = hdul[0].header['SECTOR']
307
+ q = [a and b for a, b in
308
+ zip(list(hdul[1].data['TESS_flags'] == 0), list(hdul[1].data['TGLC_flags'] == 0))]
309
+ if ymin is None and ymax is None:
310
+ ymin = np.nanmin(hdul[1].data['cal_aper_flux'][q]) - 0.05
311
+ ymax = np.nanmax(hdul[1].data['cal_aper_flux'][q]) + 0.05
305
312
  with open(glob(f'{local_directory}source/*_{sector}.pkl')[0], 'rb') as input_:
306
313
  source = pickle.load(input_)
307
314
  source.select_sector(sector=sector)
308
315
  star_num = np.where(source.gaia['DESIGNATION'] == f'Gaia DR3 {gaia_dr3}')
309
- plt.imshow(source.flux[0], origin='lower')
310
- plt.show()
311
- plt.close()
312
- # print(source.gaia[891])
313
- # print(source.gaia[star_num])
314
- nearby_stars = np.argsort(
316
+
317
+ distances = np.sqrt(
315
318
  (source.gaia[f'sector_{sector}_x'][:500] - source.gaia[star_num][f'sector_{sector}_x']) ** 2 +
316
- (source.gaia[f'sector_{sector}_y'][:500] - source.gaia[star_num][f'sector_{sector}_y']) ** 2)[0:5]
317
- # print(f'sector = {source.sector}')
319
+ (source.gaia[f'sector_{sector}_y'][:500] - source.gaia[star_num][f'sector_{sector}_y']) ** 2)
320
+
321
+ # Find closest 5 stars (6-self) or those within 5 pixels
322
+ nearby_stars = np.argsort(distances)[:6]
323
+ nearby_stars = nearby_stars[distances[nearby_stars] <= 5]
318
324
  star_x = source.gaia[star_num][f'sector_{sector}_x'][0]
319
325
  star_y = source.gaia[star_num][f'sector_{sector}_y'][0]
320
326
  max_flux = np.nanmax(
321
- np.nanmedian(source.flux[:, round(star_y) - 2:round(star_y) + 3, round(star_x) - 2:round(star_x) + 3],
322
- axis=0))
323
- fig = plt.figure(constrained_layout=False, figsize=(15, 5))
324
- gs = fig.add_gridspec(5, 16)
325
- gs.update(wspace=0.1, hspace=0.1)
326
- ax0 = fig.add_subplot(gs[:5, :5])
327
+ np.nanmedian(
328
+ source.flux[:, round(star_y) - 2:round(star_y) + 3, round(star_x) - 2:round(star_x) + 3],
329
+ axis=0))
330
+ fig = plt.figure(constrained_layout=False, figsize=(20, 12))
331
+ gs = fig.add_gridspec(21, 10)
332
+ gs.update(wspace=0.03, hspace=0.1)
333
+ ax0 = fig.add_subplot(gs[:10, :3])
327
334
  ax0.imshow(np.median(source.flux, axis=0), cmap='RdBu', vmin=-max_flux, vmax=max_flux, origin='lower')
328
-
329
- ax0.scatter(source.gaia[f'sector_{sector}_x'][:500], source.gaia[f'sector_{sector}_y'][:500], s=50,
330
- c='r', label='background stars')
331
- ax0.scatter(source.gaia[f'sector_{sector}_x'][nearby_stars],
332
- source.gaia[f'sector_{sector}_y'][nearby_stars], s=50,
335
+ ax0.set_xlabel('x pixel')
336
+ ax0.set_ylabel('y pixel')
337
+ ax0.scatter(star_x, star_y, s=300, c='r', marker='*', label='target star')
338
+ ax0.scatter(source.gaia[f'sector_{sector}_x'][:500], source.gaia[f'sector_{sector}_y'][:500], s=30,
333
339
  c='r', label='background stars')
340
+ ax0.scatter(source.gaia[f'sector_{sector}_x'][nearby_stars[nearby_stars != star_num[0][0]]],
341
+ source.gaia[f'sector_{sector}_y'][nearby_stars[nearby_stars != star_num[0][0]]],
342
+ s=30, c='r', edgecolor='black', linewidth=1, label='background stars')
343
+
334
344
  for l in range(len(nearby_stars)):
335
345
  index = np.where(
336
346
  source.tic['dr3_source_id'] == int(source.gaia['DESIGNATION'][nearby_stars[l]].split(' ')[-1]))
337
347
  gaia_targets = source.gaia
338
348
  median_time = np.median(source.time)
339
- interval = (median_time - 388.5) / 365.25 + 3000
349
+ interval = (median_time - 388.5) / 365.25 + pm_years
340
350
  ra = gaia_targets['ra'][nearby_stars[l]]
341
351
  dec = gaia_targets['dec'][nearby_stars[l]]
342
352
  if not np.isnan(gaia_targets['pmra'][nearby_stars[l]]):
@@ -352,43 +362,36 @@ def plot_contamination(local_directory=None, gaia_dr3=None):
352
362
  y_gaia - source.gaia[f'sector_{sector}_y'][nearby_stars[l]],
353
363
  width=0.02, color='r', edgecolor=None, head_width=0.1)
354
364
  try:
355
- ax0.text(source.gaia[f'sector_{sector}_x'][nearby_stars[l]] - 0.1,
356
- source.gaia[f'sector_{sector}_y'][nearby_stars[l]] + 0.3,
357
- f'TIC {int(source.tic["TIC"][index])}', rotation=90)
358
- except kindError:
359
- ax0.text(source.gaia[f'sector_{sector}_x'][nearby_stars[l]] - 0.1,
360
- source.gaia[f'sector_{sector}_y'][nearby_stars[l]] + 0.2,
361
- f'{source.gaia[f"DESIGNATION"][nearby_stars[l]]}', rotation=90)
362
- ax0.scatter(star_x, star_y, s=300, c='r', marker='*', label='target star')
365
+ txt = ax0.text(source.gaia[f'sector_{sector}_x'][nearby_stars[l]] + 0.5,
366
+ source.gaia[f'sector_{sector}_y'][nearby_stars[l]] - 0.05,
367
+ f'TIC {int(source.tic["TIC"][index])}', size=7)
368
+
369
+ except TypeError:
370
+ designation = source.gaia[f"DESIGNATION"][nearby_stars[l]]
371
+ formatted_text = '\n'.join([designation[i:i + 15] for i in range(0, len(designation), 15)])
363
372
 
364
- # ax0.legend()
373
+ txt = ax0.text(source.gaia[f'sector_{sector}_x'][nearby_stars[l]] + 0.5,
374
+ source.gaia[f'sector_{sector}_y'][nearby_stars[l]] - 0.05,
375
+ formatted_text, size=7)
365
376
  ax0.set_xlim(round(star_x) - 5.5, round(star_x) + 5.5)
366
377
  ax0.set_ylim(round(star_y) - 5.5, round(star_y) + 5.5)
367
- ax0.set_title(f'TIC_{hdul[0].header["TICID"]}_sector_{hdul[0].header["SECTOR"]:04d}')
368
- ax0.vlines(round(star_x) - 2.5, round(star_y) - 2.5, round(star_y) + 2.5, colors='k')
369
- ax0.vlines(round(star_x) + 2.5, round(star_y) - 2.5, round(star_y) + 2.5, colors='k')
370
- ax0.hlines(round(star_y) - 2.5, round(star_x) - 2.5, round(star_x) + 2.5, colors='k')
371
- ax0.hlines(round(star_y) + 2.5, round(star_x) - 2.5, round(star_x) + 2.5, colors='k')
372
- # for j in range(5):
373
- # for k in range(5):
374
- # ax_ = fig.add_subplot(gs[(4 - j), (5 + k)])
375
- # ax_.patch.set_facecolor('C0')
376
- # ax_.patch.set_alpha(max(0, np.median(source.flux[:, round(star_y) - 2 + j, round(star_x) - 2 + k]) / max_flux))
377
- # cal_lc, trend = flatten(hdul[1].data['time'],
378
- # source.flux[:, round(star_y) - 2 + j, round(star_x) - 2 + k],
379
- # window_length=1, method='biweight', return_trend=True)
380
- # ax_.plot(hdul[1].data['time'], cal_lc, '.k', ms=1, label='center pixel')
381
-
378
+ ax0.set_title(f'TIC_{hdul[0].header["TICID"]}_Sector_{hdul[0].header["SECTOR"]:04d}')
379
+ ax0.vlines(round(star_x) - 2.5, round(star_y) - 2.5, round(star_y) + 2.5, colors='k', lw=1.2)
380
+ ax0.vlines(round(star_x) + 2.5, round(star_y) - 2.5, round(star_y) + 2.5, colors='k', lw=1.2)
381
+ ax0.hlines(round(star_y) - 2.5, round(star_x) - 2.5, round(star_x) + 2.5, colors='k', lw=1.2)
382
+ ax0.hlines(round(star_y) + 2.5, round(star_x) - 2.5, round(star_x) + 2.5, colors='k', lw=1.2)
382
383
  t_, y_, x_ = np.shape(hdul[0].data)
383
384
  max_flux = np.max(
384
385
  np.median(source.flux[:, int(star_y) - 2:int(star_y) + 3, int(star_x) - 2:int(star_x) + 3], axis=0))
386
+ sns.set(rc={'font.family': 'serif', 'font.serif': 'DejaVu Serif', 'font.size': 12,
387
+ 'axes.edgecolor': '0.2', 'axes.labelcolor': '0.', 'xtick.color': '0.', 'ytick.color': '0.',
388
+ 'axes.facecolor': '0.95', 'grid.color': '0.9'})
389
+ arrays = []
385
390
  for j in range(y_):
386
391
  for k in range(x_):
387
- ax_ = fig.add_subplot(gs[(4 - j), (6 + 2 * k):(8 + 2 * k)])
388
- ax_.patch.set_facecolor('C0')
392
+ ax_ = fig.add_subplot(gs[(19 - 2 * j):(21 - 2 * j), (2 * k):(2 + 2 * k)])
393
+ ax_.patch.set_facecolor('#4682B4')
389
394
  ax_.patch.set_alpha(min(1, max(0, 5 * np.nanmedian(hdul[0].data[:, j, k]) / max_flux)))
390
- q = [a and b for a, b in
391
- zip(list(hdul[1].data['TESS_flags'] == 0), list(hdul[1].data['TGLC_flags'] == 0))]
392
395
 
393
396
  _, trend = flatten(hdul[1].data['time'][q],
394
397
  hdul[0].data[:, j, k][q] - np.nanmin(hdul[0].data[:, j, k][q]) + 1000,
@@ -396,16 +399,68 @@ def plot_contamination(local_directory=None, gaia_dr3=None):
396
399
  cal_aper = (hdul[0].data[:, j, k][q] - np.nanmin(
397
400
  hdul[0].data[:, j, k][q]) + 1000 - trend) / np.nanmedian(
398
401
  hdul[0].data[:, j, k][q]) + 1
399
- # ax_.plot(hdul[1].data['time'][q], cal_aper, '.k', ms=0.5)
400
- ax_.plot(hdul[1].data['time'][q], hdul[0].data[:, j, k][q], '.k', ms=0.5)
401
- # ax_.set_ylim(0.7, 1.3)
402
+ if 1 <= j <= 3 and 1 <= k <= 3:
403
+ arrays.append(cal_aper)
404
+ ax_.plot(hdul[1].data['time'][q], cal_aper, '.k', ms=0.5)
405
+ # ax_.plot(hdul[1].data['time'][q], hdul[0].data[:, j, k][q], '.k', ms=0.5)
406
+ ax_.set_ylim(ymin, ymax)
407
+ ax_.set_xlabel('TBJD')
408
+ ax_.set_ylabel('')
402
409
  if j != 0:
403
410
  ax_.set_xticklabels([])
411
+ ax_.set_xlabel('')
404
412
  if k != 0:
405
413
  ax_.set_yticklabels([])
406
-
407
- plt.savefig(f'{local_directory}plots/contamination_sector_{hdul[0].header["SECTOR"]:04d}.pdf',
408
- dpi=300)
414
+ if j == 2 and k == 0:
415
+ ax_.set_ylabel('Normalized and detrended Flux of each pixel')
416
+
417
+ combinations = itertools.combinations(arrays, 2)
418
+ median_abs_diffs = []
419
+ for arr_a, arr_b in combinations:
420
+ abs_diff = np.abs(arr_a - arr_b)
421
+ median_diff = np.median(abs_diff)
422
+ median_abs_diffs.append(median_diff)
423
+ median_abs_diffs = np.array(median_abs_diffs)
424
+ iqr = np.percentile(median_abs_diffs, 75) - np.percentile(median_abs_diffs, 25)
425
+ print(f"Interquartile Range (IQR): {iqr}")
426
+ std_dev = np.std(median_abs_diffs)
427
+ print(f"Standard Deviation: {std_dev}")
428
+ ax1 = fig.add_subplot(gs[:10, 4:7])
429
+ ax1.hist(median_abs_diffs, color='k', edgecolor='k', facecolor='none', rwidth=0.8, linewidth=2)
430
+ ax1.set_box_aspect(1)
431
+ ax1.set_title(f'Distribution of the MADs among combinations of the center 3*3 pixels')
432
+ ax1.set_xlabel('MAD between combinations of center 3*3 pixel fluxes')
433
+ ax1.set_ylabel('Counts')
434
+ text_ax = fig.add_axes([0.71, 0.9, 0.3, 0.3]) # [left, bottom, width, height] in figure coordinates
435
+ text_ax.axis('off') # Turn off axis lines, ticks, etc.
436
+ text_ax.text(0., 0., f"Gaia DR3 {gaia_dr3} \n"
437
+ f" ←← TESS SPOC FFI and TIC/Gaia stars with proper motions. \n"
438
+ f" Arrows show Gaia proper motion after {pm_years} years. \n"
439
+ f" ← Histogram of the MADs between 3*3 pixel fluxes. \n"
440
+ f" ↓ Fluxes of each pixels after contaminations are removed. \n"
441
+ f" The fluxes are normalized and detrended. The background \n"
442
+ f" color shows the pixel brightness after the decontamination. \n"
443
+ f"\n"
444
+ f"How to interpret these plots: \n"
445
+ f" If the signals you are interested in (i.e. transits, \n"
446
+ f" eclipses, variable stars) show similar amplitudes in \n"
447
+ f" all (especially the center 3*3) pixels, then the star \n"
448
+ f" is likely to be the source. The median absolute \n"
449
+ f" differences (MADs) taken between all combinations \n"
450
+ f" of the center pixel fluxes are shown in the histogram \n"
451
+ f" for a quantititive comparison to other possible sources. \n"
452
+ f" The star with smaller distribution width (IQR or \n"
453
+ f" STD) is more likely to be the source of the signal. \n"
454
+ f"\n"
455
+ f"Interquartile Range (IQR): {iqr:05f} \n"
456
+ f"Standard Deviation: {std_dev:05f}", transform=text_ax.transAxes, ha='left',
457
+ va='top')
458
+ plt.subplots_adjust(top=.98, bottom=0.05, left=0.05, right=0.95)
459
+ plt.savefig(
460
+ f'{local_directory}plots/contamination_sector_{hdul[0].header["SECTOR"]:04d}_Gaia_DR3_{gaia_dr3}.pdf',
461
+ dpi=300)
462
+ # plt.savefig(f'{local_directory}plots/contamination_sector_{hdul[0].header["SECTOR"]:04d}_Gaia_DR3_{gaia_dr3}.png',
463
+ # dpi=600)
409
464
  plt.close()
410
465
 
411
466
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tglc
3
- Version: 0.6.4
3
+ Version: 0.6.5
4
4
  Summary: TESS-Gaia Light Curve
5
5
  Home-page: https://github.com/TeHanHunter/TESS_Gaia_Light_Curve
6
6
  Author: Te Han
@@ -11,6 +11,17 @@ Classifier: Operating System :: OS Independent
11
11
  Requires-Python: >=3.8
12
12
  Description-Content-Type: text/x-rst
13
13
  License-File: LICENSE
14
+ Requires-Dist: astropy>=5.1
15
+ Requires-Dist: astroquery
16
+ Requires-Dist: matplotlib
17
+ Requires-Dist: numpy
18
+ Requires-Dist: oauthlib
19
+ Requires-Dist: requests
20
+ Requires-Dist: scipy
21
+ Requires-Dist: threadpoolctl
22
+ Requires-Dist: tqdm
23
+ Requires-Dist: wheel
24
+ Requires-Dist: wotan
14
25
 
15
26
  ==================================
16
27
  Introduction
@@ -1,3 +0,0 @@
1
- __version__ = "0.6.4"
2
- __author__ = 'Te Han, Timothy Brandt'
3
- __credits__ = 'University of California, Santa Barbara'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes