\name{RegimesAssign}
\alias{RegimesAssign}
\title{
Function for matching a field of anomalies with  a set of maps used as a reference (e.g. clusters obtained from the WeatherRegime function).
}
\description{
This function performs the matching between a field of anomalies and a set of maps which will be used as a reference. The anomalies will be assigned to the reference map for which the minimum Eucledian dista:nce  (method=’distance’) or maximum spatial correlation (method=‘ACC’) is obtained. 
}
\usage{
RegimesAssign(var_ano, ref_maps, lats, method = 'distance')
}
\arguments{
  \item{var_ano}{
Array of anomalies with the same structure of the Load outputs (e.g c(datasets,members,year/month, month/day, lon, lat).}
  \item{ref_maps}{
 Array with 3-dimensions (lon,lat, k) containing the maps  k=1,..,n maps that will be used as a reference for the matching. 
}
  \item{lat}{
Vector of latitudes.
  }
  \item{method}{
Whether the matching will be performed in terms of minimum distance (default=’distance’) or the maximum spatial correlation (method=’ACC’) between the maps.}
\value{
List with elements :\cr
 \item{composite}{
 3-d array (x, y, k) containing the composites k=1,..,K for case (*1)
    or only k=1 for any specific ref_map, i.e., case (*2).
 }
 \item{pvalue}{
 3-d array (x, y, k) containing the pvalue of the
    composites obtained through a t-test that accounts for the serial
    dependence of the data with the same structure as Composite.
 }
 \item{cluster}{
Array with the same dimensions that var_anom except latitude and longitude indicating the ref_map to which each point is allocated.
 }
 \item{frequencies}{
A vector of integers (from k=1,...k n reference maps) indicating the percentage of assignations corresponding to each map.
 }
}
\examples{
See Weather regime vignette: https://earth.bsc.es/gitlab/es/s2dverification/blob/develop-Regimes/vignettes/WeatherRegimesAnalysis.md
}
\author{
History:\cr
1.0  -  2018-05  (V.Torralba, \email{veronica.torralba at bsc.es} and A. Hunter, \email{alasdair.hunter at bsc.es} ) -  Original code
}

\keyword{datagen}

