% Yaros PFS
% =========
%
% Appendix: MPHR

\chapter{WMO BUFR}\label{app:bufr}

\ifbool{eps}{

This Appendix describes the mapping between variables in the EPS RO Level 1 data
format and WMO's \acrfull{bufr} format for RO measurements. The full description
of the RO BUFR format is outside the scope of this document; it is assumed that
the reader is familiar with the details of the RO BUFR format as defined in
\ref{ad:wmo_bufr}. The recommendations of IROWG (see \ref{rd:irowg_bufr}) were
taken into account, assuming they will be implemented in the foreseeable future.
}{% \ifbool{epssg} This Appendix describes the mapping between variables in the
EPS RO Level 1 data format and WMO's \acrfull{bufr} format for RO measurements.
The full description of the RO BUFR format is outside the scope of this
document; it is assumed that the reader is familiar with the details of the RO
BUFR format as defined in [RO-BUFR]. The recommendations of IROWG (see
[IROWG-BUFR]) were taken into account, assuming they will be implemented in the
foreseeable future. }

\section{BUFR Sections 1 (Identification) and 3 (Data Description)}

BUFR sections 1 is filled with meta data as described in the BUFR specification
\ifbool{eps}{(\ref{ad:wmo_bufr})}{[RO-BUFR]} using Edition 4 messages. The time
information ``most typical for [the] BUFR message content'' contained in octet
numbers 16-17 (year) and 18--22 (month, day, hour, minute and second) are
derived from the georeferencing time, i.e. from the variables
\texttt{utc_georef_absdate} and \texttt{utc_georef_abstime} in the
\texttt{/data/occultation} group.

Section 3 is to be set dynamically from the number of profiles (usually 1 in a
single BUFR message) and the message size. Note that there is no Section 2
(Optional Data) in RO BUFR products.


\section{BUFR Section 4 (Data Template)}

Quality information is stored in a single 16-bit data field (octet number 13),
where the detailed meaning of each flag is defined in Table 8 of
\ifbool{eps}{\ref{ad:wmo_bufr}}{[RO-BUFR]}. The mapping between BUFR and RO
Level 1 product quality flags is described in Tab.~\ref{tab:bufr_quality_flags}
below. 
%
\begin{table}[b]
  \centering
  \footnotesize
  \begin{tabularx}{0.95\textwidth}{cX>{\texttt\bgroup}l<{\egroup}}
    \toprule
    \multicolumn{1}{c}{\textbf{Bit}} &
    \multicolumn{1}{c}{\textbf{Description}} & 
    \multicolumn{1}{c}{\textbf{Variable}}  \\
    \midrule
    1 & Nominal / non-nominal quality            & /quality/overall\_quality \\
    2 & NRT / Offline product                    & /environment \\
    3 & Descending / ascending occultation       & /data/occultation/occultation\_type \\
    4 & Excess phase processing (non-) nominal   & /quality/cl\_snr\_[ca|p1|p2]\_ok \\
    5 & Bending angle processing (non-) nominal  & /quality/thinned\_ok \\
    6 & Refractivity processing (non-) nominal   & \textrm{\emph{Unused}} \\
    7 & Meteorological processing (non-) nominal & \textrm{\emph{Unused}} \\
    8 & Closed / open loop data only / included  & /quality/ol\_data\_used \\
    9 & (No) Surface reflections detected        & \textrm{\emph{Unused}} \\
    10 & L2P / L2C GPS signals used              & \textrm{\emph{Unused}} \\
    11-13 & Reserved                             & \textrm{\emph{Unused}} \\
    14 & Background profile (non-) nominal       & \textrm{\emph{Unused}} \\
    15 & Retrieved / background profile          & \textrm{\emph{Unused}} \\
    \bottomrule
  \end{tabularx}
  \caption{Mapping between BUFR Section 4 quality flags for RO and \ifbool{epssg}{EPS-SG RO L1}{RO level 1} data format quality flags.\label{tab:bufr_quality_flags}}
\end{table}

\begin{table}[p]
  \centering
  \footnotesize
  \begin{tabularx}{0.95\textwidth}{cX>{\texttt\bgroup}l<{\egroup}}
    \toprule
    \multicolumn{1}{c}{\textbf{Octet}} & 
    \multicolumn{1}{c}{\textbf{Variable(s)}} & 
    \multicolumn{1}{c}{\textbf{Remarks}} \\    
    \midrule
		\\ \addlinespace[-0.5em]
    \multicolumn{3}{l}{\textbf{Nominal Reporting Time}}\\
    \midrule
    7-12   & \texttt{/data/occultation/utc\_georef\_absdate} \newline 
    \texttt{/data/occultation/utc\_georef\_abstime} 
    & Assumes \ifbool{eps}{\ref{rd:irowg_bufr}}{[IROWG-BUFR]} is implemented \\
    
    \\ \addlinespace[-0.5em]
    \multicolumn{3}{l}{\textbf{RO Summary Quality Information}}\\
    \midrule
    13     & \textrm{\emph{various}}
    & see Tab.~\ref{tab:bufr_quality_flags} \\
    14     & \texttt{/quality/overall\_quality\_ok}
    & 100\% if True, 0\% otherwise \\
    
    \\ \addlinespace[-0.5em]
    \multicolumn{3}{l}{\textbf{LEO \& GNSS POD -- Location of Platform}}\\
    \midrule
    15-17  & \texttt{/data/occultation/position\_rec\_fixed} & Antenna phase centre positions\ldots \\
    18-20  & \texttt{/data/occultation/velocity\_rec}        & \ldots{}and velocities at georeferencing time \\
    21     & \texttt{/data/transmitter/satellite\_prn}       & First letter, e.g. \texttt{Gxx} $\rightarrow$ 401 (for GPS)\\
    22     & \texttt{/data/transmitter/satellite\_prn}       & Integer part, e.g. \texttt{1} $\rightarrow$ 1 (for PRN G01) \\
    23-25  & \texttt{/data/occultation/position\_gns\_fixed} &  Positions\ldots \\
    26-28  & \texttt{/data/occultation/velocity\_gns}        & \ldots{}and velocities at georeferencing time \\
    
    \\ \addlinespace[-0.5em]
    \multicolumn{3}{l}{\textbf{Local Earth Parameters}}\\
    \midrule
    29     & \textrm{\emph{always zero}}    & Assumes \ifbool{eps}{\ref{rd:irowg_bufr}}{[IROWG-BUFR]} is implemented \\
    30     & \texttt{/data/occultation/latitude} & Valid at georeferencing time \\
    31     & \texttt{/data/occultation/longitude} & \hspace{1em} \emph{ditto} \\
    32-34  & \texttt{/data/occultation/r\_curve\_centre\_fixed} &  \hspace{1em} \emph{ditto}\\
    35     & \texttt{/data/occultation/r\_curve} &  \hspace{1em} \emph{ditto}\\
    36     & \texttt{/data/occultation/azimuth\_north} &  \hspace{1em} \emph{ditto}\\
    37     & \texttt{/data/occultation/undulation} & \hspace{1em} \emph{ditto} \\
    
    \\ \addlinespace[-0.5em]
    \multicolumn{3}{l}{\textbf{RO Step 1b Data}}\\
    \midrule
    38     &  \texttt{len(/data/level\_1b/thinned/impact)} & Fixed number of levels; same for all products\\
    39     & \texttt{/data/level\_1b/thinned/lat\_tp} & \\
    40     & \texttt{/data/level\_1b/thinned/lon\_tp} & \\
    41     & \texttt{/data/level\_1b/thinned/azimuth\_tp} & \\
    42     & \texttt{3}                                   & for ionospheric corrected, L1, and L2 data \\
    43     & \texttt{0} or nominal carrier frequencies & 0 for ionospheric corrected bending angles \\
    44     & \texttt{/data/level\_1b/thinned/impact} & \\
    45     & \texttt{/data/level\_1b/thinned/bangle} \newline
    \texttt{/data/level\_1b/thinned/bangle\_ca} \newline
    \texttt{/data/level\_1b/thinned/bangle\_p2} \newline & \\
    46-48  & \textrm{\emph{Currently unused}}            & \\
    \bottomrule
  \end{tabularx}
  \caption{Mapping between BUFR Section 4 data fields and \ifbool{epssg}{EPS-SG RO L1}{RO level 1} data format variables.\label{tab:bufr_variable_mapping}}
\end{table}

Note that values stored in BUFR products will be matching BUFR conventions, in
some cases requiring a translation from the logical values used in the netCDF
granules as described in section~\ref{sec:conventions}. For example, in case on
Bit 1, the global attribute \texttt{environment} may exhibit values of
``Operational'', ``Validation'', ``Development'', ``Offline'',``Integration \&
Verification'', and ``Support'' (see section~\ref{sec:l1b_root}). Values of 
``Operational'' and ``Validation'' will be mapped to ``NRT product'', while the
remaining ones will be mapped to ``Offline product''. On the other hand, the
excess phase processing flag is calculated as the logical \texttt{and} of the
\verb|quality_snr_ca_ok|, \verb|quality_snr_p1_ok|, and \verb|quality_snr_p2_ok|
flags in the netCDF granule.

Tab.~\ref{tab:bufr_variable_mapping} links data fields as used in BUFR Section 4
entries (see Table 5 of \ifbool{eps}{\ref{ad:wmo_bufr})}{[RO-BUFR]} to the
corresponding variables in the netCDF granule data format. We finally note that
BUFR products generated by EUMETSAT do not contain any ``Step 2a'',  ``Level2a''
or ``Level2b'' data.

