以下资源来自网络,本文仅转载,希望可以帮到有需要的同学们!$ W3 `9 m* P! \
% f, [ C L: e% C* \5 G) X【前提】 最近有同学问如何批量下载海冰密集度的数据,很久前在家园里了解到了wget,今天以这个为例整理一哈…当然,实现的方式还有很多,这里用的是shell来完成。
' E' S* ?! c+ @6 i
' m" P# u6 n- U# [ a: oA【数据】 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
$ ]* p8 ~% f& T% X2 x' Y: _9 Y
8 X- |9 x. w9 ]' ?( A4 Z$ J
B 【需求】 B.1 需要下载该数据集海冰的数据,由于数据存放方式是根据时间建立的路径,需要遍历下载。如/n5eil01u.ecs.nsidc.org/PM/NSIDC-0051.001/2000.04.22
7 V' ~* K4 C( _$ W4 [" |2 l( iC【实现方式】 创建文件$ vim down_sea_ice.sh 根据需求修改代码
! Q7 t4 e$ f8 H. q3 A7 s: q在终端中$bashdown_sea_ice.sh
# `( C4 i- S+ y8 l J0 }# {/ v9 y
6 M. ?. W; u$ w! R$ N
* F0 e1 |9 x0 Y: y& e4 sC.1 使用语言:shell。MATLAB、python等也可,后面介绍。 C.2 思路:通过wget进行下载 利用shell,设置起始时间和结束时间,循环生成每个路径后,再利用wget进行下载。 / k$ Y4 L* n& u4 _( x6 H+ G; o; v
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
& j, B- f2 V; E2 {3 \; a- P/ | 1 ?! q# w: z7 V4 ~
[color=rgb(255, 0, 0) !important]复制代码( v- h& d, k6 J7 B/ v
1 U3 G8 V# f9 G+ f$ x# f* {/ z5 b
代码中配置时间,循环时间,生成路径,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" - H" n7 I9 K0 O+ b
参考网址:https://nsidc.org/support/faq/what-options-are-available-bulk-downloading-data-https-earthdata-login-enabled 3 ~9 | T, e! l! u
; T0 w+ \( i' S' x# v
9 V( [0 X" _& j7 x
C.4 遇到的问题: 最初使用了绝对路径,发现出现了404错误,排查发现是 文件名是nt_20100105_f17_v1.1_n.bin。之前以为‘f17‘是不变的。 下面是错误记录
3 P# @. H5 {. W% S9 i+ `5 M
+ E1 F4 }4 X3 |【报错】 下载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编号的规则 或者 变通配符 , Z: \1 \4 A4 `+ h9 y
参考
8 c- H" B* H+ r% n7 ~2 T3 ]+ n同时我也记录在了气象家园的网上 www.52ocean.cn |