Closedown
This commit is contained in:
@@ -1,241 +0,0 @@
|
||||
#! /usr/bin/env python
|
||||
'''
|
||||
X_X04SA_do_casave.py - Script to execute a casave command.
|
||||
====================
|
||||
|
||||
Usage:
|
||||
|
||||
%s [<options>] -- <arguments-for-casave>
|
||||
|
||||
Description:
|
||||
casave seems to be not 100%% reliable, at least when run from
|
||||
spec via a "unix" command. It sometimes hangs up.
|
||||
|
||||
X_X04SA_do_casave.py will spawn a child process to run casave
|
||||
with the given <arguments-for-casave>. If the process does
|
||||
not terminate within the timeout (default = 5 secs), the
|
||||
child process will be killed.
|
||||
|
||||
If the child process is killed, <arguments-for-casave> will
|
||||
be parsed, looking for a -asciiout option. If it is found,
|
||||
a file of the given name will be created containing the text
|
||||
|
||||
casave killed at <date> <time>
|
||||
|
||||
Options:
|
||||
-h generate this help text.
|
||||
-v display version information.
|
||||
--debug turn on debug printout.
|
||||
--timeout=<secs> specify a timeout. Default = 5 secs.
|
||||
-- marks the start of args for casave.
|
||||
'''
|
||||
#---------------------------------------------------------------------------
|
||||
import os, sys, commands
|
||||
# Make sure we are running at least python level 2.
|
||||
# CaChannel seems to give troubles otherwise!
|
||||
try:
|
||||
if sys.version[0:1] == "1":
|
||||
python2 = commands.getoutput ("type -p python2")
|
||||
if python2 == "":
|
||||
print "\n\aThe default python version is", sys.version
|
||||
print "and this script needs python level 2 or higher."
|
||||
print " Python level 2 cannot be found."
|
||||
sys.exit (1)
|
||||
#endif
|
||||
sys.argv.insert (0, python2)
|
||||
os.execv (python2, sys.argv)
|
||||
#endif
|
||||
if sys.version[0:1] == "1":
|
||||
print "\n\aThe loading of python level 2 seems to have failed!"
|
||||
sys.exit (1)
|
||||
#endif
|
||||
except:
|
||||
print "\n\aFailed to load python level 2!"
|
||||
raise
|
||||
#endtry
|
||||
#---------------------------------------------------------------------------
|
||||
import time
|
||||
import getopt
|
||||
import string
|
||||
#---------------------------------------------------------------------------
|
||||
#
|
||||
def makeErrorReport (cmnd):
|
||||
# ===============
|
||||
os.system ("echo $(date) %s >> /exchange/share/X04SA/casaveErrors.log" % cmnd)
|
||||
#enddef
|
||||
#
|
||||
#---------------------------------------------------------------------------
|
||||
#
|
||||
def show_usage ():
|
||||
# ==========
|
||||
#
|
||||
base = os.path.basename (sys.argv[0])
|
||||
print __doc__ % base
|
||||
return
|
||||
#enddef
|
||||
#
|
||||
#---------------------------------------------------------------------------
|
||||
#
|
||||
def show_version ():
|
||||
# ============
|
||||
#
|
||||
cvsrepos = \
|
||||
"$Source: /cvs/X/X04SA/App/scripts/X_X04SA_do_casave.py,v $"
|
||||
cvsdate = "$Date: 2006/07/07 11:56:16 $"
|
||||
cvsrevision = "$Revision: 1.2 $"
|
||||
#
|
||||
print
|
||||
print "File: ", sys.argv[0]
|
||||
#
|
||||
l = len (cvsrepos)
|
||||
print "Repository:", cvsrepos[9:l-1]
|
||||
#
|
||||
l = len (cvsdate)
|
||||
print "Date: ", time.strftime ("%d-%b-%Y %H:%M:%S", \
|
||||
time.strptime (cvsdate[7:l-1], "%Y/%m/%d %H:%M:%S"))
|
||||
#
|
||||
l = len (cvsrevision)
|
||||
print "Revision: ", cvsrevision[11:l-1]
|
||||
print
|
||||
return
|
||||
#enddef
|
||||
#
|
||||
#---------------------------------------------------------------------------
|
||||
#---------------------------------------------------------------------------
|
||||
#----------------------------------- The program starts here ---------------
|
||||
#---------------------------------------------------------------------------
|
||||
try:
|
||||
red = chr (0x1b) + "[01;31m"
|
||||
green = chr (0x1b) + "[01;32m"
|
||||
blue = chr (0x1b) + "[01;34m"
|
||||
off = chr (0x1b) + "[00m"
|
||||
#
|
||||
# Analyse the options
|
||||
#
|
||||
TimeOut = 5.0
|
||||
|
||||
Debug = 0
|
||||
|
||||
(opts, items) = getopt.getopt (sys.argv[1:], "h?v", \
|
||||
("help", "debug", "timeout="))
|
||||
for opt in opts:
|
||||
if opt[0] == "-h": raise "Help"
|
||||
if opt[0] == "-?": raise "Help"
|
||||
if opt[0] == "--help": raise "Help"
|
||||
if opt[0] == "-v": raise "Version"
|
||||
if opt[0] == "--debug": Debug = 1
|
||||
if opt[0] == "--timeout":
|
||||
try:
|
||||
TimeOut = float (opt[1])
|
||||
except:
|
||||
raise "BadTimeout"
|
||||
#endtry
|
||||
if TimeOut < 0.1: raise "BadTimeout"
|
||||
#endif
|
||||
#endfor
|
||||
|
||||
if Debug:
|
||||
print "Arguments for casave are:"
|
||||
for item in items:
|
||||
print " ", item
|
||||
#endfor
|
||||
print "--- End of Arguments"
|
||||
print "Time-out = %.1f secs" % TimeOut
|
||||
#endif
|
||||
|
||||
cmnd = "casave"
|
||||
for item in items:
|
||||
cmnd = cmnd + " " + item
|
||||
#endfor
|
||||
if Debug:
|
||||
print "casave command is:"
|
||||
print " ", cmnd
|
||||
#endif
|
||||
pid = os.fork ()
|
||||
if pid == 0:
|
||||
status = os.system (cmnd)
|
||||
if Debug: print "casave exit status = %d" % status
|
||||
sys.exit (0)
|
||||
else:
|
||||
nLoops = int (TimeOut * 10)
|
||||
if Debug: print "PID of casave = %d, # loops = %d" % (pid, nLoops)
|
||||
for cnt in range (nLoops):
|
||||
time.sleep (0.1)
|
||||
(childPID, childStatus) = os.waitpid (pid, os.WNOHANG)
|
||||
if childPID != 0:
|
||||
if Debug: print "Status from casave = %d" % childStatus
|
||||
sys.exit (childStatus)
|
||||
#endif
|
||||
#endfor
|
||||
print "\a<<< %scasave has timed-out, killing all casave processes%s >>>" % (red, off)
|
||||
makeErrorReport (cmnd)
|
||||
#----------------------------------------------------------
|
||||
# The following code is not completely solid ...
|
||||
#
|
||||
if Debug: print "Finding PID of process to kill ..."
|
||||
killCmnd = ""
|
||||
psCmnd = "ps -Af | grep -v grep | grep casave | grep %d" % pid
|
||||
(status, op) = commands.getstatusoutput (psCmnd)
|
||||
if status != 0:
|
||||
if Debug: print "<<< %Cannot find any casave processes to kill.%s >>>" % (red, off)
|
||||
pass
|
||||
else:
|
||||
psRecds = string.split (op, "\n")
|
||||
if len (psRecds) == 0:
|
||||
if Debug: print "<<< %sCannot find any casave processes to kill.%s >>>" % (red, off)
|
||||
pass
|
||||
elif len (psRecds) > 1:
|
||||
if Debug: print "<<< %sCannot find a unique casave process to kill.%s >>>" % (red, off)
|
||||
pass
|
||||
else:
|
||||
toks = string.split (psRecds[0])
|
||||
if Debug: print psRecds[0]
|
||||
casavePID = int (toks[1])
|
||||
killCmnd = "kill -9 %d" % casavePID
|
||||
#endif
|
||||
#endif
|
||||
if killCmnd == "":
|
||||
if Debug: print "<<< %sKilling all casave processes.%s >>>" % (red, off)
|
||||
killCmnd = "killall -KILL casave"
|
||||
#endif
|
||||
#----------------------------------------------------------
|
||||
# Remove the next command when the above code has been made solid!
|
||||
#
|
||||
killCmnd = "killall -KILL casave"
|
||||
#----------------------------------------------------------
|
||||
if Debug: print "Kill command is \"%s\"" % killCmnd
|
||||
os.system (killCmnd)
|
||||
#endif
|
||||
sys.exit (0)
|
||||
|
||||
#
|
||||
except KeyboardInterrupt:
|
||||
print "%sInterrupted!%s" % (blue, off)
|
||||
sys.exit (0)
|
||||
#
|
||||
except SystemExit, value:
|
||||
sys.exit (value)
|
||||
#
|
||||
except:
|
||||
show_usage ()
|
||||
sys.exit (0)
|
||||
|
||||
#--------------------------------------------------#
|
||||
# emacs setup - force text mode to prevent emacs #
|
||||
# from helping with the indentation #
|
||||
# and tell emacs to use spaces when #
|
||||
# tabbing. #
|
||||
# Local Variables: #
|
||||
# mode:text #
|
||||
# indent-tabs-mode:nil #
|
||||
# End: #
|
||||
#--------------------------------------------------#
|
||||
# Contact: D.Maden
|
||||
# Intial version: Oct 2003
|
||||
#
|
||||
# $Author: maden $
|
||||
# $Source: /cvs/X/X04SA/App/scripts/X_X04SA_do_casave.py,v $
|
||||
# $Revision: 1.2 $
|
||||
# $Date: 2006/07/07 11:56:16 $
|
||||
#
|
||||
#------------------------------------- End of X_X04SA_do_casave.py
|
||||
@@ -1,14 +1,3 @@
|
||||
"""
|
||||
PIX_PATHA_CHN = "X04SA-ES3-CCD:PATHa"
|
||||
PIX_PATHB_CHN = "X04SA-ES3-CCD:PATHb"
|
||||
PIX_FNAM_FMT_CHN = "X04SA-ES3-CCD:FNAM_FMT"
|
||||
PIX_FNUM_CHN = "X04SA-ES3-CCD:FNUM"
|
||||
PIX_FNAM_CHN = "X04SA-ES3-CCD:FNAM"
|
||||
PIX_EXPOSE_CHN = "X04SA-ES3-CCD:EXPOSE"
|
||||
PIX_STATUS_CHN = "X04SA-ES3-CCD:STATUS"
|
||||
PIX_TRIG_CHN = "X04SA-ES3-CCD:TRIG"
|
||||
"""
|
||||
|
||||
class ImageFilename(DeviceBase, Readable, Readable.StringType):
|
||||
def __init__(self, pixel):
|
||||
DeviceBase.__init__(self, "image filename")
|
||||
@@ -201,15 +190,9 @@ class Pixel(DeviceBase, Readable, Readable.IntegerType):
|
||||
if sms_flag == 1:
|
||||
notify ("Pixel detector seems to have recovered from error.")
|
||||
|
||||
def logwrite(self):
|
||||
filename = self.get_log_file()
|
||||
#"pixel/imagelogs/ccd-log.req"
|
||||
#inp = sprintf ("%s/ccd-log.req", _1)
|
||||
#PIX_LOG_CMND = sprintf ("X_X04SA_do_casave.py -- -asciiin %s -asciiout %%s", myFile)
|
||||
#myCmnd = sprintf (PIX_LOG_CMND, myFile)
|
||||
inp = "/sls/X04SA/data/x04sa/ES3/expdata/" + "test/" + "pixel/imagelogs/ccd-log.req"
|
||||
#run("X_X04SA_do_casave.py", ["--", "-asciiin", inp, "-asciiout", filename])
|
||||
|
||||
def set_auto_threshold(self):
|
||||
#TODO
|
||||
pass
|
||||
|
||||
def show(self):
|
||||
print "\nThe current pixel detector settings are:"
|
||||
@@ -231,6 +214,7 @@ class Pixel(DeviceBase, Readable, Readable.IntegerType):
|
||||
def read(self):
|
||||
#Readable interface: current
|
||||
return self.get_count_id()
|
||||
|
||||
|
||||
add_device( Pixel("pixel", "X04SA-ES3-CCD"), True)
|
||||
pixel.polling = 1000
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
|
||||
# parse aguments
|
||||
# image info file
|
||||
# threshold 1
|
||||
# threshold 2
|
||||
# threshold 3
|
||||
# threshold 4
|
||||
# median filter
|
||||
# filter nsigma
|
||||
info = sys.argv[1]
|
||||
thres1 = int(sys.argv[2])
|
||||
thres2 = int(sys.argv[3])
|
||||
thres3 = int(sys.argv[4])
|
||||
thres4 = int(sys.argv[5])
|
||||
|
||||
filter_median = False
|
||||
if len(sys.argv) > 6 and sys.argv[6] == '-median':
|
||||
filter_median = True
|
||||
|
||||
filter_nsigma = 0.0
|
||||
if len(sys.argv) > 7:
|
||||
filter_nsigma = float(sys.argv[7])
|
||||
|
||||
# read image info text file
|
||||
f = open(info)
|
||||
|
||||
fname = f.next().strip()
|
||||
timestamp = f.next().strip()
|
||||
header = f.next().strip()
|
||||
width, height, depth = [int(p) for p in f.next().strip().split()]
|
||||
x1,y1,x2,y2 = [int(p) for p in f.next().strip().split()]
|
||||
bx1,by1,bx2,by2 = [int(p) for p in f.next().strip().split()]
|
||||
|
||||
f.close()
|
||||
|
||||
# read actual image file
|
||||
import numpy
|
||||
img = numpy.fromfile(fname, dtype=numpy.uint32)
|
||||
img.shape = height, width
|
||||
|
||||
# signal roi
|
||||
area_I = ( x2 - x1 + 1) * ( y2 - y1 + 1)
|
||||
|
||||
I_sum = img[y1:y2, x1:x2].sum()
|
||||
thresh1_count = len(numpy.where(img>thres1)[0])
|
||||
thresh2_count = len(numpy.where(img>thres2)[0])
|
||||
thresh3_count = len(numpy.where(img>thres3)[0])
|
||||
thresh4_count = len(numpy.where(img>thres4)[0])
|
||||
|
||||
# background roi
|
||||
I_sum_bgr = img[by1:by2, bx1:bx2].sum()
|
||||
area_bgr= (bx2 - bx1 + 1) * (by2 - by1 + 1)
|
||||
|
||||
set_return ((I_sum, area_I, thresh1_count, thresh2_count, thresh3_count, thresh4_count, I_sum_bgr, area_bgr))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user