%
% To start the document, use
%  \levela{...}
% For lover level, sections use
%  \levelb{...}
%  \levelc{...}
%
\levela{Line of sight, 1D}
 \label{sec:los}


%
% Document history, format:
%  \starthistory
%    date1 & text .... \\
%    date2 & text .... \\
%    ....
%  \stophistory
%
\starthistory
  000307 & Started by Patrick Eriksson. \\
  000914 & First version finished by Patrick Eriksson.\\
\stophistory


%
% Symbol table, format:
%  \startsymbols
%    ... & \verb|...| & text ... \\
%    ... & \verb|...| & text ... \\
%    ....
%  \stopsymbols
%
%
%\startsymbols
%  \view     & \verb|view|     & zenith angle from zenith                  \\
%  $z$       & \verb|z|       & vertical altitude                          \\
%  $z_p$     & \verb|z_plat|  & platform altitude                          \\
%  $z_t$     & \verb|z_tan|   & tangent altitude                           \\
%  $z_g$     & \verb|z_ground|& altitude of the ground                     \\
%  $z_{lim}$ & \verb|z_abs_max|& practical upper limit of the atmosphere   \\
%  $l$       & \verb|l|       & distance along LOS                         \\
%  $e$       & \verb|gr_emiss|& ground emissivity                          \\
%  $\Delta l$& \verb|l_step|  & step length along LOS                      \\
%  $l_{lim}$ & \verb|llim|    & distance from lowest LOS point to $z_{lim}$\\
%  $l_p$     & \verb|l1|      & distance used for downward observation     \\
%  $i_p$     & -              & index for platform altitude for downward obs.\\
% \label{symtable:los}     
%\stopsymbols



%
% Introduction
%
This section describes how the line of sight (LOS) is determined
for situations where the atmosphere is assumed to be horizontally
stratified, a 1D atmosphere. Expressions are given both for pure
geometrical calculations and when considering refraction.



\levelb{Definitions}
 \label{sec:los:defs}
 
 Vertical (geometrical) altitudes are denoted as $z$, pressures as $p$
 and distances along the LOS are denoted as $l$. Vertical distances
 are measured from the geoid and $l$ is the distance from the lowest
 point of the LOS.
 
 As a 1D atmosphere is assumed here, the conditions are symmetrical
 around tangent points and points of ground reflection, and, for such
 cases, only one half of the LOS is stored for efficiency reasons.
 The points of the LOS are stored by increasing vertical altitude
 point. Index 1 corresponds accordingly to either the platform, the
 tangent point or the ground.  The internal description of the LOS is
 further described in the file \verb|los.h|.
  
 The line of sight is defined by two variables, the platform altitude,
 $z_p$, and the zenith angle, $\view$, (see Fig. \ref{fig:los1d:geoms}):

 \begin{description}
  \item[The platform altitude] is the altitude above the geoid of the
       sensor used to detect the spectrum simulated.
  \item[The zenith angle] is the angle between the zenith
       direction and the direction of observation. As an 1D atmosphere is
       assumed, there is no difference between positive and negative
       zenith angles.
  \end{description}

  \noindent
  The lower limit of the atmosphere is given by the ground altitude,
  $z_g$. The practical upper limit of the atmosphere is denoted
  $z_{lim}$ and is in the forward model determined by the highest
  point of the absorption grid. The absorption grid can
  extend below $z_g$. On the other hand, it is not allowed that any
  part of the LOS is between the lowest absorption altitude and the ground.
 
  If $\view>90^{\circ}$ the lowest point of the LOS is not the platform
  altitude, and this point is denoted as the tangent point, $z_t$. The
  angle between the LOS and the vector to the Earth center is at the
  tangent point $90^\circ$. If the tangent point is below ground
  level, $z_t$ is determined by an imaginary geometric prolonging of
  the LOS inside the Earth.

  \begin{figure}[tb]
   \begin{center}
    \includegraphics*[width=0.95\hsize]{Figs/geoms}
    \caption{Schematic description of the main variables of the 
             observation geometry and the LOS. $R_e$ is the Earth
             radius. Other variables defined in the text.}  
    \label{fig:los1d:geoms}  
   \end{center}
  \end{figure}
  
  The forward model uses internally three main observation geometries:

  \begin{description}
  \item[Upward looking] signifies observation from
    within the atmosphere in an upward direction ($z_p<z_{lim}$ and
    $\view\leq90^{\circ}$). 
  \item[Limb sounding] covers here all observations from a point
    outside the atmosphere ($z_p \geq z_{lim}$). All zenith angles are
    covered, and, for example, nadir looking observations
    ($\view=180$) are treated as limb sounding in the forward model.
    If the LOS does not pass the atmosphere ($z_{tan} \geq z_{lim}$),
    cosmic background radiation, or correspondingly, is returned.
  \item[Downward looking] is observation from within the atmosphere in
    a downward direction ($z_p<z_{lim}$ and $\view>90^{\circ}$).
  \end{description}
 

\levelb{Outlook towards 2D}
 \label{sec:los:2d}
 So far ARTS is only capable of calculating spectra for 1D cases.
 It is planned to also handle satellite measurements with atmospheric 
 horizontal variations, but limited to observations in the orbit
 plane, here denoted as 2D observations. 
 
 For 2D observations there is no symmetry to be used, each point of
 the LOS is unique. This is also the case for 1D upward looking
 observations, and it is planned that 2D and 1D upward calculations of
 radiative transfer and weighting functions shall be performed with
 the same general functions.  The 2D case exhibits however one
 difference compared to the 1D upward case. For 2D cases there could
 be a ground reflection along the LOS, which is never the case for 1D
 upward looking observations by definition. This question is discussed
 a bit further in Section \ref{sec:los:ground}. Note that if the 1D
 upward functions are used for 2D simulations, the point of LOS
 closest to the sensor will throughout have index 1.


 
\levelb{The step length}
 \label{sec:rte:stepl}
 
 As described in Section \ref{sec:rte}, the LOS is divided into equal
 long geometrical steps, $\Delta l$. The user gives an upper limit for
 this step length. A point of the LOS is always placed at the sensor
 (if inside the atmosphere), tangent points and points of ground
 reflection, but no adjustment to the upper atmospheric limit is made.
 This gives a single fixed point for limb sounding and upward looking
 observation and $\Delta l$ is set to the value given by the user if
 the LOS has at least two definition points. If the LOS gets only one
 point with the user defined value, for example when the tangent point
 is just below the atmospheric limit, the step length is adjusted to
 the length from the fixed point of the LOS (the sensor or the tangent 
 point) and the atmospheric limit.
 
 In contrast to upward and limb sounding observations, for downward
 observations there are two fixed points inside the atmosphere (the
 platform and the tangent point, or the point of ground reflection)
 and $\Delta l$ is here adjusted according to the the distance between
 these two points. See further Section \ref{sec:los:down}.



\levelb{Geometrical calculations}
  
 \levelc{Upward looking}   
  \label{sec:los:up}
  
  The relationship between vertical altitude ($z$) and distance along
  LOS ($l$) can be found be the law of cosines, giving
  \begin{equation}
    (R_e+z)^2 = (R_e+z_p)^2 + l^2 + 2l(R_e+z)\cos(\view)
  \end{equation}
  This equation gives
  \begin{equation}
    z = \sqrt{ (R_e+z_p)^2 + l^2 + 2l(R_e+z)\cos(\view) } - R_e
  \end{equation}
  The distance between the sensor and the limit of the atmosphere is
  \begin{equation}
      l_{lim} = \sqrt{ (R_e+z_{lim})^2 - (R_e+z_p)^2\sin^2(\view) } - 
                                       (R_e+z_p)\cos(\view)
  \end{equation}


 \levelc{Limb sounding}
  \label{sec:los:limb}
  
  The tangent altitude is
  \begin{equation}
    z_t = (R_e+z_p)\sin(\view) - R_e \qquad  \view\geq90^\circ
   \label{eq:los:ztan}
  \end{equation}
  This relationship holds even if $z_t<z_g$. Note that
  $\sin(180^\circ-\view)=\sin(\view)$ and it must be checked that
  $\view\geq90^\circ$. Zenith angles $<90^\circ$ correspond to an
  imaginary tangent point behind the sensor, and are treated as
  observations into the space.
  
  The Pythagorean relation gives the distance from the tangent point
  to the atmospheric limit:
  \begin{equation}
      l_{lim} = \sqrt{ (R_e+z_{lim})^2 - (R_e+z_t)^2}
  \end{equation}
  If $l_{lim}$ is smaller than upper limit for $\Delta l$ specified by
  the user, $\Delta l$ is set to $l_{lim}$ as also described in Section
  \ref{sec:rte:stepl}.

  The vertical altitude as a function of the distance from the
  tangent point is
  \begin{equation}
    z = \sqrt{ (R_e+z_t)^2 + l^2} - R_e
  \end{equation}
  If the tangent point is below ground, the LOS is determined by the
  upward expressions (Sec. \ref{sec:los:up}) by setting
  \begin{eqnarray}
     z_p  & \gets & z_g          \nonumber  \\
     \view & \gets & \sin^{-1}\left((R_e+z_t)/(R_e+z_g) \right) \nonumber 
  \end{eqnarray}


 \levelc{Downward looking}
  \label{sec:los:down}
  
  This observation geometry can be handled by the upward and limb
  sounding functions by suitable exchange of variables. However, as
  the lowest point of the LOS is either the tangent point or the
  ground, and one point of LOS must fit the sensor altitude, the step
  length must be adjusted to this distance.

  The distance between the sensor and a tangent point is
  \begin{equation}
    l_p = \sqrt{ (R_e+z_p)^2 - (R_e+z_t)^2 } \qquad  z_t \geq z_g
  \end{equation}
  and the distance between the sensor and a point of ground
  reflection is
  \begin{equation}
    l_p = \sqrt{ (R_e+z_p)^2 - (R_e+z_t)^2 } - \sqrt{ (R_e+z_g)^2-(R_e+z_t)^2}
            \qquad z_t < z_g
  \end{equation}
  where $z_t$ is determined by Equation \ref{eq:los:ztan}.

 The part of the LOS between the sensor and the tangent or ground
 point gets the following number of points:
 \begin{equation}
    m = 1 + \mathbf{ ceil}(l_{lim}/\Delta l_{max})
  \label{eq:los:m}
 \end{equation}
 where $\Delta l_{max}$ is the upper limit for $\Delta l$ specified by
 the user, and $\mathbf{ ceil}$ is a function giving the first integer
 larger than the argument. The step length is accordingly
 \begin{equation}
    \Delta l = \frac{l_{lim}}{m-1}
  \label{eq:los:dl}
 \end{equation} 
 If the tangent altitude is above the ground ($z_{tan} \geq z_t$),
 the LOS is determined by the same expressions as applied for limb
 sounding, but with the adjusted value for $\Delta l$.
 If there is an intersection with the ground, the upward
 looking expressions can be used as described above for limb sounding,
 again with the adjusted value for $\Delta l$.


 \levelb{With refraction}
  \label{sec:los:refraction}
  
  Refraction affects the radiative transfer in several ways. The
  distance through a layer of a fixed vertical thickness will be
  changed, and for a limb sounding observation the tangent point is
  moved both vertically and horizontally. If the atmosphere is assumed
  to be horizontally stratified, as done here (1D), a horizontal
  displacement is of no importance but for 2D calculations this effect
  must be considered. For limb sounding and a fixed zenith angle, the
  tangent point is moved downwards compared to the pure geometrical
  case, resulting in that inclusion of refraction in general gives
  higher intensities. However, the LOS is still symmetric around
  tangent and ground points.

 \levelc{General theory}
  \label{sec:los:reftheory}

   When determining the LOS through the atmosphere geometrical optics 
   can be applied because the change of the refractive index over a
   wavelength can be neglected. Applying Snell's law to the geometry 
   shown in Figure \ref{fig:los:snell} gives
   \begin{equation}
     n_i \sin (\theta_i) = n_{i+1} \sin (\theta_i')
   \end{equation}
   \begin{figure}
    \begin{center}
      \includegraphics*{Figs/snell}
      \caption{Geometry to derive Snell's law for a spherical atmosphere. 
               The Earth radius is $R_e$, the vertical
               altitude $z$, the refractive index $n$ and the angle
               between the LOS and the vector to the Earth center $\theta$.}
      \label{fig:los:snell} 
    \end{center} 
  \end{figure}
  Using the same figure, the law of sines gives the relationship
  \begin{equation}
    \frac{\sin(\theta_{i+1})}{R_e+z_i} = 
    \frac{\sin(180^\circ-\theta_{i+1}')}{R_e+z_{i+1}} =
    \frac{\sin(\theta_i')}{R_e+z_{i+1}} 
  \end{equation}
  By combining the two equations above, the Snell's law for a spherical
  atmosphere (i.e. 1D) is derived \citep[e.g.][]{kyle:91,balluch:97}:
  \begin{equation}
    c = (R_e+z_i) n_i \sin(\theta_i) = (R_e+z_{i+1}) n_{i+1}\sin(\theta_{i+1}) 
   \label{eq:los:snellspherical}
  \end{equation}
  where $c$ is a constant. With other words, the Snell's law for spherical
  atmospheres states that the product of $n$, $(R_e+z)$ and $\sin(\theta)$ is
  constant along the LOS.

  The radiative transfer is evaluated along the LOS, while Equation 
  \ref{eq:los:snellspherical} is expressed for vertical altitudes.
  The relationship between a change in vertical altitude and the
  corresponding change along the LOS is here denoted as the geometrical term
  and it is \citep{eriksson:97a}
  \begin{equation}
    g(z) = \frac{1}{\cos(\theta)}
  \end{equation}
  which can be rewritten using trigonometric identities and Equation
  \ref{eq:los:snellspherical}:
  \begin{equation}
    g(z) = \frac {(R_e+z)n(z)} {\sqrt{ (R_e+z)^2n^2(z) - c^2 }}
   \label{eq:los:gterm}
  \end{equation}
  A possible solution for calculating the LOS would be to integrating the
  geometrical term as \citep{eriksson:00a}
  \begin{eqnarray}
    l_1^2 = \int_{z_1}^{z_2}{g(z)\dd z} \nonumber
  \end{eqnarray}
  where $z_1$ and $z_2$ are two vertical altitudes and $l_1^2$ the length
  along the LOS between these two altitudes. However, this approach is
  problematic for limb sounding as the geometric factor is
  singular at the tangent point (Fig. \ref{fig:los:gfac}). 
  \begin{figure}
   \begin{center}
    \includegraphics*[width=0.8\hsize]{Figs/fig_geomfac}
     \caption{The geometrical factor, as a function of altitude, for limb 
              sounding and three tangent altitudes. Taken from
              \citet{eriksson:97a}}.
    \label{fig:los:gfac}
   \end{center} 
  \end{figure}



 \levelc{The refraction prolongation factor}
 
  To avoid the singularity of the geometrical factor at tangent points,
  the refraction prolongation factor is here introduced. This factor is 
  defined as
  \begin{equation}
    r(z) = \frac {g(z)} {g_g(z)}
   \label{eq:los:refprol1}
  \end{equation}
  where $g_g(z)$ is the geometrical factor for the geometrical LOS
  that is parallel with the refracted LOS at the lowest point. The
  $c$ constant for $g_g$ equals accordingly $(R_e+z)\sin(\theta)$ for
  the lowest altitude of the refracted LOS. If this altitude is
  denoted as $z_{min}$, the prolongation factor can be written as
  \begin{equation}
    r(z) = \frac {n(z)\sqrt{ (R_e+z)^2 - (c/n(z_{min}))^2 }} 
                 {\sqrt{ (R_e+z)^2n^2(z) - c^2 }}
   \label{eq:los:refprol2}
  \end{equation}
  The prolongation factor for limb sounding is shown in Figure 
  \ref{fig:los:pfac}.
  The value of $r$ at tangent points is discussed below.

  The factor $r$ gives the relative increase in length of the
  refracted LOS $(\Delta l)$ compared to the length of the corresponding
  geometrical LOS $(\Delta l_g)$ through a small vertical layer $(\Delta z)$:
  \begin{equation}
    \Delta l = g(z) \Delta z = r(z) g_g(z) \Delta z = r(z) \Delta l_g.
   \label{eq:los:refprol3}
  \end{equation}

  \begin{figure}
   \begin{center}
    \includegraphics*[width=0.49\hsize]{Figs/fig_pfac_z}
    \includegraphics*[width=0.46\hsize]{Figs/fig_pfac_l}
     \caption{Prolongation factors for limb sounding and three tangent
              altitudes. The figure to the left shows $r$ as a function
              of the vertical altitude, while the right figure shows $r$ as 
              a function of the distance along the LOS from the tangent point.
              The refraction index is calculated as $n=1+77.9593\ee{-6}p/T$
              where the unit of $p$ is hPa (see \citet{elgered:93}).}
    \label{fig:los:pfac}
   \end{center} 
  \end{figure}


 \levelc{Practical solution}

  The scheme applied to determine the LOS with refraction can be 
  summarized as:
  \begin{enumerate}
    \item The lowest point of the LOS and the angle $\theta$ at this point 
          are determined. 
    \item The geometrical LOS matching this point and angle is calculated
          with a step length defined by the user, $\Delta l_r$.
    \item The prolongation factor is determined for the altitudes of the
          geometrical LOS.
    \item The distances along the LOS from the lowest point are calculated
          following Eq. \ref{eq:los:refprol3}, where the applied prolongation
          factor is the mean of $r$ at the end points of the steps.
    \item The obtained distances are interpolated to obtain an equally spaced
          refractive LOS with the selected step length $(\Delta l)$.
  \end{enumerate}
  The altitude and angle in step 1 are directly given by the platform
  altitude and the zenith angle for upward observations. Limb sounding
  is discussed separately below. The constant $c$ is throughout given
  by the zenith angle and the refractive index at the sensor. Figure
  \ref{fig:los:pfac} shows that $r$ varies slowly (as a function of $l$) 
  and it should suffice to treat $r$ as piecewise linear function as
  done here. 

  The accuracy of the calculations can be controlled by the step length 
  $\Delta l_r$. As the calculations are straightforward and simple a
  relatively low value for $\Delta l_r$ can be used without increasing the
  total calculation time noteworthily. The described scheme can be said to 
  be correct to the first order, as it gives the same result as the pure
  geometrical expressions if $n$ is set to 1.

   
 \leveld{Limb sounding}
 
  The most important step for limb sounding is to get a correct
  tangent altitude. Fortunately, there is a way to determine the
  tangent altitude directly for 1D cases, without following the LOS
  from the top of the atmosphere.

  The tangent altitude is given by the relationship
  \begin{equation}
    (R_e+z_t)n(z_t) = (R_e+z_p)\sin(\view) = c
   \label{eq:los:ztan_ref}
  \end{equation}
  as $\sin(\theta)=1$ at tangent points, the refractive index in space
  is 1 and $sin(180^{\circ}-\view)=sin(\view)$. The tangent altitude
  is practically determined by finding the highest altitude where
  $(R_e+z)n(z)$ exceeds the value of $c$, followed by an interpolation
  of the product $(R_e+z)n(z)$ between the found altitude and the
  altitude above to find the altitude fulfilling Equation
  \ref{eq:los:ztan_ref}.
  
  For cases with ground reflections, a similar relationship,
  \begin{equation}
    (R_e+z_g)n(z_g)sin(\theta_g) = (R_e+z_p)\sin(\view) = c,
  \end{equation}
  gives the angle between the LOS and the ground normal. With this angle
  the LOS can be determined with the corresponding upward function.
  
  The value of the prolongation factor at tangent points cannot be
  calculated using Equation \ref{eq:los:refprol2} as the denominator
  of this expression is here zero. By using that
  $(a^2-b^2)=(a+b)(a-b)$ both in nominator and denominator, Equation
  \ref{eq:los:refprol2} can be rewritten as
  \begin{eqnarray}
    r^2(z) &=& \frac{n^2(z) \left[(R_e+z)^2-(R_e+z_t)^2\right]}
                   {(R_e+z)^2n^2(z)-(R_e+z_t)^2n^2(z_t)} = \nonumber \\
   &=&  \frac{n^2(z)\left(2R_e+z+z_t\right)}{(R_e+z)n(z)+(R_e+z_t)n(z_t)}
        \frac{z-z_t}{(R_e+z)n(z)-(R_e+z_t)n(z_t)} \nonumber
  \end{eqnarray}
  The first quotient equals $n(z_t)$ at tangent points. By adding $z_tn(z)$
  to the denominator, the second term can be
  further rewritten as
  \begin{eqnarray}
     & & \frac{z-z_t}{(R_e+z)n(z)-(R_e+z_t)n(z_t)}= \nonumber \\
     &=& \frac{z-z_t}{R_e[n(z)-n(z_t)]+n(z)(z-z_t)+z_t[n(z)-n(z_t)]}= 
                                                                 \nonumber \\
     &=& \frac{1}{n(z)+R_e\frac{n(z)-n(z_t)}{z-z_t}+
                     z_t\frac{n(z)-n(z_t)}{z-z_t}}               \nonumber
  \end{eqnarray}
  The last expression brings out that the important quantity is 
  \begin{equation}
    a = \lim_{z \to z_t^+}\frac{n(z)-n(z_t)}{z-z_t}
  \end{equation}
  The prolongation factor for the tangent point is now determined:
  \begin{equation}
    r(z_t) = \sqrt{\frac{n(z_t)}{n(z_t)+a(R_e+z_t)}}
  \end{equation}

  
  
 \levelb{Ground intersections}
  \label{sec:los:ground}
  
  Ground reflections are indicated by a special flag. This flag is
  zero when there is no ground intersection or gives the index of the
  LOS point corresponding to the ground, $i_g$. For 1D calculations,
  $i_g$ is either 0 or 1, as index 1 is here defined to always be the
  lowest altitude of the LOS. However, to pave the way for 2D
  calculations, cases where the ground is placed at other positions
  than index 1 are handled.
  
  For 1D cases, where only half of the total LOS is stored and the
  ground can only have index 1 ($i_g=1$), the effect of a ground
  reflection (Eq. \ref{eq:rte:ground}) is put in when reversing the
  loop order.  Accordingly, the calculation order is: ... step2, step
  1, ground, step 1, step 2, ... Ground reflections for 1D cases are
  treated internally in ARTS by the limb sounding functions.
  
  \begin{figure}[b]
   \begin{center}
     \includegraphics*[width=0.75\hsize]{Figs/ground}
    \caption{Schematic of ground reflections for 2D cases. The index 
             of the point corresponding to the ground is $i_g$. Point 1
             of the LOS is the point closest to the sensor. }  
    \label{fig:los1d:ground}  
   \end{center}
  \end{figure}
 
  When solving the radiative transfer (Eq. \ref{eq:rte:iteration}) for
  2D cases, the ground reflection is treated between evaluating step
  $i_g$ and $i_{g-1}$ (the iteration goes from $n$ to 1), as shown in
  Figure \ref{fig:los1d:ground}.  Ground reflections for 2D cases are
  treated internally in ARTS by the upward looking functions (Sec.
  \ref{sec:los:2d}).



%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "main"
%%% End: 
