IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 30, 2005, 11:14:48 AM (21 years ago)
Author:
eugene
Message:

serious reorg for release 13

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibADD.tex

    r3448 r3564  
    1 %%% $Id: psLibADD.tex,v 1.69 2005-03-18 20:40:14 jhoblitt Exp $
     1%%% $Id: psLibADD.tex,v 1.70 2005-03-30 21:14:48 eugene Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    1414\project{Pan-STARRS Image Processing Pipeline}
    1515\organization{Institute for Astronomy}
    16 \version{09}
     16\version{10}
    1717\docnumber{PSDC-430-006}
     18
     19\setcounter{tocdepth}{5} % lowest level to be included in toc
    1820
    1921\newcommand\citealt{}
     
    313301 & 2004 May 21 & Added section on 2D Chebyshev fitting, then removed. \\ \hline
    323402 & 2004 Jun 22 & modified stats specification \\ \hline
    33 03--05 & ??? & ??? \\ \hline
    34 06 & 2004 Sep 7 & Frozen for PSLib-2 \\ \hline
     3503 & 2004 Jul 13 & \\ \hline
     3604 & 2004 Aug 16 & \\ \hline
     3705 & 2004 Sep 01 & \\ \hline
     3806 & 2004 Sep 07 & Frozen for PSLib-2 \\ \hline
    353907 & 2004 Nov 24 & Frozen for Cycle 4 \\ \hline
    364008 & 2005 Jan 21 & Draft for Cycle 5 \\ \hline
    374109 & 2005 Feb 14 & Frozen for Cycle 5 \\ \hline
     4210 & 2005 Mar 21 & Draft for Cycle 6 \\ \hline
    3843\RevisionsEnd
    3944
     
    6974\pagenumbering{arabic}
    7075
    71 \section{Pan-STARRS Library PSLib}
    72 
    73 \subsection{Math Utilities}
    74 
    75 \subsubsection{Sorting}
     76% \section{Pan-STARRS Library PSLib}
     77
     78\section{PSLib Math Utilities}
     79
     80\subsection{Sorting}
    7681
    7782A variety of sorting algorithms exist, with a wide range in speed for
     
    103108\code{in.arr[out->arr[0]]} to \code{in.arr[out->arr[in.n - 1]]}.
    104109
    105 \subsubsection{Smoothing: Boxcar and Gaussian}
     110\subsection{Smoothing: Boxcar and Gaussian}
    106111\label{smooth}
    107112
     
    135140\end{equation}
    136141
    137 \subsubsection{Statistics}
     142\subsection{Statistics}
    138143
    139144The general statistics function \code{psStats} performs a variety of
     
    148153sample and robust estimators.
    149154
    150 \paragraph{Sample Statistics}
     155\subsubsection{Sample Statistics}
    151156
    152157We define the following statistical terms, assuming there is a set of
    153158data elements $x_i$ with (standard) errors $\sigma_i$.
    154159
    155 \subparagraph{Mean}
     160\paragraph{Mean}
    156161
    157162The simple mean is defined as:
     
    160165\end{equation}
    161166
    162 \subparagraph{Weighted Mean}
     167\paragraph{Weighted Mean}
    163168
    164169The weighted mean is defined as:
     
    170175standard definition of the mean.
    171176
    172 \subparagraph{Median}
     177\paragraph{Median}
    173178
    174179The median is defined as the value for which 50\% of the data values
     
    181186calculating the sample median.
    182187
    183 \subparagraph{Upper and Lower Quartiles}
     188\paragraph{Upper and Lower Quartiles}
    184189
    185190The upper and lower quartiles ($U_{\frac{1}{4}}$ and
     
    196201the sample quartiles.
    197202
    198 \subparagraph{Standard Deviation}
     203\paragraph{Standard Deviation}
    199204
    200205The standard deviation of the sample is given by:
     
    218223
    219224
    220 \paragraph{Clipped Statistics}
     225\subsubsection{Clipped Statistics}
    221226
    222227The clipped statistics are used to determine the mean and standard
     
    255260\bar{x}| > k \sigma_i$.
    256261
    257 \paragraph{Robust Statistics}
     262\subsubsection{Robust Statistics}
    258263
    259264The robust version of the statistics provides estimators of basic
     
    312317quartiles are estimated in the same manner as above.
    313318
    314 \paragraph{Histograms}
     319\subsubsection{Histograms}
    315320
    316321When calculating histograms in the presence of known errors in the
     
    342347Note that the total adds to one --- the number of values added.
    343348
    344 \subsubsection{Matrix Operations}
     349\subsection{Matrix Operations}
    345350
    346351In this section, we define the linear algebra operations performed on
     
    361366\code{gsl_linalg_LU_decomp}.
    362367
    363 \paragraph{LU Decomposition}
     368\subsubsection{LU Decomposition}
    364369\label{LUdecomp}
    365370
     
    402407\end{equation}
    403408
    404 \paragraph{Calculate a matrix determinant}
     409\subsubsection{Calculate a matrix determinant}
    405410
    406411The determinant $D$ of a matrix $a_{ij}$ is calculated from the
     
    418423shall be used.
    419424
    420 \paragraph{Solving a Linear Equation}
     425\subsubsection{Solving a Linear Equation}
    421426
    422427The LU decomposition of a matrix may be used to solve the
     
    438443\end{eqnarray}
    439444
    440 \paragraph{Invert a matrix}
     445\subsubsection{Invert a matrix}
    441446
    442447Inversion of a matrix using the LU decomposition is performed by
     
    447452operation shall be implemented using the GSL function \code{gsl_linalg_LU_invert}.
    448453
    449 \paragraph{Perform matrix addition, subtraction and multiplication}
     454\subsubsection{Perform matrix addition, subtraction and multiplication}
    450455
    451456Matrix binary arithmetic operations differ from image binary
     
    471476\times$.
    472477
    473 \paragraph{Transpose a matrix}
     478\subsubsection{Transpose a matrix}
    474479
    475480The transpose of a matrix is simply the reorganization of the matrix
     
    484489where $M_{ij}$ is the matrix to be transposed.
    485490
    486 \paragraph{Convert a matrix to a vector}
     491\subsubsection{Convert a matrix to a vector}
    487492
    488493Matrix-to-vector conversion is only defined for a matrix that has a
     
    493498matrix is converted to a \code{PS_DIMEN_TRANV}-type vector.
    494499
    495 \subsubsection{Fitting}
    496 
    497 \paragraph{Chi-squared}
     500\subsection{Fitting}
     501
     502\subsubsection{Chi-squared}
    498503\label{chisq}
    499504
     
    506511\end{equation}
    507512
    508 \paragraph{General Polynomial Fitting}
     513\subsubsection{General Polynomial Fitting}
    509514
    510515Given a set of data values $y_i$ with errors $\sigma_i$, related to
     
    531536(section~\ref{LUdecomp}).
    532537
    533 \subsubsection{Non-linear Minimization}
    534 
    535 \paragraph{Levenberg-Marquardt Method}
     538\subsection{Non-linear Minimization}
     539
     540\subsubsection{Levenberg-Marquardt Method}
    536541
    537542In the Levenberg-Marquardt Method (LMM; see NR \S 15.5), we make a
     
    612617
    613618
    614 \paragraph{Powell's method}
     619\subsubsection{Powell's method}
    615620
    616621Powell's method is a type of ``Direction Set'' methods in
     
    621626manner until the advances along the vectors are smaller than some
    622627pre-defined tolerance.  Such direction set methods, including Powell's
    623 Quadratically Convergent method are discussed in NR\S10.5.
     628Quadratically Convergent method are discussed in NR \S 10.5.
    624629
    625630We will use for our algorithm the modified version of Powell's
     
    665670%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    666671
    667 \subsubsection{Polynomials}
     672\subsection{Polynomials}
    668673\label{sec:polynomials}
    669674
     
    703708$-1 < x < 1$.
    704709
    705 \paragraph{Multi-dimensional polynomials}
     710\subsubsection{Multi-dimensional polynomials}
    706711
    707712Multi-dimensional polynomials shall be composed of multiplications of
     
    711716%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    712717
    713 \subsubsection{(Fast) Fourier Transforms}
     718\subsection{(Fast) Fourier Transforms}
    714719
    715720(Fast) Fourier Transforms (FFTs) shall be implemented using the
     
    717722library}.
    718723
    719 \paragraph{FFTW Plans}
     724\subsubsection{FFTW Plans}
    720725
    721726FFTW requires the user to create a ``plan'' for each transform size,
     
    733738initialisation of the PSLib FFT functions and saved at the conclusion.
    734739
    735 \paragraph{Function mapping}
     740\subsubsection{Function mapping}
    736741
    737742The forward and reverse transforms call the corresponding
     
    750755place to avoid the need to pad the input array to hold the output.
    751756
    752 \paragraph{More Complicated Functions}
     757\subsubsection{More Complicated Functions}
    753758
    754759\code{psFFTCrossCorrelate()} and \code{psFFTConvolve()} both involve
     
    772777caller, and choose to normalise by $1/N^2$.
    773778
     779\subsection{Image Manipulations}
     780
     781\subsubsection{Interpolation}
     782
     783Interpolation is needed in various image manipulation operations,
     784including rotation and resampling.  We have specified a function to
     785perform the interpolation using one of several possible interpolation
     786methods, defined below.  It is important in the discussions that
     787follow to remember that a pixel with column,row if $i,j$ has
     788coordinate at the center of $i+0.5,j+0.5$ and corners with coordinates
     789from $i,j$ to $i+1,j+1$.  Thus, the interpolation of a coordinate
     790$x,y$ = 5.0,4.0 is a value midway between the four pixels with
     791column,row of (5,4), (5,5), (6,4), (6,5). 
     792
     793\paragraph{Nearest Pixel Interpolation ({\tt PS\_INTERPOLATE\_FLAT})}
     794
     795In this interpolation, the value of the closest pixel is returned.
     796This is equivalent to pixel duplication or replication.
     797
     798\paragraph{Bilinear Interpolation ({\tt PS\_INTERPOLATE\_BILINEAR})}
     799
     800In this interpolation, the value at the coordinate is calculated using
     801linear interpolation in two dimensions from the four nearest neighbor
     802pixels.  The bilinear interpolation value at a coordinate $x,y$
     803depends on the four nearest neighbor pixels and the fractional
     804distance $fx,fy$ of the given coordinates from the centers of those
     805four pixels.  Consider four neighboring pixels at column,row of $i,j$,
     806$i+1,j$, $i,j+1$, and $i+1,j+1$ with pixel values $V_{0,0}$,
     807$V_{1,0}$, $V_{0,1}$, $V_{1,1}$.  The value at $x,y$ is given by:
     808\[ V = (V_{0,0}(1 - f_x) + V_{1,0}f_x)(1 - f_y) + (V_{0,1}(1-f_x) + V_{1,1}f_x)f_y \]
     809This expression is more efficiently evaluated by factoring and
     810calculating the expresion as:
     811\[ r_x = V_{0,0} + (V_{1,0} - V_{0,0})f_x \]
     812\[ V = r_x + (V_{0,1} + (V_{1,1} - V_{0,1})f_x - r_x)f_y \]
     813
     814Note that the values of $f_x$ and $f_y$ require some care.  Given a
     815coordinate $x,y$, the value of $f_x$ is calculated as $f_x - 0.5 -
     816int(f_x - 0.5)$.  For example, when interpolating the value at
     817(5.8.5.2), the relevant neighbor pixels are (5,4), (6,4), (5,5), (6,5)
     818and the fractional coordinate values $f_x, f_y = 0.3, 0.7$.  The
     819resulting coordinate would be contained within the pixel at column,row
     820(5,5).
     821
     822\paragraph{Sinc Interpolation ({\tt PS\_INTERPOLATE\_LANCZOS[234]})}
     823
     824Because it would be slow to specify the size of the kernel
     825dynamically, we specify three hard-coded kernel sizes: 4, 6 and 8
     826pixels in each dimension (a kernel of size 2 pixels in each dimension
     827is handled by the bilinear interpolation).  These correspond to the
     828options \code{PS_INTERPOLATE_LANCZOS2}, \code{PS_INTERPOLATE_LANCZOS3} and
     829\code{PS_INTERPOLATE_LANCZOS4}, respectively.
     830
     831Given a position on the input image, $(x_0,y_0)$, a kernel is derived
     832according to pixels local to the position:
     833\begin{equation}
     834  h(x,y) = {\rm sinc}(\pi \delta x) {\rm sinc}(\pi \delta x / N) \rm{sinc}(\pi \delta y) \rm{sinc}(\pi \delta y / N)
     835\end{equation}
     836where
     837\begin{eqnarray}
     838  \delta x & = & x - x_0 \\
     839  \delta y & = & y - y_0 \\
     840  {\rm sinc}(z) & = & \sin(z)/z
     841\end{eqnarray}
     842and $N$ corresponds to the choice of kernel size.  For $N = 2$, the
     843kernel size is 4 pixels in each dimension (i.e., $-2 < \delta x \le
     8442$).  For $N = 3$, the kernel size is 6 pixels in each dimension
     845(i.e., $-3 < \delta x \le 3$).  For $N = 4$, the kernel size is 8
     846pixels in each dimension (i.e., $-4 < \delta x \le 4$).
     847
     848The interpolated value at the given position, $(x_0,y_0)$, is then
     849simply the dot product of the kernel and the fluxes:
     850\begin{equation}
     851  f(x_0,y_0) = \sum_R f(x,y) h(x,y)
     852\end{equation}
     853where $R$ is the region defined by the kernel size, and $f(x,y)$ is
     854the flux at the pixel position.
     855
     856For further information, see the
     857\href{http://terapix.iap.fr/IMG/pdf/swarp.pdf}{SWarp manual}.
     858
     859\subsubsection{Image Cuts and Slices}
     860
     861Several functions specify operations which manipulate a collection of
     862pixels to return a statistic on the pixel collection.  In the simplest
     863case, these are trivial to define: if the boundaries of the region of
     864interest are specified along integral pixel coordinates, then the
     865pixels used to measure the statistic are always an exact integer.
     866This is the case for the function \code{psImageSlice} which requires a
     867starting coordinate which is an integer and a width in both dimensions
     868which is an integer.  For the case of the functions \code{psImageCut}
     869and \code{psImageRadialCut}, the situation is a bit more subtle.  In
     870both of these cases, the region is unlikely to contain only whole
     871pixels and some choices must be made.
     872
     873One posibility which we reject is to identify the fractional pixels
     874which are overlapped by the region of interest and add that fraction
     875of the pixel's flux when calculating the statistic of interest.  This
     876is computationally intensive, and not necessarily well defined for all
     877statistics. 
     878
     879In PSLib, we instead identify the pixels overlapped by the region, use
     880the complete set of pixel values, treating all pixels equally, and
     881renormalize as needed.  To perform this, the region of interest is
     882laid on top of the image pixels.  Any pixels which overlap the region
     883are identified as part of the input sample.  The statistic (ie, sample
     884mean, robust mode, etc), is then calculated on this collection of
     885pixels.  If the output statistic is an average value, the measured
     886value is reported.  If the output statistic is a sum value (sum of
     887counts, sum of pixels), then the value is renormalized by the ratio of
     888pixels used in the calculation to the pixel area of the region of
     889interest.  For example, if the sum within a radial aperture is
     890requested, the circle of the specified radius and center is placed on
     891the pixel grid.  Any pixels which touch the circle are then placed in
     892a list to be analysed.  The statistic of interest is the measured for
     893this collection of pixels.  In the case of a circular aperture which
     894is centered at the coordinate (2,2) and has a radius of 2, the number
     895of pixels which are touched by the circle is 16, while the total pixel
     896area of the circle is 12.57 square pixels.  In this case, the pixel
     897sum is renormalized by the ratio (12.57/16.00).
     898
     899\paragraph{Radial Cuts}
     900
     901Consider an image with pixels $x_i,y_i$ and a reference coordinate
     902$x_c, y_c$.  We want to construct a radial cut by measuring statistics
     903for pixels in a sequence of radial annulii $r_s < r < r_e$.  For each
     904annulus, we need to select the pixels which fall within this annulus.
     905The coordinates of the center of pixel $i,j$ are $i+0.5,j+0.5$.  A
     906given pixel has a distance from the reference coordinate of $dX = x_c
     907- i - 0.5, dY = y_c - j - 0.5$.  The pixels to be used for a given
     908radial annulus are all of those pixels for which $r_s < \sqrt{dX^2 +
     909  dY^2} < r_e$.  This is more efficiently calculated by comparing the
     910square of the radii and distances.  All pixels which satisfy the above
     911condition are included in a specific annular radius.  All average
     912quantities are calculated directly from the pixel ensemble
     913statistics. 
     914
     915\paragraph{Arbitrary Linear Cuts}
     916
     917Select the pixels which lie along a line following steps of 1 pixel
     918length:
     919
     920\begin{verbatim}
     921
     922  dX = xe - xs;
     923  dY = ye - ys;
     924  L = hypot (dX, dY);
     925  dX = dX / L;
     926  dY = dY / L;
     927
     928  REALLOCATE (xvec[0].elements, float, MAX (L, 1));
     929  REALLOCATE (yvec[0].elements, float, MAX (L, 1));
     930  xvec[0].Nelements = L;
     931  yvec[0].Nelements = L;
     932
     933  V = (float *)buf[0].matrix.buffer;
     934  for (i = 0; i < L; i++) {
     935    xi = xs + i*dX - 0.5;
     936    yi = ys + i*dY - 0.5;
     937    xvec[0].elements[i] = i;
     938    yvec[0].elements[i] = V[xi + Nx*yi];
     939  }
     940\end{verbatim}
     941
     942\subsubsection{Image Rotation}
     943
     944Image rotation can be performed in two possible ways under different
     945circumstances, identified in the following discussion.
     946
     947In the simplest case, the rotation angle is an integer multiple of 90
     948degrees ($\pi/2$ rad).  In these cases, the input and output pixels
     949have a one-to-one mapping.  If the input image has dimensions of $N_x,
     950N_y$, then the output image will have dimensions of either $N_x, N_y$
     951(for even multiples of 90 degrees) or $N_y, N_x$ (for odd multiples).
     952
     953If the angle of the rotation is not a multiple of 90, then the output
     954pixels necessarily result from the interpolation of several input
     955pixels.  In this case, for an input image of dimensions $N_x, N_y$ and
     956rotation angle $\theta$, the output image has dimensions $Lx = |N_x
     957\cos \theta| + |N_y \sin \theta|$ and $Ly = |N_x \sin \theta| + |N_y
     958\cos \theta|$, each dimension rounded up to the nearest integer as
     959needed.  Every pixel in the output image is in general derived from an
     960interpolation over 4 neighboring pixels.  The coordinate of a pixel in
     961the output image ($i,j$) corresponds to a fractional pixel coordinate
     962($x,y$) in the input image according to:
     963\[ x = (i - i_o)*\cos\theta + (j - j_o)*\sin\theta \]
     964\[ y = (i_o - i)*\sin\theta + (j - j_o)*\cos\theta \]
     965where the offset coordinate ($i_o,j_o$) depends on the sign of the
     966sine of the angle $\theta$.  If the sign of that sine is positive, the
     967offset coordinate is ($N_y\sin\theta$,0), otherwise it is
     968(0,$-N_x\sin\theta$).
     969
    774970%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    775971
    776 \subsection{Astronomy Utilities}
     972\pagebreak
     973\section{PSLib Astronomy Utilities}
    777974
    778975Most of the astronomy utilities will be implemented through wrapping
     
    782979the next release}
    783980
    784 \subsubsection{Time}
     981\subsection{Time}
    785982
    786983Correct time representation is \emph{critical} in astronomical software.  PSLib
     
    799996``1970-01-01T00:00:00Z'' UTC.
    800997
    801 \paragraph{Coordinated Universal Time (UTC)}
     998\subsubsection{Coordinated Universal Time (UTC)}
    802999
    8031000Coordinated Univeral Time (UTC) is defined by the International
     
    8291026timezone is forbidden.}
    8301027
    831 \paragraph{International Atomic Time (TAI)}
     1028\subsubsection{International Atomic Time (TAI)}
    8321029
    8331030International Atomic Time or Temps Atomique International (TAI) is a system of
     
    8451042seconds since the UNIX epoch of ``1970-01-01T00:00:00Z''.
    8461043
    847 \paragraph{Leap-seconds}
     1044\subsubsection{Leap-seconds}
    8481045
    8491046Leap seconds keep UTC within 0.9s of UT1.  The offset between TAI and
     
    8831080This data is available from: \code{ftp://maia.usno.navy.mil/ser7/tai-utc.dat}
    8841081
    885 \paragraph{Gregorian dates to seconds}
     1082\subsubsection{Gregorian dates to seconds}
    8861083
    8871084The Perl code below, based on an algorithm described in the book ``Calendrical
     
    10031200\end{verbatim}
    10041201Outputs year, month, day as \code{$y, $m, $d}.
     1202%$
    10051203
    10061204\emph{The above code was taken [and slightly altered] from
     
    10111209
    10121210
    1013 \paragraph{Universal Time (UT1)}
     1211\subsubsection{Universal Time (UT1)}
    10141212\label{sec:ut1}
    10151213
     
    10541252IERS publications references above, and should be interpolated in the same way.
    10551253
    1056 \paragraph{Julian Date and Modified Julian Date}
     1254\subsubsection{Julian Date and Modified Julian Date}
    10571255
    10581256The follow definitions of Julian Date (JD) and Modified Julian Date (MJD) was
     
    10621260http://www.iers.org/iers/earth/resolutions/UAI\_b1.html}.
    10631261
    1064 \subparagraph{Julian Date}
     1262\paragraph{Julian Date}
    10651263
    10661264\begin{verbatim}
     
    10891287\end{verbatim}
    10901288
    1091 \subparagraph{Modified Julian Date}
     1289\paragraph{Modified Julian Date}
    10921290
    10931291\begin{verbatim}
     
    10971295\end{verbatim}
    10981296
    1099 \subparagraph{JD and MJD conversion}
     1297\paragraph{JD and MJD conversion}
    11001298
    11011299Conversion between \code{psTime} values and MJD and JD are determined
     
    11151313\end{equation}
    11161314
    1117 \paragraph{Terrestrial Time (TT)}
     1315\subsubsection{Terrestrial Time (TT)}
    11181316
    11191317Terrestrial Time (TT) is defined as a fixed offset from TAI.
     
    11231321\end{equation}
    11241322
    1125 \paragraph{TT as Julian Centuries since J2000.0}
     1323\subsubsection{TT as Julian Centuries since J2000.0}
    11261324
    11271325The algorithm for calulating GMST requires TT formated in Julian centruies
     
    11311329\end{equation}
    11321330
    1133 \paragraph{UT1 as Julian Centuries since J2000.0}
     1331\subsubsection{UT1 as Julian Centuries since J2000.0}
    11341332
    11351333The algorithm for calulating GMST requires UT1 be formated in Julian centuries
     
    11401338\end{equation}
    11411339
    1142 \paragraph{Greenwich Mean Sidereal Time (GMST)}
     1340\subsubsection{Local Mean Sidereal Time (LMST)}
     1341
     1342Local Mean Sidereal Time (LMST) is Greenwich Mean Sideral Time (GMST) plus the
     1343observer's location in East longitude. Calculating LMST requires the input of
     1344Universal Time (UT1), Terrestrial Dynamical Time (TT) and a longitude (measured
     1345East of Greenwich).
     1346
     1347\begin{equation}
     1348LMST = GMST00(t_u, t) + longitude
     1349\end{equation}
     1350
     1351Gives $LMST$ in seconds.
     1352
     1353\subsubsection{Greenwich Mean Sidereal Time (GMST)}
    11431354
    11441355Greenwich Mean Sidereal Time (GMST) is caclulated from UT1 and TT.  This
     
    11591370Gives $GMST00$ in seconds.
    11601371
    1161 
    1162 \paragraph{Longitude}
     1372\subsubsection{Longitude}
    11631373
    11641374Longitudes are often expressed in the form of decimal degrees while the
     
    11691379\end{equation}
    11701380
    1171 \paragraph{Local Mean Sidereal Time (LMST)}
    1172 
    1173 Local Mean Sidereal Time (LMST) is Greenwich Mean Sideral Time (GMST) plus the
    1174 observer's location in East longitude. Calculating LMST requires the input of
    1175 Universal Time (UT1), Terrestrial Dynamical Time (TT) and a longitude (measured
    1176 East of Greenwich).
    1177 
    1178 \begin{equation}
    1179 LMST = GMST00(t_u, t) + longitude
    1180 \end{equation}
    1181 
    1182 Gives $LMST$ in seconds.
    1183 
    1184 \paragraph{Polar Motion}
     1381\subsubsection{Polar Motion}
     1382\tbd{move this to Earth Motion section}
    11851383
    11861384The polar coordinates, $x_p$ and $y_p$, required for the transformation from
     
    11901388%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    11911389
    1192 \subsubsection{Astronomical Image Manipulations}
    1193 
    1194 \paragraph{Interpolation}
    1195 
    1196 Interpolation is needed in various image manipulation operations,
    1197 including rotation and resampling.  We have specified a function to
    1198 perform the interpolation using one of several possible interpolation
    1199 methods, defined below.  It is important in the discussions that
    1200 follow to remember that a pixel with column,row if $i,j$ has
    1201 coordinate at the center of $i+0.5,j+0.5$ and corners with coordinates
    1202 from $i,j$ to $i+1,j+1$.  Thus, the interpolation of a coordinate
    1203 $x,y$ = 5.0,4.0 is a value midway between the four pixels with
    1204 column,row of (5,4), (5,5), (6,4), (6,5). 
    1205 
    1206 \subparagraph{Nearest Pixel Interpolation ({\tt PS\_INTERPOLATE\_FLAT})}
    1207 
    1208 In this interpolation, the value of the closest pixel is returned.
    1209 This is equivalent to pixel duplication or replication.
    1210 
    1211 \subparagraph{Bilinear Interpolation ({\tt PS\_INTERPOLATE\_BILINEAR})}
    1212 
    1213 In this interpolation, the value at the coordinate is calculated using
    1214 linear interpolation in two dimensions from the four nearest neighbor
    1215 pixels.  The bilinear interpolation value at a coordinate $x,y$
    1216 depends on the four nearest neighbor pixels and the fractional
    1217 distance $fx,fy$ of the given coordinates from the centers of those
    1218 four pixels.  Consider four neighboring pixels at column,row of $i,j$,
    1219 $i+1,j$, $i,j+1$, and $i+1,j+1$ with pixel values $V_{0,0}$,
    1220 $V_{1,0}$, $V_{0,1}$, $V_{1,1}$.  The value at $x,y$ is given by:
    1221 \[ V = (V_{0,0}(1 - f_x) + V_{1,0}f_x)(1 - f_y) + (V_{0,1}(1-f_x) + V_{1,1}f_x)f_y \]
    1222 This expression is more efficiently evaluated by factoring and
    1223 calculating the expresion as:
    1224 \[ r_x = V_{0,0} + (V_{1,0} - V_{0,0})f_x \]
    1225 \[ V = r_x + (V_{0,1} + (V_{1,1} - V_{0,1})f_x - r_x)f_y \]
    1226 
    1227 Note that the values of $f_x$ and $f_y$ require some care.  Given a
    1228 coordinate $x,y$, the value of $f_x$ is calculated as $f_x - 0.5 -
    1229 int(f_x - 0.5)$.  For example, when interpolating the value at
    1230 (5.8.5.2), the relevant neighbor pixels are (5,4), (6,4), (5,5), (6,5)
    1231 and the fractional coordinate values $f_x, f_y = 0.3, 0.7$.  The
    1232 resulting coordinate would be contained within the pixel at column,row
    1233 (5,5).
    1234 
    1235 \subparagraph{Sinc Interpolation ({\tt PS\_INTERPOLATE\_LANCZOS[234]})}
    1236 
    1237 Because it would be slow to specify the size of the kernel
    1238 dynamically, we specify three hard-coded kernel sizes: 4, 6 and 8
    1239 pixels in each dimension (a kernel of size 2 pixels in each dimension
    1240 is handled by the bilinear interpolation).  These correspond to the
    1241 options \code{PS_INTERPOLATE_LANCZOS2}, \code{PS_INTERPOLATE_LANCZOS3} and
    1242 \code{PS_INTERPOLATE_LANCZOS4}, respectively.
    1243 
    1244 Given a position on the input image, $(x_0,y_0)$, a kernel is derived
    1245 according to pixels local to the position:
    1246 \begin{equation}
    1247   h(x,y) = {\rm sinc}(\pi \delta x) {\rm sinc}(\pi \delta x / N) \rm{sinc}(\pi \delta y) \rm{sinc}(\pi \delta y / N)
    1248 \end{equation}
    1249 where
    1250 \begin{eqnarray}
    1251   \delta x & = & x - x_0 \\
    1252   \delta y & = & y - y_0 \\
    1253   {\rm sinc}(z) & = & \sin(z)/z
    1254 \end{eqnarray}
    1255 and $N$ corresponds to the choice of kernel size.  For $N = 2$, the
    1256 kernel size is 4 pixels in each dimension (i.e., $-2 < \delta x \le
    1257 2$).  For $N = 3$, the kernel size is 6 pixels in each dimension
    1258 (i.e., $-3 < \delta x \le 3$).  For $N = 4$, the kernel size is 8
    1259 pixels in each dimension (i.e., $-4 < \delta x \le 4$).
    1260 
    1261 The interpolated value at the given position, $(x_0,y_0)$, is then
    1262 simply the dot product of the kernel and the fluxes:
    1263 \begin{equation}
    1264   f(x_0,y_0) = \sum_R f(x,y) h(x,y)
    1265 \end{equation}
    1266 where $R$ is the region defined by the kernel size, and $f(x,y)$ is
    1267 the flux at the pixel position.
    1268 
    1269 For further information, see the
    1270 \href{http://terapix.iap.fr/IMG/pdf/swarp.pdf}{SWarp manual}.
    1271 
    1272 \paragraph{Image Cuts and Slices}
    1273 
    1274 Several functions specify operations which manipulate a collection of
    1275 pixels to return a statistic on the pixel collection.  In the simplest
    1276 case, these are trivial to define: if the boundaries of the region of
    1277 interest are specified along integral pixel coordinates, then the
    1278 pixels used to measure the statistic are always an exact integer.
    1279 This is the case for the function \code{psImageSlice} which requires a
    1280 starting coordinate which is an integer and a width in both dimensions
    1281 which is an integer.  For the case of the functions \code{psImageCut}
    1282 and \code{psImageRadialCut}, the situation is a bit more subtle.  In
    1283 both of these cases, the region is unlikely to contain only whole
    1284 pixels and some choices must be made.
    1285 
    1286 One posibility which we reject is to identify the fractional pixels
    1287 which are overlapped by the region of interest and add that fraction
    1288 of the pixel's flux when calculating the statistic of interest.  This
    1289 is computationally intensive, and not necessarily well defined for all
    1290 statistics. 
    1291 
    1292 In PSLib, we instead identify the pixels overlapped by the region, use
    1293 the complete set of pixel values, treating all pixels equally, and
    1294 renormalize as needed.  To perform this, the region of interest is
    1295 laid on top of the image pixels.  Any pixels which overlap the region
    1296 are identified as part of the input sample.  The statistic (ie, sample
    1297 mean, robust mode, etc), is then calculated on this collection of
    1298 pixels.  If the output statistic is an average value, the measured
    1299 value is reported.  If the output statistic is a sum value (sum of
    1300 counts, sum of pixels), then the value is renormalized by the ratio of
    1301 pixels used in the calculation to the pixel area of the region of
    1302 interest.  For example, if the sum within a radial aperture is
    1303 requested, the circle of the specified radius and center is placed on
    1304 the pixel grid.  Any pixels which touch the circle are then placed in
    1305 a list to be analysed.  The statistic of interest is the measured for
    1306 this collection of pixels.  In the case of a circular aperture which
    1307 is centered at the coordinate (2,2) and has a radius of 2, the number
    1308 of pixels which are touched by the circle is 16, while the total pixel
    1309 area of the circle is 12.57 square pixels.  In this case, the pixel
    1310 sum is renormalized by the ratio (12.57/16.00).
    1311 
    1312 \subparagraph{Radial Cuts}
    1313 
    1314 Consider an image with pixels $x_i,y_i$ and a reference coordinate
    1315 $x_c, y_c$.  We want to construct a radial cut by measuring statistics
    1316 for pixels in a sequence of radial annulii $r_s < r < r_e$.  For each
    1317 annulus, we need to select the pixels which fall within this annulus.
    1318 The coordinates of the center of pixel $i,j$ are $i+0.5,j+0.5$.  A
    1319 given pixel has a distance from the reference coordinate of $dX = x_c
    1320 - i - 0.5, dY = y_c - j - 0.5$.  The pixels to be used for a given
    1321 radial annulus are all of those pixels for which $r_s < \sqrt{dX^2 +
    1322   dY^2} < r_e$.  This is more efficiently calculated by comparing the
    1323 square of the radii and distances.  All pixels which satisfy the above
    1324 condition are included in a specific annular radius.  All average
    1325 quantities are calculated directly from the pixel ensemble
    1326 statistics. 
    1327 
    1328 \subparagraph{Arbitrary Linear Cuts}
    1329 
    1330 Select the pixels which lie along a line following steps of 1 pixel
    1331 length:
     1390\subsection{2D transformations}
     1391
     1392In PSLib, we implement 2-dimensional transformations using
     1393\code{psPlaneTransform}, which contains a matrix of polynomial
     1394coefficients for each dimension.  Since we are using these to model
     1395the real world, where, for example, a particular point on the detector
     1396maps to a particular point on the sky, we consider only
     1397transformations that are ``one-to-one''.  This makes it possible to
     1398speak of inverse transformations, and of combining multiple
     1399transformations.
     1400
     1401Given a transformation, $f(x,y)$, the inverse transformation,
     1402$g(x,y)$, is that for which $g(f(x,y)) = (x,y)$ for $(x,y)$ over the
     1403range of interest (not necessarily the entire set of real numbers).
     1404
     1405Given two transformations, $f(x,y)$ and $g(x,y)$, the combined
     1406transformation is the transformation, $h(x,y) = g(f(x,y))$ for $(x,y)$
     1407over the range of interest (not necessarily the entire set of real
     1408numbers).
     1409
     1410Both of these operations are straightforward if the transformation is
     1411linear.  If the function $(u,v) = f(x,y)$ is:
     1412\begin{eqnarray}
     1413u & = & a + bx + cy \\
     1414v & = & d + ex + fy
     1415\end{eqnarray}
     1416then the inverse transformation $(x,y) = g(u,v)$ is:
     1417\begin{eqnarray}
     1418x & = & (-fa+cd)/\Delta + fu/\Delta - cv/\Delta \\
     1419y & = & (ae-bd)/\Delta - eu/\Delta + bv/\Delta
     1420\end{eqnarray}
     1421where $\Delta = bf - ce$ is the matrix determinant.  Given two
     1422functions $f_i(x,y)$ for $i=1,2$:
     1423\begin{eqnarray}
     1424u & = & a_i + b_i x + c_i y \\
     1425v & = & d_i + e_i x + f_i y
     1426\end{eqnarray}
     1427then the combined transformation, $(u,v) = f_2(f_1(x,y))$ is:
     1428\begin{eqnarray}
     1429u & = & (a_2 + b_2 a_1 + c_2 d_1) + (b_2 b_1 + c_2 e_1) x + (b_2 c_1 + c_2 f_1) y \\
     1430v & = & (d_2 + e_2 a_1 + f_2 d_1) + (e_2 b_1 + f_2 e_1) x + (e_2 c_1 + f_2 f_1) y
     1431\end{eqnarray}
     1432
     1433When the transformations are not linear, the inverse and combined
     1434transformations can be estimated by sampling a grid over the region of
     1435interest, calculating the transformation (or double transformation)
     1436for each sample, and using this information to derive the best fit
     1437transformation that produces the inverse or combined transformation.
     1438The inverse transformation should be of the same order as that of the
     1439forward transformation, while the combined transformation should be of
     1440the higher order of the two component transformations.
     1441
     1442%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     1443
     1444\subsection{Spherical Rotations with Quaternions}
     1445
     1446\subsubsection{Quaternion Construction}
     1447
     1448The following describes the algorithms needed to implement 3-D
     1449rotations in terms of quaternions. A quaternion is an ordered set of
     1450four numbers, $\bar{q} = (q_0, q_1, q_2, q_3)$. A rotation of angle
     1451$\theta$ about the axis defined by the unit vector $(v_x, v_y, v_z)$
     1452has quaternion components:
     1453\begin{eqnarray}
     1454q_0 & = & v_x sin(\theta/2), \\
     1455q_1 & = & v_y sin(\theta/2), \\
     1456q_2 & = & v_z sin(\theta/2), and \\
     1457q_3 & = & cos(\theta/2). \\
     1458\end{eqnarray}
     1459Note that the sine and cosine are taken of the half angle of the
     1460rotation.  Note also that this implies that the quaternion components
     1461are normalized such that $|\bar{q}| \def q_0^2 + q_1^2 + q_2^2 + q_3^2
     1462= 1$.
     1463
     1464The 3-vector representation of the angle of the pole is determined
     1465from the coordinate of the pole ($\alpha_p, \delta_p$) by:
     1466\begin{eqnarray}
     1467v_x & = & \cos \delta_p \cos \alpha_p \\
     1468v_y & = & \cos \delta_p \sin \alpha_p \\
     1469v_x & = & \sin \delta_p \\
     1470\end{eqnarray}
     1471
     1472\subsubsection{Combining Two Rotations}
     1473
     1474Given two quaternions $\bar{p1}$ and $\bar{p2}$, there is a third
     1475quaternion, $\bar{p}$, which represents the result of first applying
     1476$\bar{p1}$, and then $\bar{p2}$. The components of $\bar{p}$ are given
     1477by:
    13321478
    13331479\begin{verbatim}
    1334 
    1335   dX = xe - xs;
    1336   dY = ye - ys;
    1337   L = hypot (dX, dY);
    1338   dX = dX / L;
    1339   dY = dY / L;
    1340 
    1341   REALLOCATE (xvec[0].elements, float, MAX (L, 1));
    1342   REALLOCATE (yvec[0].elements, float, MAX (L, 1));
    1343   xvec[0].Nelements = L;
    1344   yvec[0].Nelements = L;
    1345 
    1346   V = (float *)buf[0].matrix.buffer;
    1347   for (i = 0; i < L; i++) {
    1348     xi = xs + i*dX - 0.5;
    1349     yi = ys + i*dY - 0.5;
    1350     xvec[0].elements[i] = i;
    1351     yvec[0].elements[i] = V[xi + Nx*yi];
    1352   }
     1480p_0 & = &  p2_3 p1_0 + p2_2 p1_1 - p2_1 p1_2 + p2_0 p1_3 \\
     1481p_1 & = & -p2_2 p1_0 + p2_3 p1_1 + p2_0 p1_2 + p2_1 p1_3 \\
     1482p_2 & = &  p2_1 p1_0 - p2_0 p1_1 + p2_3 p1_2 + p2_2 p1_3 \\
     1483p_3 & = & -p2_0 p1_0 - p2_1 p1_1 - p2_2 p1_2 + p2_3 p1_3 \\
    13531484\end{verbatim}
    13541485
    1355 \paragraph{Image Rotation}
    1356 
    1357 Image rotation can be performed in two possible ways under different
    1358 circumstances, identified in the following discussion.
    1359 
    1360 In the simplest case, the rotation angle is an integer multiple of 90
    1361 degrees ($\pi/2$ rad).  In these cases, the input and output pixels
    1362 have a one-to-one mapping.  If the input image has dimensions of $N_x,
    1363 N_y$, then the output image will have dimensions of either $N_x, N_y$
    1364 (for even multiples of 90 degrees) or $N_y, N_x$ (for odd multiples).
    1365 
    1366 If the angle of the rotation is not a multiple of 90, then the output
    1367 pixels necessarily result from the interpolation of several input
    1368 pixels.  In this case, for an input image of dimensions $N_x, N_y$ and
    1369 rotation angle $\theta$, the output image has dimensions $Lx = |N_x
    1370 \cos \theta| + |N_y \sin \theta|$ and $Ly = |N_x \sin \theta| + |N_y
    1371 \cos \theta|$, each dimension rounded up to the nearest integer as
    1372 needed.  Every pixel in the output image is in general derived from an
    1373 interpolation over 4 neighboring pixels.  The coordinate of a pixel in
    1374 the output image ($i,j$) corresponds to a fractional pixel coordinate
    1375 ($x,y$) in the input image according to:
    1376 \[ x = (i - i_o)*\cos\theta + (j - j_o)*\sin\theta \]
    1377 \[ y = (i_o - i)*\sin\theta + (j - j_o)*\cos\theta \]
    1378 where the offset coordinate ($i_o,j_o$) depends on the sign of the
    1379 sine of the angle $\theta$.  If the sign of that sine is positive, the
    1380 offset coordinate is ($N_y\sin\theta$,0), otherwise it is
    1381 (0,$-N_x\sin\theta$).
    1382 
    1383 \subsubsection{Celestial Coordinate Conversions}
     1486\subsubsection{Rotating a Vector}
     1487
     1488You may rotate a unit vector by first constructing a quaternion
     1489$\bar{p2}$, whose first three components are the components of the
     1490unit vector, and whose fourth component is zero. To rotate this vector
     1491by a quaternion $\bar{p1}$, you apply the formula above for combining
     1492two quaternions. The rotated vector is found in the first three
     1493components of the resulting quaternion, $\bar{p}$.
     1494
     1495\subsubsection{Rotation Matrix}
     1496
     1497The rotation matrix representation of a rotation may be derived
     1498directly from the quaternion representation.  The following formulae
     1499convert a quaternion to a rotation matrix:
     1500
     1501\begin{eqnarray}
     1502    rot_{x,x} & = &  q_0 q_0 - q_1 q_1 - q_2 q_2 + q_3 q_3 \\
     1503    rot_{y,y} & = & -q_0 q_0 + q_1 q_1 - q_2 q_2 + q_3 q_3 \\
     1504    rot_{z,z} & = & -q_0 q_0 - q_1 q_1 + q_2 q_2 + q_3 q_3 \\
     1505
     1506    rot_{x,y} & = & 2 (q_0 q_1 + q_2 q_3) \\
     1507    rot_{y,x} & = & 2 (q_0 q_1 - q_2 q_3) \\
     1508
     1509    rot_{x,z} & = & 2 (q_0 q_2 - q_1 q_3) \\
     1510    rot_{z,x} & = & 2 (q_0 q_2 + q_1 q_3) \\
     1511
     1512    rot_{y,z} & = & 2 (q_1 q_2 + q_0 q_3) \\
     1513    rot_{z,y} & = & 2 (q_1 q_2 - q_0 q_3) \\
     1514\end{eqnarray}
     1515
     1516\subsubsection{Conversion to Other Representations}
     1517
     1518You may convert a rotation matrix, m, to a quaternion, p, with the following
     1519code:
     1520
     1521\begin{verbatim}
     1522double diag_sum[3];
     1523int maxi;
     1524double recip;
     1525
     1526diag_sum[0]=1+m[0][0]-m[1][1]-m[2][2];
     1527diag_sum[1]=1-m[0][0]+m[1][1]-m[2][2];
     1528diag_sum[2]=1-m[0][0]-m[1][1]+m[2][2];
     1529diag_sum[3]=1+m[0][0]+m[1][1]+m[2][2];
     1530
     1531
     1532maxi=0;
     1533for(i=1;i<4;++i) {
     1534    if(diag_sum[i]>diag_sum[maxi]) maxi=i;
     1535}
     1536
     1537
     1538p[maxi]=0.5*sqrt(diag_sum[maxi]);
     1539recip=1./(4.*p[maxi]);
     1540
     1541if(maxi==0) {
     1542    p[1]=recip*(m[0][1]+m[1][0]);
     1543    p[2]=recip*(m[2][0]+m[0][2]);
     1544    p[3]=recip*(m[1][2]-m[2][1]);
     1545
     1546} else if(maxi==1) {
     1547    p[0]=recip*(m[0][1]+m[1][0]);
     1548    p[2]=recip*(m[1][2]+m[2][1]);
     1549    p[3]=recip*(m[2][0]-m[0][2]);
     1550
     1551} else if(maxi==2) {
     1552    p[0]=recip*(m[2][0]+m[0][2]);
     1553    p[1]=recip*(m[1][2]+m[2][1]);
     1554    p[3]=recip*(m[0][1]-m[1][0]);
     1555
     1556} else if(maxi==3) {
     1557    p[0]=recip*(m[1][2]-m[2][1]);
     1558    p[1]=recip*(m[2][0]-m[0][2]);
     1559    p[2]=recip*(m[0][1]-m[1][0]);
     1560}
     1561\end{verbatim}
     1562
     1563\subsection{Celestial Coordinate Conversions}
    13841564
    13851565Changes between spherical coordinate systems (ie, Ecliptic, Galactic,
     
    14261606the forward transformation.
    14271607
    1428 \paragraph{Galactic to ICRS}
     1608\subsubsection{Galactic to ICRS}
    14291609
    14301610The appropriate values, from the Hipparcos and Tycho Catalogues are:
     
    14351615\end{eqnarray}
    14361616
    1437 \paragraph{Ecliptic to ICRS}
     1617\subsubsection{Ecliptic to ICRS}
    14381618
    14391619The appropriate values, from Zombeck, are:
     
    14451625where $T$ is the time in Julian centuries since 1900.
    14461626
    1447 \paragraph{Precession}
     1627\subsubsection{Precession}
    14481628
    14491629The appropriate values, from Elixir, are:
     
    14571637
    14581638
    1459 \paragraph{Suggested test cases}
     1639\subsubsection{Suggested test cases}
    14601640
    14611641$(\alpha,\delta) = (0^\circ,0^\circ)$ transforms to Galactic
     
    14791659
    14801660%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1481 \subsubsection{2D transformations}
    1482 
    1483 In PSLib, we implement 2-dimensional transformations using
    1484 \code{psPlaneTransform}, which contains a matrix of polynomial
    1485 coefficients for each dimension.  Since we are using these to model
    1486 the real world, where, for example, a particular point on the detector
    1487 maps to a particular point on the sky, we consider only
    1488 transformations that are ``one-to-one''.  This makes it possible to
    1489 speak of inverse transformations, and of combining multiple
    1490 transformations.
    1491 
    1492 Given a transformation, $f(x,y)$, the inverse transformation,
    1493 $g(x,y)$, is that for which $g(f(x,y)) = (x,y)$ for $(x,y)$ over the
    1494 range of interest (not necessarily the entire set of real numbers).
    1495 
    1496 Given two transformations, $f(x,y)$ and $g(x,y)$, the combined
    1497 transformation is the transformation, $h(x,y) = g(f(x,y))$ for $(x,y)$
    1498 over the range of interest (not necessarily the entire set of real
    1499 numbers).
    1500 
    1501 Both of these operations are straightforward if the transformation is
    1502 linear.  If the function $(u,v) = f(x,y)$ is:
    1503 \begin{eqnarray}
    1504 u & = & a + bx + cy \\
    1505 v & = & d + ex + fy
    1506 \end{eqnarray}
    1507 then the inverse transformation $(x,y) = g(u,v)$ is:
    1508 \begin{eqnarray}
    1509 x & = & (-fa+cd)/\Delta + fu/\Delta - cv/\Delta \\
    1510 y & = & (ae-bd)/\Delta - eu/\Delta + bv/\Delta
    1511 \end{eqnarray}
    1512 where $\Delta = bf - ce$ is the matrix determinant.  Given two
    1513 functions $f_i(x,y)$ for $i=1,2$:
    1514 \begin{eqnarray}
    1515 u & = & a_i + b_i x + c_i y \\
    1516 v & = & d_i + e_i x + f_i y
    1517 \end{eqnarray}
    1518 then the combined transformation, $(u,v) = f_2(f_1(x,y))$ is:
    1519 \begin{eqnarray}
    1520 u & = & (a_2 + b_2 a_1 + c_2 d_1) + (b_2 b_1 + c_2 e_1) x + (b_2 c_1 + c_2 f_1) y \\
    1521 v & = & (d_2 + e_2 a_1 + f_2 d_1) + (e_2 b_1 + f_2 e_1) x + (e_2 c_1 + f_2 f_1) y
    1522 \end{eqnarray}
    1523 
    1524 When the transformations are not linear, the inverse and combined
    1525 transformations can be estimated by sampling a grid over the region of
    1526 interest, calculating the transformation (or double transformation)
    1527 for each sample, and using this information to derive the best fit
    1528 transformation that produces the inverse or combined transformation.
    1529 The inverse transformation should be of the same order as that of the
    1530 forward transformation, while the combined transformation should be of
    1531 the higher order of the two component transformations.
    1532 
    1533 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1534 
    1535 \subsubsection{Projections}
    1536 
    1537 We implement three types of projections: {\em zenithal}, {\em
    1538 cylindrical} and {\em pseudocylindrical}, each requiring slightly
    1539 different handling.  Our representations are based on the treatment of
    1540 projections presented by
    1541 \href{http://www.cv.nrao.edu/fits/documents/wcs/wcs.all.ps}{Greisen \&
    1542 Calabretta (1995, ADASS, 4, 233)}.  In all of these projections, we
    1543 are converting from a spherical coordinate $\alpha,\delta$ to a linear
    1544 (2-D) coordinate $x_p,y_p$.  The projection is defined by the
    1545 projection type, the projection center ($\alpha_p, \delta_p$) and the
    1546 the plate scales in the $x_p$ and $y_p$ directions ($\rho_x,\rho_y$).
    1547 
    1548 In the structure, \code{psProjection}, the projection type is defined
    1549 by the element \code{type}, the projection center $\alpha_p,\delta_p$
    1550 is defined by the elements \code{R,D}, and the plate scales,
    1551 $\rho_x,\rho_y$, are defined by the elements \code{Xs,Ys}.  The plate
    1552 scales are applied independently to the $x$ and $y$ coordinates to
    1553 convert them to the corresponding linear units (ie, pixels):
    1554 %
    1555 \begin{eqnarray}
    1556 x_p & = & \rho_x x \\
    1557 y_p & = & \rho_y y \\
    1558 \end{eqnarray}
    1559 %
    1560 In the discussions below, we ignore this last step (or first step,
    1561 depending on the direction of the conversion).
    1562 
    1563 \paragraph{Zenithal Projections}
    1564 
    1565 The {\em zenithal} projections are defined relative to a set of
    1566 spherical coordinates with pole at the center of the projection
    1567 ($\alpha_p, \delta_p$), and which thus represents a coordinate system
    1568 rotated relative to the coordinate system of $\alpha, \delta$.  In
    1569 this spherical coordinate system, the coordinate of longitude is
    1570 labeled $\phi$, and has domain of $-\pi < \phi \le \pi$, while the
    1571 latitude, measured from the pole, is labeled $\theta$ and has domain
    1572 $0 \le \theta \le \pi$.  The coordinate frame of $\phi,\theta$ is
    1573 defined so that $\phi_p$, the longitude of the target system pole, is
    1574 0.0.
    1575 
    1576 For an arbitrary projection center, it is necessary to convert the
    1577 spherical coordinates to be projected ($\alpha,\delta$) to the
    1578 projection spherical coordinate system coordinates ($\phi, \theta$).
    1579 In practice, we construct the following useful trigonometric
    1580 relationships between $\phi$ and $\theta$ which may be employed in the
    1581 equations of $x,y$ below:
    1582 %
    1583 \begin{eqnarray}
    1584 \sin \theta           & = & \sin \delta \sin \delta_p + \cos \delta \cos \delta_p \cos (\alpha - \alpha_p) \\
    1585 \cos \theta \cos \phi & = & \sin \delta \cos \delta_p - \cos \delta \sin \delta_p \cos (\alpha - \alpha_p) \\
    1586 \cos \theta \sin \phi & = & - \cos \delta \sin (\alpha - \alpha_p)
    1587 \end{eqnarray}
    1588 %
    1589 For the inverse transformations, the equivalent relationships are:
    1590 %
    1591 \begin{eqnarray}
    1592 \sin \delta                          & = & \sin \theta \sin \delta_p + \cos \theta \cos \delta_p \cos \phi \\
    1593 \cos \delta \cos (\alpha - \alpha_p) & = & \sin \theta \cos \delta_p - \cos \theta \sin \delta_p \cos \phi \\
    1594 \cos \delta \sin (\alpha - \alpha_p) & = & - \cos \theta \sin \phi
    1595 \end{eqnarray}
    1596 %
    1597 For zenithal projections, the linear coordinates are related to
    1598 $\phi,\theta$ by:
    1599 %
    1600 \begin{eqnarray}
    1601 x & = & R_\theta \sin \phi \\
    1602 y & = & -R_\theta \cos \phi
    1603 \end{eqnarray}
    1604 %
    1605 and the inverse:
    1606 %
    1607 \begin{eqnarray}
    1608 R_\theta & = & \sqrt{x^2 + y^2} \\
    1609 \phi     & = & {\rm atan} (-y,x)
    1610 \end{eqnarray}
    1611 %
    1612 The coordinates $x,y$ above are defined to be in angular units (ie,
    1613 radians). 
    1614 
    1615 From these relationships, we can calculate $\alpha, \delta$ as:
    1616 %
    1617 \begin{eqnarray}
    1618 \alpha - \alpha_p & = & \arctan (\sin \alpha, \cos \alpha) \\
    1619 \delta            & = & \arcsin (\sin \delta) \\
    1620 \end{eqnarray}
    1621 %
    1622 Note that if $(x,y) = (0,0)$, then $\alpha = \alpha_p, \delta = \delta_p$.
    1623 
    1624 \subparagraph{Gnomonic}
    1625 
    1626 The Gnomonic projection (``TAN'') is a zenithal projection with
    1627 $R_\theta = \cot \theta$.  The resulting relationships for $(x,y)$ and
    1628 for $\sin \theta, \cos \theta$ are:
    1629 
    1630 \begin{eqnarray}
    1631 x           & = & \frac{\cos \theta \sin \phi}{\sin \theta} \\
    1632 y           & = & \frac{-\cos \theta \cos \phi}{\sin \theta} \\
    1633 \sin \theta & = & \zeta / \sqrt{1 + \zeta^2} \\
    1634 \cos \theta & = & 1 / \sqrt{1 + \zeta^2} \\
    1635 \end{eqnarray}
    1636 
    1637 where $\zeta = 1 / R_\theta$.
    1638 
    1639 \subparagraph{Orthographic}
    1640 
    1641 The Orthographic projection (``SIN'') is a zenithal projection with
    1642 $R_\theta = \cos \theta$.  The resulting relationships for $(x,y)$ and
    1643 for $\sin \theta, \cos \theta$ are:
    1644 
    1645 \begin{eqnarray}
    1646 x           & = & \cos \theta \sin \phi \\
    1647 y           & = & -\cos \theta \cos \phi \\
    1648 \sin \theta & = & \sqrt{1 - R_\theta^2} \\
    1649 \cos \theta & = & R_\theta \\
    1650 \end{eqnarray}
    1651 
    1652 \paragraph{Cylindrical and Pseudocylindrical Projections}
    1653 
    1654 The {\em cylindrical} and {\em pseudocylindrical} projections are
    1655 defined relative to a set of cylindrical coordinates whose pole is
    1656 coincident with the pole of the spherical coordinates.  These
    1657 projections are particularly used for full-sky representations, and
    1658 are only defined for projection centers with $\delta_p = 0$.  In this
    1659 spherical coordinate system, the coordinate of longitude is labeled
    1660 $\phi$, and has domain of $-\pi < \phi \le \pi$, while the latitude,
    1661 measured from the pole, is labeled $\theta$ and has domain $0 \le
    1662 \theta \le \pi$.  The projection center longitude, $\alpha_p$
    1663 corresponds to $\phi = 0$, thus the value of $\phi$ is determined as
    1664 $\alpha - \alpha_p$ for all such projections.
    1665 
    1666 \subparagraph{Cartesian}
    1667 
    1668 The Cartesian projection (``CAR'') is a very simple cylindrical
    1669 projection with the following relationships between $x,y$ and
    1670 $\phi,\theta$:
    1671 
    1672 \begin{eqnarray}
    1673 x & = & \phi \\
    1674 y & = & \theta
    1675 \end{eqnarray}
    1676 
    1677 \subparagraph{Mercator}
    1678 
    1679 The Mercator projection (``MER'') is a cylindrical projection.
    1680 
    1681 \begin{eqnarray}
    1682 x & = & \phi \\
    1683 y & = & \ln \left( \tan (\pi/4 + \theta/2) \right) \\
    1684 {\rm and}\hspace{1cm} \theta & = & 2 \arctan \left( e^y \right) - \pi/2
    1685 \end{eqnarray}
    1686 
    1687 \subparagraph{Hammer-Aitoff}
    1688 
    1689 The Hammer-Aitoff projection(``AIT'') is a pseudocylindrical projection, and is defined:
    1690 
    1691 \begin{eqnarray}
    1692 x & = & 2 \zeta \cos \theta \sin \frac{\phi}{2} \\
    1693 y & = & \zeta \sin \theta \\
    1694 {\rm where}\hspace{1cm} \zeta^{-1} & \equiv & \sqrt{\frac{1}{2}\left(1 + \cos \theta \cos \frac{\phi}{2} \right)}
    1695 \end{eqnarray}
    1696 
    1697 And in reverse:
    1698 
    1699 \begin{eqnarray}
    1700 \phi & = & 2 {\rm \arctan} (2z^2 - 1, x z) \\
    1701 \theta & = & \arcsin (yz) \\
    1702 {\rm where}\hspace{1cm} z & \equiv & \sqrt{1 - (x/2)^2 - y^2}
    1703 \end{eqnarray}
    1704 
    1705 \subparagraph{Parabolic}
    1706 
    1707 The Parabolic projection (``PAR'') is a pseudocylindrical projection, and is defined:
    1708 
    1709 \begin{eqnarray}
    1710 x & = & \phi \left( 2 \cos \frac{2 \theta}{3} - 1 \right) \\
    1711 y & = & \pi \sin \frac{\theta}{3} \\
    1712 \end{eqnarray}
    1713 
    1714 And in reverse:
    1715 
    1716 \begin{eqnarray}
    1717 \theta & = & 3 \sin^{-1} \rho \\
    1718 \phi   & = & \frac{x}{1 - 4\rho^2} \\
    1719 {\rm where}\hspace{1cm} \rho & \equiv & y/\pi \\
    1720 \end{eqnarray}
    1721 
    1722 \subsubsection{Offset}
    1723 
    1724 Coordinate offsets can be either spherical offsets or linear offsets.
    1725 
    1726 A spherical offset is performed by adding the components of the
    1727 offset, after unit conversion, to the given position.  The resulting
    1728 coordinates must be wrapped to within the allowed range ($-\pi$ to
    1729 $\pi$, 0 to $2\pi$).
    1730 
    1731 A linear offset is defined to be a linear offset in a tangent
    1732 projection centered on the starting coordinate with $y$ axis aligned
    1733 with the local direction or increasing Declination.  This projection
    1734 is undefined only for the coordinates exactly at the north and south
    1735 poles, in which case the orientation is defined to have the $y$ axis
    1736 parallel to the line of RA = 0.0.  The scale of the projection is 1.0
    1737 (ie, 1 'pixel' is 1 radian) and the given offsets must the scaled
    1738 based on the given offset units. 
    1739 
    1740 Pseudo-code to implement the above for an offset:
    1741 
    1742 \begin{verbatim}
    1743 psSphere *psSphereSetOffset (psSphere pos, psSphere offset) {
    1744 
    1745   psPlane lin;
    1746   psSphere new;
    1747   psProjection proj;
    1748 
    1749   proj.R = pos->r;
    1750   proj.D = pos->d;
    1751   proj.X = 0;
    1752   proj.Y = 0;
    1753   proj.type = PS_PROJ_TAN;
    1754 
    1755   lin.x = offset.r;
    1756   lin.y = offset.d;
    1757 
    1758   new = psDeproject (&lin, &proj);
    1759   return (new);
    1760 }
    1761 \end{verbatim}
    1762 
    1763 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1764 
    1765 \subsubsection{Tangent Plane to Sky}
     1661
     1662\subsection{Tangent Plane to Sky}
    17661663
    17671664\tbd{we will replace the SLALIB version of AOPPA with a new function}
     
    17981695%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    17991696
    1800 \subsubsection{The One-to-Many Problem with Mosaic Cameras}
     1697\subsection{Sky to Tangent Plane (II)}
     1698
     1699This section describes the transformation between celestial coordinates
     1700(R.A., Dec.) and local terrestrial coordinates (Az, Alt). This transformation
     1701is broken down into a number of steps as described below.
     1702
     1703\paragraph{Reference Implementations}
     1704
     1705There are two reference implementatins for the code to account for the
     1706motion of the Earth in space. The first are the sample routines
     1707provided by the IERS to accompany chaper 5 of IERS Bulletin 32.  This
     1708document and the code can be downloaded from
     1709http://maia.usno.navy.mil/conv2003.html .  The second reference
     1710implementation is the SOFA software package managed by the IAU and
     1711available at http://www.iau-sofa.rl.ac.uk Only the 2003-04-29 version
     1712of SOFA should be used.  The IERS code requires a few of the rotation
     1713matrix utility routines from SOFA.
     1714
     1715Both implementations are in FORTRAN 77. The SOFA code has a more
     1716complex implementation of precession-nutation for backward
     1717compatibility with the pre 2003-01-01 conventions.  The IERS code
     1718includes some tricks to achieve greater precision in the fundamental
     1719arguments of nutation, which the SOFA code omits.  Therefore, the main
     1720reference for psLib should be the IERS code.  Note that the IERS code
     1721calculates the transform from terrestrial to celestial coordinates,
     1722while the SOFA code calculates its inverse.
     1723
     1724\subsubsection{Coordinate Systems}
     1725
     1726\begin{figure}
     1727\psfig{file=transforms.ps}
     1728\caption{Coordinates systems and the transformations between them}
     1729
     1730\end{figure}
     1731Figure X shows the transformation steps and intermediate coordinate systems
     1732between celestial and local terrestrial coordinate systems. The intermediate
     1733coordinate systems are defined below.
     1734
     1735\paragraph{ICRS}
     1736The official IAU-sanctioned celestial coordinate system is the
     1737International Celestial Reference System (ICRS). It is defined in terms of
     1738a number of radio sources whose positions have been measured using VLBI.
     1739It can be tied to the optical through the Hipparcos catalog. The ICRS has its
     1740origin at the solar system barycenter.
     1741
     1742\paragraph{GCRS}
     1743The Geocentric Celestial Reference System (GCRS) corresponds to the ICRS, but
     1744has its origin at the center of the Earth. The differences between the two
     1745systems are due to the velocity of the Earth (aberration), the position of
     1746the Earth (parallax), and general relativistic bending of light rays.
     1747There is no net rotation between the ICRS and the GCRS.
     1748
     1749\paragraph{ITRS}
     1750The International Terrestrial Reference System (ITRS) is a coordinate
     1751system which is fixed with respect to the Earth's crust.
     1752
     1753\paragraph{Intermediate Coordinate Systems - CIP, CEO, TEO}
     1754The transform between the GCRS and ITRS is conventionally
     1755decomposed into three parts in order to isolate the relatively rapid rotation
     1756of the Earth from the movement of the Earth's rotational axis in the GCRS
     1757and ITRS. All three sub-transforms are rigid rotations.
     1758
     1759This decomposition results in two intermediate coordinate systems. Both of
     1760these share the same pole, known as the Celestial Intermediate Pole (CIP).
     1761The CIP is defined by its motion in the GCRS to match the Tisserand
     1762mean axis of the Earth (Seidelmann 1982, Celesial Mechanics 27, 78-106),
     1763excluding motions with periods less than or equal
     1764to two days. The CIP approximates the angular momentum vector of the
     1765rotating Earth.
     1766
     1767The X axes of the intermediate coordinate systems are known as the
     1768Celestial and Terrestrial Ephemeris Origins. (CEO and TEO). Both are defined
     1769to be non-rotating origins. A non-rotating origin is a point on the equator
     1770whose instantaneous motion is always orthogonal to the equator
     1771(Kaplan 2003 IAU XXV Joint Discussion 16
     1772\footnote{http://aa.usno.navy.mil/kaplan/NROs\%5BJD16proc\%5D.pdf}).
     1773Thus the CEO is defined by its position in the GCRS at some epoch and by the
     1774motion of the CIP in the GCRS since that date. Similarly the TEO is
     1775defined by its position in the ITRS at some epoch and the motion of the
     1776CIP in the ITRS since that date.
     1777
     1778\subsubsection{ICRS - GCRS}
     1779
     1780The transformation between barycentric (ICRS) and geocentric (GCRS) coordinates
     1781involves two components. These are
     1782the general relativistic deflection of light rays by the Sun's gravity, and
     1783aberration, due to the orbital motion
     1784of the Earth.
     1785
     1786\paragraph{Gravitational Deflection}
     1787
     1788The Sun's gravity bends the path of light rays which pass near it.
     1789To first order, a light ray is deflected by an angle of $4GM/c^2r_0$ radians,
     1790where $G$ is the gravitational constant,
     1791$M$ is the mass of the Sun,
     1792$c$ is the speed of light, and
     1793$r_0$ is the point of closest approach to the light ray to the Sun.
     1794To the same order this is equal to the impact parameter - i.e. the point
     1795of closest approach if the light ray were not deflected. Note that
     1796$r_0/d = \tan(\theta)$, where $d$ is the distance from the Earth
     1797to the Sun, and $\theta$
     1798is the angular separation of the star from the center of the Sun.
     1799
     1800There is a maximum deflection of 1.75 arc seconds if we set
     1801$r_0$ to the radius of the sun.
     1802Since the Sun bends light rays toward it, a star appears shifted away from the sun in the sky.
     1803
     1804\paragraph{Aberration}
     1805
     1806Aberration is the apparent change in direction of a ray of light in the
     1807reference frame of a moving observer. Traditionally the aberration
     1808calculation has been done with a linear expansion of the full
     1809relativistic expression, often neglecting all but the linear term in
     1810$v/c$, since the relativistic terms are on the order of a miliarcsecond.
     1811However, the full relativistic expression poses no challenge for modern
     1812computers, so psLib will use the following procedure to calculate aberration.
     1813
     1814Suppose an observer has a velocity $\beta\hat{\beta}$, with respect to
     1815the Solar System barycenter, where $\beta$ is in units of the speed of
     1816light, and $\hat{\beta}$ is a unit vector. Suppose also that the unit vector
     1817$\hat{r}$ points toward a star in the barycenter frame of reference
     1818(i.e. the ``actual'' position).
     1819and $\hat{r}'$ gives the direction of the star in the observer's frame,
     1820(i.e. the apparent position).
     1821
     1822First, decompose $\hat{r}$ into components parallel and perpendicular to
     1823$\hat{\beta}$ by calculating
     1824$\mu = \hat{r}\cdot\hat{\beta}$ and
     1825$\vec{r}_\perp = \hat{r} - \mu \hat{\beta}$.
     1826
     1827Next, use the following expression for relativistic beaming, modified
     1828slightly from equation 4.8b of Rybicki and Lightman:
     1829\begin{equation}
     1830\mu' = \mu + \beta \frac{\mu^2 - 1}{1 - \beta\mu}
     1831\end{equation}
     1832where $\mu' = \hat{r}' \cdot \hat{\beta}$.
     1833
     1834Now, the component of $\hat{r}'$ perpendicular to $\hat{\beta}$
     1835(i.e. $\vec{r}_\perp'$) must point
     1836in the same direction as $\vec{r}_\perp$, but will have a different magnitude
     1837because $\hat{r}'$ is a unit vector. In other words,
     1838$\vec{r}_\perp' = a\vec{r}_\perp$, for some scalar $a$. So the next step is
     1839to calculate $a = \sqrt{(1-\mu'^2)/\vec{r}_\perp}$.
     1840
     1841Finally, reassemble the components of
     1842$\hat{r}' = \mu'\hat{\beta} + a \vec{r_\perp}$.
     1843
     1844
     1845\subsubsection{GCRS - ITRS}
     1846The transformation between geocentric celestial coordinates and terrestrial
     1847coordinates is a solid body rotation due to the motion of the Earth is space.
     1848This is conventionally broken down into three components to isolate the
     1849relatively rapid rotation of the Earth from the motion of its rotational axis.
     1850
     1851This section is largely a summary of
     1852Chapter 5 of IERS Technical Note 32 \footnote{http://maia.usno.navy.mil/conv2003.html}
     1853(hereafter IERS32),
     1854which is a description of the implementation of the Resoltions of the
     1855XXIVth General Assembly of the IAU, available from the same URL as above.
     1856These two documents describe a set of conventions which have been in effect
     1857since 2003-01-01. The conventions in effect before that date will not be
     1858implemented by psLib.
     1859
     1860
     1861\paragraph{Precession/Nutation}
     1862
     1863The transform between the GCRS and the CIP/CEO coordinate systems is described
     1864by the IAU 2000A precession-nutation model, which is accurate to the
     18650.2 mas level.
     1866For higher accuracy the user must apply corrections to the model, which are tabulated by the IERS.
     1867
     1868
     1869
     1870The IAU 2000A precession-nutation model may be calculated in the following
     1871way. First calculate the time $t$ as the number of Julian centuries since
     18722000-01-01T12:00:00 TT.
     1873
     1874Next calculate the fundamental arguments of nutation using equations (40)
     1875and (41) of IERS32, reproduced below:
     1876\begin{eqnarray}
     1877F_1\equiv l\quad  =~&\ Mean\ Anomaly\ of\ the\ Moon \cr
     1878 =~& 134.96340251^\circ + 1717915923.2178'' t
     1879 + 31.8792'' t^2 + 0.051635'' t^3 - 0.00024470'' t^4,\cr
     1880F_2\equiv l'\quad =~&\ Mean\ Anomaly\ of\ the\ Sun\cr
     1881=~& 357.52910918^\circ + 129596581.0481'' t
     1882- 0.5532'' t^2 + 0.000136'' t^3 - 0.00001149'' t^4,\cr
     1883F_3\equiv F\quad  =~& L - \Omega\cr
     1884=~& 93.27209062^\circ + 1739527262.8478'' t - 12.7512'' t^2
     1885- 0.001037'' t^3 + 0.00000417'' t^4,\cr
     1886F_4\equiv D\quad  =~&\ Mean\ Elongation\ of\ the\ Moon\ from\ the\ Sun\cr
     1887=~& 297.85019547^\circ + 1602961601.2090'' t - 6.3706'' t^2
     1888+ 0.006593'' t^3 - 0.00003169'' t^4,\cr
     1889F_5\equiv\Omega\quad  =~&\ Mean\ Longitude\ of\ the\ Ascending\ Node\ of\
     1890the\ Moon\cr
     1891=~& 125.04455501^\circ - 6962890.5431'' t + 7.4722'' t^2 + 0.007702'' t^3 - 0.00005939'' t^4 \cr
     1892F_6\ \equiv l_{Me}\quad    =~& 4.402 608 842 + 2608.7903 141 574\times t,\cr
     1893F_7\ \equiv l_{Ve}\quad    =~& 3.176 146 697 + 1021.3285 546 211 \times t,\cr
     1894F_8\ \equiv l_{E\ }\quad   =~& 1.753 470 314 + 628.3075 849 991 \times t,\cr
     1895F_9\equiv l_{Ma}\quad    =~& 6.203 480 913 + 334.0612 426 700 \times t,\cr
     1896F_{10}\equiv l_{Ju}\quad =~& 0.599 546 497 + 52.9690 962 641 \times t,\cr
     1897F_{11}\equiv l_{Sa}\quad =~& 0.874 016 757 + 21.3299 104 960 \times t,\cr
     1898F_{12}\equiv l_{Ur}\quad =~& 5.481 293 872 +  7.4781 598 567 \times t,\cr
     1899F_{13}\equiv l_{Ne}\quad =~& 5.311 886 287 +  3.8133 035 638 \times t,\cr
     1900F_{14}\equiv p_{a\ }\quad =~& 0.024 381 750 \times t + 0.000 005 386 91 \times t^2.
     1901\end{eqnarray}
     1902
     1903Next calculate the quantities $X$, $Y$, and $s$, using expressions of the form:
     1904
     1905\begin{equation}
     1906     \sum_{j} p_j t^j + \sum_{j}\sum_{i}[
     1907     (a_{{\rm s},j})_i t^j \sin ({\rm \scriptstyle {ARG_{i,j}}})
     1908   + (a_{{\rm c},j})_i t^j \cos ({\rm \scriptstyle {ARG_{i,j}}})]
     1909   ,
     1910\end{equation}
     1911
     1912where the $\rm \scriptstyle{ARG_{i,j}} = \sum_{k} w_{i,j,k} F_k$ represent linear
     1913combinations of the fundamental arguments of nutation.
     1914
     1915The constants $p_j$, $w_{i,j,k}$, $(a_{{\rm s},j})_i$, and $(a_{{\rm c},j})_i$
     1916are given in the ASCII files:
     1917tab5.2a.txt \footnote{http://maia.usno.navy.mil/conv2000/chapter5/tab5.2a.txt} (for $X$),
     1918tab5.2b.txt \footnote{http://maia.usno.navy.mil/conv2000/chapter5/tab5.2b.txt} (for $Y$), and
     1919tab5.2c.txt \footnote{http://maia.usno.navy.mil/conv2000/chapter5/tab5.2c.txt} (for $s+XY/2$).
     1920Note that the expansion is given for $s+XY/2$, since this series converges
     1921more rapidly than the one for $s$ alone.
     1922
     1923Each file contains a human-readable header, which includes the polynomial
     1924coeficients, $p_j$ under the heading ``Polynomial part''. The data part of the
     1925file lists the remaining constants, with rows cycling first through $i$, and
     1926then through $j$. There is a separate heading each time $j$ increments.
     1927Each row contains the following columns:
     1928
     1929\begin{itemize}
     1930\item col 1 - A running index of rows in the table.
     1931\item col 2 - The sine coeficients, $(a_{{\rm s},j})_i$
     1932\item col 3 - The cosine coeficients, $(a_{{\rm c},j})_i$
     1933\item cols 4 - 17 The weighting factors for the fundamental arguments of
     1934                  nutation, $w_{i,j,k}$.
     1935\end{itemize}
     1936
     1937
     1938A FORTRAN reference implementation for the precession/nutation model is available from the IERS
     1939\footnote{http://maia.usno.navy.mil/conv2000/chapter5/XYS2000A.f}.
     1940The psLib results should agree with the reference implementation to within
     1941the limits of numerical precision.
     1942
     1943Next, corrections to $X$, and $Y$ may be obtained from the IERS as part of
     1944Bulletin A, or B. It is recommended to use the values published daily in
     1945http://maia.usno.navy.mil/ser7/finals2000A.daily, which has the format
     1946described by http://maia.usno.navy.mil/ser7/readme.finals2000A. The
     1947quantities of interest are labeled dX and dY. Note that UT1$-$UTC and the
     1948polar motion values are obtained from this same table.
     1949
     1950By convention, nutation terms with periods of less
     1951than two days
     1952are accounted for by the corresponding polar motion. So it is sufficient to
     1953interpolate the corrections tabulated daily by the IERS, and take the result as
     1954instantaneous values.
     1955
     1956The final step is to use $X$, $Y$, and $s$ to calculate the rotation
     1957matrix from the CIP/CEO system to the GCRS using IERS32 equation (10),
     1958reproduced below:
     1959
     1960\begin{equation}
     1961\begin{pmatrix}1-aX^2& -aXY& X\cr -aXY& 1-aY^2& Y\cr -X& -Y&
     19621-a(X^2+Y^2)\cr
     1963\end{pmatrix} \cdot R_3(s),
     1964\end{equation}
     1965where $R_3$ denotes a rotation about the Z axis,
     1966$a = 1/(1+\sqrt{1 - X^2 + Y^2})$,
     1967and $X$ and $Y$ are expressed in radians.
     1968A FORTRAN reference implementation for this calculation is given
     1969by the IERS \footnote{http://maia.usno.navy.mil/conv2000/chapter5/BPN2000.f}.
     1970
     1971Note that above we gave the expression for the transform toward celestial
     1972coordinates (upward in figure X), in order to match the IERS reference code.
     1973The inverse transform may be found by inverting the resulting rotation.
     1974
     1975\paragraph{Rotation of the Earth}
     1976
     1977The transform from the CIP/CEO to CIP/TEO coordinate systems is a
     1978rotation about the CIP (i.e. the Z axis) by an angle known as the
     1979``Earth Rotation Angle''.
     1980By definition the Earth Rotation Angle is given by
     1981equation (13) of IERS32, reproduced below:
     1982\begin{equation}
     1983\theta(T_u)=2\pi(0.7790572732640 + 1.00273781191135448T_u),
     1984\end{equation}
     1985where $T_u$ is the Julian UT1 date minus 2451545.0 .
     1986
     1987\paragraph{Polar Motion}
     1988
     1989The motion of the CIP in the ITRS is known as ``polar motion''. Similarly to
     1990precession/nutation, the instantaneous position of the CIP in the
     1991ITRS is specified by the quantites $x_p$, and $y_p$, and a third quantity,
     1992$s'$, gives the position of the TEO with respect to the ITRS.
     1993The values of $x_p$ and $y_p$ are published daily by the IERS in
     1994http://maia.usno.navy.mil/ser7/finals2000A.daily, which has the format
     1995described by http://maia.usno.navy.mil/ser7/readme.finals2000A.
     1996The UT1$-$UTC, and the precession/nutation corrections (discussed elsewhere
     1997in this document) come from this same source.
     1998
     1999The polar motion coordinates should be interpolated using a third order
     2000polynomial, as described in
     2001IERS Gazette \#13 \footnote{http://maia.usno.navy.mil/iers-gaz13},
     2002which gives a
     2003FORTRAN reference implementation of the correct procedure.
     2004
     2005\tbd{reference to interpolation in this doc?}
     2006
     2007The values published by the IERS are smoothed to remove noise and
     2008variations on the timescale of a day or less. There are two sources of
     2009short timescale variations - tidal effects on the order of 0.1 milliarcseconds,
     2010and short period nutation terms on the order of 15 microarcseconds.
     2011Both of these effects may be modeled and added to the interpolated values
     2012for higher accuracy.
     2013
     2014The tidal effects should be included using the FORTRAN reference implementation
     2015of the Ray tidal model given in IERS Gazette \#13. This code should be
     2016mimiced to machine accuracy by psLib.
     2017
     2018By definition of the CIP, nutation terms with periods less than 2 days are
     2019not included in the IAU 2000A precession/nutation model.
     2020So these motions
     2021must be compensated for by their equivalent polar motions. These may
     2022be calculated using a form similar to that of the precession/nutation $X$,
     2023and $Y$. The constants to use are given in Table 5.1 of IERS32.
     2024Note that only the terms with periods less than 2 days should be used.
     2025
     2026The quantity $s'$ may be approximated with microarcsecond accuracy over this
     2027century by $s' = -4.7 \times 10^{-5} t$ in arcseconds. There is no need
     2028to apply short timescale corrections to $s'$.
     2029
     2030The transform from the ITRS to the CIP/TEO frame can be constructed by
     2031first rotating about the X axis by $y_p$, then rotating about the X axis by
     2032$x_p$, and finally rotating about the Z axis by $s'$.
     2033The IERS reference implementation for this is given in the subroutine
     2034POM2000 \footnote{http://maia.usno.navy.mil/conv2000/chapter5/POM2000.f}.
     2035Note that we describe the transform toward celestial coordinates (upward in
     2036figure X), in order to match the reference implementation.
     2037
     2038\subsubsection{ITRS - Alt/Az}
     2039
     2040\paragraph{Orientation of the Observer}
     2041
     2042An observer's astronomical longitude and latitude give the orientation of
     2043the local vertical with respect to the ITRS. Note that these coordinates
     2044can be approximated by the geographic longitude and latitude of the observatory,
     2045but their exact values must be calibrated from observation of stars
     2046with known coordinates in the ICRS.
     2047
     2048The transform from the ITRS to Az/Alt in the absence of atmospheric refraction
     2049is first a rotation about the Z axis by the observer's astronomical longitude,
     2050and then a rotation about the Y axis of 90 degrees minus the observer's
     2051astronomical latitude, followed by a rotation about the Z axis of 180 degrees
     2052so that North is zero azimuth.
     2053
     2054\paragraph{Atmospheric Refraction}
     2055
     2056\tbd{add in summary of Ken's paper}
     2057
     2058\subsection{Projections}
     2059
     2060We implement three types of projections: {\em zenithal}, {\em
     2061cylindrical} and {\em pseudocylindrical}, each requiring slightly
     2062different handling.  Our representations are based on the treatment of
     2063projections presented by
     2064\href{http://www.cv.nrao.edu/fits/documents/wcs/wcs.all.ps}{Greisen \&
     2065Calabretta (1995, ADASS, 4, 233)}.  In all of these projections, we
     2066are converting from a spherical coordinate $\alpha,\delta$ to a linear
     2067(2-D) coordinate $x_p,y_p$.  The projection is defined by the
     2068projection type, the projection center ($\alpha_p, \delta_p$) and the
     2069the plate scales in the $x_p$ and $y_p$ directions ($\rho_x,\rho_y$).
     2070
     2071In the structure, \code{psProjection}, the projection type is defined
     2072by the element \code{type}, the projection center $\alpha_p,\delta_p$
     2073is defined by the elements \code{R,D}, and the plate scales,
     2074$\rho_x,\rho_y$, are defined by the elements \code{Xs,Ys}.  The plate
     2075scales are applied independently to the $x$ and $y$ coordinates to
     2076convert them to the corresponding linear units (ie, pixels):
     2077%
     2078\begin{eqnarray}
     2079x_p & = & \rho_x x \\
     2080y_p & = & \rho_y y \\
     2081\end{eqnarray}
     2082%
     2083In the discussions below, we ignore this last step (or first step,
     2084depending on the direction of the conversion).
     2085
     2086\subsubsection{Zenithal Projections}
     2087
     2088The {\em zenithal} projections are defined relative to a set of
     2089spherical coordinates with pole at the center of the projection
     2090($\alpha_p, \delta_p$), and which thus represents a coordinate system
     2091rotated relative to the coordinate system of $\alpha, \delta$.  In
     2092this spherical coordinate system, the coordinate of longitude is
     2093labeled $\phi$, and has domain of $-\pi < \phi \le \pi$, while the
     2094latitude, measured from the pole, is labeled $\theta$ and has domain
     2095$0 \le \theta \le \pi$.  The coordinate frame of $\phi,\theta$ is
     2096defined so that $\phi_p$, the longitude of the target system pole, is
     20970.0.
     2098
     2099For an arbitrary projection center, it is necessary to convert the
     2100spherical coordinates to be projected ($\alpha,\delta$) to the
     2101projection spherical coordinate system coordinates ($\phi, \theta$).
     2102In practice, we construct the following useful trigonometric
     2103relationships between $\phi$ and $\theta$ which may be employed in the
     2104equations of $x,y$ below:
     2105%
     2106\begin{eqnarray}
     2107\sin \theta           & = & \sin \delta \sin \delta_p + \cos \delta \cos \delta_p \cos (\alpha - \alpha_p) \\
     2108\cos \theta \cos \phi & = & \sin \delta \cos \delta_p - \cos \delta \sin \delta_p \cos (\alpha - \alpha_p) \\
     2109\cos \theta \sin \phi & = & - \cos \delta \sin (\alpha - \alpha_p)
     2110\end{eqnarray}
     2111%
     2112For the inverse transformations, the equivalent relationships are:
     2113%
     2114\begin{eqnarray}
     2115\sin \delta                          & = & \sin \theta \sin \delta_p + \cos \theta \cos \delta_p \cos \phi \\
     2116\cos \delta \cos (\alpha - \alpha_p) & = & \sin \theta \cos \delta_p - \cos \theta \sin \delta_p \cos \phi \\
     2117\cos \delta \sin (\alpha - \alpha_p) & = & - \cos \theta \sin \phi
     2118\end{eqnarray}
     2119%
     2120For zenithal projections, the linear coordinates are related to
     2121$\phi,\theta$ by:
     2122%
     2123\begin{eqnarray}
     2124x & = & R_\theta \sin \phi \\
     2125y & = & -R_\theta \cos \phi
     2126\end{eqnarray}
     2127%
     2128and the inverse:
     2129%
     2130\begin{eqnarray}
     2131R_\theta & = & \sqrt{x^2 + y^2} \\
     2132\phi     & = & {\rm atan} (-y,x)
     2133\end{eqnarray}
     2134%
     2135The coordinates $x,y$ above are defined to be in angular units (ie,
     2136radians). 
     2137
     2138From these relationships, we can calculate $\alpha, \delta$ as:
     2139%
     2140\begin{eqnarray}
     2141\alpha - \alpha_p & = & \arctan (\sin \alpha, \cos \alpha) \\
     2142\delta            & = & \arcsin (\sin \delta) \\
     2143\end{eqnarray}
     2144%
     2145Note that if $(x,y) = (0,0)$, then $\alpha = \alpha_p, \delta = \delta_p$.
     2146
     2147\paragraph{Gnomonic}
     2148
     2149The Gnomonic projection (``TAN'') is a zenithal projection with
     2150$R_\theta = \cot \theta$.  The resulting relationships for $(x,y)$ and
     2151for $\sin \theta, \cos \theta$ are:
     2152
     2153\begin{eqnarray}
     2154x           & = & \frac{\cos \theta \sin \phi}{\sin \theta} \\
     2155y           & = & \frac{-\cos \theta \cos \phi}{\sin \theta} \\
     2156\sin \theta & = & \zeta / \sqrt{1 + \zeta^2} \\
     2157\cos \theta & = & 1 / \sqrt{1 + \zeta^2} \\
     2158\end{eqnarray}
     2159
     2160where $\zeta = 1 / R_\theta$.
     2161
     2162\paragraph{Orthographic}
     2163
     2164The Orthographic projection (``SIN'') is a zenithal projection with
     2165$R_\theta = \cos \theta$.  The resulting relationships for $(x,y)$ and
     2166for $\sin \theta, \cos \theta$ are:
     2167
     2168\begin{eqnarray}
     2169x           & = & \cos \theta \sin \phi \\
     2170y           & = & -\cos \theta \cos \phi \\
     2171\sin \theta & = & \sqrt{1 - R_\theta^2} \\
     2172\cos \theta & = & R_\theta \\
     2173\end{eqnarray}
     2174
     2175\subsubsection{Cylindrical and Pseudocylindrical Projections}
     2176
     2177The {\em cylindrical} and {\em pseudocylindrical} projections are
     2178defined relative to a set of cylindrical coordinates whose pole is
     2179coincident with the pole of the spherical coordinates.  These
     2180projections are particularly used for full-sky representations, and
     2181are only defined for projection centers with $\delta_p = 0$.  In this
     2182spherical coordinate system, the coordinate of longitude is labeled
     2183$\phi$, and has domain of $-\pi < \phi \le \pi$, while the latitude,
     2184measured from the pole, is labeled $\theta$ and has domain $0 \le
     2185\theta \le \pi$.  The projection center longitude, $\alpha_p$
     2186corresponds to $\phi = 0$, thus the value of $\phi$ is determined as
     2187$\alpha - \alpha_p$ for all such projections.
     2188
     2189\paragraph{Cartesian}
     2190
     2191The Cartesian projection (``CAR'') is a very simple cylindrical
     2192projection with the following relationships between $x,y$ and
     2193$\phi,\theta$:
     2194
     2195\begin{eqnarray}
     2196x & = & \phi \\
     2197y & = & \theta
     2198\end{eqnarray}
     2199
     2200\paragraph{Mercator}
     2201
     2202The Mercator projection (``MER'') is a cylindrical projection.
     2203
     2204\begin{eqnarray}
     2205x & = & \phi \\
     2206y & = & \ln \left( \tan (\pi/4 + \theta/2) \right) \\
     2207{\rm and}\hspace{1cm} \theta & = & 2 \arctan \left( e^y \right) - \pi/2
     2208\end{eqnarray}
     2209
     2210\paragraph{Hammer-Aitoff}
     2211
     2212The Hammer-Aitoff projection(``AIT'') is a pseudocylindrical projection, and is defined:
     2213
     2214\begin{eqnarray}
     2215x & = & 2 \zeta \cos \theta \sin \frac{\phi}{2} \\
     2216y & = & \zeta \sin \theta \\
     2217{\rm where}\hspace{1cm} \zeta^{-1} & \equiv & \sqrt{\frac{1}{2}\left(1 + \cos \theta \cos \frac{\phi}{2} \right)}
     2218\end{eqnarray}
     2219
     2220And in reverse:
     2221
     2222\begin{eqnarray}
     2223\phi & = & 2 {\rm \arctan} (2z^2 - 1, x z) \\
     2224\theta & = & \arcsin (yz) \\
     2225{\rm where}\hspace{1cm} z & \equiv & \sqrt{1 - (x/2)^2 - y^2}
     2226\end{eqnarray}
     2227
     2228\paragraph{Parabolic}
     2229
     2230The Parabolic projection (``PAR'') is a pseudocylindrical projection, and is defined:
     2231
     2232\begin{eqnarray}
     2233x & = & \phi \left( 2 \cos \frac{2 \theta}{3} - 1 \right) \\
     2234y & = & \pi \sin \frac{\theta}{3} \\
     2235\end{eqnarray}
     2236
     2237And in reverse:
     2238
     2239\begin{eqnarray}
     2240\theta & = & 3 \sin^{-1} \rho \\
     2241\phi   & = & \frac{x}{1 - 4\rho^2} \\
     2242{\rm where}\hspace{1cm} \rho & \equiv & y/\pi \\
     2243\end{eqnarray}
     2244
     2245\subsection{Offset}
     2246
     2247Coordinate offsets can be either spherical offsets or linear offsets.
     2248
     2249A spherical offset is performed by adding the components of the
     2250offset, after unit conversion, to the given position.  The resulting
     2251coordinates must be wrapped to within the allowed range ($-\pi$ to
     2252$\pi$, 0 to $2\pi$).
     2253
     2254A linear offset is defined to be a linear offset in a tangent
     2255projection centered on the starting coordinate with $y$ axis aligned
     2256with the local direction or increasing Declination.  This projection
     2257is undefined only for the coordinates exactly at the north and south
     2258poles, in which case the orientation is defined to have the $y$ axis
     2259parallel to the line of RA = 0.0.  The scale of the projection is 1.0
     2260(ie, 1 'pixel' is 1 radian) and the given offsets must the scaled
     2261based on the given offset units. 
     2262
     2263Pseudo-code to implement the above for an offset:
     2264
     2265\begin{verbatim}
     2266psSphere *psSphereSetOffset (psSphere pos, psSphere offset) {
     2267
     2268  psPlane lin;
     2269  psSphere new;
     2270  psProjection proj;
     2271
     2272  proj.R = pos->r;
     2273  proj.D = pos->d;
     2274  proj.X = 0;
     2275  proj.Y = 0;
     2276  proj.type = PS_PROJ_TAN;
     2277
     2278  lin.x = offset.r;
     2279  lin.y = offset.d;
     2280
     2281  new = psDeproject (&lin, &proj);
     2282  return (new);
     2283}
     2284\end{verbatim}
     2285
     2286%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     2287
     2288\subsection{The One-to-Many Problem with Mosaic Cameras}
    18012289
    18022290The \PS{} focal plane consists of several chips, so we will often want
     
    18202308%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    18212309
    1822 \subsubsection{General Astronomy Functions}
     2310\subsection{General Astronomy Functions}
    18232311
    18242312\tbd{we will provide a new airmass function}
     
    18542342%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    18552343
    1856 \subsubsection{Positions of Major Solar System Objects}
     2344\subsection{Positions of Major Solar System Objects}
    18572345
    18582346\tbd{ephemerides code to replace this}
     
    18692357%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    18702358
    1871 \subsection{Missing and Todo}
    1872 
    1873 \tbd{define sunrise, sunset, sun position}
    1874 
    1875 \tbd{define moonrise, moonset, moon position, moon phase}
    1876 
    1877 \tbd{define planet functions}
    1878 
    1879 \tbd{clean up FITS I/O issues}
    1880 
    1881 \tbd{define Brent's method \& minimization bracketing}
    1882 
     2359\pagebreak
    18832360\section{Pan-STARRS Modules}
    18842361
     
    22252702%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    22262703%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     2704
     2705\section{Missing and Todo}
     2706
     2707\tbd{define sunrise, sunset, sun position}
     2708
     2709\tbd{define moonrise, moonset, moon position, moon phase}
     2710
     2711\tbd{define planet functions}
     2712
     2713\tbd{clean up FITS I/O issues}
     2714
     2715\tbd{define Brent's method \& minimization bracketing}
     2716
    22272717\appendix
    22282718\section{Change Log}
     
    22302720
    22312721\end{document}
    2232 
    2233 
    2234 \section{Modules}
    2235 
    2236 \subsection{Image Processing Modules}
    2237 \subsubsection{debias}
    2238 \subsubsection{mask}
    2239 \subsubsection{trim}
    2240 \subsubsection{flatten}
    2241 \subsubsection{sky/fringe subtract}
    2242 \subsubsection{warp}
    2243 \subsubsection{stack}
    2244 \subsubsection{difference}
    2245 \subsubsection{kernel convolution}
    2246 \subsubsection{special stack}
    2247 
    2248 \subsection{Object Detection Modules}
    2249 \subsubsection{find peaks}
    2250 \subsubsection{background }
    2251 \subsubsection{aperture photometry}
    2252 \subsubsection{get shape}
    2253 
    2254 \subsection{Miscellaneous Modules}
    2255 
    2256 \section{Analysis Stages}
    2257 \subsection{Phase 1}
    2258 \subsection{Phase 2}
    2259 \subsection{Phase 3}
    2260 \subsection{Phase 4}
    2261 \subsection{Cal 1}
    2262 \subsection{Cal 2}
    2263 \subsection{Cal 3}
    2264 \subsection{Astrom Ref}
    2265 \subsection{Photom Ref}
    2266 
    2267 \section{Architectual Components}
    2268 
Note: See TracChangeset for help on using the changeset viewer.