#!/bin/bash #****************************************************************************** # MPIA - MIDI project # # "@(#) $Id: $" # # who when what # ---------- ---------- ---------------------------------------------- # mathar 2003-08-11 created # mathar 2003-08-12 added sign change in azimuth (FITS header convention differs...) # mathar 2003-08-13 more condensed output (one file per line); consider also AT cases # mathar 2003-08-25 add rotation output # mathar 2005-03-14 also scan files with more general time stamps # mathar 2005-03-15 make sure files w/o ESO ISS CONF STATION1 are skipped # mathar 2006-03-01 changed from ksh to bash script and from centi-degrees to degrees # compute also baseline Azimuth and baseline position angle # mathar 2006-08-29 inherent search for fitshead, dfits etc # #************************************************************************ # NAME # mioFieldAng - calculate field angle in VLTI lab (V,W) coordinates # # SYNOPSIS # cd .../YYYY-MM-TT ; # move to some directory with MIDI.*.fits files # mioFieldAng # # DESCRIPTION # For all files MIDI*_01.fits and MIDI*[0-9][0-9][0-9].fits found in the # current working directory, the hierarchichal keywords ESO ISS ALT, # ESO ISS AZ and ESO ISS PARANG START are read. (These are in units of # degrees, and the coordinate frame for the azimuth is that 0 degrees points # South and +90 degrees points West.) The keywords ISS CONFIG T[12][XY] # are also read as input to a computation of the baseline direction. # # The azimuth is then turned negative to adapt to the convention # of VLT-TRE-ESO-15000-3092 where +90 degrees defines the East direction. # The ESO ISS CONF STATION1 keyword is also read to figure out whether # this is a UT or AT type of observation. # # The Field Angles are calculated according to section 5.1 of # VLT-TRE-ESO-15000-3092, and reported in units of degrees. # These refer to the directions North and East measured in the (V,W) # coordinate system after the switchyard. In MIDI FITS (detector) # coordinates, +V points towards +y and +W points towards +x; # If the angles calculated here are zero they mean the "down" (-y) # direction in the FITS images, and if they are +90 # they mean the "left" (-x) direction in the FITS # images. This interpretation includes a clarification of the # VLT-TRE-ESO-15000-3092 regarding the implicit insertion of a "virtual" # lens in the VLTI laboratory, distributed by Ph Gitton on Aug 14, 2003. # What has been called the North angle in version 1.0 of # VLT-TRE-ESO-15000-3092 is the South direction for MIDI.) # # The final output 'rot' is equivalent to the ROTATION column of the # IMAGING_DATA table as defined in VLT-ICD-ESO-15000-2764. # # The value reported as 'Ab' is the baseline azimuth angle and the value reported # as 'pbla' the projected baseline position angle according to # http://www.strw.leidenuniv.nl/~mathar/public/matharMIDI20051110.pdf # and arXiv:astro-ph/0608273. The value of 'Ab' is computed by some form of # arctangent of the baseline vector with a normalization of Ab=0 if the # baseline points to the North and Ab=+90 if the baseline points to the East. # This means the angle turns by 180 degrees if the ESO ISS T1[XY] and # ESO ISS T2[XY] values are interchanged. Note that 'pbla' has been quite # different from any value reported by the header keywords ESO ISS PBLAij, # as discussed in the aforementioned matharMIDI20051110.pdf. # # RETURN VALUE # # EXAMPLES # wmidi> cd mididata/2005-05-26 # wmidi> mioFieldAng # MIDI.2005-05-27T01:27:08.000.fits,a=47.775,A=-349.343,p=-23.777,t=U2,phiNorth=106.125,phiEast=16.125,rot=-73.875,Ab=-139.93,pbla=35.023 # MIDI.2005-05-27T01:28:01.148.fits,a=47.775,A=-349.343,p=-23.777,t=U2,phiNorth=106.125,phiEast=16.125,rot=-73.875,Ab=-139.93,pbla=35.023 # MIDI.2005-05-27T01:32:11.000.fits,a=47.981,A=-350.069,p=-22.085,t=U2,phiNorth=106.885,phiEast=16.885,rot=-73.115,Ab=-139.93,pbla=35.975 # MIDI.2005-05-27T01:33:04.149.fits,a=47.981,A=-350.069,p=-22.085,t=U2,phiNorth=106.885,phiEast=16.885,rot=-73.115,Ab=-139.93,pbla=35.975 # MIDI.2005-05-27T01:54:45.750.fits,a=45.102,A=-357.473,p=-6.545,t=U2,phiNorth=117.900,phiEast=27.900,rot=-62.100,Ab=-139.93,pbla=45.835 # MIDI.2005-05-27T01:55:30.750.fits,a=45.109,A=-357.559,p=-6.320,t=U2,phiNorth=118.032,phiEast=28.032,rot=-61.968,Ab=-139.93,pbla=45.980 # MIDI.2005-05-27T01:56:14.750.fits,a=45.116,A=-357.654,p=-6.073,t=U2,phiNorth=118.177,phiEast=28.177,rot=-61.823,Ab=-139.93,pbla=46.127 # MIDI.2005-05-27T01:58:25.000.fits,a=45.135,A=-357.924,p=-5.374,t=U2,phiNorth=118.587,phiEast=28.587,rot=-61.413,Ab=-139.93,pbla=46.556 # MIDI.2005-05-27T01:59:18.148.fits,a=45.135,A=-357.924,p=-5.374,t=U2,phiNorth=118.587,phiEast=28.587,rot=-61.413,Ab=-139.93,pbla=46.556 # MIDI.2005-05-27T02:02:11.000.fits,a=45.163,A=-358.396,p=-4.147,t=U2,phiNorth=119.314,phiEast=29.314,rot=-60.686,Ab=-139.93,pbla=47.303 # MIDI.2005-05-27T02:03:25.799.fits,a=45.163,A=-358.396,p=-4.147,t=U2,phiNorth=119.314,phiEast=29.314,rot=-60.686,Ab=-139.93,pbla=47.303 # MIDI.2005-05-27T02:06:32.750.fits,a=45.186,A=-358.937,p=-2.748,t=U2,phiNorth=120.149,phiEast=30.149,rot=-59.851,Ab=-139.93,pbla=48.162 # MIDI.2005-05-27T02:08:07.750.fits,a=45.192,A=-359.136,p=-2.231,t=U2,phiNorth=120.461,phiEast=30.461,rot=-59.539,Ab=-139.93,pbla=48.479 # MIDI.2005-05-27T02:23:23.000.fits,a=70.237,A=-19.093,p=24.018,t=U2,phiNorth=101.708,phiEast=11.708,rot=-78.292,Ab=-139.93,pbla=46.178 # ... # # ENVIRONMENT # # FILES # MIDI*.fits - files inspected one after the other. Files not providing # the input information on AZ, ALT etc are silently # skipped. # # CAUTIONS # The angles "phi" (Field Angles) are calculated as defined in VLT-TRE-ESO-15000-3092. # This means they start at phi=0 equivalent to the +V direction and turn positive # as we rotate towards the +W direction. # # The script calculates the field angles for the first of the two telescopes. # It does not check whether the field angle of the second telescope is the # same (which it would not if this was an exposure with hybrid AT-UT or # hybrid North-South stations). # # NOTES # Depending on some preprocessor definition in the mio module, OS inserts # the result of an equivalent calculation with keywords defined # in dicMIDI. # Pending an implementation in NRTS, the equivalent information may be # found in the ROTATION column of the VLTI IMAGING_DATA table. # # If mioFitsListhead(1) is not available, it may be replaced by # fitshead(1) or dfits(1) or slxCatFits(1) or any other program # that lists the primary header on stdout. The program tries to find one # of these in the executables. # # SEE ALSO # mioFitsListhead(1) VLT-TRE-ESO-15000-3092 VLT-ICD-ESO-15410-2117 VLT-ICD-ESO-15000-1918 # # BUGS # # TODO #------------------------------------------------------------------------ echo a=ALT,A=AZ with S=0,W=90,p=PARANG,t=STATION1,phi=FieldAngle,rot=Detector+y,Ab=baseAzim # define the command that is available to list the primary header keywords fcmd=`which mioFitsListhead >&/dev/null ` if [[ $? -lt 1 ]] ; then fcmd=mioFitsListhead else fcmd=`which fitshead >&/dev/null ` if [[ $? -lt 1 ]] ; then fcmd=fitshead else fcmd=`which dfits >&/dev/null ` if [[ $? -lt 1 ]] ; then fcmd=dfits else fcmd=slxCatFits fi fi fi # Consider only the first (01) files of an exposure since only these are accurate # (MIDI assembles the ISS headers only once per exposure, not once per file). # If the names are in DICB format, these first files have zero fractional seconds. for f in MIDI*_01.fits MIDI*[0-9][0-9][0-9].fits ; do # altitude at start a=`$fcmd $f | awk '/ESO ISS ALT/{print $6}'` # azimuth at start, notation is 0= south, 90=east (Table 5 of VLT-ICD-ESO-15410-2117) A=`$fcmd $f | awk '/ESO ISS AZ/{print $6}'` # parallactic angle at start p=`$fcmd $f | awk '/ESO ISS PARANG START/{print $6}'` # type of telescope (location/station on the mountain) # without the leading tic mark of the FITS string markers: U1, G0 etc t=`$fcmd $f | awk '/ESO ISS CONF STATION1/{print $6}' |cut -c 2,3` # cartesian coordinates of telescopes t1x=`$fcmd $f | awk '/ESO ISS CONF T1X/{print $7}'` t1y=`$fcmd $f | awk '/ESO ISS CONF T1Y/{print $7}'` t2x=`$fcmd $f | awk '/ESO ISS CONF T2X/{print $7}'` t2y=`$fcmd $f | awk '/ESO ISS CONF T2Y/{print $7}'` # Skip ill-formatted FITS files if [[ "x$a" != "x" && "x$A" != "x" && "x$p" != "x" && "x$t" != "x" ]] ; then # baseline azimuth angle, arctan2(Delta X, Delta Y), 0 if North, pi/2 if East (in radians) Ab=`bc -l <<++ if ( ( $t2y - $t1y ) > 0 ) a( ( $t2x - $t1x ) / ( $t2y - $t1y ) ) if ( ( $t2y - $t1y ) < 0 ) a( ( $t2x - $t1x ) / ( $t2y - $t1y ) ) + 4*a(1) ++ ` # projected baseline position angle # First we derive the auxiliary angle 'psi' of the Leinert theory from cos(psi)=cos(Ab-A)*sin(a)/sin(theta) and # sin(psi)=sin(Ab-A)/sin(theta). The sin(theta) is not actually needed because # we use the atan2() function to derive the correct branch of the arctangent. # Within the awk the output is converted from radians to degrees and cut to # two digits. This still uses the VLT convention of A=0 means south and A=90 means West. pbla=`echo $Ab $A $a | awk '{r=3.1415926535897/180. ; abb=$1 - $2*r; sinp=sin(abb); cosp= cos(abb)*sin($3*r); printf "%.2f",atan2(sinp,cosp)/r}'` # According to pbla=parallactic angle plus 180 plus psi.. pbla=`bc <<++ 180 + $pbla + $p ++ ` # convert baseline azimuth angle from radians to degrees and round to 2 digits Ab=`echo $Ab | awk '{printf "%.2f",$0 *180/3.1415926535}'` # wrap baseline azimuth angle into the interval [-180:180] Ab=`bc -l <<++ if ( ( $Ab >= -180 ) && ( $Ab < 180) ) $Ab if ( $Ab > 180 ) $Ab - 360 if ( $Ab < -180 ) $Ab + 360 ++ ` # For the following formula, need to define 0=south and 90=west, so toggle # the sign of the azimuth A=`bc <<++ -$A ++ ` if [[ $t = U* ]] ; then # Formula section 5.1 of VLT-TRE-ESO-15000-3092; UT case phiN=`bc <<++ $p - $a + $A + 167.02 ++ ` phiE=`bc <<++ $phiN - 90 ++ ` # the detector y-axis relative to the north direction rot=`bc <<++ $phiN + 180 ++ ` elif [[ $t = G2 || $t = J[3-6] ]] ; then # Formula section 5.2 of VLT-TRE-ESO-15000-3092; AT north of the delay line tunnel (G2, J3-J6) phiN=`bc <<++ - $p + $a - $A - 167.02 ++ ` phiE=`bc <<++ $phiN + 90 ++ ` rot=`bc <<++ 180 - $phiN ++ ` else # Formula section 5.3 of VLT-TRE-ESO-15000-3092; AT south of the delay line tunnel (A0-A1,B0-B5...) phiN=`bc <<++ - $p + $a - $A + 12.98 ++ ` phiE=`bc <<++ $phiN + 90 ++ ` rot=`bc <<++ 180 - $phiN ++ ` fi # normalize phiN and phiE into the range [0:360] phiN=`bc <<++ if ( $phiN > 0 ) $phiN % 360 if ( $phiN < 0 ) $phiN % 360 + 360 ++ ` phiE=`bc <<++ if ( $phiE > 0 ) $phiE % 360 if ( $phiE < 0 ) $phiE % 360 + 360 ++ ` # normalize rot the range [-360:180] rot=`bc <<++ if ( $rot > 180 ) $rot - 360 if ( $rot < 180 ) $rot ++ ` echo $f,a=$a,A=$A,p=$p,t=$t,phiNorth=$phiN,phiEast=$phiE,rot=$rot,Ab=$Ab,pbla=$pbla fi done exit 0 # __oOo__