Advertisement
Guest User

Gather data

a guest
Oct 5th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.29 KB | None | 0 0
  1. clc
  2. close all
  3. clear all
  4.  
  5. data = single(csvread('SEDAC_POP_2000-01-01_gs_3600x1800.CSV')); %read population data
  6. data(data == 99999)=0; %make sea uninhabited
  7.  
  8.  
  9. sin_vector = sin((1:1800)/1800*pi);
  10. A=sum(sin_vector*data);
  11.  
  12. %%
  13.  
  14. new_data=single(zeros(1800,3600));
  15. new_data2=single(zeros(1800,3600));
  16. tic
  17. for lat = 1:1800 %loop latitude
  18.     disp(lat/10)
  19.    
  20.     latrad = pi*lat/1800-pi/2;
  21.     Filter = single(zeros(1800,3600)); %create empty filter matrix
  22.     for lat2 = 1:1800 %loop latitude
  23.         lat2rad = pi*lat2/1800-pi/2;
  24.         delta_lat = lat2rad - latrad;  
  25.         x=sin(delta_lat/2)^2;
  26.         y= cos(latrad) * cos(lat2rad);
  27.         q=sin(lat2rad+pi/2);
  28.         for lon2 = 1:3600 %loop longitude
  29.             lon2rad = pi*lon2/1800-pi;
  30.             delta_lon = lon2rad - pi;
  31.             R = 6371;% Earth's radius in km
  32.  
  33.             d = R * 2 * asin(sqrt(x + y * sin(delta_lon/2)^2));
  34.             if d < 10000
  35.                  Filter(lat2,lon2)=q;
  36.             end
  37.         end
  38.     end
  39.    
  40.     for lon = 1:3600
  41.         if data(lat,lon) == 0
  42.             new_data(lat,lon)=sum(sum(single(circshift(Filter,[0 lon])).*data));
  43.         else
  44.             new_data2(lat,lon)=sum(sum(single(circshift(Filter,[0 lon])).*data));
  45.         end
  46.        
  47.     end
  48.     toc
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement