Skip to content
Snippets Groups Projects
Commit 38b96cd0 authored by Dominik Zobel's avatar Dominik Zobel
Browse files

Adjust postprocessing example and add Hands-on

parent aeaec7cc
No related branches found
No related tags found
1 merge request!56Debugging Strategies lecture notes
Pipeline #66870 passed
...@@ -310,7 +310,7 @@ $\Rightarrow$_Show use of `gdb`_ ...@@ -310,7 +310,7 @@ $\Rightarrow$_Show use of `gdb`_
# Errors due to data access and communication # Errors due to data access and communication
## Postprocessing example (1/3) ## Postprocessing example (1/4)
- Extract data from netCDF file and calculate interpolation weights - Extract data from netCDF file and calculate interpolation weights
- File located [here](static/vmro3_input4MIPs_ozone_1850-1855_rev.nc) - File located [here](static/vmro3_input4MIPs_ozone_1850-1855_rev.nc)
...@@ -326,7 +326,7 @@ Calculate_Weights(filename, timestamp_start, timestamp_end, timestep_days) ...@@ -326,7 +326,7 @@ Calculate_Weights(filename, timestamp_start, timestamp_end, timestep_days)
``` ```
## Postprocessing example (2/3) ## Postprocessing example (2/4)
:::{.smaller} :::{.smaller}
...@@ -358,7 +358,7 @@ def Calculate_Weights(filename, timestamp_start, timestamp_end, timestep_days): ...@@ -358,7 +358,7 @@ def Calculate_Weights(filename, timestamp_start, timestamp_end, timestep_days):
::: :::
## Postprocessing example (3/3) ## Postprocessing example (3/4)
```python ```python
...@@ -376,7 +376,31 @@ def Select_Date(ds, model_date, method): ...@@ -376,7 +376,31 @@ def Select_Date(ds, model_date, method):
'%Y-%m-%d %H:%M:%S') '%Y-%m-%d %H:%M:%S')
``` ```
:::{.fragment} <!--
```python
def Open_File(filename):
import xarray as xr
return xr.open_dataset(filename)\
.convert_calendar('standard', use_cftime=True)
def Select_Date(ds, model_date, method='ffill'):
import datetime as dt
if ( model_date < dt.datetime(1850, 1, 16, 12, 0, 0) ) \
or ( model_date > dt.datetime(1854, 12, 31, 12, 0, 0) ):
ds_elem = ds.sel(time=model_date, method='nearest')
else :
ds_elem = ds.sel(time=model_date, method=method)
return dt.datetime.strptime(str(ds_elem['time'].values),
'%Y-%m-%d %H:%M:%S')
```
-->
## Postprocessing example (4/4)
```{.python startFrom="14"} ```{.python startFrom="14"}
def Get_Time_Objects(timestamp_start, timestamp_end, timestep_days): def Get_Time_Objects(timestamp_start, timestamp_end, timestep_days):
...@@ -389,8 +413,19 @@ def Get_Time_Objects(timestamp_start, timestamp_end, timestep_days): ...@@ -389,8 +413,19 @@ def Get_Time_Objects(timestamp_start, timestamp_end, timestep_days):
return [start_date, end_date, timestep] return [start_date, end_date, timestep]
``` ```
:::
## Hands-On! {.handson}
1. Which command in the code causes the problem?
2. Describe what would you need to do?
(you can inspect the data e.g. with `print(ds['time'])`
or in your terminal with `cdo infon <file>.nc`)
<!--
```
ncdump -h
```
-->
## Parallel programs ## Parallel programs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment