-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadexpdate.py
More file actions
executable file
·49 lines (39 loc) · 1.25 KB
/
readexpdate.py
File metadata and controls
executable file
·49 lines (39 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/local/Caskroom/miniconda/base/envs/astro/bin/python
# Read the date-obs from header of HST image
### import statements ###
import argparse as ap
from glob import glob
from astropy.io import fits
from astropy.time import Time
### main function ###
def main(args: ap.Namespace) -> int:
fn = args.filename
ext = args.extension
fl = sorted(glob(fn))
for fn in fl:
with fits.open(fn) as hdu:
dateobs = hdu[ext].header['date-obs']
decyear = Time(dateobs).decimalyear
print(f'{fn}\t{dateobs}\t{decyear:.4f}')
return 0
###############################################################################
###############################################################################
if __name__ == '__main__':
s = 'Print the date of observation of an hst image.'
parser = ap.ArgumentParser(description=s)
_ = parser.add_argument(
'-f',
'--filename',
help='Name of file (wildcards are allowed).',
default='./*.fits',
type=str,
)
_ = parser.add_argument(
'-e',
'--extension',
help='Header extension in hdu (default is 0)',
default=0,
type=int,
)
args = parser.parse_args()
raise SystemExit(main(args))