Monthly data analysis ===================== Download Sample Files --------------------- SST data ^^^^^^^^ * :download:`oisst_monthly.nc ` * :download:`lsmask.nc ` Python script & Figures ^^^^^^^^^^^^^^^^^^^^^^^ Time series plots """"""""""""""""" * :download:`month_areave-v3.py ` * :download:`nino_index-v3.py ` .. image:: SRC/month_areave-v3.png :width: 200 .. image:: SRC/nino_index-v3.png :width: 200 Map plots """"""""" * :download:`month_leadlag_cor-v4.py ` * :download:`month_leadlag_cor_reg-v2.py ` .. image:: SRC/month_leadlag_cor-v4.png :width: 200 .. image:: SRC/month_leadlag_cor_reg-v2.png :width: 200 Combined plots """""""""""""" * :download:`sstDJF_nino_cor-v1.py ` * :download:`eof_sstDJF-v3.py ` * :download:`eof_cor_sstDJF-v2.py ` .. image:: SRC/sstDJF_nino_cor-v1.png :height: 200 .. image:: SRC/eof_sstDJF-v3.png :height: 200 .. image:: SRC/eof_cor_sstDJF-v2.png :height: 200 Analysis -------- Land-sea mask ^^^^^^^^^^^^^ The `NOAA OI SST dataset `_ filled the fake values over the land produced by linear interpolation. To identify the ocean area, they also provide the land-sea mask file. The land-sea mask consists of the grided values filled by 1 over the land and 0 over the sea. This example shows how to mask the land area using the `Xarray.DataArray.where `_ function. .. literalinclude:: SRC/month_areave-v3.py :language: python :lines: 14-16,19,22 Anomalies and Climatology ^^^^^^^^^^^^^^^^^^^^^^^^^ The most prominent feature of climate data is the annual cycle called **climatology**. The climatology represents the seasonal cycle and generally consists of one value in each month. Climate scientist characterizes warmer/colder climate or **anomalies** by comparing with the climatology. We define anomalies as the deviation of climatology. As a result, the dimension size of time is 12 for climatology and the data length for anomalies. The following is an example for Xarray to calculate climatology and anomalies using *groupby*. .. literalinclude:: SRC/month_areave-v3.py :language: python :lines: 23-24 Output of DataArrays 'clm' and 'anm' looks like this:: print(' ---- clm ----') array([[[-1.7900007, -1.7900007, -1.7900007, ..., -1.7900007, ..., [ nan, nan, nan, ..., nan, nan, nan]]], dtype=float32) Coordinates: * lat (lat) float32 89.5 88.5 87.5 86.5 85.5 ... -86.5 -87.5 -88.5 -89.5 * lon (lon) float32 0.5 1.5 2.5 3.5 4.5 ... 355.5 356.5 357.5 358.5 359.5 * month (month) int64 1 2 3 4 5 6 7 8 9 10 11 12 print(' ---- anm ----') array([[[ 7.1525574e-07, 7.1525574e-07, 7.1525574e-07, ..., ..., [ nan, nan, nan, ..., nan, nan, nan]]], dtype=float32) Coordinates: * lat (lat) float32 89.5 88.5 87.5 86.5 85.5 ... -86.5 -87.5 -88.5 -89.5 * lon (lon) float32 0.5 1.5 2.5 3.5 4.5 ... 355.5 356.5 357.5 358.5 359.5 * time (time) datetime64[ns] 1981-12-01 1982-01-01 ... 2021-07-01 month (time) int64 12 1 2 3 4 5 6 7 8 9 10 ... 9 10 11 12 1 2 3 4 5 6 7 Regional average ^^^^^^^^^^^^^^^^ We can simply calculate the globally averaged temperature anomalies like this. .. code-block:: python glob=anm.mean(("lon", "lat"), skipna=True) The above approach assumes that all grid points have the same area. However, the areas in a general latitude-longitude grid are a function of the latitude, which requires a latitude-weighted area average. The following function calculates the latitude-weighted area average. This function is also applicable for the longitude range from -180 to 360. .. literalinclude:: SRC/month_areave-v3.py :language: python :lines: 30-49, 51-53 Running mean and standardaized ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A function `DataArray.std `_ calcuates the standard deviation. We can also apply a running mean filter using a function `DataArray.rolling `_ with a option. Here is an example, which applys a 7-month running mean filter. You may prefer a option `center=True` to keep the center point for filtering. .. literalinclude:: SRC/nino_index-v3.py :language: python :lines: 59,61,62 Sample program: :download:`nino_index-v3.py ` .. image:: SRC/nino_index-v3.png :height: 200 Detrending ^^^^^^^^^^ This is an example for a linear detrending function. .. literalinclude:: SRC/month_leadlag_cor_reg-v2.py :language: python :lines: 61-70 Correlation & regression ^^^^^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: SRC/month_leadlag_cor_reg-v2.py :language: python :lines: 83-84 Sample program: :download:`month_leadlag_cor_reg-v2.py ` .. image:: SRC/month_leadlag_cor_reg-v2.png :height: 200 Lead-lag correlation ^^^^^^^^^^^^^^^^^^^^ .. literalinclude:: SRC/month_leadlag_cor_reg-v2.py :language: python :lines: 76-92 Significant test for correlation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is an example of two-side Student t-test for correlation at 90% and 95% significance level with 40 degrees of freedom. The sample script makes a correlation plot hatched by dots in the region above 95% level. We require the package 'SciPy' to conduct the statistical test. .. code:: from scipy import stats Using a function **stats.t.ppf**, we can calculate t-value based on the degrees of freedom and probability. .. literalinclude:: SRC/month_leadlag_cor-v4.py :language: python :lines: 151-162 Sample program: :download:`sstDJF_nino_cor-v1.py ` .. image:: SRC/sstDJF_nino_cor-v1.png :height: 200 EOF analysis ^^^^^^^^^^^^ The Empirical Orthogonal Function (EOF) analysis is a statistical tool commonly used in climate science. It defines the dominant modes by decomposing 3-dimensional climate data (time, latitude, and longitude) into the spatial pattern and time series. In this example, we apply EOF analysis to sea surface temperature anomalies averaged for the boreal winter (DJF). We use general python packages as shown below. There is excellent documentation for EOF analysis by GeoCAT (`here `_). This example uses the package **geocat.comp** as highlighted below. We also define the year and the region to apply the EOF analysis here. The parameter **neof = 3** indicates the number of leading EOF modes. .. literalinclude:: SRC/eof_sstDJF-v3.py :language: python :lines: 1-30 :emphasize-lines: 17 Next, we calculate the seasonal mean of sea surface temperature anomalies. In this example, we obtain monthly climatology and anomalies for the data period. We apply a 3-month running mean filter to the monthly anomalies and then extract the December-January-February (DJF) mean (i.e., **anmDJF**). There are several ways to calculate the seasonal mean, such as **groupby('time.season')** or a GeoCAT function **month_to_season**. You can apply the most convenient way for you. .. literalinclude:: SRC/eof_sstDJF-v3.py :language: python :lines: 42-51 The goal of EOF analysis is to obtain an eigenvector and a principal component. The GeoCAT functions **eofunc_eofs** and **eofunc_pcs** highlighted below can provide the eigenvectors and the principal components. However, we require several techniques for the EOF analysis. The steps include: 1. Removing a lear trend in each grid point. 2. Sorting the latitude coordinate for the assessing order. 3. Applying the latitude weight to the anomalies. 4. Rotating the longitude if necessary. 5. Extracting the domain to apply the EOF analysis. 6. Conducting the EOF analysis. 7. Normalizing the principal components based on one standard deviation. 8. Defining the eigenvectors. .. literalinclude:: SRC/eof_sstDJF-v3.py :language: python :lines: 59-93 :emphasize-lines: 24-25 Once we obtain the principal components, we can get the correlation and regression maps with the time series. .. literalinclude:: SRC/eof_sstDJF-v3.py :language: python :lines: 95-101 Finaly, we make the figure plot of eigenvectors and principal components for the three leading EOF modes. Let's see the sample program and its output below. Source file: :download:`eof_sstDJF-v3.py ` .. image:: SRC/eof_sstDJF-v3.png :height: 200