以下资源来自网络,本文仅转载,希望可以帮到有需要的同学们!; ^ t/ B2 O2 b3 I
P) |' U' R) {) C
【前提】 最近有同学问如何批量下载海冰密集度的数据,很久前在家园里了解到了wget,今天以这个为例整理一哈…当然,实现的方式还有很多,这里用的是shell来完成。4 m/ [3 r% @5 s; {2 v
; F/ h0 h1 P2 G( Q4 ]
A【数据】 A.1 数据名Sea Ice Concentrations from Nimbus-7 SMMR and DMSP SSM/I-SSMISPassive Microwave Data, Version 1 A.2 数据主页 https://nsidc.org/data/nsidc-0051/; 数据说明 www.52ocean.cn
1 n) S$ E: C5 ?! q
5 n I7 X9 a' J# X }/ D7 F4 y+ n) i6 G
B 【需求】 B.1 需要下载该数据集海冰的数据,由于数据存放方式是根据时间建立的路径,需要遍历下载。如/n5eil01u.ecs.nsidc.org/PM/NSIDC-0051.001/2000.04.22
6 B; [: S2 M1 K) i( L0 xC【实现方式】 创建文件$ vim down_sea_ice.sh 根据需求修改代码
, Q4 ?3 ]8 d* Z; U8 }* G在终端中$bashdown_sea_ice.sh
& r5 P: t/ N( j4 [6 ?8 x* z3 ]+ M0 t/ P
$ X* z p0 Y1 X0 L3 s
* P) U& B1 X/ P2 B( k, e" MC.1 使用语言:shell。MATLAB、python等也可,后面介绍。 C.2 思路:通过wget进行下载 利用shell,设置起始时间和结束时间,循环生成每个路径后,再利用wget进行下载。 2 a0 x" @2 D' `2 d6 B M2 q- f7 J
C.3 代码 - #
- # www.52ocean.cn
- startdate=2000-01-01
- enddate=2010-12-31
- sDateTs=`date -j -f "%Y-%m-%d" $startdate "+%s"`
- eDateTs=`date -j -f "%Y-%m-%d" $enddate "+%s"`
- dateTs=$sDateTs
- offset=86400
- while [ "$dateTs" -le "$eDateTs" ]
- do
- date=`date -j -f "%s" $dateTs "+%Y-%m-%d"`
- year=`date -j -f "%s" $dateTs "+%Y"`
- month=`date -j -f "%s" $dateTs "+%m"`
- day=`date -j -f "%s" $dateTs "+%d"`
- printf "wget --load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies --keep-session-cookies --no-check-certificate --auth-no-challenge=on -r --reject \047index.html*\047 -np -e robots=off www.52ocean.cn\n" $year $month $day $year $month $day
- wget --load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies --keep-session-cookies --no-check-certificate --auth-no-challenge=on -r --reject 'index.htm;*' -c -np -e robots=off -A "*_n.*" "https://n5eil01u.ecs.nsidc.org/PM/NSIDC-0051.001/${year}.${month}.${day}/"
- dateTs=$(($dateTs+$offset))
- done
: R! H* D h5 |& V# x
6 l! y. D3 w; Y: C! |[color=rgb(255, 0, 0) !important]复制代码* t0 a, h( Y; H9 g, q
) A% x) i; j" U5 N
代码中配置时间,循环时间,生成路径,wget下载【linux】 wget--load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies--keep-session-cookies --no-check-certificate --auth-no-challenge=on -r --reject 'index.htm;*' -c -np -erobots=off -A "*_n.*" "https://n5eil01u.ecs.nsidc.org/PM/NSIDC-0051.001/${year}.${month}.${day}/" 【windows】 wget--http-user=[USERNAME] --http-password=[PASSWORD] --load-cookies mycookies.txt--save-cookies mycookies.txt --keep-session-cookies--no-check-certificate--auth-no-challenge -r --reject "index.html*" –c-np -e robots=off -A "*_n.*""https://n5eil01u.ecs.nsidc.org/PM/NSIDC-0051.001/${year}.${month}.${day}/" 基本参考冰雪中心给的下载方式(下面有网址),额外加了 1. -c:断点 2. -A "*_n.*" :通配符,可下载北极的数据,见图1中的蓝色方框。若只下载bin文件,则改为-A "*_n.bin"
) R' l- z% ?) y& e: j: a# q6 }参考网址:https://nsidc.org/support/faq/what-options-are-available-bulk-downloading-data-https-earthdata-login-enabled 7 v. t9 w; _$ _3 R- ?2 c/ h
t4 n: @& }; L
9 q' k! t- d1 f6 @C.4 遇到的问题: 最初使用了绝对路径,发现出现了404错误,排查发现是 文件名是nt_20100105_f17_v1.1_n.bin。之前以为‘f17‘是不变的。 下面是错误记录 ; g! F9 f! g3 D! ?0 q
8 l: a4 m5 L( W& e
【报错】 下载2000年的数据发现404报错 wget --load-cookies ~/.urs_cookies --save-cookies~/.urs_cookies --keep-session-cookies --no-check-certificate--auth-no-challenge=on -r --reject 'index.html*' -np -e robots=offwww.52ocean.cn Resolving n5eil01u.ecs.nsidc.org... 128.138.97.102 Connecting to n5eil01u.ecs.nsidc.org|128.138.97.102|:443...connected. HTTP request sent, awaiting response... 404 Not Found 2019-06-11 16:12:17 ERROR 404: Not Found. 【原因】 文件名发生变化 变成了f07 不是 n07 nt_20100105_f17_v1.1_n.bin 【解决思路】 1 找到f编号的规则 或者 变通配符
9 O0 r, E, ]/ O: J) F. C参考 2 u9 u! ^9 T0 W+ |8 |' p7 m
同时我也记录在了气象家园的网上 www.52ocean.cn |