#! /bin/csh -f # # # Find the beam center in the camera field of view # # set path = ( /programs/kuim/bin $path ) # decide which camera we can see through set camera = `camera.com | awk '/camera is/{print $NF}'` # remember where the shutter is (so we can put it back) set oldstate = `shutter.com | awk '{print $NF}'` # take a picture with the beam on shutter.com open if($status) exit 9 snap.com on.jpg -nodisplay >& /dev/null # take another one with the beam off shutter.com close if($status) exit 9 snap.com off.jpg -nodisplay >& /dev/null # put the shutter back where we found it shutter.com $oldstate set blur = 3 # convert the "on" and "off" images to KUIM format rm -f on.im off.im type -f on.jpg on.im > /dev/null type -f off.jpg off.im > /dev/null # subtract "off" from "on" rm -f diff.im diff.jpg add -a 1 -b -1 on.im off.im diff.im > /dev/null type -j diff.im diff.jpg > /dev/null cp diff.im out.im # make it FFTable for gaussian blur mv out.im in.im interp -x 512 -y 512 in.im out.im > /dev/null # apply gaussian blur mv out.im in.im gauss -s $blur in.im out.im > /dev/null # back to original size mv out.im in.im interp -x 704 -y 480 in.im out.im > /dev/null # now center it (mean=0) mv out.im in.im rm -f one.im set mean = `header in.im |& awk '/^Mean /{print -$NF}'` thresh -t -10000 in.im one.im > /dev/null add -a 1 -b $mean in.im one.im out.im > /dev/null mv out.im diff.im # make a mask using the automatic threshold rm -f mask.im imask.im cp diff.im in.im thresh -o in.im mask.im > /dev/null add -a -1 -b 1 mask.im one.im imask.im > /dev/null rm -f out.im one.im mult imask.im diff.im out.im > /dev/null set noise = `header out.im |& awk '/^StdDev/{print $NF}'` rm -f out.im mult mask.im diff.im out.im > /dev/null #mv out.im in.im #extrema -d -l in.im out.im > /dev/null make_raw -A out.im pixels.txt > /dev/null cat pixels.txt |\ awk 'NR>1{for(i=1;i<=NF;++i) {++n; if($i!=0) print n%704, int(n/704), $i}}' |\ awk '{++count;norm+=$3;xc+=$1*$3;yc+=$2*$3; xa+=$1;ya+=$2} \ END{if(count) print xc/norm,yc/norm, xa/count,ya/count,norm/count,count}' |\ cat >! centroid.txt # format: x_center y_center x_centroid y_centroid avgpixel pixels rm -f pixels.txt set signal = `awk -v noise=$noise 'NF==6&&noise+0>0{print $5/noise}' centroid.txt` set centroid = `awk '{printf "%.1f %.1f ", $1,$2}' centroid.txt` set center = `awk '{printf "%.1f %.1f ", $3,$4}' centroid.txt` set frac = `echo $center | awk '{printf "%.4f %.4f", $1/704, $2/480}'` set area = `awk '{printf "%d", 1.25*$6}' centroid.txt` set diameter = `awk '{print int(2*sqrt(1.25*$6/2/3.14)/10)*10}' centroid.txt` echo "beam centroid: $centroid" echo "beam center: $center" echo "beam center: $frac" echo "pinhole dia: $diameter" echo "I/sigma = $signal" rm -f in.jpg out.jpg type -j in.im in.jpg > /dev/null type -j out.im out.jpg > /dev/null #animate -delay 20 on.jpg in.jpg out.jpg rm -f diff.im in.im out.im mask.im imask.im on.im off.im mv out.jpg beam.jpg if ( `echo $signal | awk '{print ($1<4)}'` ) then set BAD goto exit endif # update this setting in /data/calibrations and in DCSS beam.com $frac rm -f /data/calibrations/beam.jpg cp beam.jpg /data/calibrations/ if (! $status) echo "beam in camera $camera updated in DCSS" change.com Beam in camera $camera $frac set radius = $diameter set disk1 = `echo $center $radius | awk '{printf "%d,%d %d,%d", $1,$2,$1,$2-$3}'` set disk2 = `echo $center $radius | awk '{printf "%d,%d %d,%d", $1,$2,$1,$2-$3+1}'` convert -pen black -fill black -draw 'rectangle 0,0 704,480' \ -fill white -draw "circle $disk1" -fill black \ -fill black -draw "circle $disk2" -fill white \ beam.jpg /data/calibrations/beamring.bmp if ( $area > 5000 ) then # 100um pinhole change.com 100um pinhole else # 30um pinhole change.com 30um pinhole endif exit: rm -f off.jpg if ($?BAD) exit 9 rm -f centroid.txt in.jpg on.jpg >& /dev/null rm -f diff.jpg beam.jpg >& /dev/null exit ######################################################################################################### ######################################################################################################### ######################################################################################################### ######################################################################################################### #########################################################################################################