Weather Regimes
==========
  Weather regimes can be calculated using the k-means clustering algorithm,
typically applied to the EOFs of anomalies from selected variables, after 
smoothing and detrending.

The work flow will be something like:
  
  - [**Load data**](#loading): `Load()`.
  - [**Calculate the anomalies**](#anomalies): `Ano()`.
  - [**Smooth the anomalies**](#smoothing): `Smooth()`.
  - [**Detrend the smoothed anomalies**](#detrending): `Trend()`.
  - [**Calculate the EOFs**](#EOF): `EOF()`.
  - [**Calculate the k-means clusters**](#clusters): `Cluster()`.
  - [**Calculate the Composites**](#Composites): `Composite()`.
  - [**Visualize the results**](#Visualize): `PlotEquiMap()`.
            
Some steps may be omitted/altered, for example, the user may wish to use are averages
instead of the EOFs, or even apply clustering directly to the spatial data (after detrending
and calculating the anomalies) although this may be computationall expensive.
            
North Atlantic Weather Regimes"></a>
------------------

Below is a simple example of calculating the weather regimes for the North Atlantic from JRA55 SLP for January.

    ```r
    library(s2dverification)
    library(reshape2)
    JRA55 <- '/esnas/recon/jma/jra55/$STORE_FREQ$_mean/$VAR_NAME$_f6h/$VAR_NAME$_$YEAR$$MONTH$.nc'
    psl <- "psl"
    year.start <- 1981 
    year.end <- 2016
    #Euro-Atlantic region
    lat.max <- 81 
    lat.min <- 27 
    lon.max <- 45 
    lon.min <- 274.5
    firstmonth <- 1                              
    leadmonth <- 0      
    psl <-  Load(var = psl, exp = NULL, obs = list(list(path=JRA55)), paste0(year.start:year.end,'0101'), storefreq = 'daily', leadtimemax = 366, output = 'lonlat', latmin = lat.min,       latmax = lat.max, lonmin = lon.min, lonmax = lon.max, nprocs=8)
    lon <- psl$lon
    lat <- psl$lat
    psl <- Trend(psl$obs, posTR = 3)$detrended 
    psl <- psl[1, 1, , , , ]  # Drop the dataset and members dimensions
    psl <- Subset(psl, 2, 1 : 31) # Select the month of January
    psl_ano <- psl - InsertDim(Mean1Dim(psl, 1), 1, 36)
    names(dim(psl_ano)) <- c("ftime", "sdate", "lon", "lat")
    WR <- WeatherRegime(psl_ano, lon = lon, lat = lat, ncenters = 4)
    PlotEquiMap(WR$test[1,,], lon = lon, lat = lat) #Plot the 1st regime
   ```
<img src="WeatherRegime1.png" />
       