_Diagnostics.dox

1/*! \page Diagnostics Diagnostics
2
3\brief Controlling run-time diagnostics and how to add diagnostics to the code
4
5MOM6 diagnostics are orchestrated via the FMS diag_manager, as for previous versions of MOM.
6However, because MOM6 is a general coordinate model, the model native-coordinae output can be less familiar to users of earlier generations of MOM.
7To alleviate this problem, MOM6 provides both "native" and "remapped" diagnostics;
8the former being diagnostics in the actual model coordinate space, and the latter in user-defined coordinates.
9
10\section diag_table The "diag_table"
11
12At run-time, diagnostics are controlled by the input file `diag_table` which is interpreted but the FMS package diag_manager.
13
14The diag_table file has three kinds of section: Title, File and Field. The title section is mandatory and always the first.
15There can be multiple file and field sections, typically either in pairs or grouped in to all files and all fields,
16but always with the file section preceding the corresponding field section.
17
18\subsection diag_table_title Title section
19
20The first two lines are mandatory and comprise a line with a title and a line with six integers defining a base date against which time will be referenced.
21
22```
23"My ocean-only test case"
241900 1 1 0 0 0
25```
26
27
28\subsection diag_table_files File section
29
30This section defines an arbitrary number of files that will be created.
31Each file is limited to a single rate of either sampling or time-averaging.
32
33```
34"file_name", output_freq, "output_freq_units", file_format, "time_axis_units", "time_axis_name"
35```
36
37- `file_name` : The name of the file that contains diagnostics at the given frequency (excluding the ".nc" extension).
38
39- `output_freq` : The period between records in `file_name`, if positive.
40 Special values of 0 mean write every time step and -1 write only at the end of the run.
41
42- `output_freq_units` : The units in which `output_freq` is given.
43 Valid values are "years", "months", "days", "hours", "minutes" or "seconds".
44
45- `file_format` : Always set to 1, meaning netcdf.
46
47- `time_axis_units` : The units to use for the time-axis in the file.
48 Valid values are "years", "months", "days", "hours", "minutes" or "seconds".
49
50- `time_axis_name` : The name of the time-axis (usually "Time").
51
52Optional entries in the file line allow the generation of multiple files are intervals:
53
54```
55"file_name", output_freq, "output_freq_units", file_format, "time_axis_units", "time_axis_name"[, new_file_freq, "new_file_freq_units"[, "start_time"[, file_duration, "file_duration_units"]]]
56```
57
58- file_name : The base name of the file that contains diagnostics at the given frequency (excluding the ".nc" extension).
59 The strings %%yr, %%mo, %%dy, %%hr %%mi, %%sc are expanded to the current year, month, day, hour, minute and second respectively, with new files created every new_file_freq.
60
61- `new_file_freq` : The period between generation of new files.
62
63- `new_file_freq_units` : The units in which `new_file_freq` is given.
64
65- `start_time`, `file_duration`, `file_duration_units` : Even finer grain control of output files.
66
67
68\subsection diag_table_fields Field section
69
70An arbitrary number of lines, one per diagnostic field:
71
72```
73"module_name", "field_name", "output_name", "file_name", "time_sampling", "reduction_method", "regional_section", packing
74```
75
76- `module_name` : Name of the component model.
77 For native ocean variables this should be "ocean_model".
78 See \ref remapped_diagnostics for non-native vertical-grid diagnostics in the ocean model.
79
80- `field_name` : The name of the variable as registered in the model.
81
82- `output_name` " The name of the variable as it will appear in the file.
83 This is usually the same as the `field_name` but can be used to rename a diagnostic.
84
85- `file_name` : One of the files defined above in the section \ref diag_table_files.
86
87- `time_sampling` : Always set to "all".
88
89- `reduction_method` : "none" means sample or snapshot.
90 "average" or "mean" performs a time-average.
91 "min" or "max" diagnose the minium or maxium over each time period.
92
93- `regional_section` : "none" means global output. A string of six space separated numbers, "lon_min lon_max lat_min lat_max vert_min vert_max", limits the diagnostic to a region.
94
95- `packing` : Data representation in the file. 1 means "real*8", 2 means "real*4", 4 mean 16-bit integers, 8 means 1-byte.
96
97
98\subsection diag_table_example Example
99
100
101```
102"OM4 1/4 degree"
1031900 1 1 0 0 0
104
105# Static file
106"ocean_static", -1, "months", 1, "days", "time" # ocean_static is a protected name. Do not change this line.
107"ocean_model", "deptho", "deptho", "ocean_static", "all", "none", "none", 2
108"ocean_model", "geolon", "geolon", "ocean_static", "all", "none", "none", 2
109"ocean_model", "geolat", "geolat", "ocean_static", "all", "none", "none", 2
110"ocean_model", "wet", "wet", "ocean_static", "all", "none", "none", 2
111
112# High-frequency file
113"surf_%4yr_%3dy", 1, "hours", 1, "days", "time", 1, "months"
114"ocean_model","SSH","SSH","surf_%4yr_%3dy","all","none","none",2
115
116# Daily averages
117"ocean_daily", 1, "days", 1, "days", "time"
118"ocean_model", "tos", "tos", "ocean_daily", "all", "mean", "none",2
119
120# Monthly averages
121"ocean_month", 1, "months", 1, "days", "time"
122"ocean_model", "thetao", "thetao", "ocean_month", "all", "mean", "none",2
123
124# Annual averages
125"ocean_annual", 12, "months", 1, "days", "time"
126"ocean_model", "thetao", "thetao", "ocean_annual", "all", "mean", "none",2
127
128# Vertical section
129"ocean_Bering_Strait", 5, "days", 1, "days", "time"
130"ocean_model", "thetao","thetao", "ocean_Bering_Strait", "all", "mean", "-171.4 -168.7 66.1 66.1 -1 -1",2
131```
132
133
134\section native_diagnostics Native diagnostics
135
136The list of available diagnostics is dependent on the particular configuration of the model.
137For this reason the model writes a record of the available diagnostic fields at run-time into a file "available_diags.*".
138See, for example, [available_diags.000000](https://github.com/NOAA-GFDL/MOM6-examples/blob/dev/master/ocean_only/global_ALE/z/available_diags.000000) for the global_ALE z-coordinate ocean-only test case.
139
140Diagnostic fields in the module "ocean_model" refer to the native variables or diagnostics in the native grid.
141Since the model can be run in arbitrary coordinates, say in hybrid-coordinate mode, then native-space diagnostics can be potentially confusing.
142Native diagnostics are useful when examining exactly what the model is doing,
143or if the vertical coordinate of the model is configured to be a natural coordinate such as pure isopycnal or z* geopotential.
144
145
146\section remapped_diagnostics Vertically remapped diagnostics
147
148Alternative vertical coordinates can be configured for diagnostic purposes only.
149
150The run-time parameter `NUM_DIAG_COORDS` controls how many diagnostic coordinates to use.
151
152The run-time parameter `DIAG_COORDS` defines the mapping between each coordinate, the name of the module in the diag_table and run-time parameter names that define the coordinate.
153A list of string tuples, separated by commas, with each tuple in the form of MODULE_SUFFIX PARAMETER_SUFFIX COORDINATE_NAME.
154`MODULE_SUFFIX` is the string appended to "ocean_model" to create a module in the diag_table.
155`PARAMETER_SUFFIX` is the string appended to "DiAG_COORD_DEF", and other parameters, used to control the generation of the named coordinate.
156`COORDINATE_NAME` is a name understood by the MOM6 regridding module. Valid examples are "ZSTAR", "SIGMA", "RHO", etc.
157
158By default, `NUM_DIAG_COORDS=1` and `DIAG_COORDS="z Z ZSTAR"`, meaning the module "ocean_model_z" provides diagnostics in "z*" coordinates and uses the parameter `DIAG_COORD_DEF_Z`.
159
160For example, multiple z*-coordinates could be used for diagnostics with
161```
162NUM_DIAG_COORDS = 2
163DIAG_COORDS = "z 01 ZSTAR,abc 02 ZSTAR"
164DIAG_COORD_DEF_01 = "WOA09"
165DIAG_COORD_DEF_02 = "UNIFORM:10,20."
166```
167would create the diag_manager modules "ocean_model_z" and "ocean_model_abc".
168
169The above is equivalent to
170```
171NUM_DIAG_COORDS = 2
172DIAG_COORDS = "z ZA ZSTAR,abc ZB ZSTAR"
173DIAG_COORD_DEF_ZA = "WOA09"
174DIAG_COORD_DEF_ZB = "UNIFORM:10,20."
175```
176
177To obtain a diagnostic of monthly-averaged potential temperature in both these coordinate systems the diag_table must include the lines
178
179```
180"ocean_month_z", 1, "months", 1, "days", "time"
181"ocean_month_abc", 1, "months", 1, "days", "time"
182"ocean_model_z", "temp", "temp", "ocean_month_z", "all", "mean", "none",2
183"ocean_model_abc", "temp", "temp", "ocean_month_abc", "all", "mean", "none",2
184```
185
186
187\subsection diag_table_vertical_coords Diagnostic vertical coordinates
188
189For each of the `NUM_DIAG_COORDS` vertical coordinates listed in `DIAG_COORDS` the corresponding `DIAG_COORD_DEF_%` parameter must be provided.
190It can take the following values:
191- PARAM : In this case, a corresponding parameter `DIAG_COORD_RES_%` is read that lists the deltas for each level in the coordinate.
192 For example, DIAG_COODS="z Z ZTAR", DIAG_COORD_DEF_Z="PARAM", DIAG_COORD_RES_Z=5,10,10,15 creates z*-level with 5,10,10,15 meters thicknesses.
193- UNIFORM : Uniform distribution down to the maximum depth of the model using the same number of levels as he model.
194- UNIFORM:N : Uniform distribution down to the maximum depth of the model using `N` levels.
195- UNIFORM:N,D : Uniform distribution of `N` levels with thickness `D`.
196- FILE:filename,varname : Reads vector of coordinate thicknesses from field "varname" from file "filename".
197- FILE:filename,interfaces=varname : Reads vector of coordinate positions from field "varname" from file "filename".
198- WOA09 : Z-levels that correspond to the World Ocean Atlas, 2009, standard levels down to and including the maximum depth of the model.
199- WOA09:N : The first `N` levels of the World Ocean Atlas, 2009, standard levels.
200
201
202
203\section diagnostics_implementation APIs for diagnostics
204
205The multiple diagnostic-coordinates are implemented in a layer that sits on top of the FMS diag_manager known as the mom6_diag_mediator.
206
207A diagnostic is registered with register_diag_field() which is an API that looks similar to the FMS diag_manager routine of the same name:
208```
209diag_id = register_diag_field(module_name, diag_name, axes, ...)
210```
211
212The MOM6 version of this routine optionally allows the specification of CMOR names in addition to the native names which then registers the diagnostic twice, once with each name.
213
214For each of the native and CMOR names, the diagnostic is registered in the native module "ocean_model", corresponding to the native model coordinate, and a module associated with each of the diagnostic coordinates.
215
216For each diagnostic coordinate, a horizontally-averaged diagnostic is also registered.
217
218In all, for each 3D diagnostic, the are 2 + 4N diagnostics registered, where N is the number of diagnostic coordinates.
219As a result, the global_ALE examples have of order 900 total diagnostics available in the shipped configuration.
220
221
222The data is made available to the diag_manager via a call to post_data() which is a wrapper that does all the vertical remapping before calling FMS's send_data():
223```
224call post_data(diag_id, data, diag_control)
225```
226
227\subsection diag_post_frequency Artifacts of posting frequency for diagnostics
228
229Variables area "posted" for i/o or averaging to the diag_manager (via MOM6's diag_mediator) at different frequencies relative to each other.
230This is because the MOM6 algorithm takes the form of nested sub-cycles with different time-steps in each loop (e.g. barotropic solver with dynamics).
231A consequence of this is that a time average of a related quantities may appear to be inconsistent since the diagnostic posted with higher frequency may not vary linearly between the end-points seen on the longer time-step.
232The differences are usually small, but if you see large differences it might indicate you should re-examine the time-steps used for the various sub-cycles.
233
234*/