This commit is contained in:
gac-x04sa
2018-10-18 17:36:39 +02:00
parent 33162e7927
commit 2ed890b76b
7 changed files with 4452 additions and 1 deletions
+1 -1
View File
@@ -41,4 +41,4 @@ oa=ch.psi.pshell.epics.Motor|X04SA-ES3-XPS:OMEGAA|||true
#sixch=ch.psi.pshell.device.MotorGroupBase|alpha delta gamma omegaH nu phi|||
fourcv=ch.psi.pshell.device.MotorGroupBase|alpha delta gamma omegaV|||
$energy=ch.psi.pshell.epics.Positioner|X04SA-DCM:E X04SA-DCM:E-READ|||true
transm=ch.psi.pshell.epics.ControlledVariable|X04SA-ES2-FI:TRANSM-SET X04SA-ES2-FI:TRANSM|||
transm=ch.psi.pshell.epics.ControlledVariable|X04SA-ES2-FI:TRANSM-SET X04SA-ES2-FI:TRANSM|||true
+8
View File
@@ -0,0 +1,8 @@
#Thu Oct 18 17:36:38 CEST 2018
maxValue=1.0
minValue=0.0
offset=0.0
precision=5
resolution=NaN
scale=1.0
unit=
+757
View File
@@ -0,0 +1,757 @@
#==============================================================================
# Macroname: image.mac
# =========
#+
# $Date: 2008/03/20 13:36:14 $
# $Author: schlepuetz $
# $Source: /cvs/G/SPEC/local/X04SA/ES3/image.mac,v $
# $Revision: 1.11 $
# $Tag: $
#
# Description: This macro file provides a set of macro definitions which are
# used to analyze images (taken by any sort of imaging device)
# on-line during data acquisition and return a set of charac-
# teristic values to SPEC.
# It is thus possible to plot results of a scan (usually an
# intensity value) during data acquisition with the imaging
# device, just like one would with a point detector.
# Furthermore, the image information can be used to automate
# filter transmission and exposure time settings during a scan
# (refer to auto.mac for more information on automated scans).
#
# Note: This macro is based on an earlier version by O. Bunk
# and R. Herger
#
# Author: C. M. Schlepuetz (CS)
# Co-author(s): R. Herger (RH), P. R. Willmott (PW)
# Address: Surface Diffraction Station
# Materials Science Beamline X04SA
# Swiss Light Source (SLS)
# Paul Scherrer Institute
# CH - 5232 Villigen PSI
# Created: 2005/07/12
#
#-
# Chained macro definitions affected by this macro:
# -------------------------------------------------
# - user_getcounts
#
# Change Log:
# -----------
#
# 2005/07/12 (CS):
# - created first version of this file.
#
# 2005/12/10 (CS):
# - fixed bug in imageGetInt: background region area was not correctly
# calculated in the c-routine and consequently all intensities were wrong.
# (also changed the c-routine, of course)
#
# 2005/12/11 (CS):
# - attempt to generalize the image_get_int routine to images of different
# sizes and color-depths, and possibly header lengths.
# Introduced new globals variables:
# IMAGE_INFO_FILENAME
# IMAGE_HEADER_LENGTH (in bytes)
# IMAGE_COLOR_DEPTH (in number of bits, e.g. 16 or 32)
# - write an info-file with information about each image in imageUserGetcounts
# which can be accessed by all external programs which want to look at the
# images.
# - Increase the number of threshold levels for image analysis to 4. That way,
# the thresholds for adjusting the exposure time automatically (see also
# auto.mac) and the filter transmission are independent of each other.
# Introduced new global variables:
# IMAGE_THRESH4
# IMAGE_THRESH4_COUNT
#
# 2006/01/27 (CS):
# - fixed typo in imageCheckRoi
#
# 2006/06/23 (CS):
# - retrieve IMAGE_PATH from IMAGE_FILENAME with unix command DIRNAME.
# - copy image information file into IMAGE_PATH such that it is accessible
# to all applications which have access to the image path.
#
# 2006/08/09 (CS):
# - input to 'imgeSetRoi' is now possible in several ways, including user
# interaction.
# - removed old commented out workarounds.
#
# 2006/09/21 (CS):
# - added new functionality to the image_get_int.c routine for selectively
# median filtering only those pixels where the measured intensity differs
# from the mean of the surrounding pixels by more than N times the standard
# deviation of these neighbours. N is presently set to 30 in imageGetInt.
#
# 2006/11/29 (CS):
# - include wait loop in imageUserGetcounts to make sure the image file is
# available an non-empty in order to do statistical analysis with
# image_get_int.c.
#
# 2007/04/05 (CS):
# - new error message if image file to be analyzed is not found.
#
# 2007/04/22 (CS):
# - changed imageCheckROI to allow for ROIs of 1 pixel width/height (used to
# be at least 2 pixels).
#
# 2008/03/19 (CS):
# - removed quotation marks around argument variables $1,$2 in imageSetRoi,
# allowing one to also pass the arguments via variables.
# - added imageShowRoi.
#
#==============================================================================
#
global IMAGE_MAC
#
IMAGE_MAC = DOFILE # Save the name of this macro file.
# (Used for the help function).
#+
#==============================================================================
# This macro file contains the following commands:
#-
#
#+
#------------------------------------------------------------------------------
# imagehelp - generates this help text. This is obtained by
# displaying the file image.txt, which should sit in the
# same directory as this macro file.
#-
# allow for misspelled help commands
def helpimage 'imagehelp'
def helpImage 'imagehelp'
def imageHelp 'imagehelp'
def imagehelp '{
# =========
unix (sprintf ("dirname %s", IMAGE_MAC), _1)
ll = length (_1)
if (substr (_1, ll, 1) == "\n") _1 = substr (_1, 1, (ll - 1))
file = sprintf ("%s/image.txt", _1)
if (file_info (file, "-e")) {
unix (sprintf ("cat %s | less", file))
} else {
printf("\n Macros available in file image.mac ($Revision: 1.11 $):\n")
printf( " ========="\n)
printf("\n")
printf(" imagehelp - creates this help text\n")
printf(" imageOn - turn on image analysis functionality\n")
printf(" imageOff - turn off image analysis functionality\n")
printf(" imageShow - show current image analysis setup.\n")
printf(" imageShowRoi - show current region of interest info.\n")
printf(" imageSetRoi - define a signal and background region-\n")
printf(" of-interest (ROI).")
printf(" imageCheckRoi - checks whether ROI is valid and within\n")
printf(" image bounds.
printf(" imageGetInt - description\n")
}
}'
#+
#------------------------------------------------------------------------------
# imageInit - initializes all global variables used by image.mac
#-
def imageInit '{
# =========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
}'
#+
#------------------------------------------------------------------------------
# imageOn - turn on macro functionality to analyze images acquired by
# an area detector on-line and return the results to SPEC.
#-
def imageon 'imageOn'
def imageOn '{
# =======
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
#--------------------------------------------
# include necessary chained macro definitions
#---------------------
def imageUserGetcounts \'
# ==================
if (IMAGE_IS_ON) {
# update IMAGE_PATH variable
unix(sprintf("dirname %s",IMAGE_FILENAME), IMAGE_PATH)
# write important image information to file so image_get_int.c and other
# possible helper applications can read it.
local ux_cmd
ux_cmd = ""
IMAGE_INFO_FILENAME = "/tmp/spec_image_info.dat"
ux_cmd = sprintf("echo \"%s\" > %s",\\
IMAGE_FILENAME, IMAGE_INFO_FILENAME)
if (unix(ux_cmd) != 0) {
eprint ">> Cannot store image information file <<"
} else {
ux_cmd = sprintf("echo \"%.6f\" >> %s",\\
time(), IMAGE_INFO_FILENAME)
if (unix(ux_cmd) != 0) {
eprint ">> Cannot store image information file <<"
}
unix(sprintf("echo \"%d\" >> %s",\\
IMAGE_HEADER_LENGTH,IMAGE_INFO_FILENAME))
unix(sprintf("echo \"%d %d %d\" >> %s",\\
IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH,\\
IMAGE_INFO_FILENAME))
unix(sprintf("echo \"%d %d %d %d\" >> %s",\\
IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2, \\
IMAGE_INFO_FILENAME))
unix(sprintf("echo \"%d %d %d %d\" >> %s",\\
IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2, \\
IMAGE_INFO_FILENAME))
}
# copy information file into image path
unix(sprintf("cp -f %s %s", IMAGE_INFO_FILENAME, IMAGE_PATH))
# get the AUTO_THRESH2 value if auto levels are enabled
if ((whatis("AUTO_THRESH2") & 0x08000000) == 0) {
IMAGE_THRESH2=AUTO_THRESH2
}
# check whether image file is ready to be read (size > 0 bytes)
retry = 0
_tmp_filename = IMAGE_FILENAME
while((!(file_info(_tmp_filename,"-s"))) & (retry<3000)){
printf("waiting for image file %s\n",IMAGE_FILENAME)
printf("retry %d of 3000\n",retry)
retry++
if (retry%100 == 0) {
unix(sprintf("head -n 1 %f", IMAGE_FILENAME))
}
sleep(0.01)
}
# get the integrated intensity in the intensity and background boxes
imageGetInt IMAGE_THRESH1 IMAGE_THRESH2 IMAGE_THRESH3 IMAGE_THRESH4
# update the auto-level threshold count values if auto-level support
# is available
if ((whatis("AUTO_THRESH1_COUNT") & 0x08000000) == 0) {
AUTO_THRESH1_COUNT=IMAGE_THRESH1_COUNT
AUTO_THRESH2_COUNT=IMAGE_THRESH2_COUNT
AUTO_THRESH3_COUNT=IMAGE_THRESH3_COUNT
AUTO_THRESH4_COUNT=IMAGE_THRESH4_COUNT
}
# return the background corrected intensity
if (IMAGE_AREA_BG > 0){
S[2] = (IMAGE_I_SUM - IMAGE_I_BG/IMAGE_AREA_BG*IMAGE_AREA_SIG)
} else{
S[2] = IMAGE_I_SUM
}
# correct for filter transmission and exposure time
# p epics_get("X04SA-ES2-FI:TRANSM")
S[3] = S[2] / COUNT_TIME / epics_get("X04SA-ES2-FI:TRANSM")
# write plot information for Matlab
local ux_cmd, comFile, tmpFile
ux_cmd = ""
tmpFile = "/tmp/spec_image_temp.dat"
comFile = "/tmp/spec_matlab_image.dat"
ux_cmd = sprintf("echo \"%s\" > %s",\\
IMAGE_FILENAME, tmpFile)
if (unix(ux_cmd) != 0) {
eprint ">> Can not store Matlab plot information <<"
} else {
ux_cmd = sprintf("echo \"%.6f\" >> %s",\\
time(), tmpFile)
if (unix(ux_cmd) != 0) {
eprint ">> Can not store Matlab plot information <<"
}
unix(sprintf("echo \"%d %d\" >> %s",\\
IMAGE_XDIM, IMAGE_YDIM, tmpFile))
unix(sprintf("echo \"%d %d %d %d\" >> %s",\\
IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2, tmpFile))
unix(sprintf("echo \"%d %d %d %d\" >> %s",\\
IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2, tmpFile))
# overwrite the last file
unix(sprintf("mv -f %s %s",tmpFile,comFile))
}
}
\'
# add imageUserGetcounts to middle of user_getcounts
cdef("user_getcounts","imageUserGetcounts; ","image_user_getcounts_key")
#---------------------------------------------------
# update the global variables for auto-level support
if ((whatis("AUTO_THRESH1") & 0x08000000) == 0) {
AUTO_THRESH1 = IMAGE_THRESH1
AUTO_THRESH2 = IMAGE_THRESH2
AUTO_THRESH3 = IMAGE_THRESH3
AUTO_THRESH4 = IMAGE_THRESH4
}
IMAGE_IS_ON=1
imageShow
}'
#+
#------------------------------------------------------------------------------
# imageOff - turn off macro functionality to analyze images acquired by
# an area detector on-line and return the results to SPEC.
#-
def imageoff 'imageOff'
def imageOff '{
# ========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
#---------------------------------------------
# remove unnecessary chained macro definitions
# remove imageUserGetcounts from user_getcounts
cdef("user_getcounts","imageUserGetcounts; ","image_user_getcounts_key",\\
"delete")
IMAGE_IS_ON=0
imageShow
}'
#+
#------------------------------------------------------------------------------
# imageShow - show whether image analysis is currently enabled and
# display the region-of-interest (ROI) settings.
#-
def imageshow 'imageShow'
def imageInfo 'imageShow'
def imageinfo 'imageShow'
def imageShow '{
# =========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
if(IMAGE_IS_ON==1){
printf("\nImage analysis is currently enabled.\n")
printf("The active imaging device name is: %s\n", IMAGE_DEVICE)
imageShowRoi
} else{
printf("Image analysis is disabled.\n")
}
}'
#+
#------------------------------------------------------------------------------
# imageShowRoi - show information on the currently active region of interest
#-
def imageshowroi 'imageShowRoi'
def imageshowROI 'imageShowRoi'
def imageShowROI 'imageShowRoi'
def imageShowRoi '{
# ============
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
imageCheckRoi
}'
#+
#------------------------------------------------------------------------------
# imageSetRoi - set the region-of-interest for intensity and background
# integration.
#
# Usage : imageSetRoi
# prompts user for roi coordinates
# or imageSetRoi <Sx1> <Sy1> <Sx2> <Sy2>
# set signal roi to <Sx1> <Sy1> <Sx2> <Sy2> and use same
# coordinates for background roi
# (as a result, no background is subtracted)
# or imageSetRoi <Sx1> <Sy1> <Sx2> <Sy2> <Bx1> <By1> <Bx2> <By2>
# set signal roi to <Sx1> <Sy1> <Sx2> <Sy2> and background
# roi to <Bx1> <By1> <Bx2> <By2>.
#-
def imagesetroi 'imageSetRoi'
def imageSetROI 'imageSetRoi'
def imageSetRoi '{
# ===========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
if ($# == 8) {
IMAGE_SX1 = $1
IMAGE_SY1 = $2
IMAGE_SX2 = $3
IMAGE_SY2 = $4
IMAGE_BX1 = $5
IMAGE_BY1 = $6
IMAGE_BX2 = $7
IMAGE_BY2 = $8
} else if($# == 4){
IMAGE_SX1 = $1
IMAGE_SY1 = $2
IMAGE_SX2 = $3
IMAGE_SY2 = $4
IMAGE_BX1 = $1
IMAGE_BY1 = $2
IMAGE_BX2 = $3
IMAGE_BY2 = $4
} else if($# == 0){
sig_roi = getval("Signal Roi (sx1 sy1 sx2 sy2):",sprintf("%d %d %d %d",\
IMAGE_SX1,IMAGE_SY1,IMAGE_SX2,IMAGE_SY2))
sscanf(sig_roi,"%d %d %d %d",IMAGE_SX1,IMAGE_SY1,IMAGE_SX2,IMAGE_SY2)
bg_roi = getval("Background Roi (bx1 by1 bx2 by2):",sprintf("%d %d %d %d",\
IMAGE_SX1,IMAGE_SY1,IMAGE_SX2,IMAGE_SY2))
sscanf(bg_roi,"%d %d %d %d",IMAGE_BX1,IMAGE_BY1,IMAGE_BX2,IMAGE_BY2)
} else{
eprint "Wrong number of arguments in \'imageSetRoi\'"
eprint "Usage:"
eprint " imageSetRoi"
eprint " prompts the user for input"
eprint " imageSetRoi <sx1> <sy1> <sx2> <sy2>"
eprint " set background roi = signal roi (no background subtraction)"
eprint " imageSetRoi <sx1> <sy1> <sx2> <sy2> <bx1> <by1> <bx2> <by2>"
eprint " sets signal and background roi individually"
exit
}
imageCheckRoi
}'
#+
#------------------------------------------------------------------------------
# imageCheckRoi - Check the region of interest for intensity and background
# integration for consistency with the image dimensions, etc.
#
# Usage : imageCheckRoi # no arguments needed
#-
def imageCheckRoi '{
# =============
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
local coordAdjusted
coordAdjusted = 0
#-----------------
# check signal box
if (IMAGE_SX1 < 1) {
IMAGE_SX1 = 1
coordAdjusted = 1
}
if (IMAGE_SY1 < 1) {
IMAGE_SY1 = 1
coordAdjusted = 1
}
if (IMAGE_SX1 > IMAGE_XDIM-1) {
IMAGE_SX1 = IMAGE_XDIM-1
coordAdjusted = 1
}
if (IMAGE_SY1 > IMAGE_YDIM-1) {
IMAGE_SY1 = IMAGE_YDIM-1
coordAdjusted = 1
}
if (IMAGE_SX2 > IMAGE_XDIM-1) {
IMAGE_SX2 = IMAGE_XDIM-1
coordAdjusted = 1
}
if (IMAGE_SY2 > IMAGE_YDIM-1) {
IMAGE_SY2 = IMAGE_YDIM-1
coordAdjusted = 1
}
if (IMAGE_SX2 < IMAGE_SX1) {
IMAGE_SX2 = IMAGE_SX1
coordAdjusted = 1
}
if (IMAGE_SY2 < IMAGE_SY1) {
IMAGE_SY2 = IMAGE_SY1
coordAdjusted = 1
}
#---------------------
# check background box
if (IMAGE_BX1 < 1) {
IMAGE_BX1 = 1
coordAdjusted = 1
}
if (IMAGE_BY1 < 1) {
IMAGE_BY1 = 1
coordAdjusted = 1
}
if (IMAGE_BX1 > IMAGE_XDIM-1) {
IMAGE_BX1 = IMAGE_XDIM-1
coordAdjusted = 1
}
if (IMAGE_BY1 > IMAGE_YDIM-1) {
IMAGE_BY1 = IMAGE_YDIM-1
coordAdjusted = 1
}
if (IMAGE_BX2 > IMAGE_XDIM-1) {
IMAGE_BX2 = IMAGE_XDIM-1
coordAdjusted = 1
}
if (IMAGE_BY2 > IMAGE_YDIM-1) {
IMAGE_BY2 = IMAGE_YDIM-1
coordAdjusted = 1
}
if (IMAGE_BX2 < IMAGE_BX1) {
IMAGE_BX2 = IMAGE_BX1
coordAdjusted = 1
}
if (IMAGE_BY2 < IMAGE_BY1) {
IMAGE_BY2 = IMAGE_BY1
coordAdjusted = 1
}
if (coordAdjusted != 0) {
eprint">> Coordinates out of range - automatically adjusted. <<"
}
printf("signal region of interest : (%3d,%3d) (%3d,%3d)\n",\\
IMAGE_SX1,IMAGE_SY1,IMAGE_SX2,IMAGE_SY2)
printf("background region of interest: (%3d,%3d) (%3d,%3d)\n",\\
IMAGE_BX1,IMAGE_BY1,IMAGE_BX2,IMAGE_BY2)
printf("image dimensions (x*y) : %3d * %3d pixels\n",\\
IMAGE_XDIM,IMAGE_YDIM)
}'
#+
#------------------------------------------------------------------------------
# imageGetInt - This macro analyzes the last image taken by the active area
# detector. It checks the region-of-interest defined via
# imageSetRoi and sets some global variables to the intensity
# values determined. Calling parameters are the three threshold
# values (no. of pixels with intensity above these values is
# returned).
#-
def imagegetint 'imageGetInt'
def imageGetInt '{
# ===========
global IMAGE_DEVICE, IMAGE_IS_ON
global IMAGE_FILENAME, IMAGE_PATH, IMAGE_FNUM, IMAGE_FBASE
global IMAGE_INFO_FILENAME, IMAGE_HEADER_LENGTH
global IMAGE_XDIM, IMAGE_YDIM, IMAGE_COLOR_DEPTH
global IMAGE_I_SIG, IMAGE_I_BG, IMAGE_I_SUM
global IMAGE_AREA_SIG, IMAGE_AREA_BG
global IMAGE_THRESH1, IMAGE_THRESH2, IMAGE_THRESH3, IMAGE_THRESH4
global IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT
global IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT
global IMAGE_SX1, IMAGE_SY1, IMAGE_SX2, IMAGE_SY2
global IMAGE_BX1, IMAGE_BY1, IMAGE_BX2, IMAGE_BY2
local unixCommand, unixReturn
if ($# != 4) {
eprint "Wrong number of arguments in \'imageGetInt\'"
eprint "Usage:"
eprint "imageGetInt <threshold1> <threshold2> <threshold3> <threshold4>"
exit
}
commandDir = ""
unix(sprintf("dirname %s", IMAGE_MAC),commandDir)
if(index(commandDir,"\n") != 0){
commandDir = substr(commandDir,0,length(commandDir)-1)
}
unixCommand = sprintf("%s%s %s %d %d %d %d -median 30",\\
commandDir,\\
"/bin/image_get_int.py",\\
"/tmp/spec_image_info.dat",\\
$1, $2, $3, $4)
if(IMAGE_DEBUG){
printf("unix command: %s\n", unixCommand)
}
unixReturn = ""
unix(unixCommand,unixReturn)
if(IMAGE_DEBUG){
printf("unix return: %s\n", unixReturn)
}
IMAGE_I_SUM = ""
IMAGE_AREA_SIG = ""
IMAGE_THRESH1_COUNT = ""
IMAGE_THRESH2_COUNT = ""
IMAGE_THRESH3_COUNT = ""
IMAGE_I_BG = ""
IMAGE_AREA_BG = ""
if (sscanf(unixReturn,"I_sum %d area_I %d Threshold1 %d Threshold2 %d Threshold3 %d Threshold4 %d I_bgr %d area_bgr %d",\\
IMAGE_I_SUM, IMAGE_AREA_SIG,\\
IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT, IMAGE_THRESH3_COUNT,\\
IMAGE_THRESH4_COUNT, IMAGE_I_BG, IMAGE_AREA_BG) != 8) {
printf("Couldn\'t get intensity data\n")
exit
}
if (IMAGE_AREA_BG > 0){
IMAGE_I_SIG = IMAGE_I_SUM - ((IMAGE_I_BG / IMAGE_AREA_BG) * IMAGE_AREA_SIG)
} else {
IMAGE_I_SIG = IMAGE_I_SUM
}
if (IMAGE_DEBUG){
printf("I_sum: %d, area_I: %d\nthresh1: %d, thresh2: %d, thresh3: %d, thresh4: %d\n",\\
IMAGE_I_SUM, IMAGE_AREA_SIG,\\
IMAGE_THRESH1_COUNT, IMAGE_THRESH2_COUNT,\\
IMAGE_THRESH3_COUNT, IMAGE_THRESH4_COUNT)
printf("I_bgr: %d, area_bgr: %d\n",IMAGE_I_BG,IMAGE_AREA_BG)
}
}'
#+
#------------------------------------------------------------------------------
#-
#==============================================================================
#
#####################################################
# emacs setup: force text mode to get no help with #
# indentation and force use of spaces #
# when tabbing. #
# Local Variables: #
# mode:text #
# indent-tabs-mode:nil #
# End: #
#####################################################
#
# $Log: image.mac,v $
# Revision 1.11 2008/03/20 13:36:14 schlepuetz
# removed quotation marks around argument variables ,,... in imageSetRoi, added imageShowRoi.
#
# Revision 1.10 2007/04/22 15:42:11 schlepuetz
# changed imageCheckROI to allow for ROIs of 1 pixel width/height.
#
# Revision 1.9 2007/04/05 09:57:21 schlepuetz
# new error message if image file to be analyzed is not found
#
# Revision 1.8 2006/12/01 08:28:52 schlepuetz
# include wait loop in imageUserGetcounts to make sure the image file is available and non-empty
#
# Revision 1.7 2006/09/21 11:49:43 schlepuetz
# added new feature in imageGetInt to selectively median filter hot and dead pixels
#
# Revision 1.6 2006/08/09 13:44:38 schlepuetz
# added more input options for imageSetRoi.
#
# Revision 1.5 2006/06/23 16:26:52 schlepuetz
# missing bracket...
#
# Revision 1.4 2006/06/23 08:07:32 schlepuetz
# copy image info file also into image directory for accessibility
#
# Revision 1.3 2006/03/01 13:02:47 maden
# Check-in newer version from /work ...
#
# Revision 1.2 2005/12/10 16:32:57 schlepuetz
# fixed bug in imageGetInt.
#
# Revision 1.1 2005/11/10 11:01:21 schlepuetz
# first tested version of this file
#
#
#============================= End of $RCSfile: image.mac,v $ ===
+1525
View File
File diff suppressed because it is too large Load Diff
+427
View File
@@ -0,0 +1,427 @@
#==============================================================================
# Macroname: sdStartup.mac
# =============
#
# $Date: 2009/05/28 10:09:21 $
# $Header: /cvs/G/SPEC/local/X04SA/ES3/sdStartup.mac,v 1.10 2009/05/28 10:09:21 schlepuetz Exp $
#+
# $Source: /cvs/G/SPEC/local/X04SA/ES3/sdStartup.mac,v $
# $Revision: 1.10 $
#
# Description: specialized startup macro for the surface diffraction station.
# includes all setup routines required to use the pixel detector.
#
# Note:
#
# Author(s): C. M. Schlepuetz (CS)
# Co-author(s): P. R. Willmott (PW)
# Address: Surface Diffraction Station
# Materials Science Beamline X04SA
# Swiss Light Source (SLS)
# Paul Scherrer Institut
# CH - 5232 Villigen PSI
# Created: 2005/06/10
#
#-
# Chained macro definitions affected by this macro:
# -------------------------------------------------
# - none
#
# Change Log:
# -----------
#
# 2005/06/10 (CS):
# - created the first version of this macro.
#
# 2005/11/30 (CS):
# - modified sdStartup to make sure that no previous experiment is still active
# when starting a new one.
#
# 2006/04/24 (CS):
# - changed call to 'setsample' (which was part of the hkl-workaround) to
# 'startgeo'.
#
# 2006/08/08 (CS):
# - avoid that a logfile is overwritten if sdStartup is called twice with the
# same logfile name. Now, information is appended to an existing logfile.
# - included call to scanlist.mac in sdStartup.
#
# 2008/02/20 (CS):
# - removed links to 'specmacros' and 'scanlogs' in directory tree. This led to
# confusion and sometimes the duplication of the data if links were not
# followed correctly by backup software.
#
# 2008/02/21 (CS):
# - removed 'archives' directory under 'pixel'
# - renamed 'analyzed_data' to 'analysis_runtime'
#
# 2009/05/27 (CS):
# - enable scanlists and scanlogs by default (remove user option to turn it on)
# - force use of pixel detector (shortened setup routine)
#
# 2009/05/28 (CS):
# - change permissions of pixel directory recursively by 'a+w' automatically
# when created (chmod -R a+w pixel).
#
#==============================================================================
#
global SD_STARTUP_MAC
#
SD_STARTUP_MAC = DOFILE # Save the name of this macro file.
_sav_geo_mot = 1 # spec's global variable used by setscans macro
#+
#==============================================================================
# This macro file contains the following commands:
#-
#
#+
#------------------------------------------------------------------------------
# sdStartuphelp - generates this help text. This is obtained by
# displaying the file sd_startup.txt, which should sit in
# the same directory as this file.
#-
def helpSdStartup 'sdStartuphelp'
def sdStartupHelp 'sdStartuphelp'
def sdstartuphelp 'sdStartuphelp'
def sdStartuphelp '{
# =============
unix (sprintf ("dirname %s", _MAC), _1)
ll = length (_1)
if (substr (_1, ll, 1) == "\n") _1 = substr (_1, 1, (ll - 1))
file = sprintf ("%s/sms.txt", _1)
if (file_info (file, "-e")) {
unix (sprintf ("cat %s | less", file))
} else {
printf ("\n Macros available in file sd_startup.mac ($Revision: 1.10 $):\n")
print " =============="
print ""
print " sdStartuphelp - creates this help text"
print " sdStartup - startup routine for the surface diffraction"
print " station. Sets all important parameters and"
print " paths."
print " sdShutdown - shutdown routine for the surface diffraction"
print " station. Resets all paths and filenames to"
print " standard values to prevent writing to"
print " experiment-specific files."
}
}'
#+
#------------------------------------------------------------------------------
# sdStartup - startup procedure for the surface diffraction station.
# It sets up important parameters and the data storage
# environment for the experiment. Experimental data is
# stored in the following directory structure:
#
# [<E-ACCOUNT>]
# `-- <PROJECT_NAME>
# |-- analysis_runtime # on-the-fly analysis during experiments
# |-- archive # backup directory for experimental data (zip)
# | |-- images # zip-files of images
# | |-- imagelogs # zip-files of imagelogs
# |-- fotos # fotos of experimental setup, etc.
# |-- pixel # pixel detector related information
# | |-- flatfield # flatfield data
# | | |-- flatfield(1) # 1st flatfield data set
# | | |-- flatfield(2) # 2nd flatfield data set
# | | `-- ... # ...
# | |-- imagelogs # logfiles for each individual pixel image
# | |-- images # the pixel detector images themselves
# |-- software # user made software (i.e. shell scripts, etc.)
# | |-- matlab # matlab routines for data analysis
# | |-- shell_scripts # shell scripts
# `-- spec # SPEC related information
# |-- logs # logfiles (.spec, .log, etc.)
# |-- scanlogs # log files for each individual scan
# `-- specmacros # working directory for user made SPEC macros
#
# <PROJECT_NAME> is set during the startup procedure. If the user is running
# from an e-account, the above directory tree is created inside the e-account
# directory <E-ACCOUNT> (i.e. e10003/<PROJECTNAME>/pixel/...)
#-
def sdStartup '{
# =========
global DATAFILE, LOGFILE, DO_DIR
global TITLE, COUNT, UPDATE
global SDSTARTUP_ON, SDSTARTUP_PROJECT
local dataBaseDir, expBaseDir, pixelBaseDir
local eAccount, projectDirName, _dir
local _append, _cont
local specFile
dataBaseDir = "/sls/X04SA/data/"
expBaseDir = "/sls/X04SA/data/x04sa/ES3/expdata/"
pixelBaseDir = "/sls/X04SA/data/x04sa/ES3/pixel/"
tmpLog = "/tmp/tmpLog.spec"
def sdStartupCleanupOnce \'
tty_cntl("se")
\'
cdef("cleanup_once","sdStartupCleanupOnce;","sdStartup_cleanup_once_key")
if(SDSTARTUP_ON){
printf("Currently, the following experiment is still active:\n%s\n", \\
SDSTARTUP_PROJECT)
tty_cntl("so")
if(yesno("Close the active experiment and start a new one?",0)){
tty_cntl("se")
close(DATAFILE)
close(LOGFILE)
} else{
tty_cntl("se")
printf("Startup routine aborted...\n")
exit
}
}
# turn on logging to a temporary file (this will be moved to
# the projects permanent log file later).
on(tmpLog)
#-------------------------------
# get information on the project
tty_cntl("so")
if(yesno("Are you using an e-account?",0) == 1){
eAccount=getsval("Please enter your e-account name \(i.e. e10003\)")
}
else{
eAccount=""
}
tty_cntl("se")
_cont=0
while(_cont==0){
printf("\nPlease enter a name for your project\'s data directory ending ")
printf("with the current\ndate in the following format: _yyyymmdd")
printf("\(e.g., Ni111_20050226\)\n")
tty_cntl("so")
projectDirName=getsval("Project name:","")
tty_cntl("se")
# set up the project directory
if(eAccount != ""){
_dir=sprintf("%s%s/%s/",dataBaseDir,eAccount,projectDirName)
}
else{
_dir=sprintf("%s%s/",expBaseDir,projectDirName)
}
printf("\nYour project directory name is:\n %s\n",projectDirName)
tty_cntl("so")
if(yesno("Is that o.k.?",1)){
_cont=1
}
tty_cntl("se")
if(file_info(_dir,"-d")== 1){
printf("\nDirectory %s already exists!\n", _dir)
printf("It contains the following items:\n")
unix(sprintf("ls -g --color %s",_dir))
tty_cntl("so")
if(yesno("Change your project name?",1)==0){
_cont=1
_append=1
} else{
_cont=0
}
tty_cntl("se")
}
}
printf("\nYour data will be stored in\n %s\n", _dir)
SDSTARTUP_PROJECT = projectDirName
#----------------------------------
# set up the project directory tree
cmd_file="/tmp/startup_cmd.sh"
unix(sprintf("rm -f %s",cmd_file))
open(cmd_file)
fprintf(cmd_file,"mkdir %s\n", _dir)
fprintf(cmd_file,"cd %s\n", _dir)
fprintf(cmd_file,"mkdir spec pixel fotos software analysis_runtime ")
fprintf(cmd_file,"archive \n")
fprintf(cmd_file,"# create subdirs of archive\n")
fprintf(cmd_file,"cd archive; mkdir images imagelogs; cd ..\n")
fprintf(cmd_file,"# create subdirs of spec\n")
fprintf(cmd_file,"cd spec; mkdir logs scanlogs specmacros; cd ..\n")
fprintf(cmd_file,"# create subdirs of pixel\n")
fprintf(cmd_file,"cd pixel; mkdir images imagelogs ")
fprintf(cmd_file,"flatfield; cd ..\n")
fprintf(cmd_file,"# create subdirs of software\n")
fprintf(cmd_file,"cd software; mkdir matlab shell_scripts; cd ..\n")
fprintf(cmd_file,"# change permissions on pixel directory\n")
fprintf(cmd_file,"chmod -R a+w pixel\n")
close(cmd_file)
unix(sprintf("chmod 700 %s; %s",cmd_file,cmd_file))
unix(sprintf("rm -f %s",cmd_file))
printf("directory structure:\n")
unix(sprintf("tree %s",_dir),_tmp)
print _tmp #this ensures that the tree appears in the log file
# set working directory
chdir(sprintf("%s%s",_dir,"spec/specmacros"))
DO_DIR=sprintf("%s%s",_dir,"spec/specmacros")
# open the spec file
specFile=sprintf("%sspec/logs/%s.spec",_dir,projectDirName)
eval(sprintf("newfile %s 0",specFile))
# turn on the log file and copy
# contents of temporary log into it.
LOGFILE=sprintf("%sspec/logs/%s.log",_dir,projectDirName)
close(tmpLog)
if(file_info(LOGFILE,"-e")){
# if logfile already exists, append contents of temporary file to the end.
open(LOGFILE)
fprintf(LOGFILE,"\n\n-----------------------------------------------\n\n")
close(LOGFILE)
unix(sprintf("cat %s >> %s",tmpLog,LOGFILE))
unix(sprintf("rm -f %s",tmpLog))
} else{
unix(sprintf("mv %s %s",tmpLog,LOGFILE))
}
on(LOGFILE)
tty_cntl("so")
TITLE=getsval("\nTitle for scan headers (i.e. sample name)",TITLE)
COUNT = getval("Default count time for ct and uct",COUNT)
UPDATE = getval("Update interval for umv, uct, etc. in seconds",UPDATE)
tty_cntl("se")
# set geometry parameters
printf("\nSet the geometry parameters: \(startgeo\)\n")
startgeo
# set scan options
printf("\nSet some scan options: \(setscans\)\n")
setscans
# enable scanlogs
if (SCANLOG_MAC){
eval(sprintf("scanlogSetPath %s%s", _dir,"spec/scanlogs/"))
scanlogOn
}
# enable scanlist
if (SCANLIST_MAC){
eval(sprintf("scanlistFilename %s%s",_dir,"spec/logs/scanlist.txt"))
scanlistOn
}
# set plot options
printf("\nSet some plotting options: \(setplot\)\n")
setplot
# set up the pixel detector as default detector
printf("\nSet up the PILATUS Pixel detector\n")
if(eAccount != ""){
eprint "e-Accounts are not yet supported in conjunction with the pixel"
eprint "detector. This is due to write permission errors and will be"
eprint "resolved with the new generation of the pixel detector control"
eprint "software. Please contact your user-supporter if you encounter"
eprint "this problem here."
exit
} else{
pixFilePath = sprintf("%s%s%s","../../expdata/",projectDirName,\\
"/pixel/images/")
eval(sprintf("pixsetup %s",pixFilePath)) # run the setup routine
pixon # enable the pixel detector
# turn on logging for each image taken to standard path:
pixLogPath = sprintf("%s%s", _dir,"pixel/imagelogs/")
eval(sprintf("pixlogon %s", pixLogPath))
}
printf("\n%s\n%s\n%s\n",\\
"Your experiment has been set up successfully. Please remember to",\\
"run \'sdShutdown\' after completing your measurements to prevent",\\
"other users from accidentally modifying your experimental data.")
SDSTARTUP_ON = 1
cdef("cleanup_once","","sdStartup_cleanup_once_key","delete")
}'
#+
#------------------------------------------------------------------------------
# sdShutdown - Cleanup procedure to be executed after an experiment.
# Experimental files are closed and logging is redirected
# to some standard files. The entire experimenal environ-
# ment used before is abandoned by SPEC.
#-
def sdShutdown '{
# ==========
global DATAFILE, LOGFILE, DO_DIR
# reset the current working directory to standard location
chdir(sprintf("%s","~/specmacros"))
# close the SPEC data file and reopen the standard file.
close(DATAFILE)
eval(sprintf("newfile %s 0","/sls/X04SA/data/x04sa/ES3/tmp/dummy.spec"))
# close the SPEC log file and reset the global variable to the standard value
close(LOGFILE)
LOGFILE = "/sls/X04SA/data/x04sa/ES3/tmp/dummy.log"
# redirect pixel detector output to standard locations
pixsetpath "tmp/"
pixlogoff
SDSTARTUP_ON = 0
}'
#+
#------------------------------------------------------------------------------
#-
#####################################################
# emacs setup: force text mode to get no help with #
# indentation and force use of spaces #
# when tabbing. #
# Local Variables: #
# mode:text #
# indent-tabs-mode:nil #
# End: #
#####################################################
#
# $Log: sdStartup.mac,v $
# Revision 1.10 2009/05/28 10:09:21 schlepuetz
# change permissions on pixel directory automatically by a+w
#
# Revision 1.9 2009/05/27 15:59:36 schlepuetz
# shortened setup routine
#
# Revision 1.8 2008/02/21 09:59:25 schlepuetz
# updated documentation
#
# Revision 1.7 2008/02/21 09:55:35 schlepuetz
# removed archives directory under pixel, renamed analyzed_data to analysis_runtime
#
# Revision 1.6 2008/02/20 09:10:13 schlepuetz
# removed links to specmacros and scanlogs in directory tree
#
# Revision 1.5 2006/08/11 10:34:10 schlepuetz
# improved output formatting of sdStartup
#
# Revision 1.4 2006/08/08 14:07:38 schlepuetz
# prevent overwrite of old log files, added enable/disble of scanlist
#
# Revision 1.3 2006/05/04 10:15:23 schlepuetz
# call startgeo instead of setsample
#
# Revision 1.2 2005/11/30 15:33:11 schlepuetz
# modified sdStartup to make sure that no previous experiment is still active when starting a new one.
#
# Revision 1.1 2005/11/10 11:24:07 schlepuetz
# first tested version of this file
#
#
#============================= End of $RCSfile: sdStartup.mac,v $ ===
File diff suppressed because it is too large Load Diff
+142
View File
@@ -0,0 +1,142 @@
def count (count_time):
waitmove
count_em (count_time) # triggers the counting process
waitcount # waits for counting to finish
count_end # clean up after counting
get_counts # retrieve the counts from detectors
chk_xray # verify quality of xray
chk_counts # verify quality of counts
chk_beam # terminate this count loop
if (S[sec] && MON >= 0)
MON_RATE=S[MON]/S[sec]
def count_em (count_time):
# ========
while (mythen.is_acquiring()):
mythen.stop()
time.sleep(0.25)
user_precount()
if (count_time != 0):
if (count_time > 0):
# MYTHEN
mythen.set_acquire_time(count_time)
mythen.set_acquire_mode("Single")
mythen.start()
else:
print "Preset monitor counting is not supported\!"
user_postcount()
# define new count_end, chk_counts, and chk_xray macros:
def count_end 'user_count_end'
def chk_counts 'user_chk_counts'
def chk_xray 'user_chk_xray'
# use the EPICS DCR508 scaler
# initially, user_count_end, user_chk_counts, and user_chk_xray are empty:
def user_count_end '' # if used, this should be a chained macro definition
def user_chk_counts '' # if used, this should be a chained macro definition
def user_chk_xray '' # if used, this should be a chained macro definition
#+
#------------------------------------------------------------------------------
# ct - second lowest level count command - for manual count.
# This version is slightly expanded with respect to
# the original definition in standard.mac:
# count_end has been added to provide further
# flexibility regarding the use of various detectors.
#
# Note: See also the description of the modified 'count' command for more
# information.
#-
def ct (count_time):
# ==
cdef("cleanup_once", "onp; show_cnts; offp; user_ct", "ct")
waitmove
count_em (count_time) # triggers the counting process
waitcount # waits for counting to finish
count_end # clean up after counting
cdef("cleanup_once", "", "ct", "delete")
onp; show_cnts; offp
user_ct
}'
#+
#------------------------------------------------------------------------------
# recount - allows to retake the last data point - useful when
# files (images) need to be overwritten. Include
# device-specific code in user_pre_recount and
# user_post_recount.
#
# Note: This is essentially a modified version of count
# without the check commands (chk_xray, chk_counts,
# and chk_beam) at the end.
#-
def recount '{
# =======
waitmove
user_pre_recount # should be a chained macro definition
count_em $1 # triggers the counting process
waitcount # waits for counting to finish
count_end # clean up after counting
get_counts # retrieve the counts from detectors
user_post_recount # should be a chained macro definition
}'
# initially, user_pre_recount and user_post_recount are empty.
def user_pre_recount ''
def user_post_recount ''
#+
#------------------------------------------------------------------------------
# waitcount - waits for counting to stop
#-
def waitcount(count_time):
user_waitcount()
i = 0
while (mythen.is_acquiring()):
sleep (0.05)
i += 1
if (i * 0.05 >= count_time * 2):
print "MYTHEN Izero times out, status: " + str(mythen.get_status())
break
#+
#------------------------------------------------------------------------------
# get_counts - lowest level counter reading macro.
#-
def get_counts():
# ==========
S[0] = mythen.get_acquire_time(readback=False)
S[1] = mythen.get_total_counts()
# S[2] is detector counts from image.mac
S[3] = S[2] / COUNT_TIME / epics_get("X04SA-ES2-FI:TRANSM")
S[5] = epics_get ("X04SA-ES2-FI:TRANSM")
COUNT_ID++ # increment the exposure ID
# set threshold counts in case auto-level support is available
if ((whatis("AUTO_THRESH1") & 0x08000000) == 0) {
AUTO_THRESH1_COUNT = (S[2]>=AUTO_THRESH1)?S[2]:0
AUTO_THRESH2_COUNT = (S[2]>=AUTO_THRESH2)?S[2]:0
AUTO_THRESH3_COUNT = (S[2]>=AUTO_THRESH3)?S[2]:0
AUTO_THRESH4_COUNT = (S[2]>=AUTO_THRESH4)?S[2]:0
}
user_getcounts
}'