Changes between Initial Version and Version 1 of OMI_debugging_PDAF3


Ignore:
Timestamp:
May 27, 2025, 3:48:49 PM (5 days ago)
Author:
lnerger
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OMI_debugging_PDAF3

    v1 v1  
     1= PDAF-OMI Debugging Information =
     2
     3{{{
     4#!html
     5<div class="wiki-toc">
     6<h4>PDAF-OMI Guide</h4>
     7<ol><li><a href="PDAF_OMI_Overview_PDAF3">Overview</a></li>
     8<li><a href="OMI_Callback_obs_pdafomi_PDAF3">callback_obs_pdafomi.F90</a></li>
     9<li><a href="OMI_observation_modules_PDAF3">Observation Modules</a></li>
     10<li><a href="OMI_observation_operators_PDAF3">Observation operators</a></li>
     11<li><a href="OMI_error_checking_PDAF3">Checking error status</a></li>
     12<li>Debugging functionality</li>
     13<li><a href="nondiagonal_observation_error_covariance_matrices_PDAF3">Using nondiagonal R-matrices</a></<li>
     14<li><a href="OMI_additional_functionality_PDAF3">Additional OMI Functionality</a></li>
     15<li><a href="Porting_to_OMI_PDAF3">Porting an existing implemention to OMI</a></li>
     16<br>
     17<li>Related page in Implementation Guide<li>
     18<ol>
     19<li><a href="ImplementationofAnalysisStep_PDAF3">Implementing the analysis step</a></li>
     20</ol>
     21</ol>
     22</div>
     23}}}
     24
     25[[PageOutline(2-3,Contents of this page)]]
     26
     27== Overview ==
     28
     29When implementing an observation with PDAF, or when performing the very first implementation of PDAF with a new model, it is useful to check whether the inputs to the PDAF-routines are correctly used. For this purpose, PDAF-OMI provides a debugging functionality. It allows you to activate debugging output e.g. for a single local analysis domain on a single process of a complex application of a local filter like LETKF.
     30
     31Note: There is a separate debugging output functionality for PDAF itself. For details see the [wiki:PDAF_debugging documentation on PDAF debugging]. One can activate the debugging for PDAF and PDAF-OMI separately or can used both in combination.
     32
     33
     34== Activating Debugging Output ==
     35
     36Debugging output is activated by a call of the form
     37{{{
     38   USE PDAFomi, ONLY: PDAFomi_set_debug_flag
     39   INTEGER :: dbg_id  ! Debugging flag: >0 for debug output; =0 for no debug output
     40
     41   CALLOMI PDAFomi_set_debug_flag(dbg_id)
     42}}}
     43In particular this call can be inserted in any routines contained in `callback_obs_pdafomi.F90`. Setting the single argument of `PDAFomi_set_debug_flag` to a value larger 0 will active the output, while =0 will deactivate it. For the debugging it is useful to keep the number of observations low since for a large number of observations, the output will be very lengthy. This can particularly be the case when using the debugging output in `init_dim_obs_pdafomi` or `obs_op_pdafomi`. To this end, it can be useful to intentionally reduce the number of observations for the debugging. For the localized filters (LESTKF, LETKF, LNETF, LSEIK) it is recommended to only activate the debugging for a single local analysis domain as shown below. The particular domain index can be chosen e.g. based on the coordinates of the domain, which are usually determined in `init_dim_l_pdaf`.
     44
     45For example to activate debugging in `init_dim_obs_l_pdafomi` for the local analysis domain `domain_p=10` and filter process 0, one uses
     46{{{
     47SUBROUTINE init_dim_obs_l_pdafomi(domain_p, step, dim_obs, dim_obs_l)
     48
     49  USE PDAFomi, ONLY: PDAFomi_set_debug_flag
     50  USE mod_parallel_pdaf, ONLY: mype_filter
     51
     52  ...
     53
     54  IF (domain_p==10 .AND. mype_filter==0) THEN
     55    CALL PDAFomi_set_debug_flag(domain_p)
     56  ELSE
     57    CALL PDAFomi_set_debug_flag(0)
     58  ENDIF
     59
     60  ...
     61
     62}}}
     63
     64== Understanding the Debugging Output ==
     65
     66The debugging output mainly writes information about the different variables contained in the full data type `obs_f` allocated as `thisobs` and the local type `obs_l` allocate as `thisobs_l`. For reference we list the full declaration of these types. When reading the debugging output one can check for the meaning of the variables.
     67
     68{{{
     69  TYPE obs_f
     70     ! ---- Mandatory variables to be set in INIT_DIM_OBS ----
     71     INTEGER :: doassim=0                 !< Whether to assimilate this observation type
     72     INTEGER :: disttype                  !< Type of distance computation to use for localization
     73     INTEGER :: ncoord                    !< Number of coordinates use for distance computation
     74     INTEGER, ALLOCATABLE :: id_obs_p(:,:) !< Indices of process-local observed field in state vector
     75
     76     ! ---- Optional variables - they can be set in INIT_DIM_OBS ----
     77     REAL, ALLOCATABLE :: icoeff_p(:,:)   !< Interpolation coefficients for obs. operator (optional)
     78     REAL, ALLOCATABLE :: domainsize(:)   !< Size of domain for periodicity (<=0 for no periodicity) (optional)
     79
     80     ! ---- Variables with predefined values - they can be changed in INIT_DIM_OBS  ----
     81     INTEGER :: obs_err_type=0            !< Type of observation error: (0) Gauss, (1) Laplace
     82     INTEGER :: use_global_obs=1          !< Whether to use (1) global full obs.
     83                                          !< or (0) obs. restricted to those relevant for a process domain
     84     REAL :: inno_omit=0.0                !< Omit obs. if squared innovation larger this factor times
     85                                          !<     observation variance (only active for >0)
     86     REAL :: inno_omit_ivar=1.0e-12       !< Value of inverse variance to omit observation
     87                                          !<     (should be much larger than actual observation error variance)
     88
     89     ! ----  The following variables are set in the routine PDAFomi_gather_obs ---
     90     INTEGER :: dim_obs_p                 !< number of PE-local observations
     91     INTEGER :: dim_obs_f                 !< number of full observations
     92     INTEGER :: dim_obs_g                 !< global number of observations
     93     INTEGER :: off_obs_f                 !< Offset of this observation in overall full obs. vector
     94     INTEGER :: off_obs_g                 !< Offset of this observation in overall global obs. vector
     95     INTEGER :: obsid                     !< Index of observation over all assimilated observations
     96     REAL, ALLOCATABLE :: obs_f(:)        !< Full observed field
     97     REAL, ALLOCATABLE :: ocoord_f(:,:)   !< Coordinates of full observation vector
     98     REAL, ALLOCATABLE :: ivar_obs_f(:)   !< Inverse variance of full observations
     99     INTEGER, ALLOCATABLE :: id_obs_f_lim(:) !< Indices of domain-relevant full obs. in global vector of obs.
     100  END TYPE obs_f
     101}}}
     102
     103{{{
     104  TYPE obs_l
     105     INTEGER :: dim_obs_l                 !< number of local observations
     106     INTEGER :: off_obs_l                 !< Offset of this observation in overall local obs. vector
     107     INTEGER, ALLOCATABLE :: id_obs_l(:)  !< Indices of local observations in full obs. vector
     108     REAL, ALLOCATABLE :: distance_l(:)   !< Distances of local observations
     109     REAL, ALLOCATABLE :: cradius_l(:)    !< directional cut-off radii of local observations
     110     REAL, ALLOCATABLE :: sradius_l(:)    !< directional support radii of local observations
     111     REAL, ALLOCATABLE :: ivar_obs_l(:)   !< Inverse variance of local observations
     112     INTEGER :: locweight                 !< Specify localization function
     113     REAL, ALLOCATABLE :: cradius(:)      !< Localization cut-off radius (single value or vector)
     114     REAL, ALLOCATABLE :: sradius(:)      !< support radius for localization function (single value or vector)
     115  END TYPE obs_l
     116}}}
     117
     118=== Example output ===
     119
     120For illustration we insert the above call to PDAFomi_set_debug flag into the routine `init_dim_obs_l_pdafomi` the file `callback_obs_pdafomi.F90` in `tutorial/online_2D_serialmodel/`. Then we compile and execute the tutorial program with:
     121{{{
     122  mpirun -np 4 ./model_pdaf -dim_ens 4 -filtertype 7 -cradius 5 -locweight 2
     123}}}
     124
     125The first lines of the debugging output looks like this:
     126{{{
     127 ++ OMI-debug set_debug_flag: mype_filter           0 activate          10
     128 ++ OMI-debug:           10 PDAFomi_init_dim_obs_l -- START
     129 ++ OMI-debug:           10    PDAFomi_init_dim_obs_l -- count local observations
     130 ++ OMI-debug init_dim_obs_l:          10   Re-init dim_obs_l=0
     131 ++ OMI-debug init_dim_obs_l:          10   coords_l   1.0000000000000000        10.000000000000000     
     132 ++ OMI-debug init_dim_obs_l:          10   Note: Please ensure that coords_l and observation coordinates have the same unit
     133 ++ OMI-debug cnt_dim_obs_l:           10   thisobs%ncoord           2
     134 ++ OMI-debug cnt_dim_obs_l:           10   thisobs_l%cradius   5.0000000000000000     
     135 ++ OMI-debug cnt_dim_obs_l:           10   Check for observations within radius
     136 ++ OMI-debug comp_dist2:              10   compute Cartesian distance
     137 ++ OMI-debug cnt_dim_obs_l:           10   valid observation with coordinates   5.0000000000000000        8.0000000000000000     
     138 ++ OMI-debug cnt_dim_obs_l:           10   valid observation with coordinates   5.0000000000000000        12.000000000000000     
     139 ++ OMI-debug:           10    PDAFomi_init_dim_obs_l -- initialize local observation arrays
     140 ++ OMI-debug comp_dist2:              10   compute Cartesian distance
     141 ++ OMI-debug init_dim_obs_l:          10   thisobs_l%dim_obs_l           2
     142 ++ OMI-debug init_dim_obs_l:          10   thisobs_l%id_obs_l           2           3
     143 ++ OMI-debug init_dim_obs_l:          10   thisobs_l%distance_l   4.4721359549995796        4.4721359549995796     
     144 ++ OMI-debug:           10 PDAFomi_init_dim_obs_l -- END
     145}}}
     146
     147The first line
     148{{{
     149 ++ OMI-debug set_debug_flag: mype_filter           0 activate          10
     150}}}
     151is from PDAFomi_set_debug_flag showing that debugging is activates with value 10 (which is values fo `domain_p` specified in the call)
     152
     153The next lines are
     154{{{
     155 ++ OMI-debug:           10 PDAFomi_init_dim_obs_l -- START           
     156 ++ OMI-debug:           10    PDAFomi_init_dim_obs_l -- count local observations
     157 ++ OMI-debug init_dim_obs_l:          10   Re-init dim_obs_l=0
     158}}}
     159show that debugging output for PDAFomi_init_dim_obs_l is shown. Most routines show such a 'START' line. The second line shows that a segment of the routine started, the counting of local observations. The third line states that dim_obs_l=0 is set. This line, as many others shows the name of the subroutine in short form without `PDAFomi` at the beginning of the line.
     160
     161The following lines show variable values
     162{{{
     163 ++ OMI-debug init_dim_obs_l:          10   coords_l   1.0000000000000000        10.000000000000000     
     164 ++ OMI-debug cnt_dim_obs_l:           10   thisobs%ncoord           2
     165 ++ OMI-debug cnt_dim_obs_l:           10   thisobs_l%cradius   5.0000000000000000     
     166}}}
     167First, we see that the coordinates `coords_l` of the grid point corresponding to domain_p=10 are (1.0, 10.0). Further we have two dimensions (thisobs%ncoord=2) and the localization radius is set to 5.0.
     168In the following lines
     169{{{
     170 ++ OMI-debug cnt_dim_obs_l:           10   Check for observations within radius
     171 ++ OMI-debug comp_dist2:              10   compute Cartesian distance
     172 ++ OMI-debug cnt_dim_obs_l:           10   valid observation with coordinates   5.0000000000000000        8.0000000000000000     
     173 ++ OMI-debug cnt_dim_obs_l:           10   valid observation with coordinates   5.0000000000000000        12.000000000000000 
     174}}}
     175it is checked which observations lie within the distance thisobs_l%cradius=5.0 from coords_l=(1.0, 10.0). Two observations with coordinates (5.0, 8.0) and (5.0, 12.0) are found. The following lines
     176{{{
     177 ++ OMI-debug:           10    PDAFomi_init_dim_obs_l -- initialize local observation arrays
     178 ++ OMI-debug comp_dist2:              10   compute Cartesian distance
     179 ++ OMI-debug init_dim_obs_l:          10   thisobs_l%dim_obs_l           2
     180 ++ OMI-debug init_dim_obs_l:          10   thisobs_l%id_obs_l           2           3
     181 ++ OMI-debug init_dim_obs_l:          10   thisobs_l%distance_l   4.4721359549995796        4.4721359549995796     
     182}}}
     183show that observation arrays are initialized. A Cartesian distance is computrd. `thisobs_l%dim_obs_l` confirms that 2 local observation were found and they are the elements 2 and 3 of the full observation vector (thisobs_l%id_obs_l= (2, 3)) and the distances are thisobs_l%distance_l=(4.4721359549995796, 4.4721359549995796)
     184
     185One could now compare this with the input information. Are the values of coords_l correct? Are the coordinates shown those of the second and third observation?
     186
     187Later in the debugging output (not shown above) we find, for example,
     188{{{
     189 ++ OMI-debug:           10    PDAFomi_init_obs_l -- Get local vector of observations
     190 ++ OMI-debug g2l_obs:                 10   thisobs_l%id_obs_l           2           3
     191 ++ OMI-debug g2l_obs:                 10   obs_l -0.84588099999999999       -1.5201499999999999     
     192 ++ OMI-debug:           10    PDAFomi_init_obs_l -- Get local vector of inverse obs. variances
     193 ++ OMI-debug g2l_obs:                 10   thisobs_l%id_obs_l           2           3
     194 ++ OMI-debug g2l_obs:                 10   obs_l   4.0000000000000000        4.0000000000000000   
     195}}}
     196These lines are from the internal routine `PDAFomi_init_obs_l`, which initializes the local vector of observations. (This is functionality also existing in the 'traditional' form of implementing the observation handling. The documention page about [wiki:init_obs_l_pdaf init_obs_l_pdaf] explains what is done here.) Important is that not only the local observation vector (two values) is initialized, but also the inverse observation variance (4.0 in this example).
     197
     198Similarly
     199{{{
     200 ++ OMI-debug:           10 PDAFomi_g2l_obs -- START Get local observed ensemble member           1
     201 ++ OMI-debug g2l_obs:                 10   thisobs_l%id_obs_l           2           3
     202 ++ OMI-debug g2l_obs:                 10   obs_l -0.53940120224649080       0.56425243172725248     
     203 ++ OMI-debug:           10 PDAFomi_g2l_obs -- END
     204}}}
     205shows the localization of the observed ensemble member 1. This is performed in the internal routine `PDAFomi_g2l_obs` (see the page about [wiki:g2l_obs_pdaf g2l_obs_pdaf]). There is analogous output for all of the 4 ensemble states.
     206
     207