You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _episodes/05-preprocessor.md
+83-20Lines changed: 83 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,18 @@
1
1
---
2
2
title: "Working with preprocessors"
3
-
teaching: 20?
4
-
exercises: 15?
3
+
teaching: 20
4
+
exercises: 20
5
5
questions:
6
6
- "How do I set up a preprocessor?"
7
7
- "Can I use different preprocessors for different variables?"
8
8
- "Can I use different datasets for different variables?"
9
+
- "How can I combine different preprocessor functions?"
9
10
objectives:
10
11
- "Create a recipe with multiple preprocessors"
11
12
- "Use different preprocessors for different variables"
12
13
- "Run a recipe with variables from different datasets"
13
14
keypoints:
14
-
- "A recipe can run different preprocessors at the same time."
15
+
- "A recipe can work with different preprocessors at the same time."
15
16
- "The setting additional_datasets can be used to add a different dataset."
16
17
- "Variable groups are useful for defining different settings for different variables."
17
18
---
@@ -38,7 +39,7 @@ Each preprocessor section includes a preprocessor name, a list of preprocessor s
38
39
39
40
For instance, the 'annual_statistics' with the 'operation: mean' argument preprocessor receives an iris cube, takes the annual average for each year of data in the cube, and returns the processed cube.
40
41
41
-
You could use several preprocessor steps listed in the [documentation](https://docs.esmvaltool.org/projects/esmvalcore/en/latest/recipe/preprocessor.html). The standardised interface between the preprocessors allows them to be used modularly - like lego blocks. Almost any conceivable preprocessing order of operations can be performed using ESMValTool preprocessors.
42
+
You may use one or more of several preprocessors listed in the [documentation](https://docs.esmvaltool.org/projects/esmvalcore/en/latest/recipe/preprocessor.html). The standardised interface between the preprocessors allows them to be used modularly - like lego blocks. Almost any conceivable preprocessing order of operations can be performed using ESMValTool preprocessors.
42
43
43
44
> ## The 'custom order' command.
44
45
>
@@ -50,16 +51,16 @@ You could use several preprocessor steps listed in the [documentation](https://d
50
51
>
51
52
>The default preprocessor order is listed in the [ESMValCore preprocessor API page](>https://docs.esmvaltool.org/projects/ESMValCore/en/latest/api/esmvalcore.preprocessor.html).
52
53
>
53
-
> Also note that not preprocessor operations aren't always commutative - meaning that the order of operations matters. For instance, if you run the preprocessor 'extract_volume' to extract the top 100m of the ocean surface, then 'volume_statistics' to calculate the volume-weighted mean of the data, then your result will differ depending on the order of these two preprocessors. In fact, the 'extract_volume' preprocessor will fail if you try to run it on a 2D dataset.
54
+
> Also note that preprocessor operations aren't always commutative - meaning that the order of operations matters. For instance, when you run the two preprocessors -- 'extract_volume' to extract the top 100m of the ocean surface and 'volume_statistics' to calculate the volume-weighted mean of the data, your result will differ depending on the order of these two preprocessors. In fact, the 'extract_volume' preprocessor will fail if you try to run it on a 2D dataset.
54
55
>
55
56
> Changing the order of preprocessors can also speed up your processing. For instance, if you want to extract a two-dimensional layer from a 3D field and re-grid it, the layer extraction should be done first. If you did it the other way around, then the regridding function would be applied to all the layers of your 3D cube and it would take much more time.
56
57
{: .callout}
57
58
58
-
Some preprocessor stages are always applied and do not need to be called. This includes the preprocessors that load the data, apply the fixes, and save the data file afterwards. They do not need to be explicitly included in recipes.
59
+
Some preprocessor modeules are always applied and do not need to be called. This includes the preprocessors that load the data, apply any fixes and save the data file afterwards. These do not need to be explicitly included in recipes.
59
60
60
61
> ## Exercise: Adding more preprocessor steps
61
62
>
62
-
> Edit the [example recipe](LINK to episode #4) to change the variable in ?thetao? and to add preprocessors which take the average over the latitude and longitude dimensions and the average over the depth. And then run the recipe.
63
+
> Edit the [example recipe](LINK to episode #4) to first change the variable thetao, then add preprocessors to average over the latitude and longitude dimensions and finally average over the depth. Now run the recipe.
63
64
>
64
65
>> ## Solution
65
66
>>
@@ -78,7 +79,7 @@ Some preprocessor stages are always applied and do not need to be called. This i
78
79
79
80
## Using different preprocessors for different variables
80
81
81
-
You could define different preprocessors with several preprocessor sections (setting different preprocessor names). In the variable section you call the specific preprocessor which should be applied.
82
+
You can also define different preprocessors with several preprocessor sections (setting different preprocessor names). In the variable section you call the specific preprocessor which should be applied.
82
83
83
84
> ## Example
84
85
>~~~YAML
@@ -91,7 +92,7 @@ You could define different preprocessors with several preprocessor sections (set
@@ -114,14 +115,14 @@ You could define different preprocessors with several preprocessor sections (set
114
115
> short_name: thetao
115
116
> preprocessor: prep_timeseries_2
116
117
> scripts:
117
-
> timeseries_diag:
118
+
> timeseries_diag:
118
119
> script: ocean/diagnostic_timeseries.py
119
120
>~~~
120
121
>{: .source}
121
122
{: .solution}
122
123
123
124
>## Challenge : How to write a recipe with multiple preprocessors
124
-
> We now know that a recipe can have more than one diagnostic, variable or preprocessor. As we saw in the examples so far, we can group preprocessors with a single user defined name and can have more than one such preprocessor group in the recipe as well. Write two different preprocessors - one to regrid the data to a 1x1 resolution and the second preprocessor to mask out sea and ice grid cells before regridding to the saem resolution. In the second case, ensure you perform the masking first before regridding (hint: custom order your operations). Now, use the two preprocessors in different diagnostics within the same recipe. You may use any variable(s) of your choice. Once you succeed, try to add new datasets to the same recipe. Placeholders for the different components are provided below:
125
+
> We now know that a recipe can have more than one diagnostic, variable or preprocessor. As we saw in the examples so far, we can group preprocessors with a single user defined name and can have more than one such preprocessor group in the recipe as well. Write two different preprocessors - one to regrid the data to a 1x1 resolution and the second preprocessor to mask out sea and ice grid cells before regridding to the same resolution. In the second case, ensure you perform the masking first before regridding (hint: custom order your operations). Now, use the two preprocessors in different diagnostics within the same recipe. You may use any variable(s) of your choice. Once you succeed, try to add new datasets to the same recipe. Placeholders for the different components are provided below:
125
126
>
126
127
>> ## Recipe
127
128
>>
@@ -168,8 +169,7 @@ You could define different preprocessors with several preprocessor sections (set
168
169
>
169
170
>> ## Solution:
170
171
>>
171
-
>> Here is one possible way to use two different preprocessors including a
172
-
>> group of preprocessors on different variables.
172
+
>> Here is one solution to complete the challenge above using two different preprocessors
173
173
>>
174
174
>>~~~YAML
175
175
>>
@@ -184,7 +184,7 @@ You could define different preprocessors with several preprocessor sections (set
184
184
>> scheme: linear #how to interpolate for regridding
185
185
>>
186
186
>> prep_map_land:
187
-
>> custom_order: true #ensure order follows a given
187
+
>> custom_order: true #ensure that given order of preprocessing is followed
188
188
>> mask_landsea: #apply a mask
189
189
>> mask_out: sea #mask out sea grid cells
190
190
>> regrid: # now apply the preprocessor to regrid
@@ -205,7 +205,6 @@ You could define different preprocessors with several preprocessor sections (set
205
205
>> grid: gn #can change for variables from the same model
206
206
>> start_year: 1970
207
207
>> end_year: 2000
208
-
>> additional_datasets:
209
208
>> scripts: null
210
209
>>
211
210
>> diag_land_only_plot:
@@ -217,7 +216,6 @@ You could define different preprocessors with several preprocessor sections (set
217
216
>> grid: gn #can change for variables from the same model
218
217
>> start_year: 1970
219
218
>> end_year: 2000
220
-
>> additional_datasets:
221
219
>> scripts: null
222
220
>> ~~~
223
221
>> {: .source}
@@ -226,7 +224,7 @@ You could define different preprocessors with several preprocessor sections (set
226
224
227
225
## Adding different datasets for different variables
228
226
229
-
Sometimes, we may want to include specific datasets for certain variables. An example is when we use observations for two different variables in a diagnostic. While the CMIP dataset details for the two variables may be common, the observations will likely not be so. It would be useful to know how to include different datasets for different variables. Here is an example of a simple preprocessor and diagnostic setup for that:
227
+
Sometimes, we may want to include specific datasets only for certain variables. An example is when we use observations for two different variables in a diagnostic. While the CMIP dataset details for the two variables may be common, the observations will likely not be so. It would be useful to know how to include different datasets for different variables. Here is an example of a simple preprocessor and diagnostic setup for that:
230
228
231
229
> ## Example
232
230
>~~~YAML
@@ -254,7 +252,7 @@ Sometimes, we may want to include specific datasets for certain variables. An ex
254
252
> mip: Amon
255
253
> grid: gn #can change for variables from the same model
256
254
> start_year: 1970
257
-
> end_year: 2000 # start and end years for a30 year period,
255
+
> end_year: 2000 # start and end years for a 30 year period,
258
256
> # we assume this is common and exists for all
259
257
> # model and obs data
260
258
> additional_datasets:
@@ -269,16 +267,81 @@ Sometimes, we may want to include specific datasets for certain variables. An ex
> version: 1, tier: 2} #dataset specific to the temperature var
270
+
> version: 1, tier: 2} #dataset specific to the temperature variable
273
271
>
274
272
> scripts: null
275
273
>~~~
276
274
>{: .source}
277
275
{: .solution}
278
276
277
+
## Creating variable groups
278
+
279
+
Variable grouping can be used to preprocess different clusters of data for the same variable. For instance, the example below illustrates how we can compute separate multimodel means for CMIP5 and CMIP6 data given the same variable. Additionally we can also preprocess observed data for evaluation.
280
+
281
+
> ## Example
282
+
>~~~YAML
283
+
>
284
+
>preprocessors:
285
+
> prep_mmm:
286
+
> custom_order: true
287
+
> regrid:
288
+
> target_grid: 2.5 x 2.5
289
+
> scheme: linear
290
+
> multi_model_statistics:
291
+
> span: full
292
+
> statistics: [mean, median]
293
+
>
294
+
> prep_obs:
295
+
> mask_landsea:
296
+
> mask_out: sea
297
+
> regrid:
298
+
> target_grid: 2.5 x 2.5
299
+
> scheme: linear
300
+
>
301
+
> #note that there is no field called datasets anymore
302
+
> #note how multiple ensembles are added by using (1:4)
> additional_datasets: *cmip6_datasets #nothing changes from cmip5 except the data set
335
+
> scripts: null
336
+
>~~~
337
+
>{: .source}
338
+
{: .solution}
339
+
340
+
You should be able to see the variables grouped under different subdirectories under your output preproc directory. The different groupings can be accessed in your diagnostic by selecting the key name of the field variable_group such as tas_cmip5, tas_cmip6 or tas_obs.
341
+
>
279
342
> ## How to find what CMIP data is available?
280
343
>
281
-
> [CMIP5](https://pcmdi.llnl.gov/mips/cmip5/index.html) and [CMIP6](https://pcmdi.llnl.gov/CMIP6/Guide/dataUsers.html) data obey the [CF-conventions](http://cfconventions.org/). Available variables could be found under the [CMIP5 data request](https://pcmdi.llnl.gov/mips/cmip5/docs/standard_output.pdf?id=28) and the [CMIP6 Data Request](http://clipc-services.ceda.ac.uk/dreq/index.html).
344
+
> [CMIP5](https://pcmdi.llnl.gov/mips/cmip5/index.html) and [CMIP6](https://pcmdi.llnl.gov/CMIP6/Guide/dataUsers.html) data obey the [CF-conventions](http://cfconventions.org/). Available variables can be found under the [CMIP5 data request](https://pcmdi.llnl.gov/mips/cmip5/docs/standard_output.pdf?id=28) and the [CMIP6 Data Request](http://clipc-services.ceda.ac.uk/dreq/index.html).
282
345
>
283
346
> CMIP data is widely available via the Earth System Grid Federation ([ESGF](https://esgf.llnl.gov/)) and is accessible to users either via download from the ESGF portal or through the ESGF data nodes hosted by large computing facilities (like [CEDA-Jasmin](https://esgf-index1.ceda.ac.uk/), [DKRZ](https://esgf-data.dkrz.de/), etc). The ESGF also hosts observations for Model Intercomparison Projects (obs4MIPs) and reanalyses data (ana4MIPs).
0 commit comments