tglc 0.6.5__tar.gz → 0.6.6__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.5
3
+ Version: 0.6.6
4
4
  Summary: TESS-Gaia Light Curve
5
5
  Home-page: https://github.com/TeHanHunter/TESS_Gaia_Light_Curve
6
6
  Author: Te Han
@@ -8,11 +8,11 @@ Author-email: tehanhunter@gmail.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
11
+ Requires-Python: >=3.8, <3.13
12
12
  Description-Content-Type: text/x-rst
13
13
  License-File: LICENSE
14
14
  Requires-Dist: astropy>=5.1
15
- Requires-Dist: astroquery
15
+ Requires-Dist: astroquery==0.4.7
16
16
  Requires-Dist: matplotlib
17
17
  Requires-Dist: numpy
18
18
  Requires-Dist: oauthlib
@@ -22,6 +22,7 @@ Requires-Dist: threadpoolctl
22
22
  Requires-Dist: tqdm
23
23
  Requires-Dist: wheel
24
24
  Requires-Dist: wotan
25
+ Requires-Dist: seaborn
25
26
 
26
27
  ==================================
27
28
  Introduction
@@ -29,6 +30,7 @@ Introduction
29
30
 
30
31
  TESS-Gaia Light Curve (`TGLC <https://archive.stsci.edu/hlsp/tglc>`_) is a dataset of TESS full-frame image light curves publicly available via the MAST portal. It is fitted with effective PSF and decontaminated with Gaia DR3 and achieved percent-level photometric precision down to 16th TESS magnitude! It unlocks astrophysics to a vast number of dim stars below 12th TESS magnitude. A package called tglc is pip-installable for customized light curve fits.
31
32
 
33
+
32
34
  ==================================
33
35
  Usage
34
36
  ==================================
@@ -4,6 +4,7 @@ Introduction
4
4
 
5
5
  TESS-Gaia Light Curve (`TGLC <https://archive.stsci.edu/hlsp/tglc>`_) is a dataset of TESS full-frame image light curves publicly available via the MAST portal. It is fitted with effective PSF and decontaminated with Gaia DR3 and achieved percent-level photometric precision down to 16th TESS magnitude! It unlocks astrophysics to a vast number of dim stars below 12th TESS magnitude. A package called tglc is pip-installable for customized light curve fits.
6
6
 
7
+
7
8
  ==================================
8
9
  Usage
9
10
  ==================================
@@ -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.5',
9
+ version='0.6.6',
10
10
  author="Te Han",
11
11
  author_email="tehanhunter@gmail.com",
12
12
  description="TESS-Gaia Light Curve",
@@ -18,9 +18,9 @@ setuptools.setup(
18
18
  "License :: OSI Approved :: MIT License",
19
19
  "Operating System :: OS Independent",
20
20
  ],
21
- install_requires=['astropy>=5.1', 'astroquery', 'matplotlib', 'numpy', 'oauthlib', 'requests', 'scipy',
22
- 'threadpoolctl', 'tqdm', 'wheel', 'wotan'],
21
+ install_requires=['astropy>=5.1', 'astroquery==0.4.7', 'matplotlib', 'numpy', 'oauthlib', 'requests', 'scipy',
22
+ 'threadpoolctl', 'tqdm', 'wheel', 'wotan', 'seaborn'],
23
23
  packages=setuptools.find_packages(include=['tglc', 'tglc.*']),
24
- python_requires=">=3.8",
24
+ python_requires=">=3.8, <3.13",
25
25
  include_package_data=True
26
26
  )
@@ -0,0 +1,3 @@
1
+ __version__ = "0.6.6"
2
+ __author__ = 'Te Han, Timothy Brandt'
3
+ __credits__ = 'University of California, Santa Barbara'
@@ -191,16 +191,19 @@ def fit_lc(A, source, star_info=None, x=0., y=0., star_num=0, factor=2, psf_size
191
191
  coord = np.arange(size ** 2).reshape(size, size)
192
192
  index = np.array(coord[down:up, left:right]).flatten()
193
193
  A_cut = np.zeros((len(index), np.shape(A)[1]))
194
+ A_target = np.zeros((len(index), np.shape(A)[1]))
194
195
  for i in range(len(index)):
195
196
  A_ = np.zeros(np.shape(A)[-1])
196
197
  star_pos = np.where(star_info_num[0] == index[i])[0]
197
198
  A_[star_info_num[1][star_pos]] = star_info_num[2][star_pos]
199
+ A_target[i] = A_
198
200
  A_cut[i] = A[index[i], :] - A_
199
201
  aperture = np.zeros((len(source.time), len(index)))
200
202
  for j in range(len(source.time)):
201
203
  aperture[j] = np.array(source.flux[j][down:up, left:right]).flatten() - np.dot(A_cut, e_psf[j])
202
204
  aperture = aperture.reshape((len(source.time), up - down, right - left))
203
- # np.save(f'_residual_{source.sector}.npy', aperture)
205
+ target_5x5 = (np.dot(A_target, np.nanmedian(e_psf, axis=0)).reshape(cut_size, cut_size))
206
+ field_stars_5x5 = (np.dot(A_cut, np.nanmedian(e_psf, axis=0)).reshape(cut_size, cut_size))
204
207
 
205
208
  # psf_lc
206
209
  over_size = psf_size * factor + 1
@@ -262,7 +265,7 @@ def fit_lc(A, source, star_info=None, x=0., y=0., star_num=0, factor=2, psf_size
262
265
  portion = np.nansum(psf_shape[:, 4:7, 4:7]) / np.nansum(psf_shape)
263
266
  # print(np.nansum(psf_shape[:, 5, 5]) / np.nansum(psf_shape))
264
267
  # np.save(f'toi-5344_psf_{source.sector}.npy', psf_shape)
265
- return aperture, psf_lc, y - down, x - left, portion
268
+ return aperture, psf_lc, y - down, x - left, portion, target_5x5, field_stars_5x5
266
269
 
267
270
 
268
271
  def fit_lc_float_field(A, source, star_info=None, x=np.array([]), y=np.array([]), star_num=0, factor=2, psf_size=11,
@@ -86,7 +86,7 @@ def convert_gaia_id(catalogdata_tic):
86
86
  FROM gaiadr3.dr2_neighbourhood
87
87
  WHERE dr2_source_id IN {gaia_ids}
88
88
  """
89
- gaia_array = np.array(catalogdata_tic['GAIA'])
89
+ gaia_array = np.array([str(item) for item in catalogdata_tic['GAIA']], dtype=object)
90
90
  gaia_array = gaia_array[gaia_array != 'None']
91
91
  # np.save('gaia_array.npy', gaia_array)
92
92
  segment = (len(gaia_array) - 1) // 10000
@@ -14,8 +14,9 @@ from astroquery.mast import Catalogs
14
14
  import astropy.units as u
15
15
  from astropy.coordinates import SkyCoord
16
16
  from astroquery.mast import Tesscut
17
+ import sys
18
+ import warnings
17
19
  # Tesscut._service_api_connection.TIMEOUT = 6000
18
-
19
20
  # warnings.simplefilter('ignore', UserWarning)
20
21
  from threadpoolctl import ThreadpoolController, threadpool_limits
21
22
  import numpy as np
@@ -297,8 +298,7 @@ def plot_pf_lc(local_directory=None, period=None, mid_transit_tbjd=None, kind='c
297
298
  def plot_contamination(local_directory=None, gaia_dr3=None, ymin=None, ymax=None, pm_years=3000):
298
299
  sns.set(rc={'font.family': 'serif', 'font.serif': 'DejaVu Serif', 'font.size': 12,
299
300
  'axes.edgecolor': '0.2', 'axes.labelcolor': '0.', 'xtick.color': '0.', 'ytick.color': '0.',
300
- 'axes.facecolor': '0.95', "axes.grid": False})
301
-
301
+ 'axes.facecolor': '0.95', 'grid.color': '0.9'})
302
302
  files = glob(f'{local_directory}lc/*{gaia_dr3}*.fits')
303
303
  os.makedirs(f'{local_directory}plots/', exist_ok=True)
304
304
  for i in range(len(files)):
@@ -307,8 +307,8 @@ def plot_contamination(local_directory=None, gaia_dr3=None, ymin=None, ymax=None
307
307
  q = [a and b for a, b in
308
308
  zip(list(hdul[1].data['TESS_flags'] == 0), list(hdul[1].data['TGLC_flags'] == 0))]
309
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
310
+ ymin = np.nanmin(hdul[1].data['cal_aper_flux'][q]) - 0.01
311
+ ymax = np.nanmax(hdul[1].data['cal_aper_flux'][q]) + 0.01
312
312
  with open(glob(f'{local_directory}source/*_{sector}.pkl')[0], 'rb') as input_:
313
313
  source = pickle.load(input_)
314
314
  source.select_sector(sector=sector)
@@ -340,7 +340,7 @@ def plot_contamination(local_directory=None, gaia_dr3=None, ymin=None, ymax=None
340
340
  ax0.scatter(source.gaia[f'sector_{sector}_x'][nearby_stars[nearby_stars != star_num[0][0]]],
341
341
  source.gaia[f'sector_{sector}_y'][nearby_stars[nearby_stars != star_num[0][0]]],
342
342
  s=30, c='r', edgecolor='black', linewidth=1, label='background stars')
343
-
343
+ ax0.grid(False)
344
344
  for l in range(len(nearby_stars)):
345
345
  index = np.where(
346
346
  source.tic['dr3_source_id'] == int(source.gaia['DESIGNATION'][nearby_stars[l]].split(' ')[-1]))
@@ -380,12 +380,13 @@ def plot_contamination(local_directory=None, gaia_dr3=None, ymin=None, ymax=None
380
380
  ax0.vlines(round(star_x) + 2.5, round(star_y) - 2.5, round(star_y) + 2.5, colors='k', lw=1.2)
381
381
  ax0.hlines(round(star_y) - 2.5, round(star_x) - 2.5, round(star_x) + 2.5, colors='k', lw=1.2)
382
382
  ax0.hlines(round(star_y) + 2.5, round(star_x) - 2.5, round(star_x) + 2.5, colors='k', lw=1.2)
383
- t_, y_, x_ = np.shape(hdul[0].data)
383
+ try:
384
+ t_, y_, x_ = np.shape(hdul[0].data)
385
+ except ValueError:
386
+ warnings.warn('Light curves need to have the primary hdu. Set save_aperture=True when producing the light curve to enable this plot.')
387
+ sys.exit()
384
388
  max_flux = np.max(
385
389
  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
390
  arrays = []
390
391
  for j in range(y_):
391
392
  for k in range(x_):
@@ -461,8 +462,6 @@ def plot_contamination(local_directory=None, gaia_dr3=None, ymin=None, ymax=None
461
462
  dpi=300)
462
463
  # plt.savefig(f'{local_directory}plots/contamination_sector_{hdul[0].header["SECTOR"]:04d}_Gaia_DR3_{gaia_dr3}.png',
463
464
  # dpi=600)
464
- plt.close()
465
-
466
465
 
467
466
  def plot_epsf(local_directory=None):
468
467
  files = glob(f'{local_directory}epsf/*.npy')
@@ -513,7 +512,7 @@ def get_tglc_lc(tics=None, method='query', server=1, directory=None, prior=None)
513
512
 
514
513
  if __name__ == '__main__':
515
514
  tics = [16005254]
516
- directory = f'/home/tehan/data/'
515
+ directory = f'/Users/tehan/Downloads/'
517
516
  os.makedirs(directory, exist_ok=True)
518
517
  get_tglc_lc(tics=tics, method='query', server=1, directory=directory)
519
518
  # plot_lc(local_directory=f'{directory}TIC {tics[0]}/', kind='cal_aper_flux')
@@ -20,7 +20,7 @@ warnings.simplefilter('always', UserWarning)
20
20
  def lc_output(source, local_directory='', index=0, time=None, psf_lc=None, cal_psf_lc=None, aper_lc=None,
21
21
  cal_aper_lc=None, bg=None, tess_flag=None, tglc_flag=None, cadence=None, aperture=None,
22
22
  cut_x=None, cut_y=None, star_x=2, star_y=2, x_aperture=None, y_aperture=None, near_edge=False,
23
- local_bg=None, save_aper=False, portion=1, prior=None, transient=None):
23
+ local_bg=None, save_aper=False, portion=1, prior=None, transient=None, target_5x5=None, field_stars_5x5=None):
24
24
  """
25
25
  lc output to .FITS file in MAST HLSP standards
26
26
  :param tglc_flag: np.array(), required
@@ -82,6 +82,13 @@ def lc_output(source, local_directory='', index=0, time=None, psf_lc=None, cal_p
82
82
  primary_hdu = fits.PrimaryHDU(aperture)
83
83
  else:
84
84
  primary_hdu = fits.PrimaryHDU()
85
+ # Simulated star images based on ePSF, used to estimate contamination ratio and others
86
+ image_data = np.zeros((3, 5, 5))
87
+ image_data[0] = target_5x5
88
+ image_data[1] = field_stars_5x5
89
+ # This is the pixel-wise contamination ratio
90
+ image_data[2] = field_stars_5x5/target_5x5
91
+ image_hdu = fits.ImageHDU(data=image_data)
85
92
 
86
93
  primary_hdu.header = fits.Header(cards=[
87
94
  fits.Card('SIMPLE', True, 'conforms to FITS standard'),
@@ -116,6 +123,7 @@ def lc_output(source, local_directory='', index=0, time=None, psf_lc=None, cal_p
116
123
  fits.Card('GAIA_bp', gaia_bp, 'Gaia DR3 bp band magnitude'),
117
124
  fits.Card('GAIA_rp', gaia_rp, 'Gaia DR3 rp band magnitude'),
118
125
  fits.Card('RAWFLUX', raw_flux, 'median flux of raw FFI'),
126
+ fits.Card('CONTAMRT', round(np.nansum(field_stars_5x5[1:4,1:4])/np.nansum(target_5x5[1:4,1:4]), 9), 'contamination ratio of default 3*3 aperture'),
119
127
  fits.Card('CALIB', 'TGLC', 'pipeline used for image calibration')])
120
128
  if save_aper:
121
129
  primary_hdu.header.comments['NAXIS1'] = "Time (hdul[1].data['time'])"
@@ -190,13 +198,14 @@ def lc_output(source, local_directory='', index=0, time=None, psf_lc=None, cal_p
190
198
  if type(prior) == float:
191
199
  table_hdu.header.append(('PRIOR', prior, 'prior of field stars'), end=True)
192
200
 
193
- hdul = fits.HDUList([primary_hdu, table_hdu])
201
+ hdul = fits.HDUList([primary_hdu, table_hdu, image_hdu])
194
202
  hdul.writeto(
195
- f'{local_directory}hlsp_tglc_tess_ffi_gaiaid-{objid}-s{source.sector:04d}-cam{source.camera}-ccd{source.ccd}_tess_v1_llc.fits',
203
+ f'{local_directory}hlsp_tglc_tess_ffi_gaiaid-{objid}-s{source.sector:04d}-cam{source.camera}-ccd{source.ccd}_tess_v2_llc.fits',
196
204
  overwrite=True)
197
205
  return
198
206
 
199
207
 
208
+
200
209
  def epsf(source, psf_size=11, factor=2, local_directory='', target=None, cut_x=0, cut_y=0, sector=0,
201
210
  limit_mag=16, edge_compression=1e-4, power=1.4, name=None, save_aper=False, no_progress_bar=False, prior=None):
202
211
  """
@@ -310,7 +319,7 @@ def epsf(source, psf_size=11, factor=2, local_directory='', target=None, cut_x=0
310
319
  fit_lc_float_field(A, source, star_info=star_info, x=x_round, y=y_round, star_num=i, e_psf=e_psf,
311
320
  near_edge=near_edge, prior=prior)
312
321
  else:
313
- aperture, psf_lc, star_y, star_x, portion = \
322
+ aperture, psf_lc, star_y, star_x, portion, target_5x5, field_stars_5x5 = \
314
323
  fit_lc(A, source, star_info=star_info, x=x_round[i], y=y_round[i], star_num=i, e_psf=e_psf,
315
324
  near_edge=near_edge)
316
325
  aper_lc = np.sum(
@@ -359,4 +368,4 @@ def epsf(source, psf_size=11, factor=2, local_directory='', target=None, cut_x=0
359
368
  bg=background_, time=source.time, psf_lc=psf_lc, cal_psf_lc=cal_psf_lc, aper_lc=aper_lc,
360
369
  cal_aper_lc=cal_aper_lc, local_bg=local_bg, x_aperture=x_aperture[i],
361
370
  y_aperture=y_aperture[i], near_edge=near_edge, save_aper=save_aper, portion=portion,
362
- prior=prior, transient=source.transient)
371
+ prior=prior, transient=source.transient, target_5x5=target_5x5, field_stars_5x5=field_stars_5x5)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tglc
3
- Version: 0.6.5
3
+ Version: 0.6.6
4
4
  Summary: TESS-Gaia Light Curve
5
5
  Home-page: https://github.com/TeHanHunter/TESS_Gaia_Light_Curve
6
6
  Author: Te Han
@@ -8,11 +8,11 @@ Author-email: tehanhunter@gmail.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
11
+ Requires-Python: >=3.8, <3.13
12
12
  Description-Content-Type: text/x-rst
13
13
  License-File: LICENSE
14
14
  Requires-Dist: astropy>=5.1
15
- Requires-Dist: astroquery
15
+ Requires-Dist: astroquery==0.4.7
16
16
  Requires-Dist: matplotlib
17
17
  Requires-Dist: numpy
18
18
  Requires-Dist: oauthlib
@@ -22,6 +22,7 @@ Requires-Dist: threadpoolctl
22
22
  Requires-Dist: tqdm
23
23
  Requires-Dist: wheel
24
24
  Requires-Dist: wotan
25
+ Requires-Dist: seaborn
25
26
 
26
27
  ==================================
27
28
  Introduction
@@ -29,6 +30,7 @@ Introduction
29
30
 
30
31
  TESS-Gaia Light Curve (`TGLC <https://archive.stsci.edu/hlsp/tglc>`_) is a dataset of TESS full-frame image light curves publicly available via the MAST portal. It is fitted with effective PSF and decontaminated with Gaia DR3 and achieved percent-level photometric precision down to 16th TESS magnitude! It unlocks astrophysics to a vast number of dim stars below 12th TESS magnitude. A package called tglc is pip-installable for customized light curve fits.
31
32
 
33
+
32
34
  ==================================
33
35
  Usage
34
36
  ==================================
@@ -1,5 +1,5 @@
1
1
  astropy>=5.1
2
- astroquery
2
+ astroquery==0.4.7
3
3
  matplotlib
4
4
  numpy
5
5
  oauthlib
@@ -9,3 +9,4 @@ threadpoolctl
9
9
  tqdm
10
10
  wheel
11
11
  wotan
12
+ seaborn
@@ -1,3 +0,0 @@
1
- __version__ = "0.6.5"
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