B.Aires, 20-24/02/06 - Centro de Investigaciones del Mar y la Atmosfera & Department of Atmospheric and Oceanic Sciences (UBA) DAY1 Exercise n. 1 Read an SST field in netcdf format, subsample and save in matlab format. [ 2 solutions] Exe-1_mod_1.m cd C:\ENRICO\tutorials\esercizi\day_1\ex1; Choose your work directory Use the NCBROWSER command to view nc-files content in../data directory. ncload../data/skt.mon.mean.nc Load all the content of the nc file whos Name Size Bytes Class ans 1x4 266 cell array lat 94x1 752 double array lon 192x1 1536 double array skt 687x94x192 99191808 double array time 687x1 5496 double array time is in hours since 1-1-1 00:00:0.0... diff(time)/24 Show n-days series. lat variable is N-S order >> lat(1) ans = 88.5420 >> lat(end) ans = -88.5420 select a subregion: southern ocean --> lat(end-20:end) latitude -50-90 lon(:) longitude 0 360 lat_so=lat(end-20:end); Remember: lat vector is N-S lon_so=lon; skt_so=skt(:,end-20:end,:); whos *so View your news matrices Name Size Bytes Class lat_so 21x1 168 double array lon_so 192x1 1536 double array skt_so 687x21x192 22159872 double array save./output/skt.so.mon.mean.mat lat_so lon_so skt_so Save your new matrices or save./output/skt.so.mon.mean.mat *so 1
Exe-1_mod_2.m exercise 1 cd C:\ENRICO\tutorials\esercizi\day_1\ex1; filenamein = '../data/skt.mon.mean.nc'; f = netcdf(filenamein,'nowrite'); var1= f{'skt'}; skt_so=var1(:,end-20:end,:); var2= f{'lat'}; lat_so=var2(end-20:end); var3= f{'lon'}; lon_so=var3(:); Choose your work directory Filenamein is a char array The variable f is the netcdf object. var1 is the ncvar object. whos *so View your news matrices lat_so 21x1 168 double array lon_so 192x1 1536 double array skt_so 687x21x192 22159872 double array save./output/skt.so.mon.mean.mat lat_so lon_so skt_so or save./output/skt.so.mon.mean.mat *so Save your new matrices 2
Exercise n. 2 Read an SST field, create nino3 time series and save it in binary format. Exe-2.m cd C:\ENRICO\tutorials\esercizi\day_1\ex2; ncload../data/skt.mon.mean.nc NCEP SKT dataset 01/1948-03/2004 index_lat_n3=find(-5<=lat&lat<=5); Select nino3 area: index_lon_n3=find(210<=lon&lon<=270); lat = 5S 5N lon = 210E :270E index_time=[22*12+1:22*12+30*12]; and the 1970-1999 period. lat_n3=lat(index_lat_n3); lon_n3=lon(index_lon_n3); skt_n3=skt(index_time,index_lat_n3,index_lon_n3); 360x6x33 whos skt_n3 Name Size Bytes Class skt_n3 360x6x33 1088208 double array Verify dimensions Create a 4d array: [YEARS x MONTHS x LAT x LON] skt_n3=reshape(skt_n3,12,30,6,33); skt_n3=permute(skt_n3,[2 1 3 4]); clima_skt_n3=squeeze(mean(skt_n3)); clima_skt_n3=repmat(clima_skt_n3,[30 1 1]); clima_skt_n3=reshape(clima_skt_n3,12,30,6,33); clima_skt_n3=permute(clima_skt_n3,[2 1 3 4]); ssta=skt_n3-clima_skt_n3; ssta2=reshape(ssta,30,12,6*33); ssta3=squeeze(mean(permute(ssta2,[3 1 2]))); ssta_series=reshape(ssta3',1,12*30); Simple plot... tomorrow we will plot better the same series plot(ssta_series); grid on; fid=fopen('./output/ssta_nino3_30y.dat','w','b'); 12x30x6x33 30x12x6x33 12x6x33 360x6x33 12x30x6x33 30x12x6x33 30x12x6x33 30x12x198 30x12 1x360 Save nino3 time series in binary format count=fwrite(fid,ssta_series,'float32') If count = 360, you have written correctly. fclose(fid); Close the file. 3
Exercise n. 3 Read an SST field, mask and compute global mean... esercizi\day_1\data\lsmask.19294.nc ncload../data/skt.mon.mean.nc ncload../data/lsmask.19294.nc Load skin temperature field time series and land-sea mask. pcolor(flipud(lsmask));colorbar; lsm=lsmask+1; lsm(lsm==0)=nan; skt_y1=squeeze(mean(skt(1:12,:,:))); lsmask skt sst_y1=skt_y1.*lsm; pcolor(flipud(sst_y1)); view the mask field N.B. not geo-referenced. Set "1" on the sea and "nan" on the land. 94x192 subsample the T time series in time: get the first year of mm. 94x192 94x192 View the sst field created masking the skin temperature annual field (skt_y1). N.B. not geo-referenced. 1x1 sst_global=nanmean(sst_y1(:)) sst_global = 10.1268 This is the global averaged sst value. True only considering regular grid. No weighting needed. 4
Exercise n. 4 Load monthly SST fields in structured array, mean in time and concatenate annual averages...esercizi\day_1\data\skt.25x25.????.mat list=num2str([1980:1:1989]'); Create a char array list for the years 1980-1989 for i=1:10 filenamein=strcat('../data/skt.25x25.',list(i,:),'.mat'); STRCAT Concatenate strings. varname_tmp=strcat('skt1_mm(',num2str(i),')'); string_to_eval=strcat(varname_tmp,'=load(', '''', filenamein, '''', ');') eval([string_to_eval]); EVAL Execute string with end MATLAB expression. exe: skt1_mm(1)=load('../data/skt.25x25.1980.mat') skt2_mm=squeeze(struct2cell(skt1_mm)) skt2_mm = skt3_mm=squeeze(cell2mat(skt2_mm)); STRUCT2CELL create a cell array from a struct array CELL2MAT create a double array from a cell array whos skt* skt1_mm 1x10 10162264 struct array skt2_mm 10x1 10162200 cell array skt3_mm 120x73x145 10161600 double array skt4_mm=reshape(skt3_mm,12,10,73,145); skt_y_1980_1989=squeeze(mean(skt4_mm)); save./output/skt_y_1980_1989.mat skt_y_1980_1989 12x10x73x45 10x73x145 skt annual average 5