esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#
# File and processing commands for spec
# These are being replaced by a python script and so are
# being saved here D.S 20081116
# Below are also call methods for the files
# If the user types process, it means he wants to reprocess the data and therefor re-convert
# the detector images to edf using saxs_mac in order feed in the modified input parameters.

def process '{
  if ( "$1" == 0 ) {
    how = "reprocess"
  } else {
    how = "$1"
  }
  process_1d(how,$2,$3)
}'


def process_1d(opt,first,last) '{
  global numberOfFrames COLLECT_SEQ
  if (COLLECT_SEQ["bsdiode"] != 0) { 
    normalisedCts = (COLLECT_SEQ["normalise_coeff"]/COLLECT_SEQ["bsdiode"])/TimePerFrame
    #print "Normalisation is " normalisedCts 
  } else { 
    print "Normalisation Failed, setting to 0"; normalisedCts = 0 
  }
  
  if (opt != "last" && opt != "convertToEdf") {
    dir         = getval ("Directory",COLLECT_SEQ["fileinfo"]["directory"])
    prefix      = getval ("Prefix",COLLECT_SEQ["fileinfo"]["prefix"])
    run         = getval("Run number",COLLECT_SEQ["fileinfo"]["run_number"])
    mask        = getval("Mask",COLLECT_SEQ["fileinfo"]["mask"])
    firstImage  = getval ("First image number",1)
    lastImage   = getval ("Last Image number",numberOfFrames)
    bsdiode     = getval ("Diode counts (default value only valid if it was the last collection)",COLLECT_SEQ["bsdiode"])
    machCurr    = getval ("Machine Current (not garanteed)",MI_PAR["CURR"])
    concentration = getval ("Sample Concentration ",MXSAMPLE_PARS["concentration"])
    comments    = getval ("Comments ",MXSAMPLE_PARS["comments"])
    sampd       = getval ("Sample Detector Distance ",MXBCM_PARS["sampd"])
    wavelength  = getval ("Wavelength (nm)",MXBCM_PARS["lambda"])
    pixelSizeX  = getval ("X Pixel size (um)",MXBCM_PARS["pixelSizeX"])
    pixelSizeY  = getval ("Y Pixel size (um)",MXBCM_PARS["pixelSizeY"])
    beamX       = getval ("X beam centre( no pixels from left side)",MXBCM_PARS["beamx"])
    beamY       = getval ("Y beam centre (no pixels from top side)",MXBCM_PARS["beamy"])
    normalisedCts        = getval ("Normalisation factor?",normalisedCts)
  } else {
    dir         = COLLECT_SEQ["fileinfo"]["directory"]
    prefix      = COLLECT_SEQ["fileinfo"]["prefix"]
    run         = CURRENT_RUN
    mask        = COLLECT_SEQ["fileinfo"]["mask"]
    firstImage  = first
    lastImage   = last
    bsdiode     = COLLECT_SEQ["bsdiode"]
    machCurr    = MI_PAR["CURR"]
    concentration = MXSAMPLE_PARS["concentration"]
    sampd       = MXBCM_PARS["sampd"]
    wavelength  = MXBCM_PARS["lambda"]
    pixelSizeX  = MXBCM_PARS["pixelSizeX"]
    pixelSizeY  = MXBCM_PARS["pixelSizeY"]
    beamX       = MXBCM_PARS["beamx"]
    beamY       = MXBCM_PARS["beamy"]
    comments    = MXSAMPLE_PARS["comments"]
  }
  if ( opt == "last" ) opt = "convertTo1d"
  call_server(opt,dir,prefix,run,firstImage,lastImage,mask,\
               bsdiode,machCurr,concentration,comments,COLLECT_SEQ["defaultTimePerFrame"], \
               sampd,normalisedCts,wavelength,pixelSizeX,pixelSizeY,beamX,beamY)

}'

def call_server(func,dir,prefix,run,firstImage,lastImage,mask,\
                bsdiode,machCurr,concentration,comments,expTime, \
                sampd,normalisedCts,wavelength,pixelSizeX,pixelSizeY,beamX,beamY) '{
  pcmd = sprintf("RedSaxs.py --func=\'%s\' --fdir=%s --prefix=%s_%03d --firstidx=%d --lastidx=%d \
    --mask=%s \
    --ofac=%s \
    --otit=\"DiodeCurr=%6.4g, MachCurr=%6.2f mA, Concentration=%6.3f, Comments: %s\" \
    --nooverwrite=\'n\' \
    --sleepTime=%d \
    --odis=\'%s\' \
    --i1wvl=\'%s\' \
    --i1pix=\'%6.1f_um %6.1f_um\' \ \
    --i1cen=\'%6.4f %6.4f\' \
    --bsdiode=\'%s\' \
    --machCurrent=\'%s\' \ \
    --concentration=\'%s\' \
    --comments=\'%s\' \
    &",func,dir,prefix,run,firstImage,lastImage,mask,normalisedCts,\
       bsdiode,machCurr,concentration,comments,\
       COLLECT_SEQ["defaultTimePerFrame"],sampd,wavelength,pixelSizeX,pixelSizeY,beamX,beamY, \
       bsdiode,machCurr,concentration,comments)
  #print pcmd
  if ( unix(pcmd) != 0 ) exit
}'