Commit 92d89cd6 authored by Tom Dwelly's avatar Tom Dwelly
Browse files

added handling of spZall files to convert_sdss_plate_to_speccy.csh

parent ac844871
...@@ -15,18 +15,29 @@ foreach HELPER ( ftlist awk paste ) ...@@ -15,18 +15,29 @@ foreach HELPER ( ftlist awk paste )
endif endif
end end
set FIRST_FIBER = 1
if ( $#argv != 3 ) then set LAST_FIBER = 1000
echo "Error, incorrect number of input parameters"
echo "Usage: ${0:t} SPPLATE_FILENAME SPZBEST_FILENAME OUTDIR" if ( $#argv == 4 ) then
set SPPLATE = "${argv[1]}"
set SPZBEST = "${argv[2]}"
set SPZALL = "${argv[3]}"
set OUTDIR = "${argv[4]}"
else if ( $#argv == 6 ) then
set SPPLATE = "${argv[1]}"
set SPZBEST = "${argv[2]}"
set SPZALL = "${argv[3]}"
set OUTDIR = "${argv[4]}"
set FIRST_FIBER = "${argv[5]}"
set LAST_FIBER = "${argv[6]}"
else
echo "Error, incorrect number of input parameters ($#argv)"
echo "Usage: ${0:t} SPPLATE_FILENAME SPZBEST_FILENAME SPZALL_FILENAME OUTDIR [FIRST_FIBER LAST_FIBER]"
exit 1 exit 1
endif endif
set SPPLATE = "${argv[1]}"
set SPZBEST = "${argv[2]}"
set OUTDIR = "${argv[3]}"
# check if the requisite files exist # check if the requisite files exist
if ( ! -e "$SPPLATE" ) then if ( ! -e "$SPPLATE" ) then
...@@ -39,6 +50,13 @@ if ( ! -e "$SPZBEST" ) then ...@@ -39,6 +50,13 @@ if ( ! -e "$SPZBEST" ) then
exit 1 exit 1
endif endif
if ( "$SPZALL" == "NONE" || "$SPZALL" == "-" || "$SPZALL" == "" ) then
set SPZALL = "NONE"
else if ( ! -e "$SPZALL" ) then
echo "Cannot find specified spZall file: $SPZALL"
exit 1
endif
# make output directory for speccy format files: # make output directory for speccy format files:
mkdir -p "$OUTDIR" mkdir -p "$OUTDIR"
if ( ! -d "$OUTDIR" ) then if ( ! -d "$OUTDIR" ) then
...@@ -48,14 +66,23 @@ endif ...@@ -48,14 +66,23 @@ endif
# set NFIBERS = 1000 if ( -X gethead ) then
set NFIBERS = `ftlist "${SPPLATE}[0]" K include="NAXIS2" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'` set NFIBERS = `gethead "${SPPLATE}[0]" "NAXIS2" `
set PLATE = `ftlist "${SPPLATE}[0]" K include="PLATEID" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'` set PLATE = `gethead "${SPPLATE}[0]" "PLATEID"`
set MJD = `ftlist "${SPPLATE}[0]" K include="MJD" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'` set MJD = `gethead "${SPPLATE}[0]" "MJD" `
set CRVAL1 = `ftlist "${SPPLATE}[0]" K include="CRVAL1" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'` set CRVAL1 = `gethead "${SPPLATE}[0]" "CRVAL1" `
set CRPIX1 = `ftlist "${SPPLATE}[0]" K include="CRPIX1" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'` set CRPIX1 = `gethead "${SPPLATE}[0]" "CRPIX1" `
set CD1_1 = `ftlist "${SPPLATE}[0]" K include="CD1_1" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'` set CD1_1 = `gethead "${SPPLATE}[0]" "CD1_1" `
set BUNIT = (`ftlist "${SPPLATE}[0]" K include="BUNIT" | awk '{print $3}'`) set BUNIT = (`gethead "${SPPLATE}[0]" "BUNIT" `)
else
set NFIBERS = `ftlist "${SPPLATE}[0]" K include="NAXIS2" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'`
set PLATE = `ftlist "${SPPLATE}[0]" K include="PLATEID" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'`
set MJD = `ftlist "${SPPLATE}[0]" K include="MJD" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'`
set CRVAL1 = `ftlist "${SPPLATE}[0]" K include="CRVAL1" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'`
set CRPIX1 = `ftlist "${SPPLATE}[0]" K include="CRPIX1" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'`
set CD1_1 = `ftlist "${SPPLATE}[0]" K include="CD1_1" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'`
set BUNIT = (`ftlist "${SPPLATE}[0]" K include="BUNIT" | awk -v comm='/' '{print substr($0,10);}'` )
endif
set TEMP0 = "${OUTDIR}/convert_to_speccy_temp0_$$" set TEMP0 = "${OUTDIR}/convert_to_speccy_temp0_$$"
set TEMP1 = "${OUTDIR}/convert_to_speccy_temp1_$$" set TEMP1 = "${OUTDIR}/convert_to_speccy_temp1_$$"
...@@ -66,10 +93,10 @@ set TEMP5 = "${OUTDIR}/convert_to_speccy_temp5_$$" ...@@ -66,10 +93,10 @@ set TEMP5 = "${OUTDIR}/convert_to_speccy_temp5_$$"
echo "Extracting speccy files from ${SPPLATE} and ${SPZBEST}" echo "Extracting speccy files from ${SPPLATE} and ${SPZBEST}"
printf 'Output files will be at: %s/spec-%04d-%05d-{FIBERID}_speccy.txt\n' "$OUTDIR" ${PLATE} ${MJD} printf 'Output files will be at: %s/spec-%04d-%05d-{FIBERID}_speccy.txt\n' "$OUTDIR" ${PLATE} ${MJD}
echo -n "Working on FIBERID (total $NFIBERS): " echo -n "Working on FIBERID range [${FIRST_FIBER}:${LAST_FIBER}] (total $NFIBERS): "
set FIBERID = 1 set FIBERID = $FIRST_FIBER
while ( $FIBERID <= $NFIBERS ) while ( $FIBERID <= $NFIBERS && $FIBERID <= $LAST_FIBER )
echo -n " $FIBERID" echo -n " $FIBERID"
set SPECCY_OUTFILE = `printf '%s/spec-%04d-%05d-%04d_speccy.txt' "$OUTDIR" ${PLATE} ${MJD} ${FIBERID} ` set SPECCY_OUTFILE = `printf '%s/spec-%04d-%05d-%04d_speccy.txt' "$OUTDIR" ${PLATE} ${MJD} ${FIBERID} `
rm $TEMP0 $TEMP1 $TEMP2 $TEMP3 $TEMP4 $TEMP5 >>& /dev/null rm $TEMP0 $TEMP1 $TEMP2 $TEMP3 $TEMP4 $TEMP5 >>& /dev/null
...@@ -79,14 +106,12 @@ while ( $FIBERID <= $NFIBERS ) ...@@ -79,14 +106,12 @@ while ( $FIBERID <= $NFIBERS )
ftlist "${SPPLATE}[SKY][*,${FIBERID}:${FIBERID}]" I rownum=no colheader=no mode=q | awk '//{for(i=1;i<=NF;i++){print $i}}' > $TEMP2 ftlist "${SPPLATE}[SKY][*,${FIBERID}:${FIBERID}]" I rownum=no colheader=no mode=q | awk '//{for(i=1;i<=NF;i++){print $i}}' > $TEMP2
ftlist "${SPZBEST}[2][*,${FIBERID}:${FIBERID}]" I rownum=no colheader=no mode=q | awk '//{for(i=1;i<=NF;i++){print $i}}' > $TEMP3 ftlist "${SPZBEST}[2][*,${FIBERID}:${FIBERID}]" I rownum=no colheader=no mode=q | awk '//{for(i=1;i<=NF;i++){print $i}}' > $TEMP3
# now dump the contents of the relevant tables in the SPZBEST and SPPLATE # now dump the contents of the relevant tables in the SPZBEST and SPPLATE
# files to ascii and format them them as speccy keywords (i.e. "# keyname = value") # files to ascii and format them them as speccy keywords (i.e. "# keyname = value")
ftlist "${SPZBEST}[1]" C mode=q | tail -n +4 | awk '//{print "KEYNAME",$2}' > $TEMP4 ftlist "${SPZBEST}[1]" C mode=q | tail -n +4 | awk '//{print "KEYNAME",$2}' > $TEMP4
ftlist "${SPZBEST}[1][FIBERID==${FIBERID}]" T mode=q separator='|' rownum=no colheader=no > $TEMP5 ftlist "${SPZBEST}[1][FIBERID==${FIBERID}]" T mode=q separator='|' rownum=no colheader=no > $TEMP5
# awk --field-separator='|' '$0!~/^KEYNAME/ {n++;if(n==1){nkey=NF;for(i=1;i<=nkey;i++){keyval[i]=$i}}} $0~/^KEYNAME/ {k++;split($0,a," ");keyname[k]=a[2]} END {for(i=1;i<=nkey;i++){printf("# %-20s = %s\n", keyname[i], keyval[i])}}' $TEMP4 $TEMP5 > $SPECCY_OUTFILE # deal with vector columns properly
# awk --field-separator='|' '$0!~/^KEYNAME/ {n++;nkey=NF;for(i=1;i<=nkey;i++){n_i=sprintf("%d_%d",n,i);keyval[n_i]=$i}} $0~/^KEYNAME/ {k++;split($0,a," ");keyname[k]=a[2]} END {for(i=1;i<=nkey;i++){printf("# %-20s = ", keyname[i]);for(m=1;m<=n;m++){m_i=sprintf("%d_%d",m,i); printf("%s ",keyval[m_i])};printf("\n")}}' $TEMP4 $TEMP5 | awk --field-separator='' '//{for(m=1;m<=NF;m++){if($m!=" "){break;}};for(n=NF;n>0;n--){if($n!=" "){break;}};print substr($0,m,n-m+1)}' > $SPECCY_OUTFILE
# deal with vector columns better
awk --field-separator='|' '\ awk --field-separator='|' '\
function trim_string(s) {\ function trim_string(s) {\
for(__m=1;__m<=length(s);__m++){if(substr(s,__m,1)!=" "){break;}};\ for(__m=1;__m<=length(s);__m++){if(substr(s,__m,1)!=" "){break;}};\
...@@ -105,9 +130,54 @@ END {for(i=1;i<=nkey;i++){\ ...@@ -105,9 +130,54 @@ END {for(i=1;i<=nkey;i++){\
ftlist "${SPPLATE}[PLUGMAP]" C mode=q | tail -n +4 | awk '//{print "KEYNAME",$2}' > $TEMP4 ftlist "${SPPLATE}[PLUGMAP]" C mode=q | tail -n +4 | awk '//{print "KEYNAME",$2}' > $TEMP4
ftlist "${SPPLATE}[PLUGMAP][FIBERID==${FIBERID}]" T mode=q separator='|' rownum=no colheader=no > $TEMP5 ftlist "${SPPLATE}[PLUGMAP][FIBERID==${FIBERID}]" T mode=q separator='|' rownum=no colheader=no > $TEMP5
awk --field-separator='|' '$0!~/^KEYNAME/ {n++;if(n==1){nkey=NF;for(i=1;i<=nkey;i++){keyval[i]=$i}}} $0~/^KEYNAME/ {k++;split($0,a," ");keyname[k]=a[2]} END {for(i=1;i<=nkey;i++){printf("# %-20s = %s\n", keyname[i], keyval[i])}}' $TEMP4 $TEMP5 >> $SPECCY_OUTFILE # awk --field-separator='|' '$0!~/^KEYNAME/ {n++;if(n==1){nkey=NF;for(i=1;i<=nkey;i++){keyval[i]=$i}}} $0~/^KEYNAME/ {k++;split($0,a," ");keyname[k]=a[2]} END {for(i=1;i<=nkey;i++){printf("# %-20s = %s\n", keyname[i], keyval[i])}}' $TEMP4 $TEMP5 >> $SPECCY_OUTFILE
awk --field-separator='|' '\
function trim_string(s) {\
for(__m=1;__m<=length(s);__m++){if(substr(s,__m,1)!=" "){break;}};\
for(__n=length(s);__n>0;__n--) {if(substr(s,__n,1)!=" "){break;}};\
return(substr(s,__m,__n-__m+1))}\
$0!~/^KEYNAME/ {\
n++;nkey=NF;\
for(i=1;i<=nkey;i++){\
n_i=sprintf("%d_%d",n,i);\
keyval[n_i]=trim_string($i)}}\
$0~/^KEYNAME/ {\
k++;split($0,a," ");keyname[k]=a[2]}\
END {for(i=1;i<=nkey;i++){\
printf("# %-20s = ", keyname[i]);\
for(m=1;m<=n;m++){m_i=sprintf("%d_%d",m,i); printf("%s ",keyval[m_i])};printf("\n")}}' $TEMP4 $TEMP5 >> $SPECCY_OUTFILE
if ( "$SPZALL" != "NONE" ) then
if ( -X gethead ) then
set DIMS0 = `gethead "${SPZALL}[0]" "DIMS0" `
else
set DIMS0 = `ftlist "${SPZALL}[0]" K include="DIMS0" | awk -v comm='/' '{a=substr($0,10);split(a,b,comm);print b[1]}'`
endif
ftlist "${SPZALL}[1]" C mode=q | tail -n +4 | awk '//{print "KEYNAME",$2}' > $TEMP4
foreach FIT ( 1 2 3 )
ftlist "${SPZALL}[1][FIBERID==${FIBERID}&&(#row%${DIMS0}==${FIT})]" T mode=q separator='|' rownum=no colheader=no > $TEMP5
awk --field-separator='|' -v prefix="SPZALL_FIT${FIT}_" '\
function trim_string(s) {\
for(__m=1;__m<=length(s);__m++){if(substr(s,__m,1)!=" "){break;}};\
for(__n=length(s);__n>0;__n--) {if(substr(s,__n,1)!=" "){break;}};\
return(substr(s,__m,__n-__m+1))}\
$0!~/^KEYNAME/ {\
n++;nkey=NF;\
for(i=1;i<=nkey;i++){\
n_i=sprintf("%d_%d",n,i);\
keyval[n_i]=trim_string($i)}}\
$0~/^KEYNAME/ {\
k++;split($0,a," ");keyname[k]=a[2]}\
END {for(i=1;i<=nkey;i++){\
printf("# %s%-20s = ", prefix,keyname[i]);\
for(m=1;m<=n;m++){m_i=sprintf("%d_%d",m,i); printf("%s ",keyval[m_i])};printf("\n")}}' $TEMP4 $TEMP5 >> $SPECCY_OUTFILE
end
endif
paste $TEMP0 $TEMP1 $TEMP2 $TEMP3 $TEMP4 $TEMP5 | awk -v lcrval=$CRVAL1 -v crpix=${CRPIX1} -v lcdelt=${CD1_1} -v bunit="$BUNIT" 'BEGIN {printf("#Wavelength(AA,observed,vacuum),FluxDensity,Error,Sky,bestModel (all %s)\n", bunit)} //{i++;l=10.0**(lcrval + (i-crpix)*lcdelt);printf("%.2f,%.6g,%.6g,%.6g,%.6g\n", l, $1, ($2>0.0?$2**-0.5:0.0), $3, $4)} END {print _}' >> $SPECCY_OUTFILE paste $TEMP0 $TEMP1 $TEMP2 $TEMP3 | awk -v lcrval=$CRVAL1 -v crpix=${CRPIX1} -v lcdelt=${CD1_1} -v bunit="$BUNIT" 'BEGIN {printf("#Wavelength(AA,observed,vacuum),FluxDensity,Error,Sky,bestModel (all %s)\n", bunit)} //{i++;l=10.0**(lcrval + (i-crpix)*lcdelt);printf("%.2f,%.6g,%.6g,%.6g,%.6g\n", l, $1, ($2>0.0?$2**-0.5:0.0), $3, $4)} END {print _}' >> $SPECCY_OUTFILE
rm $TEMP0 $TEMP1 $TEMP2 $TEMP3 $TEMP4 $TEMP5 >>& /dev/null rm $TEMP0 $TEMP1 $TEMP2 $TEMP3 $TEMP4 $TEMP5 >>& /dev/null
@ FIBERID ++ @ FIBERID ++
end end
......
...@@ -406,8 +406,8 @@ linelist_ea.push({name:"SiIV " , lambda: 1402.770 }); // Charlton ...@@ -406,8 +406,8 @@ linelist_ea.push({name:"SiIV " , lambda: 1402.770 }); // Charlton
linelist_ea.push({name:"CIV " , lambda: 1549.48 }); // spZ linelist_ea.push({name:"CIV " , lambda: 1549.48 }); // spZ
linelist_ea.push({name:"HeII " , lambda: 1640.42 }); // spZ linelist_ea.push({name:"HeII " , lambda: 1640.42 }); // spZ
linelist_ea.push({name:"CIII] " , lambda: 1908.734 }); // spZ linelist_ea.push({name:"CIII] " , lambda: 1908.734 }); // spZ
linelist_ea.push({name:"FeII " , lambda: 2382.765 }); // Charlton //linelist_ea.push({name:"FeII " , lambda: 2382.765 }); // Charlton
linelist_ea.push({name:"FeII " , lambda: 2600.173 }); // Charlton //linelist_ea.push({name:"FeII " , lambda: 2600.173 }); // Charlton
//linelist_ea.push({name:"MgII " , lambda: 2800.3152}); // spZ //linelist_ea.push({name:"MgII " , lambda: 2800.3152}); // spZ
linelist_ea.push({name:"MgII " , lambda: 2796.3522}); // NIST linelist_ea.push({name:"MgII " , lambda: 2796.3522}); // NIST
linelist_ea.push({name:"MgII " , lambda: 2803.5300}); // NIST linelist_ea.push({name:"MgII " , lambda: 2803.5300}); // NIST
...@@ -423,7 +423,7 @@ linelist_ab.push({name:"CaII H " , lambda: 3969.591 }); // msw ...@@ -423,7 +423,7 @@ linelist_ab.push({name:"CaII H " , lambda: 3969.591 }); // msw
linelist_ea.push({name:"H\u03B4 " , lambda: 4102.92 }); // msw Hdelta linelist_ea.push({name:"H\u03B4 " , lambda: 4102.92 }); // msw Hdelta
linelist_ab.push({name:"G-band " , lambda: 4305.2 }); // no ref - converted from lambda_air=4304A linelist_ab.push({name:"G-band " , lambda: 4305.2 }); // no ref - converted from lambda_air=4304A
linelist_ea.push({name:"H\u03B3 " , lambda: 4341.69 }); // msw Hgamma linelist_ea.push({name:"H\u03B3 " , lambda: 4341.69 }); // msw Hgamma
linelist_ea.push({name:" [OIII]" , lambda: 4364.44 }); // msw //linelist_ea.push({name:" [OIII]" , lambda: 4364.44 }); // msw
linelist_ea.push({name:"HeII " , lambda: 4686.9915}); // spZ linelist_ea.push({name:"HeII " , lambda: 4686.9915}); // spZ
linelist_ea.push({name:"H\u03B2 " , lambda: 4862.69 }); // msw Hbeta linelist_ea.push({name:"H\u03B2 " , lambda: 4862.69 }); // msw Hbeta
linelist_ea.push({name:"[OIII] " , lambda: 4960.30 }); // msw linelist_ea.push({name:"[OIII] " , lambda: 4960.30 }); // msw
...@@ -433,7 +433,7 @@ linelist_ab.push({name:"Mgb " , lambda: 5174.125 }); // msw ...@@ -433,7 +433,7 @@ linelist_ab.push({name:"Mgb " , lambda: 5174.125 }); // msw
linelist_ab.push({name:"Mgb " , lambda: 5185.048 }); // msw linelist_ab.push({name:"Mgb " , lambda: 5185.048 }); // msw
linelist_ea.push({name:"NI " , lambda: 5199.35 }); // NIST linelist_ea.push({name:"NI " , lambda: 5199.35 }); // NIST
linelist_ea.push({name:"NI " , lambda: 5201.71 }); // NIST linelist_ea.push({name:"NI " , lambda: 5201.71 }); // NIST
linelist_ea.push({name:"FeII " , lambda: 5271.50 }); // NIST - strongest one of a blend //linelist_ea.push({name:"FeII " , lambda: 5271.50 }); // NIST - strongest one of a blend
linelist_ea.push({name:"[OI] " , lambda: 5578.8878}); // spZ linelist_ea.push({name:"[OI] " , lambda: 5578.8878}); // spZ
linelist_ea.push({name:"HeII " , lambda: 5413.0245}); // spZ linelist_ea.push({name:"HeII " , lambda: 5413.0245}); // spZ
linelist_ea.push({name:"[NII] " , lambda: 5756.1862}); // spZ linelist_ea.push({name:"[NII] " , lambda: 5756.1862}); // spZ
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment