-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadexptime.py
More file actions
executable file
·55 lines (45 loc) · 1.4 KB
/
readexptime.py
File metadata and controls
executable file
·55 lines (45 loc) · 1.4 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
50
51
52
53
54
55
#! /usr/local/Caskroom/miniconda/base/envs/astro/bin/python
# Read the exptime from header of HST image
### import statements ###
import argparse as ap
from glob import glob
from astropy.io import fits
from numpy import mean
### main function ###
def main(args: ap.Namespace) -> int:
fn = args.filename
ext = args.extension
fl = sorted(glob(fn))
et = []
for fn in fl:
with fits.open(fn) as hdu:
try:
et_i = hdu[ext].header['exptime']
except KeyError:
et_i = hdu[ext].header['effexptm']
et += [et_i]
print(f'{fn}\t{et_i}')
print(f'\nNumber of images: {len(et)}')
print(f'Mean Exp. Time: {mean(et):.0f} seconds')
return 0
###############################################################################
###############################################################################
if __name__ == '__main__':
s = 'Print the exposure time 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))