MATLAB数据下载:自动化获取ERSSTv5数据

此代码可实现自动化下载ERSSTv5数据,这是一款空间分辨率2°,时间跨度可追溯到1854年的SST数据,是计算nino指数的常用数据。

该数据似乎不支持ftp下载,故以此数据为例尝试了一下如何用matlab批量下载nc数据。如果再遇到类似的仅提供网页下载的数据,可尝试以此脚本为参考。

blibili代码块不支持MATLAB,用的是python的高亮显示。

% automated download ERSSTv5
% Data path: https://www.ncei.noaa.gov/products/extended-reconstructed-sst
%
% Jia-Shun Wang
% wjs@outlook.at
% 2022/09/21
%
% Reference:
% Huang, B., Thorne, P.W., Banzon, V.F., Boyer, T., Chepurin, G.,
% Lawrimore, J.H., Menne, M.J., Smith, T.M., Vose, R.S., Zhang, H.-M.,
% 2017. Extended Reconstructed Sea Surface Temperature,
% Version 5 (ERSSTv5): Upgrades, Validations, and Intercomparisons.
% Journal of Climate 30, 81798205.https://doi.org/10.1175/JCLI-D-16-0836.1
clc;clear;close
%% setting
prefix='ersst.v5.';
suffix='.nc';
mkdir ../data ERSSTv5 %Create the output first
output_path='data/ERSSTv5/';
input_path='https://www.ncei.noaa.gov/pub/data/cmb/ersst/v5/netcdf/';
start_year=double(string(datetime(1854,01,01,'Format','yyyy')));%1854.01
end_date=datetime('today');
this_year=double(string(datetime('today','Format','yyyy')));
this_month=double(string(datetime('today','Format','MM')));%ignore this month
h=waitbar(0,'please wait');
end_year=this_year;% test
%% judge
if end_year==this_year
    bd=1;
else
    bd=0;
end
total=(end_year-start_year+1-bd)*12+bd*this_month-1;%ignore this month
%% implement
tic
for y=start_year:end_year
    if y~=this_year
        for m=1:12
            filename=[prefix,char(datetime(y,m,1,'Format','yyyyMM')),suffix];
            url=[input_path,filename];
            websave([output_path,filename],url);% save it to the local disk.
            str=['Downloading...',num2str(((y-start_year)*12+m)/...
                total*100,'%4.2f'),'%'];
            waitbar(((y-start_year)*12+m)/total,h,str)
        end
    else
        for m=1:this_month-1 %ignore this month
            filename=[prefix,char(datetime(y,m,1,'Format','yyyyMM')),suffix];
            url=[input_path,filename];
            websave([output_path,filename],url);% save it to the local disk.
            str=['Downloading...',num2str(((y-start_year)*12+m)/...
                total*100,'%4.2f'),'%'];
            waitbar(((y-start_year)*12+m)/total,h,str)
        end
    end
end
fprintf(2,'Awesome!\n You have download all data.\n')
toc

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空