-
Notifications
You must be signed in to change notification settings - Fork 4
/
ftpgetmodis.m
188 lines (180 loc) · 6.24 KB
/
ftpgetmodis.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
function [f] = ftpgetmodis(tiles,subdir,ftpsite,dest,styr,endyr,interval,start)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%% ftpgetmodis.m %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% matlab code to do automated downloading of large MODIS files from the
% MODIS/ASTER FTP data pool, found at:
% https://lpdaac.usgs.gov/lpdaac/get_data/data_pool
% This is designed to download all composites from a given year for a
% certain MODIS tile. Code is currently able to download data from
% 2000 to 2020, by which point, a new system will surely have made this
% code obsolete.
%
% SYNTAX:
% [f] = ftpgetmodis(tiles,subdir,ftpsite,dest,styr,endyr,interval,start)
% where:
% tiles = MODIS tile text
% subdir = subdirectory of FTP site - there's one folder for each product
% ftpsite = FTP site address of FTP site
% dest = local directory to receive downloaded files
% styr = start year
% endyr = end year
% interval= compositing interval, can be 1, 8 or 16
% start = starting composite for year, should be 1
%
% EXAMPLE: To download MODIS 8-day (interval) Land surface reflectance data
% - MOD09A1 (subdir) - from the Terra site, starting with 2000 (styr) and
% going until 2010 (endyr) and if I want all composites from the year
% (start). To download tile h12v11 (tiles), to the N drive (dest),
% use the following:
%
% ftpgetmodis('h12v11','MOLT/MOD09A1.005/','e4ftl01.cr.usgs.gov','N:\',...
% 2000, 2010, 8, 1)
% Essentially, this is opening the ftp site,
% ftp://e4ftl01.cr.usgs.gov/MOLT/MOD09A1.005 and getting all of the files
% that satisfy the other conditions.
%
%
% by Michael Toomey, [email protected]
% last modified April 26, 2011
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% K FOR loop should be from beginning to end year
for k=styr:endyr
disp(k)
% assign increment to "yearrange"
yearrange = k;
% calculate the serial dates for each year
% these must be done separately because of the leap years
% and the uneven splitting of the year into intervals
tmp=find(yearrange==2000);
if numel(tmp)==1
yr2000=730566:interval:730851;
end
tmp=find(yearrange==2001);
if numel(tmp)==1
yr2001=730852:interval:731216;
end
tmp=find(yearrange==2002);
if numel(tmp)==1
yr2002=731217:interval:731581;
end
tmp=find(yearrange==2003);
if numel(tmp)==1
yr2003=731582:interval:731946;
end
tmp=find(yearrange==2004);
if numel(tmp)==1
yr2004=731947:interval:732311;
end
tmp=find(yearrange==2005);
if numel(tmp)==1
yr2005=732313:interval:732677;
end
tmp=find(yearrange==2006);
if numel(tmp)==1
yr2006=732678:interval:733042;
end
tmp=find(yearrange==2007);
if numel(tmp)==1
yr2007=733043:interval:733407;
end
tmp=find(yearrange==2008);
if numel(tmp)==1
yr2008=733408:interval:733772;
end
tmp=find(yearrange==2009);
if numel(tmp)==1
yr2009=733774:interval:734138;
end
tmp=find(yearrange==2010);
if numel(tmp)==1
yr2010=734139:interval:734503;
end
tmp=find(yearrange==2011);
if numel(tmp)==1
yr2011=734504:interval:734868;
end
tmp=find(yearrange==2012);
if numel(tmp)==1
yr2012=734869:interval:735234;
end
tmp=find(yearrange==2013);
if numel(tmp)==1
yr2013=735235:interval:735599;
end
tmp=find(yearrange==2014);
if numel(tmp)==1
yr2014=735600:interval:735964;
end
tmp=find(yearrange==2015);
if numel(tmp)==1
yr2015=735965:interval:736329;
end
tmp=find(yearrange==2016);
if numel(tmp)==1
yr2016=736330:interval:736695;
end
tmp=find(yearrange==2017);
if numel(tmp)==1
yr2017=736696:interval:737060;
end
tmp=find(yearrange==2018);
if numel(tmp)==1
yr2018=737061:interval:737425;
end
tmp=find(yearrange==2019);
if numel(tmp)==1
yr2019=737426:interval:737790;
end
tmp=find(yearrange==2020);
if numel(tmp)==1
yr2020=737791:interval:738156;
end
% populate list of all years
years = whos('yr*');
% concatenate all dates together
dates = eval(years(1).name); clear('years(1).name')
% convert all of these serial numbers into MODIS folder names
for j=1:numel(dates)
% convert serial number to date vector
tmp=datevec(dates(j));
% make folder names by concatenating year, month and date. the sprintf
% function places a zero before the ones digit if it is < 10
yrstr = num2str(tmp(1));
datestr{j} = cat(2,yrstr,'.',sprintf('%02d',tmp(2)),'.',...
sprintf('%02d',tmp(3)));
end
% now, start doing that FTP jive, opening up each folder in "datestr" and
% getting its contents according to the search tiles
% first, open the anonymous FTP and change to any subdirectory
f = ftp(ftpsite);
cd(f,subdir);
% now, going through all folders in datestr, open each folder up, get the
% files matching the tiles and then go back up to the above directory
for i=start:numel(dates)
try
cd(f,datestr{i});
tmpstr=cat(2,'Opening folder ',datestr{i});
disp(tmpstr)
% concatenate asterisks to make the appropriate search filter
tile = cat(2,'*',tiles,'*');
% use try/catch statement to try the file acquisition with the
% error message of 'can't overwrite file' if there is some kind of
% problem.
try
mget(f,tile,dest);
catch
disp('Can''t overwrite or access file')
end
% switch back to upper folder
cd(f,'..');
catch
disp('Cannot find specified folder. Moving on.')
end
end
% clear any year variables
clear yr*
clear datestr
clear dates
end