<jupyter_start><jupyter_text>Worksheet 6: Investigating Extremes This final worksheet is a chance for you to put together all the techniques you have learned in the previous worksheets.Working with the same datasets, write some code to undertake an analysis of temperature extremes over our South East Asia domain.You have the following datasets available to you:**PRECIS data** (_cahpa_ and _cahpb_)  * Maximum daily temperature  * Minimum daily temperature  * Mean daily temperature  * Daily precipitation flux  * Monthly mean preciptation and temperature data as used in previous worksheets**Observations**  * APHRODITE rainfall data  * CRU temperature data  **Extremes indicies**The full list of 27 core extreme indices are listed on the [CLIMDEX website](https://www.climdex.org/learn/indices/), or look at the summary table take from the IPCC AR5 report below.  We suggest you look at one of the following:  * Number of tropical nights (*TR*): $\mathrm{TN}_{ij} > 20^{\circ}C$  * Percentage of days when max temperature is > 90th percentile (*TX90p*): $\mathrm{TX}_{ij} > \mathrm{TX}_{in}90$  * Monthly maximum 1-day precipitation (*Rx1day*): $\mathrm{Rx1day}_j = max (\mathrm{RR}_{ij})$Speak to your instructor if you would like to look at alternative indicies.**Table 1:** Definitions of extreme temperature and precipitation indices used in IPCC Assessment Report 5 (after Zhang et al., 2011). The most common units are shown but these  may be shown as normalized or relative depending on application in different chapters. Figure, Tables and Section numbers refer to the IPCC AR5 report [here](https://www.ipcc.ch/report/ar5/wg1/). By the end of this worksheet you should be able to: - Build a coding workflow to undertake extremes analysis- Understand the different stages of post-processing- Have an appreciation of data storage and file naming issues.  Preamble<jupyter_code># Code preamble - these libraries will be used in this worksheet.
# This code block needs to be re-run every time you restart this worksheet!
%matplotlib inline 
import os
import iris
import iris.coord_categorisation
import iris.quickplot as qplt
import iris.plot as iplt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import numpy as np
import dask
dask.config.set(get=dask.get)
import dask.array as da
from iris.analysis import Aggregator

# Some helpful data locations
DATADIR = '/project/ciid/projects/PRECIS/worksheets/data'
PPDIR = os.path.join(DATADIR, 'pp')
CLIMDIR = os.path.join(DATADIR, 'climatology')
HISTDIR = os.path.join(DATADIR, 'historical')
FUTRDIR = os.path.join(DATADIR, 'future')
APHRODIR = os.path.join(DATADIR, 'APHRODITE')
CRUDIR = os.path.join(DATADIR, 'CRU')
JOBIDS = ['cahpa', 'cahpb']
TIME_PERIODS = {'historical':'1961_1990', 'future':'2021_2050'}<jupyter_output><empty_output><jupyter_text>Step 1: Process raw pp files Remember to: * Select the correct variable from the pp file * Remove the rim * Concatenate into a single netCDF file * Tidy cube metadata * Save the netCDF file so you can access it later<jupyter_code>'''
Step 1: Process the raw pp files
'''<jupyter_output><empty_output><jupyter_text>Step 2: Calculate the extreme indexRemember to:  * Consider which observational data set to use for comparison  * Calculate the index for both the model data you prepared in step 1, but also the observed data  * Calculate the index for present and future model periods  * Save your index data sets as a netCDF file with appropriate metadata<jupyter_code>'''
Step 2: Calculate the extreme index
'''<jupyter_output><empty_output><jupyter_text>Step 3: Plot some resultsRemember to:  * Think about plotting absolute values, differences, or scaled differences.  Which one communicates your message best?  * Choose an appropriate colour scale<jupyter_code>'''
Step 3: Plot some results
'''<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07985574446161772, 'fraction_numerical': 0.012107161257083977, 'mean_word_length': 5.355155482815057, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '593897', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1087, 'n_words': 482, 'path': 'notebooks/worksheet6.ipynb', 'repo_name': 'MetOffice/PyPRECIS', 'size': '3882'}