\name{EuroAtlanticTC}
THIS DOCUMENTATION IS TO BE UPDATED WITH NEW INFO
##############################################################
# A function to compute EuroAtlantic Teleconnection Indices and 
# Patterns, using a Rotated EOF over the EuroAtlantic region.
# The region is hardcoded. 
# NOTE: The patterns and series can appear with opposed sign
# NOTE: Check which pattern appears in each position
#-------------------------------------------------------------
# Input: anomalies with dims (ntimes,nlat,nlon)
#        longitudes, latitudes and number of eofs to truncate.
# Output: patterns (4,nlat,nlon)
#	  indices (ntimes,4)
##############################################################
#----------------------------    
# Usage example
#----------------------------    
## Load data
#pslFull <-  Load(var = "psl", exp = NULL, obs = list(list(path=rean)),paste0(year.start:year.end,'1201'), storefreq = 'monthly', leadtimemin = 1, leadtimemax = 3,output = 'lonlat', latmin = 0, latmax = 90)

## Compute seasonal average
#seasonal <- Mean1Dim(pslFull$obs,4)

## Compute anomalies
#clim <- Mean1Dim(seasonal,3)
#anom <- sweep(seasonal,c(1,2,4,5),clim,FUN="-")

## Get the TCs
#EAT <- EuroAtlantic_TC(anom,pslFull$lat,pslFull$lon)

## Get correlation patterns:
#cor.map <- getCorPatterns(anom, pslFull$lat, pslFull$lon, 4)
\alias{EuroAtlanticTC}
\title{
EuroAtlantic Teleconnection indices using REOF.
}
\description{
Performs a Rotated EOF over the EuroAtlantic region (20N-80N, 90W-60E) and returns the first 4 modes of variability. 
The Rotated EOF uses varimax rotation and is area-weighted.
}
\usage{
EuroAtlanticTC(ano, lon, lat, ntrunc = 30)
}
\arguments{
  \item{ano}{
Array of anomalies with dimensions (number of timesteps, number of latitudes,
number of longitudes).
  }
  \item{lon}{
Vector of longitudes of \code{ano}.
  }
  \item{lat}{
Vector of latitudes of \code{ano}.
  }
  \item{ntrunc}{
Number of EOF modes to be kept before doing varimax rotation. Default = 30.
  }
}
\value{
  \item{patterns}{
An array of teleconnection patterns normalized to 1 (unitless) and then divided by area wieghts, with dimensions (4, 
number of latitudes, number of longitues). 
  }
  \item{indices}{
An array of teleconnection indices with the units of the original field to the 
power of 2, with dimensions (number of time steps, 4). \code{indices} 
contains already the percentage of explained variance (i.e. it is not normalized).
  }
  \item{var}{
Percentage (%) of variance fraction of total variance explained by each mode
(number of modes).
  }
  \item{mask}{
Mask with dimensions (number of latitudes, number of lonfitudes).
  }
  \item{wght}{
Weights with dimensions (number of latitudes, number of longitudes).
  }
}
\examples{
# See examples on Load() to understand the first lines in this example
  \dontrun{
data_path <- system.file('sample_data', package = 's2dverification')
expA <- list(name = 'experiment', path = file.path(data_path, 
             'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly',
             '$VAR_NAME$_$START_DATE$.nc'))
obsX <- list(name = 'observation', path = file.path(data_path, 
             '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$',
             '$VAR_NAME$_$YEAR$$MONTH$.nc'))

# Now we are ready to use Load().
startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101')
sampleData <- Load('tos', list(expA), list(obsX), startDates,
                   leadtimemin = 1, leadtimemax = 4, output = 'lonlat',
                   latmin = 27, latmax = 48, lonmin = -12, lonmax = 40)
  }
  \dontshow{
startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101')
sampleData <- s2dverification:::.LoadSampleData('tos', c('experiment'),
                                                c('observation'), startDates,
                                                leadtimemin = 1,
                                                leadtimemax = 4,
                                                output = 'lonlat',
                                                latmin = 27, latmax = 48,
                                                lonmin = -12, lonmax = 40)
  }
# This example computes the EOFs along forecast horizons and plots the one that 
# explains the greatest amount of variability. The example data is very low 
# resolution so it does not make a lot of sense.
ano <- Ano_CrossValid(sampleData$mod, sampleData$obs)
eof <- EOF(Mean1Dim(ano$ano_exp, 2)[1, , 1, , ], sampleData$lon, sampleData$lat)
PlotEquiMap(eof$EOFs[1, , ], sampleData$lon, sampleData$lat)
}
\author{
History:\cr
0.1  -  2012-10  (F. Lienert, \email{fabian.lienert at ic3.cat})  -  Original\cr
code, inspired by R. Benestad's EOF() in R package clim.pact.\cr
0.2  -  2014-03  (Lauriane Batte, \email{lauriane.batte at ic3.cat})  -  Bug-fixes:\cr
        1- Reversion of latitudes in the weights\cr
        2- Correlation matrix was used instead of covariance\cr
        3- Double use of the weights\cr
0.3  -  2014-03  (Virginie Guemas, \email{virginie.guemas at bsc.es})  -  Bug-fixes:\cr
        1- Weight computation - division by sum of cos(lat)\cr
        2- Shuffling of EOFs in EOF.2 intermediate vector\cr
        3- Crash when neofs = 1 sorted out\cr
        4- Crash when neofs > nt sorted out\cr
0.4  -  2014-03  (Lauriane Batte, \email{lauriane.batte at ic3.cat})  -  Fixes:\cr
        1- BIG cleanup of code and clarification\cr
        2- Reduction of the number of transpositions and associated bug-fixes\cr
        4- Remove of the obsolete LINPACK options\cr
0.5  -  2014-04  (Virginie Guemas, \email{virginie.guemas at bsc.es})  - Fixes:\cr
        1- Bug-fix in dimensions handling EOF composition restitutes now the\
original field in all cases\cr
        2- Simplification of the convention transpose\cr
        3- Options to use the correlation matrix rather than the 
covariance matrix\cr
        4- Security checks\cr
        5- New normalization of PCs so that PC*EOF only reconstruct the 
original file\cr
        6- Weights = sqrt(cos(lat)) for ano so that covariance matrice 
weighted by cos(lat)\cr
        7- Division of EOF by weights so that the reconstruction is simply 
EOF * PC\cr
1.0  -  2016-03  (N. Manubens, \email{nicolau.manubens at bsc.es})  -  Formatting to R CRAN
}
\seealso{ProjectField, NAO, PlotBoxWhisker}
\keyword{datagen}
