%%% This codes helps to load the precipitation, one column array, %%% data for the HW #3 for ATMO 529 class. %%% Basic script by A.O. %%% loads the database load precipmonthly_usmx.asci %%% assigns the database a shorter variable name d=precipmonthly_usmx; %%% removes the original database to free memory clear precipmonthly_usmx; %%%% The following lines of code will help to place the %%%% database in a 3D array l=1; %%% index for k=1:660, %%%% loop on the months for j=1:51, %%%% loop on the latitude range for i=1:81, %%%% loop on the longitude range P(i,j,k) = d(l); l=l+1; %%%% increases the index in the databse by one unit end end end %%% calculates the mean and standard deviations ingnoring the -999.9 values for i=1:81, for j=1:51, %% get the indexes for the cells with numbers different from -999.9 q=find(P(i,j,:) ~= -999.9); %this returns an array % Uses the good data only to compute the mean and std (as defined % in Matlab) meanP(i,j) = mean(P(i,j,q)); % standard deviation normalizes by N (uses flag =1 as second % arument). If normalization by N-1 is required, change flag=1 for % flag=0 or remove the second argument. stdP(i,j) = std(P(i,j,q),1); end end %%% now we create a latitude and longitude vectors lon=(-140:1:-60); % longitude from 140W to 60W lat=(10:1:60); % latitude from 10N to 60N % meshgrid needed to be use together with pcolor.m or m_pcolor.m functions [LON,LAT]=meshgrid(lon,lat); LON=LON'; LAT=LAT'; %%%example of how to extract the data for a given month (here month=200) A=P(:,:,200); %%% A is a 2D array %%% plots the images for the computed mean and standard deviations %%%% figure imagesc(lon,lat,meanP',[0 200]); %%%% plots data in the range 0 to 500 mm colorbar; axis xy; %%% places the US/Mexico States boundaries on top hold; %%% holds the figure plot_us_states(0,'black.',5,0); fix_map('black',5,0) plot_state('MX','black.',5,0) title('Mean Precipitation in the contiguos US and Mexico'); xlabel('Longitude [deg]'); ylabel('Latitude [deg]'); figure imagesc(lon,lat,stdP',[0 200]); %%%% plots data in the range 0 to 500 mm colorbar; axis xy; %%% places the US/Mexico States boundaries on top hold; %%% holds the figure plot_us_states(0,'black.',5,0); fix_map('black',5,0) plot_state('MX','black.',5,0) title('Standard deviation (1 \sigma) for Precipitation in the contiguos US and Mexico'); xlabel('Longitude [deg]'); ylabel('Latitude [deg]');