本文整理汇总了Python中sentinelsat.sentinel.SentinelAPI.download方法的典型用法代码示例。如果您正苦于以下问题:Python SentinelAPI.download方法的具体用法?Python SentinelAPI.download怎么用?Python SentinelAPI.download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentinelsat.sentinel.SentinelAPI
的用法示例。
在下文中一共展示了SentinelAPI.download方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_scene
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import download [as 别名]
def download_scene(scene):
"""Download a scene and change its status """
from sentinelsat.sentinel import SentinelAPI
from django.conf import settings
path = join(settings.MEDIA_ROOT, scene.sat, scene.identifier)
check_create_folder(path)
try:
api = SentinelAPI(
settings.SENTINEL_USER,
settings.SENTINEL_PASSWORD,
settings.SENTINEL_API_URL
)
except AttributeError:
api = SentinelAPI(settings.SENTINEL_USER, settings.SENTINEL_PASSWORD)
try:
print('Changing status of scene %s to downloading' % scene.identifier)
scene.change_status('downloading')
print('Starting download of product %s on path %s' %
(scene.product, path))
api.download(scene.product, path)
print('Changing status of scene %s to downloaded' % scene.identifier)
scene.change_status('downloaded')
except Exception as exp:
print('Unexpected error: %s' % exp)
print('Changing status of scene %s to dl_failed' % scene.identifier)
scene.change_status('dl_failed')
示例2: download
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import download [as 别名]
def download(user, password, productid, path, md5, url):
"""Download a Sentinel Product. It just needs your SciHub user and password
and the id of the product you want to download.
"""
api = SentinelAPI(user, password, url)
try:
api.download(productid, path, md5)
except SentinelAPIError as e:
if 'Invalid key' in e.msg:
logger.error('No product with ID \'%s\' exists on server', productid)
else:
raise
示例3: test_download
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import download [as 别名]
def test_download(tmpdir):
api = SentinelAPI(**_api_auth)
uuid = "1f62a176-c980-41dc-b3a1-c735d660c910"
filename = "S1A_WV_OCN__2SSH_20150603T092625_20150603T093332_006207_008194_521E"
expected_path = tmpdir.join(filename + ".zip")
# Download normally
path, product_info = api.download(uuid, str(tmpdir), checksum=True)
assert expected_path.samefile(path)
assert product_info["id"] == uuid
assert product_info["title"] == filename
assert product_info["size"] == expected_path.size()
hash = expected_path.computehash()
modification_time = expected_path.mtime()
expected_product_info = product_info
# File exists, test with checksum
# Expect no modification
path, product_info = api.download(uuid, str(tmpdir), check_existing=True)
assert expected_path.mtime() == modification_time
assert product_info == expected_product_info
# File exists, test without checksum
# Expect no modification
path, product_info = api.download(uuid, str(tmpdir), check_existing=False)
assert expected_path.mtime() == modification_time
assert product_info == expected_product_info
# Create invalid file, expect re-download
with expected_path.open("wb") as f:
f.seek(expected_product_info["size"] - 1)
f.write(b'\0')
assert expected_path.computehash("md5") != hash
path, product_info = api.download(uuid, str(tmpdir), check_existing=True)
assert expected_path.computehash("md5") == hash
assert product_info == expected_product_info
# Test continue
with expected_path.open("rb") as f:
content = f.read()
with expected_path.open("wb") as f:
f.write(content[:100])
assert expected_path.computehash("md5") != hash
path, product_info = api.download(uuid, str(tmpdir), check_existing=True)
assert expected_path.computehash("md5") == hash
assert product_info == expected_product_info
# Test MD5 check
with expected_path.open("wb") as f:
f.write(b'abcd' * 100)
assert expected_path.computehash("md5") != hash
with pytest.raises(InvalidChecksumError):
api.download(uuid, str(tmpdir), check_existing=True, checksum=True)
示例4: download
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import download [as 别名]
def download(user, password, productid, path):
"""Download a Sentinel-1 Product. It just needs your SciHub user and password
and the id of the product you want to download.
"""
api = SentinelAPI(user, password)
api.download(productid, path)