필터 지우기
필터 지우기

Download all hours of all days of the year from CMORPH

조회 수: 1 (최근 30일)
This script below wants to download all hours of all days of the year from 2000 to 2005, but the following error appears:
clc
clearvars
% Download the CPC data used in the script below
which_years = (2000:2005); % years to download
httpsUrl = "https://www.ncei.noaa.gov/data/cmorph-high-resolution-global-precipitation-estimates/access/30min/8km/";
% filename_tmp="temp.nc"; % temporary filename (for loop); data will be always stored under this temp name
%% main loop
mm = (1:12); % all monthes in year
% mm = [1 6]; % process only some specific monthes in year
for cc = 1:numel(which_years) % loop over years
this_year = which_years(cc);
for ci = 1:numel(mm) % loop over monthes
days_per_month = datenum(this_year, mm(ci)+1, 1) - datenum(this_year, mm(ci), 1); % compute how many days this month/year
for ck = 1:days_per_month % loop over days
ymd_str = datenum(this_year, mm(ck)+1, 1) - datenum(this_year, mm(ck), 1); % year month day string
for ch = 1:ymd_str
hora_str = strcat(sprintf('%04d',this_year), sprintf('%02d', mm(ci)), sprintf('%02d', ch));
Url = strcat(httpsUrl, sprintf('%04d', this_year), "/", sprintf('%02d', mm(ci)),"/");
filename = strcat("CMORPH_V1.0_ADJ_8km-30min_", hora_str ,".nc"); % create filename according to list above
disp(strcat(filename, " is processed"));
dataUrl = strcat(Url, filename);
data = webread(dataUrl);
filename_tmp=strcat("data_5", ymd_str ,".nc"); % temporary filename (for loop); data will be always stored under this temp name
filename_out = websave(filename_tmp,dataUrl); % save downloaded data
% ncdisp(filename_tmp,'/','min'); % commented, just to avoid filling the command window
precip=ncread(filename_tmp,'cmorph'); % Dimensions: lon,lat,time
long=ncread(filename_tmp,'lon');
lat=ncread(filename_tmp,'lat');
time=ncread(filename_tmp,'time');
end
end
end
end
The error reported is this:
Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray (line 396)
The server returned the status 404 with message "Not Found" in response to the request to
URL
https://www.ncei.noaa.gov/data/cmorph-high-resolution-global-precipitation-estimates/access/30min/8km/2000/01/CMORPH_V1.0_ADJ_8km-30min_20000101.nc.
Error in readContentFromWebService (line 46)
byteArray = copyContentToByteArray(connection);
Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Error in Untitled (line 36)
data = webread(dataUrl);
  댓글 수: 1
Peter Perkins
Peter Perkins 2022년 12월 19일
Two things:
1) You probably want to look at using a datastore for this. They are specifically designed for this kind of multiple file scenario.
2) You are not doing yourself any favors by using datenums. Use datetimes.

댓글을 달려면 로그인하십시오.

채택된 답변

Augusto Gabriel da Costa Pereira
Augusto Gabriel da Costa Pereira 2022년 12월 18일
편집: Augusto Gabriel da Costa Pereira 2022년 12월 19일
Script to download CMORPH reanalysis data that is inserted in the following link: https://www.ncei.noaa.gov/data/cmorph-high-resolution-global-precipitation-estimates/access/daily/0.25deg/
%% Part 1
clc
clearvars
% Download the CMORPH data used in the script below
which_years = (2000:2021); % years to download
httpsUrl = "https://www.ncei.noaa.gov/data/cmorph-high-resolution-global-precipitation-estimates/access/30min/8km/";
% filename_tmp="temp.nc"; % temporary filename (for loop); data will be always stored under this temp name
%% main loop
mm = (1:12); % all monthes in year
% mm = [1 6]; % process only some specific monthes in year
for cc = 1:numel(which_years) % loop over years
this_year = which_years(cc);
for ci = 1:numel(mm) % loop over monthes
days_per_month = datenum(this_year, mm(ci)+1, 1) - datenum(this_year, mm(ci), 1); % compute how many days this month/year
for ck = 1:days_per_month % loop over days
ymd_str = datenum(this_year, mm(ci)+1, 1) - datenum(this_year, mm(ci), 1); % year month day string
for ch = 1:ymd_str
hora_str = strcat(sprintf('%04d',this_year), sprintf('%02d', mm(ci)), sprintf('%02d', ch));
Url = strcat(httpsUrl, sprintf('%04d', this_year), "/", sprintf('%02d', mm(ci)),"/",sprintf('%02d',ch),'/');
for i = 0:23
filename = strcat("CMORPH_V1.0_ADJ_8km-30min_", hora_str ,sprintf('%02d',i),".nc"); % create filename according to list above
disp(strcat(filename, " is processed"));
dataUrl = strcat(Url, filename);
data = webread(dataUrl);
filename_tmp=strcat("data", num2str(hora_str), num2str(sprintf('%02d',i)) ,".nc"); % temporary filename (for loop); data will be always stored under this temp name
filename_out = websave(filename_tmp,dataUrl); % save downloaded data
% ncdisp(filename_tmp,'/','min'); % commented, just to avoid filling the command window
precip=ncread(filename_tmp,'cmorph'); % Dimensions: lon,lat,time
long=ncread(filename_tmp,'lon');
lat=ncread(filename_tmp,'lat');
time=ncread(filename_tmp,'time');
end
end
end
end
end
  댓글 수: 3
Augusto Gabriel da Costa Pereira
Augusto Gabriel da Costa Pereira 2022년 12월 18일
편집: Augusto Gabriel da Costa Pereira 2022년 12월 18일
Here is:
hora_str = strcat(sprintf('%04d',this_year), sprintf('%02d', mm(ci)), sprintf('%02d', ck(ch)));
filename_tmp=strcat("data", num2str(hora_str), num2str(sprintf('%02d',i)) ,".nc"); % temporary filename (for loop); data will be always stored under this temp name
VBBV
VBBV 2022년 12월 20일
Ok, The problem was with error located in the line
data = webread(dataUrl);
which was resolved, Regarding the download of data, did you look at my updated comment ? . You need to use { } to store all files for years as shown below
filename_out{i+1} = websave(filename_tmp,dataUrl); % save /downloaded all data

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

VBBV
VBBV 2022년 12월 17일
편집: VBBV 2022년 12월 17일
Note the following changes
clc
clearvars
% Download the CPC data used in the script below
which_years = (2000:2005); % years to download
httpsUrl = "https://www.ncei.noaa.gov/data/cmorph-high-resolution-global-precipitation-estimates/access/30min/8km/";
% filename_tmp="temp.nc"; % temporary filename (for loop); data will be always stored under this temp name
%% main loop
mm = (1:12); % all monthes in year
% mm = [1 6]; % process only some specific monthes in year
for cc = 1:numel(which_years) % loop over years
this_year = which_years(cc);
for ci = 1:numel(mm) % loop over monthes
days_per_month = datenum(this_year, mm(ci)+1, 1) - datenum(this_year, mm(ci), 1); % compute how many days this month/year
for ck = 1:days_per_month % loop over days
ymd_str = datenum(this_year, mm(ci)+1, 1) - datenum(this_year, mm(ci), 1); % year month day string
for ch = 1:ymd_str
hora_str = strcat(sprintf('%04d',this_year), sprintf('%02d', mm(ci)), sprintf('%02d', ch));
Url = strcat(httpsUrl, sprintf('%04d', this_year), "/", sprintf('%02d', mm(ci)),"/",sprintf('%02d',ch),'/');
for i = 0:23
filename = strcat("CMORPH_V1.0_ADJ_8km-30min_", hora_str ,sprintf('%02d',i),".nc"); % create filename according to list above
disp(strcat(filename, " is processed"));
dataUrl = strcat(Url, filename);
data = webread(dataUrl);
filename_tmp=strcat("data_5", num2str(ymd_str) ,".nc"); % temporary filename (for loop); data will be always stored under this temp name
filename_out = websave(filename_tmp,dataUrl); % save downloaded data
% ncdisp(filename_tmp,'/','min'); % commented, just to avoid filling the command window
precip=ncread(filename_tmp,'cmorph'); % Dimensions: lon,lat,time
long=ncread(filename_tmp,'lon');
lat=ncread(filename_tmp,'lat');
time=ncread(filename_tmp,'time');
end
end
end
end
end
  댓글 수: 8
Augusto Gabriel da Costa Pereira
Augusto Gabriel da Costa Pereira 2022년 12월 18일
I was able to modify the code and find the error
I modified the following command below
filename_tmp=strcat("data", num2str(hora_str), num2str(sprintf('%02d',i)) ,".nc"); % temporary filename (for loop); data will be always stored under this temp name
The script that is working is this right after:
clc
clearvars
% Download the CMORPH data used in the script below
which_years = (2000:2005); % years to download
httpsUrl = "https://www.ncei.noaa.gov/data/cmorph-high-resolution-global-precipitation-estimates/access/30min/8km/";
% filename_tmp="temp.nc"; % temporary filename (for loop); data will be always stored under this temp name
%% main loop
mm = (1:12); % all monthes in year
% mm = [1 6]; % process only some specific monthes in year
for cc = 1:numel(which_years) % loop over years
this_year = which_years(cc);
for ci = 1:numel(mm) % loop over monthes
days_per_month = datenum(this_year, mm(ci)+1, 1) - datenum(this_year, mm(ci), 1); % compute how many days this month/year
for ck = 1:days_per_month % loop over days
ymd_str = datenum(this_year, mm(ci)+1, 1) - datenum(this_year, mm(ci), 1); % year month day string
for ch = 1:ymd_str
hora_str = strcat(sprintf('%04d',this_year), sprintf('%02d', mm(ci)), sprintf('%02d', ck(ch)));
Url = strcat(httpsUrl, sprintf('%04d', this_year), "/", sprintf('%02d', mm(ci)),"/",sprintf('%02d',ch),'/');
for i = 0:23
filename = strcat("CMORPH_V1.0_ADJ_8km-30min_", hora_str ,sprintf('%02d',i),".nc"); % create filename according to list above
disp(strcat(filename, " is processed"));
dataUrl = strcat(Url, filename);
data = webread(dataUrl);
filename_tmp=strcat("data", num2str(hora_str), num2str(sprintf('%02d',i)) ,".nc"); % temporary filename (for loop); data will be always stored under this temp name
filename_out = websave(filename_tmp,dataUrl); % save downloaded data
% ncdisp(filename_tmp,'/','min'); % commented, just to avoid filling the command window
precip=ncread(filename_tmp,'cmorph'); % Dimensions: lon,lat,time
long=ncread(filename_tmp,'lon');
lat=ncread(filename_tmp,'lat');
time=ncread(filename_tmp,'time');
end
end
end
end
end
VBBV
VBBV 2022년 12월 18일
편집: VBBV 2022년 12월 18일
If you want to save all the files, change this line
filename_out = websave(filename_tmp,dataUrl); % save downloaded data
to
filename_out{i+1} = websave(filename_tmp,dataUrl); % save downloaded data
Which downloads and saves data for all files

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by