Assessng nter-annual and seasonal varablty Least square fttng wth Matlab: Applcaton to SSTs n the vcnty of Cape Town Francos Dufos Department of Oceanography/ MARE nsttute Unversty of Cape Town
Introducton 1- Whch data are we usng? 2- What can we do wth SST tme seres (examples n False Bay)... 3- Least square fttng 3-1- Lnear least square fttng 3-2- Non lnear least square fttng 4- How to evaluate models?
1- Whch data are we usng? Monthly SST tme seres Pathfnder (from 1981) Long seres Resoluton (tme, space) http://www.nodc.noaa.gov/sog/pathfnder4km/usergude.html M atlab fle: SST_Pathfnder_1D.mat, SST a poston 16W 40S M ODIS TERRA (from 2000) Spatal resoluton Short seres http://www.afro-sea.org.za/ M atlab fles: SST_upwellng_1D.mat, SST a poston 18W 34.2S SST_FalseBay_1D.mat, SST a poston 18.6W 34.2S SST_CapePennsula_3D.mat, SST around Cape Town tme s n day n Matlab fles: datestr(tme) gves you the date n a readable format... SEVIRI (from 2004) Temporal resoluton Spatal resoluton, flags, short seres
2- Examples of analyss Fast Fourer Transform: decomposes a sequence of values nto components of dfferent frequences. performed usng Sevr data (1h resoluton data) functon fft n matlab + (trcky!!!)
2- Examples of analyss Wavelet: to see how the strength of the key temporal varablty changes over tme. Wavelet transforms a one-dmensonal tme seres to a two-dmensonal mage that portrays the evoluton of scales and frequences wth tme. Very user-frendly matlab packages, wth wavelet coherence as well: http://www.pol.ac.uk/home/research/waveletcoherence/
2- Examples of analyss Emprcal Orthonormal Functon: explans the varance wth the smallest possble number of modes Bascally, the frst EOF s the pattern that represents the most varablty Intra-annual varablty/seasonalty s the frst mode when lookng at EOF decomposton on SST absolute values... 1- Seasonalty needs to be assessed... 2- When usng EOF to assess nter-annual varablty, seasonal cycle has to be removed by usng anomales to the clmatology User-frendly matlab packages? http://www.mathworks.com/matlabcentral/
2- Examples of analyss Emprcal Orthonormal Functon (on SST anomales) to answer : What are the domnant modes of the nter-annual varablty? Usng 3-monthly runnng mean of SST from TERRA
2- Example of analyss Composte: a good way to look at the patterns of anomales for specfc perods Anomaly durng La Nña ( 2000/2001/2008 ) Mean SST durng summer Anomaly durng El Nño ( 2003/05/08/10 )
3- Least square fttng How to assess the seasonalty? We need to fnd a model for the monthly SST tme seres... All models are wrong, but some are useful George E.P. Box We need to : 1- Identfy a useful model 2- Fnd the parameters of the model (wth a least square fttng) 3- Evaluate the model
3- Least square fttng Prncple of the least square fttng: y s the measured value at the tme step (N tme step n total) yˆ s the modeled value at the same tme step Measure = model y yˆ +resdual We want to fnd a model dependant on an explanatory varable (x ) by mnmsng the sum of the squared resduals: SS N 1 The basc dea of any least square ft s to fnd the model whch mnmzes the sum of the vertcal dstances squared between all data pont and the least square model. 2
response varable (e.g. SST) 3-1- Lnear least square fttng Lnear least square fttng or lnear regresson y ax b ˆ model ( yˆ ) measure (y ) explanatory varable (e.g. tme) An analytcal soluton exsts for the lnear regresson: 2 2 y x 1/ n y x a b y ax x 1/ n x
3-1- Lnear least square fttng Example: How to fnd the temperature trend on Pathfnder tme seres In Matlab we can use operator \ or functon polyft... %% LOAD fle load( SST_Pathfnder_1D.mat ) %% Remove bad values (-1) tme(sst==-1)=[]; sst(sst==-1)=[]; %% Lnear Least square fttng % frst method [a]=polyft(tme,sst,1); %2 nd method [a1]=[tme ones(length(sst),1)]\sst;
3-2- Non lnear least square fttng If the model that we want to ft s not just a straght lne, we have to mnmze SS N 1 2 on our own... Example: How to assess the seasonalty of an SST MODIS tme seres... We chose the followng model: SST=mean(SST)+A*cos(2π/T*(tme-wd)) We need to fnd: wth T=365 days A=ampltude of the seasonal cycle wd=warmer day of the year
3-2- Non lnear least square fttng We can use Matlab functon fmnsearch for ths purpose: FMINSEARCH Multdmensonal unconstraned nonlnear mnmzaton (Nelder-Mead). X = FMINSEARCH(FUN,X0) starts at X0 and attempts to fnd a local mnmzer X of the functon FUN. FUN s a functon handle. FUN accepts nput X and returns a scalar functon value F evaluated at X. X0 can be a scalar, vector or matrx. Man program: global sst tme f1 f1=1/365.2523; a0=10;%ampltude close to the soluton wd0=0; %warmer day close to the soluton parameters=... fmnsearch( SquaredResdualSum',[a0 wd0]); A=parameters(1); wd=parameters(2); Functon: functon SS=... SquaredResdualSum(parameters) global sst tme f1 A=parameters(1); wd=parameters(2); sst_model=a*cos(2*p*f1*(tme-wd)); SS=sum((sst_model-sst).^2);
3-2- Non lnear least square fttng What does the seasonal cycle look lke wthn False Bay? SST(TERRA)=mean(SST)+A*cos(2π/T*(tme-wd)) wth T=365 days usefularesomebut, wrongaremodelsall George E.P. Box How good s our model?
4- How to evaluate models? Several ndex can help evaluatng a model, and among them: Correlaton Coeffcent (COR), the Bas, the Root Mean Square Error (RMSE) and the Relatve Root Mean Square Error also called Scatter Index (SI). y y If s the measured value at the tme step, the modeled value at the same tme step, and are respectvely ther mean for the N tme step, then we have : ŷ y ˆ SI N 1 ( yˆ y ) N 1 BIAS yˆ y y 2 2 COR RMSE N 1 ( y y)( yˆ yˆ) N N 2 2 ( y ) ( ˆ ˆ y y y) 1 1 N 1 ( yˆ y ) N 2
4- How to evaluate models? For ths knd of applcaton, a good ndex s the correlaton coeffcent... R 2 2 yˆ COR var( ) var( y) provde a clear budget of how much of the total varance can be explaned by the model
4- How to evaluate models? The model could also smply be the clmatology Is the clmatology representatve n ths regon? Varance of the monthly SST(TERRA) explaned (%) by the seasonal cycle/monthly clmatology
5- Practcal 1- Compute the lnear trend of Pathfnder SST south of Cape Town at lattude 40S and longtude 16W (usng SST_Pathfnder_1D.mat) 2- Fnd warmer day and ampltude of a snusodal seasonal model (a*cos(wt+ph)) n False Bay (SST_FalseBay_1D.mat) and west of Cape Town n the upwellng (SST_upwellng_1D.mat). Whch part of the total varance s explaned by the model? 3- Compute mean SST, warmer day and ampltude of the seasonal cycle, and R 2 n the vcnty of Cape Town usng the 3D fle (tme,lat,lon) SST_CapePennsula_3D.mat.