Presentation is loading. Please wait.

Presentation is loading. Please wait.

Overview %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%

Similar presentations


Presentation on theme: "Overview %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%"— Presentation transcript:

1 Overview %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%

2

3

4 %nakedsoftware.org opensource license, copyright 2010 stephane.poirier@oifii.org % %developed by Stephane Poirier, M.Sc. Optical Physics, Remote Sensing Application Software Developer (1991-2010) % %this function is part of oifii.org's ar\sp\ Microwave- derived 30-year Canada-Alaska Daily Temperature and Snowcover Databases library % %this function is part of oifii.org's ar\sp\'this folder' application (lauched with ar\sp\'this file'.m) %oifii.org's ar\sp\affiche_carte application is part of the oifii.org's ar\sp set of applications which %may also contain similar variant versions of this function with identical filename. % %A geophysical research paper about this work has been submitted in June 2009 for publication in JGR-Atmosphere %Royer, A. and Poirier S., Surface temperature spatial and temporal variations in North America from homogenized %satellite SMMR-SSM/I microwave measurements and reanalysis for 1979-2008, Journal of Geophysical Research - Atmosphere, %Submitted June 2009, http://www.oifii.org/tsatdb/Royer- Poirier_Microwave-derived-daily-surface- temperature_JGR2009JD012760_R2.pdf % %This study's database can be downloaded from the author web site at: %http://www.oifii.org/tsatdb/Royer-Poirier_Microwave-derived- daily-surface-temperature-db_1979-2008.zip % %this function is used to display the raw microwave raster data (NSIDC's SMMR and SSMI satellite, ref. nsidc.org) % %usage: % 20yymmmdd % %version 0.2, 2008sep02, spi, use C:\AR\SP\MASK\CAN_MASK_PROV to filter out all but one province %version 0.1, 20yymmmdd, spi, unoptimized when called within a loop because always regenerating filename g:/tsat_kml/xyz_lonlatalt.xls %version 0.1, 20yymmmdd, spi, create a kml file (.kml) file wrapper for 28-years tsat db %version 0.0, 20yymmmdd, spi, initial function draft % %nakedsoftware.org opensource license, copyright 2010 stephane.poirier@oifii.org

5 %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%

6

7 function tsat2kml(province) yearmax=2008; if nargin<1 province='all';end %default province='all' or specify province for generating a subset kml file for the province %{ 1 for Alberta 2 for Saskatchewan 3 for Manitoba 4 for Newfoundland & Labrador 5 for Prince Edward Island 6 for Nova Scotia 7 for Northwest Territories 8 for Nunavut 9 for Ontario 10 for New Brunswick 11 for Yukon Territory 12 for British Columbia 13 for Quebec %} id_province=-1; if strcmpi(province,'all')==1 id_province=-1; elseif ~isempty(str2num(province)) id_province=str2num(province); elseif(exist('C:\spoirier\oifii-org\httpdocs\ns- org\nsd\ar\sp\tsat_shp\dcw_provinces\provinces.shp', 'file')) provinces=shaperead('C:\spoirier\oifii- org\httpdocs\ns- org\nsd\ar\sp\tsat_shp\dcw_provinces\provinces.shp','UseGeoCo ords',true); id_province=-1; for index=1:numel(provinces) if ~isempty(strfind(provinces(index,1).NAME,province(2:end))) %kick out the first letter because most likely uppercase in the shapefile id_province=index; break; end end%for index=1:numel(provinces) if(id_province==-1) display('id_province not found, will use -1 for all provinces');end %{ geoshow([provinces.Lat],[provinces.Lon],'DisplayType','polygo n','FaceColor','None'); for index=1:numel(provinces) h=textm((provinces(index).BoundingBox(1,2)+provinces(index).B oundingBox(2,2))/2,... (provinces(index).BoundingBox(1,1)+provinces(index).BoundingB ox(2,1))/2,provinces(index).NAME); trimcart(h) rotatetext(h) end %} end %initialize land/water mask m=masque(2,2); %land=1, water=0 %prepare xlsfilename xlsfilename='g:/tsat_kml/xyz_lonlatalt.xls'; display(['preparing filename ',num2str(xlsfilename)]); %initialize xls matrix xls=[]; xls=cat(1,xls,{'longitude','latitude','altitude variation'}); %read can3d300 ease grid dem fid=fopen(fullfile('c:/ar/sp/dem/dem_can3d300/','can3d300_eas e'),'r'); elevations_m=fread(fid,160*240,'float32'); %in meter fclose(fid); elevations_m=reshape(elevations_m,160,240); for row=1:160 for col=1:240 %get latitude and longitude [x_pix,y_pix]=pixel2pix(col,161-row,'canada'); [longitude,latitude]=pix2latlon(x_pix,y_pix); if(m(row,col)==1) %m==1 land %write one xls matrix line xls=cat(1,xls,{num2str(longitude),num2str(latitude),num2str(e levations_m(row,col))}); end end%for col end%for row %write xls matrix into an.xls file xlswrite(xlsfilename,xls); %prepare shapefile points [points(1:length(xls)-1).Geometry]=deal('Point'); %As Geometry is the same for all elements, assign it with deal: np=0; for i=1:length(xls)-1 %get longitude points(i).Lon=str2num(xls{i+1,1}); %get latitude points(i).Lat=str2num(xls{i+1,2}); %get altitude if(~isnan(str2num(xls{i+1,3}))) points(i).Alt=str2num(xls{i+1,3}); else points(i).Alt=0.0; np=np+1; end end%for display(['the number of NaN points is ',num2str(np),' (these are mostly usa points for which can3d300 db was not returning an altitude, altitude variation will be set to 0.0 in the shapefiles)']); %spi, 2008 sept 02, begin if(id_province~=-1 && id_province>0 && id_province<14) %use province mask if it exists, this mask is generated by the function readshp_xyz_lonlatalt_provinces(province) %fid=fopen('C:\AR\SP\MASK\CAN_MASK_PROV','r'); fid=fopen('C:\spoirier\oifii-org\httpdocs\ns- org\nsd\ar\sp\MASK\CAN_MASK_PROV','r'); if fid~=-1 can_mask_prov=fread(fid,[160,240],'float32'); status=fclose(fid); end end%if(id_province~=-1 && id_province>0 && id_province<14) %spi, 2008 sept 02, end %write one kml file per day per year for year=1979:2007 %year=[1979 2007] %year=1979:1979 %year=2007:2007 %year=1979:2007 for year=1979:yearmax tic; %set filename %outputfilename=['g:\tsat_kml\','tsat_',num2str(year)]; %raster data for day=182:182 %for day=182:182+2*31 %for day=1:366 provincename='';if(id_province~=-1) provincename=['_',province]; end outputfilename=['g:\tsat_kml\','tsat_',num2str(year),'_D',spr intf('%03d',day),provincename,'.kml']; copyfile('kml_header.kml',outputfilename); fid_output=fopen(outputfilename,'a'); if((day==366)&&(((~rem(year,4)&rem(year,100))|~rem(year,400)) ==0));continue;end display(['year/day ',num2str(year),'/',num2str(day)]); inputfilename=['D:\tsat\canada\',num2str(year),'\',sprintf('% 03d',day)]; [pathstr,name,ext,versn]=fileparts(inputfilename); [d1 d2 f]=autodimformat(pathstr,name); dim=[d1 d2]; format=f; fid=fopen(inputfilename,'r'); if(fid~=-1) data=fread(fid,[1 inf],format); data=reshape(data,160,240); fclose(fid); else disp('error'); return; end%if %set tsat daily temperatures as attributes to points ip=0; for row=1:160 for col=1:240 if(m(row,col)==1) %m==1 land %spi, 2008 sept 02, begin if(id_province~=-1 && can_mask_prov(row,col)~=id_province) continue; end %spi, 2008 sept 02, end ip=ip+1; if(data(row,col)>0) %points(ip).d(day)=data(row,col); %eval(['points(ip).d',sprintf('%03d',day),'=data(row,col);']) ; tsat=data(row,col)-273.16; %write lon,lat,alt,tsat to kml file %fprintf(fid_output,' Celcius (%d,%d)=%f %f,%f,%f \n',row,col,tsat,points(ip).Lon, points(ip).Lat,points(ip).Alt); fprintf(fid_output,' Celcius %.2f %f,%f,0 \n',tsat,points(ip).Lon,points(ip).Lat); else %points(ip).d(day)=0.0; %eval(['points(ip).d',sprintf('%03d',day),'=0;']); %'=0.0;']); end end%for col end%for row %write kml footer fprintf(fid_output,' \n'); %close kmlfile fclose(fid_output); end%for day toc; end%for year end%function


Download ppt "Overview %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%% %%%%%%%"

Similar presentations


Ads by Google