Exercise
Contents
Exercise¶
Text Data¶
- Load the data from - ../../data/nao_station_monthly.txt. Mask every missing value. Therefore you will need the following parameters of the function np.genfromtxt:- skipt_header 
- missing_values 
- usemask 
 
- Restructure the loaded data as arrays. Create a time vector (1D-array) called - timeand a 1D data vector called- nao. Use the code below to plot the NAO time series.
plt.plot(time, nao)
plt.xlabel('year')
plt.ylabel('nao')
plt.title('station based monthly NAO index');
NetCDF data¶
- Open the dataset - ../../data/CRUTEM.4.6.0.0.anomalies.nc
- Inspect the content of the attributes - dimensionsand- variables. How long are the dimensions- longitudeand- time? Which unit and data type does the variable- temperature_anomalyhave and on which dimensions is it defined?
- Read the last time step of the variable - temperature_anomalyto the memory.
- Compute the globally averaged temperature anomaly. The data is given in spherical coordinates. Therefore single data points need to be weighted with the cosine of the latitude in radians: \[t_{global} = \frac{1}{N M}\sum_{j=1}^M\sum_{i=1}^{N} t_{anom}(j, i) \cos(\theta(j))\]- Try to use the broadcasting functionality and the mean function from numpy! Use the code below to plot the time series of globally averaged temperature anomaly. 
# create a plotable time axis
# encode numerical time representation into datetime information
# comprehensible by matplotlib
time = nc.num2date(
    ds.variables['time'][:],
    units=ds.variables['time'].units,
    calendar=ds.variables['time'].calendar,
    only_use_cftime_datetimes=False,
    only_use_python_datetimes=True
)
plt.plot(time, t_global);
- Write the computed global mean temperature anomaly time series from above with all necessary metadata as a NetCDF data set. Include as many information from the source data set as possible. - Hint: To overwrite an existing data set, the argument - clobber=Trueis needed for the creation of the data set.
