#!/usr/bin/perl -w # Files needed: # the only file needed is the output from hedit. For example, type the # following line at the iraf prompt: # hedit @filenames fields=exptime value="." add- delete- verify- >hedit_out # Make sure "filenames" contains only files that you want to use. For example, # if you took one test exposures to check exposure times, and the exp time # is not the same as the rest, and you don't want to use these files, DON'T # include them in "filenames". # The script reads in hedit_out and extracts filenames, exposure times and # prefixes. # Then I create an iraf # batch file that initializes iraf, combines darks of the same exposure time # (assumes that darks start with dk), runs ccdproc for dark subtraction # using dark=dk$exptime on all images with this same exptime. # Then, files are grouped according to prefix, and batch file then # runs ccdproc for # masking, flattens images, combines, makes object masks, makes # masklets, reflattens, corrects for distortion, realigns and recombines. # And that's it! # # # Make sure the following tasks are loaded before starting batch file # stsdas # toolbox # imgtools # phiirs # phat # task getshifts=home$scripts/getshifts.cl # task domanygeotran=home$scripts/domanygeotran.cl # RAF 6/3/99 open (BATCH,">batch.cl") || die "cannot open file"; get_name_exptime(); # reads output of hedit file that contains file # names and exp times. Groups files with same exp time. initialize_iraf(); #initializes iraf group_prefixes(); #subroutine to sort prefixes and write all files with #same prefix into a file called $prefix # comment next three commands if you don't want to do dark subtraction. # comment next command if you are using darks from another night but still # want to run dark subtraction on images. combine_darks(); #write to batch file to combine darks, assumes darks start with dk group_exptimes(); #groups files with same exptime and writes filenames #to FILE$exptime dark_subtract(); #write out commands to batch file to dark-subtract files #with same exptime image_process(); #subroutine that writes the rest of the image-processsing #commands to BATCH close (BATCH) || die "couldn't close batch.cl: $!"; ############################################################################# ################## subroutines ############################# ########################################################################### #subroutine to read in output from hedit and get filenames and exptimes. #this also stores a prefix for each file, which is the filename, minus .*, #minus the last 3 characters which are presumably the 3 numbers assigned #by wfirc data acquisition software sub get_name_exptime { $nfiles=0; open (HEDIT, "hedit_out") || die "can't open hedit_out: $!"; while (defined ($temp = )) { chomp($temp); #removes \n from line ($name{$nfiles},$t1)=split(/,/,$temp); #print "$name{$nfiles}\n"; ($t2,$time[$nfiles])=split(/=/,$t1); #print "$time[$nfiles]\n"; $exptime{$nfiles}=$time[$nfiles]; ($allprefix{$nfiles},$t3) = split(/\./,$name{$nfiles}); #print "$allprefix{$nfiles}\n"; $length = length($allprefix{$nfiles}); #print "$length\n"; $noextention[$nfiles]=$allprefix{$nfiles}; $end=$length-3; $allprefix[$nfiles] = substr($noextention[$nfiles],0,$end); #print "$allprefix[$nfiles]\n"; $nfiles++; } } ##################################################################### #initializes iraf sub initialize_iraf { print BATCH "images\n"; print BATCH "imred\n"; print BATCH "ccdred\n"; print BATCH "unlearn imcombine\n"; } ################################################################### #subroutine to sort prefixes and write all files with same prefix into #a file called $prefix sub group_prefixes { $i=0; $j=0; $k=0; $t1=0; $temp="none"; #print "@allprefix\n"; @sorted_prefix = sort @allprefix; #sorts names in alphabetical order #print "@allprefix\n"; #print "@sorted_prefix\n"; while ($k < $nfiles) { $t1 = $sorted_prefix[$k]; #print "$t1\n"; if ($t1 ne $temp) { $f = join "",("FILE",$t1); #reference for file = FILEprefix #$times{$j}=$t1; #saves an array of exposure times open ($f, ">$t1") || die "can't open $t1: $!"; $i=0; while ($i < $nfiles) { if ($allprefix[$i] eq $t1) { print $f "$noextention[$i]\n"; #print "$i $name{$i}\n"; } $i++; } $temp=$t1; $prefix{$j}=$temp; #print "$prefix{$j}\n"; #print "help\n"; $j++; $nprefix=$j; close ($f) || die "can't close $f: $!"; } $k++; } $i=0; while ($i < $nprefix) { $dummy[$i]=0; $i++; } $i=0; while ($i < $nprefix) { $j=0; while ($j < $nfiles) { #print "$name{$j} $prefix{$i}\n"; if ($noextention[$j] =~ /^$prefix{$i}/){ if ($dummy[$i] == 0) { $ref[$i]=$noextention[$j]; #print "reference = $ref[$i]\n"; $dummy[$i]++; } } $j++; } $i++; } } ####################################################################### # writes to BATCH file to combine darks, assumes darks start with dk. # combined dark is called for example, dk10 for 10 sec darks. sub combine_darks { #print "combining darks\n"; $index=0; while ($index < $nprefix) { # combines darks first if ( $prefix{$index} =~ /^dk/ ){ #print "file starting with dk"; print BATCH "chpixtype \@$prefix{$index} \@$prefix{$index} newpixtype=short\n"; print BATCH "imcombine \@$prefix{$index} $prefix{$index} combine=ave reject=minmax lsigma=3 hsigma=3\n"; } $index++; } } ################################################################## # groups filenames according to exposure times and writes filenames to files # called FILE$exptime for dark subtraction. Filenames starting with dk are # ignored sub group_exptimes { $temp=0; $i=0; $j=0; $k=0; @sorted_times= sort {$a <=> $b} @time; while ($k < $nfiles) { $t1=$sorted_times[$k]; if ($t1 != $temp) { $f = join "" ,("FILE",$t1); $times{$j}=$t1; #saves an array of exposure times $t2="FILE".(1*$t1); #print "filename = $t2\n"; open ($f, ">$t2") || die "can't open $t2: $!"; $i=0; while ($i < $nfiles) { if (!($name{$i} =~ /^dk/)){ if ($exptime{$i} == $t1) { print $f "$name{$i}\n"; } } $i++; } $temp=$t1; $j++; $ntimes=$j; # keeps track of number of different exposure times close ($f) || die "can't close $f: $!"; } $k++; } } ######################################################################### #write out commands to batch files to change pixtype to ushort for object #frames and dark-subtract files with same exptime sub dark_subtract { $i=0; while ( $i < $ntimes ) { $darkname="dk".(1*$times{$i}); #assumes darks are named dk## #print "$darkname\n"; $f="FILE".(1*$times{$i}); #file containing files w/same exptime print BATCH "chpixtype \@$f \@$f newpixtype=ushort\n"; print BATCH "ccdproc \@$f fixpix- overscan- trim- zerocor- darkcor=yes flatcor- dark+ dark=$darkname\n"; $i++; } } ########################################################################## #subroutine that writes the rest of the image-processsing commands to BATCH sub image_process{ $index=0; while ($index < $nprefix) { #print "$prefix{$index}\n"; if ( !($prefix{$index} =~ /^dk/)) { print BATCH "mask files=\@$prefix{$index} mask=invmaskj.imh invmask=maskj.pl\n"; # mask has good values=1, invmask has good value=0 print BATCH "flush\n"; print BATCH "irflat $prefix{$index} flatstring=f number=8 log=log objmask- stdpars+\n"; print BATCH "irshiftrf flatlist=$prefix{$index}f refimage=$ref[$index]f prefix=$prefix{$index} suffix=shift\n"; print BATCH "imcopy $ref[$index] qem$index\n"; print BATCH "imarith qem$index / qem$index qem$index\n"; print BATCH "ircoadd comblist=$prefix{$index}f outimage=$prefix{$index}f expmap=qem$index shiftlist=$prefix{$index}.roundoff.shift scaling=none weighting=none zeroing=mode unzero+ stdpars+ magfac=1 stack- logfile=ircoad\n"; print BATCH "imcopy $prefix{$index}f $prefix{$index}em\n"; print BATCH "imarith $prefix{$index}em / $prefix{$index}em $prefix{$index}em\n"; print BATCH "mkobjmask image=$prefix{$index}f expname=$prefix{$index}em i_nsmooth=3 i_subsample=1 i_filtsize=15 i_ngrow=1 suffix=mask prefix=norm nsmooth=3 subsample=1 filtsize=15 ngrow=1 interact- echog+ mode=ql\n"; print BATCH "masklet image=$prefix{$index}f objmask=$prefix{$index}fmask.pl suffix=om shiftfile=$prefix{$index}f.imshifts flip- update+ echog+\n"; print BATCH "imdel \@$prefix{$index}f\n"; print BATCH "irflat imagelist=$prefix{$index} flatstring=fm number=8 log=log objmask+ stdpars+\n"; print BATCH "domanygeotran $prefix{$index} $prefix{$index} H_9904_geomapout geo.dat\n"; print BATCH "irshiftrf flatlist=$prefix{$index}fm refimage=$ref[$index]fm prefix=$prefix{$index}fm suffix=shift\n"; print BATCH "ircoadd comblist=$prefix{$index}fm outimage=$prefix{$index}fm expmap=qem$index shiftlist=$prefix{$index}fm.roundoff.shift scaling=none weighting=none zeroing=mode unzero+ stdpars+ magfac=1 stack- logfile=ircoad\n"; } $index++; } }