scidoc0319 — Document

OLDWPREP2 - prepare raw WHIRC data

October 1, 2013

# OLDWPREP2 - prepare raw WHIRC data
# 10MAR2009: Adapted from Mike Merrill's SQCORR script
# 08DEC2010: Using revised WCS values after orientation of array on sky
# apparently changed between June and November 2009. Data prior to this
# should be corrected using OLDWPREP1.CL
# 22MAR2013: WHIRC headers were modified in mid-2012 so that ROTANGLE and
# ROTOFF are in degrees rather than radians! The script OLDWPREP1
# should be used for data taken prior to November 2009, the current script
# OLDWPREP2 for data taken between November 2009 and June 2012, and WPREP for
# data taken thereafter. If ROTOFF=0, there is no difference between
# OLDWPREP2 and WPREP.
# Carries out the following: Fowler renormalization; linearity correction;
# WCS recalculation for instrument rotator offset; trim to 2048X2048;
# Add header flag WPREP=2 (OLDWPREP1 flag = 1)

procedure oldwprep2 (input, output)

string input {prompt="Input raw images"}
string output {prompt="Output image descriptor: @list||.ext||%in%out%"}

bool verbose {yes,prompt="Verbose output?"}
file logfile {"STDOUT",prompt="logfile name"}

struct *inlist,*outlist,*l_list

begin

int nin, irootlen, orootlen, stat, pos1b, pos1e, pos2b, pos2e,nex
string in,in1,in2,out,iroot,oroot,uniq,sopt,img,sname,sout,sbuff,sjunk,
smean, smedian, smode, front, srcsub, color, sexpr
file blank, nflat, infile, outfile, im1, tmp1, tmp2, l_log,
colorlist
bool found
string gimextn, imextn, imname, imroot, fowler, rotoff
real ff, rr, cd11, cd12, cd21, cd22, aa, bb

struct line = ""

# Make sure that correct packages are loaded
noao.imred.irred

# Assign positional parameters to local variables
in = input
out = output

# get IRAF global image extension
show("imtype") | translit ("",","," ",delete-) | scan (gimextn)
nex = strlen(gimextn)

uniq = mktemp ("_Tirp")
infile = mktemp ("tmp$irp")
outfile = mktemp ("tmp$irp")
tmp1 = mktemp ("tmp$irp")
tmp2 = mktemp ("tmp$irp")
l_log = mktemp ("tmp$irp")
im1 = uniq // ".im1"

l_list = l_log
# check whether input stuff exists
if ((stridx("@%.",out) != 1) && (stridx(",",out) <= 1)) {
# Verify format of output descriptor
print ("Improper output descriptor format: ",out)
print (" Use @list or comma delimited list for fully named output")
print (" Use .extension for appending extension to input list")
print (" Use %inroot%outroot% to substitute string within input list")
goto skip
}

# check whether input stuff exists
l_list = l_log
print (in) | translit ("", "@:", " ") | scan(in1,in2)

if ((stridx("@",in) == 1) && (! access(in1))) { # check input @file
print ("Input file ",in1," does not exist!")
goto skip
}

print (in) | translit ("", ":", " ") | scan(in1,in2)
sections (in1,option="nolist")
if (sections.nimages == 0) { # check input images
print ("Input images in file ",in, " do not exist!")
goto skip
}

# Expand input file name list
sections (in1, option="root",> infile)

# Expand output image list
if (stridx("@,",out) != 0) { # @-list
# Output descriptor is @-list or comma delimited list
sections (out, option="root",> outfile)
} else { # namelist/substitution/append
inlist = infile
for (nin = 0; fscan (inlist,img) !=EOF; nin += 1) {
# Get past any directory info
if (stridx("$/",img) != 0) {
print (img) | translit ("", "$/", " ", >> l_log)
stat = fscan(l_list,img,img,img,img,img,img,img,img)
}
i = strlen(img)
if (substr(img,i-nex,i) == "."//gimextn) # Strip off imextn
img = substr(img,1,i-nex-1)
# Output descriptor indicates append or substitution based on input list
if (stridx("%",out) > 0) { # substitution
print (out) | translit ("", "%", " ") | scan(iroot,oroot)
if (nscan() == 1) oroot = ""
irootlen = strlen(iroot)
while (strlen(img) >= irootlen) {
found = no
pos2b = stridx(substr(iroot,1,1),img) # match first char
pos2e = pos2b + irootlen - 1 # presumed match end
pos1e = strlen(img)
if ((pos2b > 0) && (substr(img,pos2b,pos2e) == iroot)) {
if ((pos2b-1) > 0)
sjunk = substr(img,1,pos2b-1)
else
sjunk = ""
print(sjunk//oroot//
substr(img,min(pos2e+1,pos1e),pos1e), >> outfile)
found = yes
break
} else if (pos2b > 0) {
img = substr(img,pos2b+1,pos1e) # move past first match
} else { # no match
found = no
break
}
}
if (! found) { # no match
print ("root ",iroot," not found in ",img)
goto skip
}
} else # name/append
print(img//out,>> outfile)
}
}

count(infile) | scan (pos1b); count(outfile) | scan (pos2b)
if (pos1b != pos2b) {
print ("Mismatch between input and output lists: ",pos1b,pos2b)
join (tmp1,outfile)
goto skip
}
nin = pos1b
inlist = ""

# send newline if appending to existing logfile
if (access(logfile)) print("\n",>> logfile)

# Loop through data
inlist = infile; outlist = outfile
while ((fscan (inlist,sname) != EOF) && (fscan(outlist,sout) != EOF)) {

# Fowler renormalization and linearity correction
fowler = "FOWLER"
imgets(sname,fowler)
ff = real(imgets.value)
imarith (sname,"/",ff,sout,pixtype="r",calctype="r",hparams="")
irlincor(sout,sout,coeff1=1.00,coeff2=0.004227,coeff3=0.02691)

# WCS recalculation for nonzero rotator offset angles
rotoff = "ROTOFF"
imgets(sout,rotoff)
rr = real(imgets.value)
aa = 2.7374523e-5 + 0.0469199e-5*cos(2*rr)
bb = 2.7374523e-5 + 0.0469199e-5*cos(2*(rr+1.570796))

cd11 = aa*cos(4.7115163 - rr)
cd12 = aa*sin(4.7115163 - rr)
cd21 = bb*cos(3.1401969 - rr)
cd22 = bb*sin(3.1401969 - rr)

hedit(sout,"CD1_1",cd11,add=no,verify=no,show=no,update=yes)
hedit(sout,"CD1_2",cd12,add=no,verify=no,show=no,update=yes)
hedit(sout,"CD2_1",cd21,add=no,verify=no,show=no,update=yes)
hedit(sout,"CD2_2",cd22,add=no,verify=no,show=no,update=yes)

hedit(sout,"WPREP", "2", add=yes,verify=no,show=no,update=yes)

# Trim off 128 reference columns
sout = sout + "[1:2048,1:2048]"
imcopy (sout, sout, ver-)
sections (sout, option="root")
}


skip:

# Finish up
inlist = ""; outlist = ""; l_list = ""
delete (im1//","//tmp1//","//tmp2//","//l_log, verify-,>& "dev$null")
delete (infile//","//outfile//","//colorlist, verify-,>& "dev$null")

end

About the Document

Id: scidoc0319
Release date: October 1, 2013, 4:06 pm

Document Formats