1
- from functools import lru_cache
1
+ from functools import lru_cache , cached_property
2
2
from typing import Optional , Union , Dict
3
3
4
4
import numpy as np
@@ -64,7 +64,7 @@ def __init__(self, sector: int, camera: int, ccd: int):
64
64
def __repr__ (self ):
65
65
return f"TESSCube [Sector { self .sector } , Camera { self .camera } , CCD { self .ccd } ]"
66
66
67
- @property
67
+ @cached_property
68
68
def header_dict (self ) -> Dict :
69
69
"""
70
70
Get the header keywords from the MAST cube.
@@ -103,12 +103,12 @@ def from_skycoord(coord: SkyCoord, sector: int):
103
103
if cube .wcs .footprint_contains (coord ):
104
104
return cube
105
105
106
- @property
106
+ @cached_property
107
107
def primary_hdu (self ):
108
108
"""The primary HDU of the cube file."""
109
109
return get_primary_hdu (object_key = self .object_key )
110
110
111
- @property
111
+ @cached_property
112
112
def last_hdu (self ):
113
113
"""The last HDU of the cube file."""
114
114
end = (
@@ -117,11 +117,23 @@ def last_hdu(self):
117
117
)
118
118
return get_last_hdu (object_key = self .object_key , end = end )
119
119
120
- @property
120
+ @cached_property
121
121
def ffi_names (self ):
122
122
"""The FFI names used to make the cube."""
123
123
return list (self .last_hdu .data ["FFI_FILE" ])
124
124
125
+ @cached_property
126
+ def tstart (self ):
127
+ return self .last_hdu .data ["TSTART" ]
128
+
129
+ @cached_property
130
+ def tstop (self ):
131
+ return self .last_hdu .data ["TSTOP" ]
132
+
133
+ @cached_property
134
+ def telapse (self ):
135
+ return self .last_hdu .data ["TELAPSE" ]
136
+
125
137
@lru_cache (maxsize = 4 )
126
138
def get_ffi (
127
139
self ,
@@ -159,8 +171,8 @@ def get_ffi(
159
171
)
160
172
161
173
if time is not None :
162
- start = Time (self .last_hdu . data [ "TSTART" ] + 2457000 , format = "jd" )
163
- end = Time (self .last_hdu . data [ "TSTART" ] + 2457000 , format = "jd" )
174
+ start = Time (self .tstart + 2457000 , format = "jd" )
175
+ end = Time (self .tstop + 2457000 , format = "jd" )
164
176
t = Time .now ()
165
177
t = Time (2459343.87182313 , format = "jd" )
166
178
if not ((t > start ).any () & (t < end ).any ()):
@@ -296,8 +308,8 @@ def get_tpf(
296
308
)
297
309
mask = np .in1d (cadenceno , idxs )
298
310
time = (
299
- self .last_hdu . data [ " tstop" ] [k ][mask ][::frame_bin ]
300
- + self .last_hdu . data [ " tstart" ] [k ][mask ][(frame_bin - 1 ) :: frame_bin ]
311
+ self .tstop [k ][mask ][::frame_bin ]
312
+ + self .tstart [k ][mask ][(frame_bin - 1 ) :: frame_bin ]
301
313
) / 2
302
314
timecorr = np .nanmean (
303
315
np .asarray (
@@ -454,33 +466,30 @@ def get_tpf(
454
466
hdulist = fits .HDUList ([self .output_primary_ext , table_hdu , aperture_hdu ])
455
467
return hdulist
456
468
457
- @property
469
+ @cached_property
458
470
def time (self ):
459
471
"""Time of the frames in BTJD. Note this is the time at the center of the FFI."""
460
- return (self .last_hdu . data [ "TSTART" ] + self .last_hdu . data [ "TSTOP" ] ) / 2
472
+ return (self .tstart + self .tstop ) / 2
461
473
462
- @property
474
+ @cached_property
463
475
def timecorr (self ):
464
476
"""Barycentric time correction for the center of the FFI."""
465
477
return self .last_hdu .data ["BARYCORR" ]
466
478
467
- @property
479
+ @cached_property
468
480
def quality (self ):
469
481
"""SPOC provided quality flags for each cadence."""
470
482
return self .last_hdu .data ["DQUALITY" ]
471
483
472
- @property
484
+ @cached_property
473
485
def cadence_number (self ):
474
486
"""Cadence number for each frame. Note this is not the same as the SPOC provided cadence numbers."""
475
487
cadence_number = np .cumsum (
476
- np .round (
477
- np .diff (self .last_hdu .data ["TSTART" ])
478
- / np .median (self .last_hdu .data ["TELAPSE" ])
479
- ).astype (int )
488
+ np .round (np .diff (self .tstop ) / np .median (self .telapse )).astype (int )
480
489
)
481
490
return np .hstack ([cadence_number , cadence_number [- 1 ] + 1 ])
482
491
483
- @property
492
+ @cached_property
484
493
def exposure_time (self ):
485
494
"""Exposure time in days"""
486
495
return self .last_hdu .data ["EXPOSURE" ][0 ]
0 commit comments