最近从NSIDC下载数据,想批量下载每一年的1-2月数据
因此对他官方的代码修改如下
只需要修改main方法即可
其实主要是在每个循环中对filename_filter进行修改
并且每次循环都要将url_list=None,否则后面就不会重新搜索文件
def main(argv=None):
global short_name, version, time_start, time_end, bounding_box, \
polygon, filename_filter, url_list
sy=1979
ey=2020
for num in range(sy,ey+1):
filename_filter = '*'+str(num)+'01*_n.bin'
print(filename_filter)
if argv is None:
argv = sys.argv[1:]
force = False
quiet = False
usage = 'usage: nsidc-download_***.py [--help, -h] [--force, -f] [--quiet, -q]'
try:
opts, args = getopt.getopt(argv, 'hfq', ['help', 'force', 'quiet'])
for opt, _arg in opts:
if opt in ('-f', '--force'):
force = True
elif opt in ('-q', '--quiet'):
quiet = True
elif opt in ('-h', '--help'):
print(usage)
sys.exit(0)
except getopt.GetoptError as e:
print(e.args[0])
print(usage)
sys.exit(1)
# Supply some default search parameters, just for testing purposes.
# These are only used if the parameters aren't filled in up above.
if 'short_name' in short_name:
short_name = 'ATL06'
version = '003'
time_start = '2018-10-14T00:00:00Z'
time_end = '2021-01-08T21:48:13Z'
bounding_box = ''
polygon = ''
filename_filter = '*ATL06_2020111121*'
url_list = []
url_list=None
try:
if not url_list:
url_list = cmr_search(short_name, version, time_start, time_end,
bounding_box=bounding_box, polygon=polygon,
filename_filter=filename_filter, quiet=quiet)
cmr_download(url_list, force=force, quiet=quiet)
except KeyboardInterrupt:
quit()