本文整理汇总了Python中sentinelsat.sentinel.SentinelAPI类的典型用法代码示例。如果您正苦于以下问题:Python SentinelAPI类的具体用法?Python SentinelAPI怎么用?Python SentinelAPI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SentinelAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_scene
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: test_small_query
def test_small_query():
api = SentinelAPI(**_api_kwargs)
api.query(**_small_query)
assert api.last_query == (
'(beginPosition:[2015-01-01T00:00:00Z TO 2015-01-02T00:00:00Z]) '
'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))")')
assert api.last_status_code == 200
示例3: test_get_product_info
def test_get_product_info():
api = SentinelAPI(**_api_auth)
expected_s1 = {
'id': '8df46c9e-a20c-43db-a19a-4240c2ed3b8b',
'size': 143549851,
'md5': 'D5E4DF5C38C6E97BF7E7BD540AB21C05',
'url': "https://scihub.copernicus.eu/apihub/odata/v1/Products('8df46c9e-a20c-43db-a19a-4240c2ed3b8b')/$value",
'date': '2015-11-21T10:03:56Z',
'footprint': '-63.852531 -5.880887,-67.495872 -5.075419,-67.066071 -3.084356,-63.430576 -3.880541,'
'-63.852531 -5.880887',
'title': 'S1A_EW_GRDM_1SDV_20151121T100356_20151121T100429_008701_00C622_A0EC'
}
expected_s2 = {
'date': '2015-12-27T14:22:29Z',
'footprint': '-58.80274769505742 -4.565257232533263,-58.80535376268811 -5.513960396525286,'
'-57.90315169909761 -5.515947033626909,-57.903151791669515 -5.516014389089381,-57.85874693129081 -5.516044812342758,'
'-57.814323596961835 -5.516142631941845,-57.81432351345917 -5.516075248310466,-57.00018056571297 -5.516633044843839,'
'-57.000180565731384 -5.516700066819259,-56.95603179187787 -5.51666329264377,-56.91188395837315 -5.516693539799448,'
'-56.91188396736038 -5.51662651925904,-56.097209386295305 -5.515947927683427,-56.09720929423562 -5.516014937246069,'
'-56.053056977999596 -5.5159111504805916,-56.00892491028779 -5.515874390220655,-56.00892501130261 -5.515807411549814,'
'-55.10621586418906 -5.513685455771881,-55.108821882251775 -4.6092845892233,-54.20840287327946 -4.606372862374043,'
'-54.21169990975238 -3.658594390979672,-54.214267703869346 -2.710949551849636,-55.15704255065496 -2.7127451087194463,'
'-56.0563616875051 -2.71378646425769,-56.9561852630143 -2.7141556791285275,-57.8999998009875 -2.713837142510183,'
'-57.90079161941062 -3.6180222056692726,-58.800616247288836 -3.616721351843382,-58.80274769505742 -4.565257232533263',
'id': '44517f66-9845-4792-a988-b5ae6e81fd3e',
'md5': '48C5648C2644CE07207B3C943DEDEB44',
'size': 5854429622,
'title': 'S2A_OPER_PRD_MSIL1C_PDMC_20151228T112523_R110_V20151227T142229_20151227T142229',
'url': "https://scihub.copernicus.eu/apihub/odata/v1/Products('44517f66-9845-4792-a988-b5ae6e81fd3e')/$value"
}
assert api.get_product_info('8df46c9e-a20c-43db-a19a-4240c2ed3b8b') == expected_s1
assert api.get_product_info('44517f66-9845-4792-a988-b5ae6e81fd3e') == expected_s2
示例4: test_large_query
def test_large_query():
api = SentinelAPI(**_api_kwargs)
api.query(**_large_query)
assert api.last_query == (
'(beginPosition:[2015-01-01T00:00:00Z TO 2015-12-31T00:00:00Z]) '
'AND (footprint:"Intersects(POLYGON((0 0,0 10,10 10,10 0,0 0)))")')
assert api.last_status_code == 200
assert len(api.products) > api.page_size
示例5: test_SentinelAPI_wrong_credentials
def test_SentinelAPI_wrong_credentials():
api = SentinelAPI(
"wrong_user",
"wrong_password"
)
with pytest.raises(SentinelAPIError) as excinfo:
api.query(**_small_query)
assert excinfo.value.http_status == 401
示例6: test_format_url_custom_api_url
def test_format_url_custom_api_url():
api = SentinelAPI("user", "pw", api_url='https://scihub.copernicus.eu/dhus/')
url = api.format_url()
assert url.startswith('https://scihub.copernicus.eu/dhus/search')
api = SentinelAPI("user", "pw", api_url='https://scihub.copernicus.eu/dhus')
url = api.format_url()
assert url.startswith('https://scihub.copernicus.eu/dhus/search')
示例7: test_format_url
def test_format_url():
api = SentinelAPI(**_api_kwargs)
start_row = 0
url = api.format_url(start_row=start_row)
assert url is api.url
assert api.url == 'https://scihub.copernicus.eu/apihub/search?format=json&rows={rows}&start={start}'.format(
rows=api.page_size, start=start_row)
示例8: test_get_products_size
def test_get_products_size():
api = SentinelAPI(
environ.get('SENTINEL_USER'),
environ.get('SENTINEL_PASSWORD')
)
api.query(
get_coordinates('tests/map.geojson'),
"20151219", "20151228", platformname="Sentinel-2"
)
assert api.get_products_size() == 63.58
示例9: test_footprints
def test_footprints():
api = SentinelAPI(
environ.get('SENTINEL_USER'),
environ.get('SENTINEL_PASSWORD')
)
api.query(get_coordinates('tests/map.geojson'), datetime(2014, 10, 10), datetime(2014, 12, 31), producttype="GRD")
expected_footprints = geojson.loads(open('tests/expected_search_footprints.geojson', 'r').read())
# to compare unordered lists (JSON objects) they need to be sorted or changed to sets
assert set(api.get_footprints()) == set(expected_footprints)
示例10: test_SentinelAPI_connection
def test_SentinelAPI_connection():
api = SentinelAPI(
environ.get('SENTINEL_USER'),
environ.get('SENTINEL_PASSWORD')
)
api.query('0 0,1 1,0 1,0 0', datetime(2015, 1, 1), datetime(2015, 1, 2))
assert api.url == 'https://scihub.copernicus.eu/apihub/search?format=json&rows=15000' + \
'&q=(beginPosition:[2015-01-01T00:00:00Z TO 2015-01-02T00:00:00Z]) ' + \
'AND (footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))")'
assert api.content.status_code == 200
示例11: test_footprints_s1
def test_footprints_s1():
api = SentinelAPI(**_api_auth)
api.query(
get_coordinates('tests/map.geojson'),
datetime(2014, 10, 10), datetime(2014, 12, 31), producttype="GRD"
)
with open('tests/expected_search_footprints_s1.geojson', 'r') as geojson_file:
expected_footprints = geojson.loads(geojson_file.read())
# to compare unordered lists (JSON objects) they need to be sorted or changed to sets
assert set(api.get_footprints()) == set(expected_footprints)
示例12: test_get_product_info_scihub_down
def test_get_product_info_scihub_down():
api = SentinelAPI("mock_user", "mock_password")
with requests_mock.mock() as rqst:
rqst.get(
"https://scihub.copernicus.eu/apihub/odata/v1/Products('8df46c9e-a20c-43db-a19a-4240c2ed3b8b')/?$format=json",
text="Mock SciHub is Down", status_code=503
)
with pytest.raises(ValueError) as val_err:
api.get_product_info('8df46c9e-a20c-43db-a19a-4240c2ed3b8b')
assert val_err.value.message == "Invalid API response. JSON decoding failed."
示例13: test_footprints_s2
def test_footprints_s2():
api = SentinelAPI(**_api_auth)
api.query(
get_coordinates('tests/map.geojson'),
"20151219", "20151228", platformname="Sentinel-2"
)
with open('tests/expected_search_footprints_s2.geojson', 'r') as geojson_file:
expected_footprints = geojson.loads(geojson_file.read())
# to compare unordered lists (JSON objects) they need to be sorted or changed to sets
assert set(api.get_footprints()) == set(expected_footprints)
示例14: download
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
示例15: test_get_product_info
def test_get_product_info():
api = SentinelAPI(
environ.get('SENTINEL_USER'),
environ.get('SENTINEL_PASSWORD')
)
expected = {'id': '079ed72f-b330-4918-afb8-b63854e375a5',
'title': 'S1A_IW_GRDH_1SDV_20150527T081303_20150527T081328_006104_007EB2_E65B',
'size': 1051461964,
'footprint': '-21.032057 -39.925808,-20.472944 -42.301277,-18.975924 -41.904408,-19.528255 -39.549416,-21.032057 -39.925808',
'url': "https://scihub.esa.int/dhus/odata/v1/Products('079ed72f-b330-4918-afb8-b63854e375a5')/$value"
}
assert api.get_product_info('079ed72f-b330-4918-afb8-b63854e375a5') == expected