Skip to content

Commit d235de0

Browse files
authored
Merge branch 'mahf708/eamxx/subsampling-diags' (PR #7508)
The conditional sampling diagnostic allows youto extract field values where a specified condition is met, filling other locations with a default fill value. This is useful for analyzing field behavior under specific atmospheric conditions or at particular levels. The goal of the diagnostics is to enable you to discard unwanted data via other reductions, such as horizontal and vertical reductions (see "Field contraction" section of the docs). Additionally they allow you to better track certain diagnostics. [BFB]
2 parents 262cb1f + eceb906 commit d235de0

16 files changed

+1190
-34
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Conditional sampling
2+
3+
The conditional sampling diagnostic allows you to extract field values
4+
where a specified condition is met, filling other locations with a
5+
default fill value. This is useful for analyzing field behavior under
6+
specific atmospheric conditions or at particular levels.
7+
The goal of the diagnostics is to enable you to discard unwanted data
8+
via *other* reductions, such as horizontal and vertical reductions
9+
(see "Field contraction" section of the docs).
10+
11+
## Overview
12+
13+
Conditional sampling creates a new field where:
14+
15+
- Values from the input field are preserved
16+
where the condition is **true**
17+
- Fill values (default: large number) are used
18+
where the condition is **false**
19+
20+
The general syntax is: `<input>_where_<condition>_<operator>_<value>`
21+
22+
## Supported operators
23+
24+
| Operator | Aliases | Description |
25+
| -------- | ------- | ----------- |
26+
| `eq` | `==` | Equal to |
27+
| `ne` | `!=` | Not equal to |
28+
| `gt` | `>` | Greater than |
29+
| `ge` | `>=` | Greater than or equal to |
30+
| `lt` | `<` | Less than |
31+
| `le` | `<=` | Less than or equal to |
32+
33+
## Field-based conditional sampling
34+
35+
Compare the input field against another field at each grid point.
36+
37+
**Examples**:
38+
39+
- `T_mid_where_qv_gt_0.01`
40+
- `p_mid_where_T_mid_le_273.15`
41+
- `qv_where_p_mid_lt_50000`
42+
43+
## Level-based conditional sampling
44+
45+
Compare against the vertical level index (0-based indexing).
46+
Use the special condition field name `lev`.
47+
48+
**Examples**:
49+
50+
- `T_mid_where_lev_gt_5`
51+
- `p_mid_where_lev_eq_0`
52+
- `qv_where_lev_le_10`
53+
54+
## Count-based conditional sampling
55+
56+
Count the number of grid points where a condition is met.
57+
Use the special input field name `count`. The output will be `1.0`
58+
where the condition is satisfied and the fill value elsewhere.
59+
This is particularly useful when combined with horizontal or vertical
60+
reductions to count occurrences of specific conditions.
61+
62+
**Examples**:
63+
64+
- `count_where_qv_gt_0.01`
65+
- `count_where_T_mid_le_273.15`
66+
- `count_where_p_mid_lt_50000`
67+
- `count_where_lev_gt_5`
68+
69+
## Caveats
70+
71+
- For now, we only support 1D or 2D fields.
72+
These include most fields of interest with the following layouts
73+
(ncol,), (nlev,), (ncol,nlev).
74+
Adding support for higher-dimensioned fields is straightforward,
75+
but we will add it when requested.
76+
- The condition and input fields must have the same layout
77+
(except for level-based sampling). In level-based sampling,
78+
the level index must be present in the field.
79+
- The condition is provided as a triplet of information string
80+
(`<condition>_<operator>_<value>`). We assume the user knows
81+
the standard unit of the condition that is used internally
82+
in EAMxx field manager (there is no way to specify it).
83+
84+
## Example configuration
85+
86+
```yaml
87+
%YAML 1.1
88+
---
89+
filename_prefix: conditional_sampling_outputs
90+
averaging_type: instant
91+
fields:
92+
physics_pg2:
93+
field_names:
94+
# Field-based conditional sampling
95+
- T_mid_where_qv_gt_0.01
96+
- p_mid_where_T_mid_le_273.15
97+
- qv_where_p_mid_lt_50000
98+
# Level-based conditional sampling
99+
- T_mid_where_lev_gt_5
100+
- p_mid_where_lev_eq_0
101+
- qv_where_lev_le_10
102+
# Count-based conditional sampling
103+
- count_where_qv_gt_0.01
104+
- count_where_T_mid_le_273.15
105+
- count_where_lev_gt_5
106+
output_control:
107+
frequency: 6
108+
frequency_units: nhours
109+
```

components/eamxx/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ nav:
1818
- 'Diagnostics':
1919
- 'Overview': 'user/diags/index.md'
2020
- 'Field contraction diagnostics': 'user/diags/field_contraction.md'
21+
- 'Conditional sampling': 'user/diags/conditional_sampling.md'
2122
- 'Presentations': 'user/presentations.md'
2223
- 'Developer Guide':
2324
- 'Quick-start Guide': 'developer/dev_quickstart.md'

components/eamxx/src/diagnostics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ set(DIAGNOSTIC_SRCS
2424
wind_speed.cpp
2525
vert_contract.cpp
2626
zonal_avg.cpp
27+
conditional_sampling.cpp
2728
)
2829

2930
add_library(diagnostics ${DIAGNOSTIC_SRCS})

0 commit comments

Comments
 (0)