Source code for process_lrs2_images_step1
Updated: Nov16,2018
#!/bin/bash
# Check command line arguments
if [ -z "$1" ]
then
printf "Usage: process_lrs2_images_step1 list.Qth Y N \n"
printf "arg1 - Name of file with list of raw LRS2images (should be full path)\n"
printf "arg2 - Use ds9 to set statistics box? (Y/N)\n"
printf "arg3 - run in debug mode (Y/N)\n"
exit
fi
if [ $1 = "--help" ]
then
show_help process_lrs2_images_step1
exit
fi
if [ -z "$2" ]
then
printf "Usage: process_lrs2_images_step1 list.Qth Y N \n"
printf "arg2 - Use ds9 to set statistics box? (Y/N)\n"
exit
fi
if [ -z "$3" ]
then
printf "Usage: process_lrs2_images_step1 list.10 N \n"
printf "arg3 - run in debug mode (Y/N)\n"
exit
fi
# assign useful names to input arguments
fitslist="$1"
useds9="$2"
debug="$3"
if [ $debug = "Y" ]
then
printf "\n"
printf "The debug flag is ON in process_lrs2_images_step1.\n"
printf "Name of input FITS file list of LRS2 images = $fitslist\n"
printf "Use ds9_imstats to set the box = $useds9\n"
message_and_read s
fi
# Check that your basic file list is present
if [ -e "$fitslist" ]
then
printf "input list is present\n" > /dev/null
else
printf "ERROR: No file = $fitslist\n"
exit
fi
# Find total number of images in the input list
linecnt $fitslist > junk.number
read totalims < junk.number
\rm -f junk.number
#-----------------------------------------------------------------------------------------
# Read the box to be used for basic stats
if [ $useds9 != "Y" ]
then
printf "\nFor basic box stats enter ixmin,ixmax,iymin,iymax (890 909 487 491): "
read ixmin ixmax iymin iymax
fi
#-----------------------------------------------------------------------------------------
#=========================================================================================
exec 3<$fitslist
i="0"
while read -u3 fullfits
do
i=$[$i+1]
printf "\nReady to process image $i of $totalims\n"
# Get the base image name
just_fitsname.sh $fullfits > base.1
read nchars fitsname < base.1
locfits="${fitsname}.fits"
# subtract the bias (this make the local image named "lrs_bsub.fits"
lrs2_bias_sub.sh $fullfits
read biaslev biaserr biascomm < lrs2_bias_sub.out
if [ $debug = "Y" ]
then
printf "\n"
printf "Bias and Bias_error = $biaslev $biaserr\n"
message_and_read s
fi
# Make a local version of the bias-subtracted image with the basename of the input image
mv lrs_bsub.fits $locfits
#----------------------------------------------------------
if [ $useds9 = "Y" ]
then
# Handle the first image
if [ $i = "1" ]
then
ds9_imstats $locfits N
reg1="${fitsname}.reg"
midodata.sh $locfits
read inum regtype commo < midodata.1
if [ $regtype != "box" ]
then
printf "ERROR: You must set a single BOX region only. \n"
exit
fi
read p1 p2 p3 p4 p5 < midodata.5pars
ixmin=`rounder.sh $p1 0`
ixmax=`rounder.sh $p2 0`
iymin=`rounder.sh $p3 0`
iymax=`rounder.sh $p4 0`
fi
if [ $debug = "Y" ]
then
printf "\nThe box limits (xmin,xmax,ymin,ymax) = $ixmin $ixmax $iymin $iymax\n"
message_and_read s
fi
# Handle images after the firt image
if [ $i != "1" ]
then
cp $reg1 ${fitsname}.reg
ds9_imstats $locfits N
fi
fi
#----------------------------------------------------------
# Run the basic box statistics routine
clip_imstat.sh $locfits $ixmin $ixmax $iymin $iymax
read fmean fme fsig NpixBox fmin fmax < clip_imstat.out
\rm -f clip_imstat.out
#----------------------------------------------------------
# If ds9_imstats was run, then collect some of those values
fmeanDS9="none"
if [ $useds9 = "Y" ]
then
midodata.sh $locfits
read xcen ycen fmeanDS9 fsigDS9 fmeDS9 NumDS9 < midodata.imstats
midoclean
fi
#----------------------------------------------------------
# Grab a local version of the image
# Get a local version to work on
# mli_copy $fullfits
# locfits="${fitsname}.fits"
# locinfo="${fitsname}.info"
# locreg="${fitsname}.reg"
# Print the final answers
printf "$i $biaslev $fmean $fmeanDS9 $fmax $locfits \n" | tee -a process_lrs2_images_step1.out
done
#=========================================================================================
#------------------------------------------------------------------------------------------
# Make a table file
printf "# data\n" > head
cat head process_lrs2_images_step1.out > process_lrs2_images_step1.table
printf "ImNum Image number \n" > process_lrs2_images_step1.parlab
printf "Bias Mean image BIAS value \n" >> process_lrs2_images_step1.parlab
printf "Fmean Average pixel value in box (ADU) \n" >> process_lrs2_images_step1.parlab
printf "FmeanDS9 Average pixel from ds9_imstats \n" >> process_lrs2_images_step1.parlab
printf "Fmax Maximum pixel value in box \n" >> process_lrs2_images_step1.parlab
printf "Name Bias-subtracted image name \n" >> process_lrs2_images_step1.parlab
#------------------------------------------------------------------------------------------
if [ $debug = "Y" ]
then
printf "\nYou are in debug mode, but you might want to clean up files anyway.\n"
printf "Do you want to cleanup local files anyway? (Y/N): "
read anso
if [ $anso != "Y" ]
then
exit
fi
fi
# make a last clean up
\rm -f pars.in fitsr2048.header_copy base.1 clip_imstat.explain
\rm -f lrs2_bias_sub.out
midoclean
profclean
Back