-
Notifications
You must be signed in to change notification settings - Fork 2
/
MakeFrameList.py
executable file
·77 lines (70 loc) · 2.48 KB
/
MakeFrameList.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
from astropy.io import fits as pf
from astropy.time import Time
import numpy as np
import sys,os,glob
import numpy as np
sys.path.append("/home/utsumi/bin")
import config
import argparse
def ChangeDir(DIR):
if os.path.exists(DIR):
cDIR = os.getcwd()
os.chdir(DIR)
return cDIR
else:
print("%s does not exist"%DIR)
return
def ExistKey(Header, KEY, EXCEPT=None):
try:
return Header[KEY]
except:
return EXCEPT
def Header(Fits):
hdulist = pf.open(Fits)
prihdr = hdulist[0].header
EXPID = ExistKey(prihdr, "EXP-ID")
FRAMEID = ExistKey(prihdr, "FRAMEID")
OBJECT = ExistKey(prihdr, "OBJECT", "none")
FILTER = ExistKey(prihdr, "FILTER")
EXPTIME = ExistKey(prihdr, "EXPTIME")
RA = ExistKey(prihdr, "RA-DEG")
DEC = ExistKey(prihdr, "DEC-DEG")
CDITH = ExistKey(prihdr, "CDITHER")
NDITH = ExistKey(prihdr, "NDITHER")
if OBJECT.lower().find("dark") > -1:
MODE = "DARK"
elif OBJECT.lower().find("flat") > -1:
MODE = "FLAT"
else:
MODE = "OBJECT"
TIME = Time(ExistKey(prihdr, "DATE-OBS", "2018-05-17")+" "+ExistKey(prihdr, "UT", "15:01:02"))
MJD = TIME.mjd
MEAN = hdulist[0].data.astype("float").mean()
LINE = hdulist[0].data.astype("float").flatten()
LINE.sort()
MEDIAN = LINE[int(len(LINE)/2)]
STD = hdulist[0].data.astype("float").std()
MAX = hdulist[0].data.astype("float").max()
return [EXPID,FRAMEID,MODE,EXPTIME,FILTER,RA,DEC,OBJECT,CDITH,NDITH,MJD,MEAN,MEDIAN,STD,MAX]
parser = argparse.ArgumentParser(
prog="Make Frame List",
usage="MakeFrameList.py -d directory \n",
description='Print Header info to log file.',
add_help=True)
parser.add_argument('-d', '--directory', metavar='directory', type=str,
default=config.targetdir, help='Directory to save log file')
args = parser.parse_args()
if __name__ == '__main__':
import glob
currentdir = ChangeDir(args.directory)
LIST = sorted(glob.glob("*-?.fits"))
Column = ["EXPID","FRAMEID","MODE","EXPTIME","FILTER","RA","DEC","OBJECT","CDITH","NDITH","MJD","MEAN","MEDIAN","STD","MAX"]
aa = [Column]
for F1 in LIST:
aa.append(Header(F1))
outf = "header.log"
data = np.array(aa)
np.savetxt(outf,data,delimitr="\t",fmt="$s")
currentdir = ChangeDir(currentdir)
print("Saved log file is : \n%s" % os.path.join(currentdir, outf))