"# Calculate a climate index in a server hosting all the climate model data: \n",
"# Calculate a climate index in a server hosting all the climate model data: \n",
"## run faster and without data transfer\n",
"## run faster and without data transfer\n",
"\n",
"\n",
"We will show here how to count the annual summer days for a particular location of your choice using the results of a climate model, in particular, the historical and socioeconomics pathways of the Coupled Model Intercomparison Project [CMIP6](https://pcmdi.llnl.gov/CMIP6/).\n",
"We will show here how to count the annual summer days for a particular location of your choice using the results of a climate model, in particular, the historical and shared socioeconomic pathway (ssp) experiments of the Coupled Model Intercomparison Project [CMIP6](https://pcmdi.llnl.gov/CMIP6/).\n",
"\n",
"\n",
"This Jupyter notebook runs in the Jupyterhub server of the German Climate Computing Center [DKRZ](https://www.dkrz.de/) which is an [ESGF](https://esgf.llnl.gov/) repository that hosts and maintains more than 3 Petabytes of CMIP6 data. Please, choose the ... kernel on the right uper corner of this notebook.\n",
"This Jupyter notebook runs in the Jupyterhub server of the German Climate Computing Center [DKRZ](https://www.dkrz.de/) which is an [ESGF](https://esgf.llnl.gov/) repository that hosts and maintains more than 3 Petabytes of CMIP6 data. Please, choose the ... kernel on the right uper corner of this notebook.\n",
"\n",
"\n",
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {},
"metadata": {},
"source": [
"source": [
"## 1. Which data set do we need? -> Choose Scenario, Place, and Year\n",
"## 1. Which data set do we need? -> Choose Shared Socioeconomic Pathway, Place, and Year\n",
"query_result_df[\"start_year\"] = query_result_df[\"time_range\"].str[0:4].astype(int) # add column with start year\n",
"query_result_df[\"start_year\"] = query_result_df[\"time_range\"].str[0:4].astype(int) # add column with start year\n",
"query_result_df[\"end_year\"] = query_result_df[\"time_range\"].str[9:13].astype(int) # add column with end year\n",
"query_result_df[\"end_year\"] = query_result_df[\"time_range\"].str[9:13].astype(int) # add column with end year\n",
...
@@ -425,7 +425,7 @@
...
@@ -425,7 +425,7 @@
"no_summer_days_model = tasmax_year_place_xr[tasmax_year_place_xr > 25].size # count the number of summer days\n",
"no_summer_days_model = tasmax_year_place_xr[tasmax_year_place_xr > 25].size # count the number of summer days\n",
"\n",
"\n",
"# Print results in a sentence\n",
"# Print results in a sentence\n",
"print(\"According to the German Weather Service definition, in the scenario \" +scenario_box.label +\" the \" +climate_model +\" model shows \" +str(no_summer_days_model) +\" summer days for \" +str(place_box.value) + \" in \" + str(year_box.value) +\".\")"
"print(\"According to the German Weather Service definition, in the \" +experiment_box.label +\" experiment the \" +climate_model +\" model shows \" +str(no_summer_days_model) +\" summer days for \" +str(place_box.value) + \" in \" + str(year_box.value) +\".\")"
]
]
},
},
{
{
...
@@ -438,9 +438,9 @@
...
@@ -438,9 +438,9 @@
],
],
"metadata": {
"metadata": {
"kernelspec": {
"kernelspec": {
"display_name": "Python 3 unstable (using the module python3/unstable)",
"display_name": "test_env",
"language": "python",
"language": "python",
"name": "python3_unstable"
"name": "test_env"
},
},
"language_info": {
"language_info": {
"codemirror_mode": {
"codemirror_mode": {
...
@@ -452,7 +452,7 @@
...
@@ -452,7 +452,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.7.8"
"version": "3.8.5"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Calculate a climate index in a server hosting all the climate model data:
# Calculate a climate index in a server hosting all the climate model data:
## run faster and without data transfer
## run faster and without data transfer
We will show here how to count the annual summer days for a particular location of your choice using the results of a climate model, in particular, the historical and socioeconomics pathways of the Coupled Model Intercomparison Project [CMIP6](https://pcmdi.llnl.gov/CMIP6/).
We will show here how to count the annual summer days for a particular location of your choice using the results of a climate model, in particular, the historical and shared socioeconomic pathway (ssp) experiments of the Coupled Model Intercomparison Project [CMIP6](https://pcmdi.llnl.gov/CMIP6/).
This Jupyter notebook runs in the Jupyterhub server of the German Climate Computing Center [DKRZ](https://www.dkrz.de/) which is an [ESGF](https://esgf.llnl.gov/) repository that hosts and maintains more than 3 Petabytes of CMIP6 data. Please, choose the ... kernel on the right uper corner of this notebook.
This Jupyter notebook runs in the Jupyterhub server of the German Climate Computing Center [DKRZ](https://www.dkrz.de/) which is an [ESGF](https://esgf.llnl.gov/) repository that hosts and maintains more than 3 Petabytes of CMIP6 data. Please, choose the ... kernel on the right uper corner of this notebook.
Thanks to the data and computer scientists Marco Kulüke, Fabian Wachsmann, Regina Kwee-Hinzmann, Caroline Arnold, Felix Stiehler, Maria Moreno, and Stephan Kindermann at DKRZ for their contribution to this notebook.
Thanks to the data and computer scientists Marco Kulüke, Fabian Wachsmann, Regina Kwee-Hinzmann, Caroline Arnold, Felix Stiehler, Maria Moreno, and Stephan Kindermann at DKRZ for their contribution to this notebook.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
In this Use Case you will learn the following:
In this Use Case you will learn the following:
- How to access a data set from the DKRZ CMIP6 model data archive
- How to access a data set from the DKRZ CMIP6 model data archive
- How to count the annual number of summer days for a particular location using this model data set
- How to count the annual number of summer days for a particular location using this model data set
- How to visualize the results
- How to visualize the results
\
\
You will use:
You will use:
-[Intake](https://github.com/intake/intake) for finding the data in the DKRZ catalog
-[Intake](https://github.com/intake/intake) for finding the data in the DKRZ catalog
-[Xarray](http://xarray.pydata.org/en/stable/) for loading and processing the data in the DKRZ Jupyterhub server
-[Xarray](http://xarray.pydata.org/en/stable/) for loading and processing the data in the DKRZ Jupyterhub server
-[hvPlot](https://hvplot.holoviz.org/index.html) for visualizing the data in the Jupyter notebook and save the plots in your local computer
-[hvPlot](https://hvplot.holoviz.org/index.html) for visualizing the data in the Jupyter notebook and save the plots in your local computer
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 0. Load Packages
## 0. Load Packages
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
importintake# a general interface for loading data from an existing catalog
importintake# a general interface for loading data from an existing catalog
We have defined the place and time. Now, we can search for the climate model data set.
We have defined the place and time. Now, we can search for the climate model data set.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 2. Intake Catalog
## 2. Intake Catalog
Similar to the shopping catalog at your favorite online bookstore, the intake catalog contains information (e.g. model, variables, and time range) about each data set (the title, author, and number of pages of the book, for instance) that you can access before loading the data (so thanks to the catalog, you do not need to open the book to know the number of pages of the book, for instance).
Similar to the shopping catalog at your favorite online bookstore, the intake catalog contains information (e.g. model, variables, and time range) about each data set (the title, author, and number of pages of the book, for instance) that you can access before loading the data (so thanks to the catalog, you do not need to open the book to know the number of pages of the book, for instance).
### 2.1 Load the Intake Catalog
### 2.1 Load the Intake Catalog
We load the catalog descriptor with the intake package. The catalog is updated daily.
We load the catalog descriptor with the intake package. The catalog is updated daily.
# Open the catalog with the intake package and name it "col" as short for collection
# Open the catalog with the intake package and name it "col" as short for collection
col=intake.open_esm_datastore(col_url)
col=intake.open_esm_datastore(col_url)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Let's see what is inside the intake catalog. The underlying data base is given as a pandas dataframe which we can access with "col.df". Then, "col.df.head()" shows us the first rows of the table of the catalog.
Let's see what is inside the intake catalog. The underlying data base is given as a pandas dataframe which we can access with "col.df". Then, "col.df.head()" shows us the first rows of the table of the catalog.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
This catalog contains all data sets of the CMIP6 archive at DKRZ. In the next step we narrow the results down by chosing a model and variable.
This catalog contains all data sets of the CMIP6 archive at DKRZ. In the next step we narrow the results down by chosing a model and variable.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### 2.2 Browse the Intake Catalog
### 2.2 Browse the Intake Catalog
In this example we chose the Max-Planck Earth System Model in High Resolution Mode ("MPI-ESM1-2-HR") and the maximum temperature near surface ("tasmax") as variable.
In this example we chose the Max-Planck Earth System Model in High Resolution Mode ("MPI-ESM1-2-HR") and the maximum temperature near surface ("tasmax") as variable.
\
\
CMIP6 comprises several kind of experiments. Each experiment has various simulation members. More information can be found via the [CMIP6 Model and Experiment Documentation](https://pcmdi.llnl.gov/CMIP6/Guide/dataUsers.html#5-model-and-experiment-documentation).
CMIP6 comprises several kind of experiments. Each experiment has various simulation members. More information can be found via the [CMIP6 Model and Experiment Documentation](https://pcmdi.llnl.gov/CMIP6/Guide/dataUsers.html#5-model-and-experiment-documentation).
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
climate_model="MPI-ESM1-2-LR"
climate_model="MPI-ESM1-2-LR"
query=dict(
query=dict(
source_id=climate_model,# here we choose Max-Plack Institute's Earth Sytem Model in high resolution
source_id=climate_model,# here we choose Max-Plack Institute's Earth Sytem Model in high resolution
variable_id="tasmax",# temperature at surface, maximum
variable_id="tasmax",# temperature at surface, maximum
Here we see our query results. This is like the list of results you get when you search for keywords with a search engine. In the next section we will find the data set which contains our selected year.
Here we see our query results. This is like the list of results you get when you search for keywords with a search engine. In the next section we will find the data set which contains our selected year.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 3. Load the model data
## 3. Load the model data
### 3.1 Find Data Set Which Contains the Year You Selected in Drop Down Menu Above
### 3.1 Find Data Set Which Contains the Year You Selected in Drop Down Menu Above
Climate models have a finite resolution. Hence, models do not provide the data of a particular point, but the mean over a model grid cell. Take this in mind when comparing model data with observed data (e.g. weather stations).
Climate models have a finite resolution. Hence, models do not provide the data of a particular point, but the mean over a model grid cell. Take this in mind when comparing model data with observed data (e.g. weather stations).
\
\
\
\
Now, we will visualize the daily maximum temperature time series of the model grid cell.
Now, we will visualize the daily maximum temperature time series of the model grid cell.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 5. Draw Temperature Time Series and Count Summer days
## 5. Draw Temperature Time Series and Count Summer days
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
The definition of a summer day varies from region to region. According to the [German Weather Service](https://www.dwd.de/EN/ourservices/germanclimateatlas/explanations/elements/_functions/faqkarussel/sommertage.html), "a summer day is a day on which the maximum air temperature is at least 25.0°C". Depending on the place you selected, you might want to apply a different threshold.
The definition of a summer day varies from region to region. According to the [German Weather Service](https://www.dwd.de/EN/ourservices/germanclimateatlas/explanations/elements/_functions/faqkarussel/sommertage.html), "a summer day is a day on which the maximum air temperature is at least 25.0°C". Depending on the place you selected, you might want to apply a different threshold.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
tasmax_year_place_xr=tasmax_year_xr[:,yloc,xloc]-273.15# Convert Kelvin to °C
tasmax_year_place_xr=tasmax_year_xr[:,yloc,xloc]-273.15# Convert Kelvin to °C
tasmax_year_place_df=pd.DataFrame(index=tasmax_year_place_xr['time'].values,columns=['Temperature','Summer Day Threshold'])# Create Pandas Series
tasmax_year_place_df=pd.DataFrame(index=tasmax_year_place_xr['time'].values,columns=['Temperature','Summer Day Threshold'])# Create Pandas Series
tasmax_year_place_df.loc[:,'Model Temperature']=tasmax_year_place_xr.values# Insert model data into Pandas Series
tasmax_year_place_df.loc[:,'Model Temperature']=tasmax_year_place_xr.values# Insert model data into Pandas Series
tasmax_year_place_df.loc[:,'Summer Day Threshold']=25# Insert threshold into Pandas series
tasmax_year_place_df.loc[:,'Summer Day Threshold']=25# Insert threshold into Pandas series
# Plot data and define title and legend
# Plot data and define title and legend
tasmax_year_place_df.hvplot.line(y=['Model Temperature','Summer Day Threshold'],
tasmax_year_place_df.hvplot.line(y=['Model Temperature','Summer Day Threshold'],
value_label='Temperature in °C',legend='bottom',title='Daily maximum Temperature near Surface for '+place_box.value,height=500,width=620)
value_label='Temperature in °C',legend='bottom',title='Daily maximum Temperature near Surface for '+place_box.value,height=500,width=620)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
As we can see, the maximum daily temperature is highly variable over the year. As we are using the mean temperature in a model grid cell, the amount of summer days might we different that what you would expect at a single location.
As we can see, the maximum daily temperature is highly variable over the year. As we are using the mean temperature in a model grid cell, the amount of summer days might we different that what you would expect at a single location.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# Summer days index calculation
# Summer days index calculation
no_summer_days_model=tasmax_year_place_xr[tasmax_year_place_xr>25].size# count the number of summer days
no_summer_days_model=tasmax_year_place_xr[tasmax_year_place_xr>25].size# count the number of summer days
# Print results in a sentence
# Print results in a sentence
print("According to the German Weather Service definition, in the scenario "+scenario_box.label+" the "+climate_model+" model shows "+str(no_summer_days_model)+" summer days for "+str(place_box.value)+" in "+str(year_box.value)+".")
print("According to the German Weather Service definition, in the "+experiment_box.label+"experiment the "+climate_model+" model shows "+str(no_summer_days_model)+" summer days for "+str(place_box.value)+" in "+str(year_box.value)+".")