-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshowfits.py
More file actions
executable file
·67 lines (59 loc) · 1.9 KB
/
Copy pathshowfits.py
File metadata and controls
executable file
·67 lines (59 loc) · 1.9 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
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env python
#
# show FLI camera images on ds9
# showfits.py
#
# Ver 1.0 2018/06/13 H. Akitaya
# Ver 1.1 2019/11/05 M. Sasada
import sys,os,re,tempfile, time, shutil
import astropy.io.fits as fits
import datetime
from subprocess import Popen, PIPE
import config
IntPattern = re.compile('\d+')
TMPIMGDIR=config.DATADIR
#RECENTFN_RECORD_COMMON_FN="recent.log"
imginfo=[['0', 0.0], ['1', 0.0], ['2', 0.0]]
def showFitsImage(fn, frame_n):
#cmd0 = "xpaget xpans"
os.system("xpaset -p ds9 frame %s"%str(int(frame_n)+1))
os.system("cat %s | xpaset ds9 fits"%fn)
os.system("xpaset -p ds9 frame center")
os.system("xpaset -p ds9 zoom to fit")
os.system("xpaset -p ds9 scale mode zscale")
if int(Frame) == 0 or int(Frame) == 2:
os.system("xpaset -p ds9 orient X")
def getRecentFn(info):
File = "recent." + info[0] + ".log"
FILE = os.path.join(TMPIMGDIR,File)
return FILE
#return ('%s%s%s' % (TMPIMGDIR, info[1], RECENTFN_RECORD_COMMON_FN))
def checkFileUpdate():
for info in imginfo:
fn = getRecentFn(info)
if not os.path.isfile(fn):
continue
try:
f = open(fn, 'r')
fitsfn=f.readline().strip()
f.close()
except:
continue
if os.path.isfile(fitsfn):
tms = os.stat(fitsfn).st_mtime
if (tms > info[2]):
showFitsImage(fitsfn, info[0])
# showFitsImage(d, fitsfn, info[0])
info[2] = tms
dt = datetime.datetime.fromtimestamp(tms)
print("%s: %s" % (dt.strftime('%Y/%m/%d %H:%M:%S'), os.path.basename(fitsfn)))
def loopChkFile():
while(True):
try:
checkFileUpdate()
time.sleep(1)
except KeyboardInterrupt:
sys.stderr.write('Ctrl+C Interruption\n')
exit(1)
if __name__ == "__main__":
loopChkFile()