本文整理汇总了Python中sentinelsat.sentinel.SentinelAPI.query方法的典型用法代码示例。如果您正苦于以下问题:Python SentinelAPI.query方法的具体用法?Python SentinelAPI.query怎么用?Python SentinelAPI.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentinelsat.sentinel.SentinelAPI
的用法示例。
在下文中一共展示了SentinelAPI.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_small_query
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
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
示例2: test_large_query
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
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
示例3: test_SentinelAPI_wrong_credentials
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
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
示例4: query_and_create
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
def query_and_create(self, start=None, end=None):
'''Query the last scene available on period filtered by start time
and end dates. By default start is current time and end is 7 days ago.'''
end = end or datetime.utcnow()
start = start or datetime.utcnow() - timedelta(days=7)
coords = ','.join([('%f %f' % coord) for coord in self.geom.coords[0]])
scenes_created = []
try:
api = SentinelAPI(settings.SENTINEL_USER, settings.SENTINEL_PASSWORD, settings.SENTINEL_API_URL)
print('sentinel initialized on %s, with %s - %s' %
(settings.SENTINEL_API_URL, settings.SENTINEL_USER, settings.SENTINEL_PASSWORD))
except AttributeError:
api = SentinelAPI(settings.SENTINEL_USER, settings.SENTINEL_PASSWORD)
print('sentinel initialized on %s, with %s - %s' %
(settings.SENTINEL_API_URL, ettings.SENTINEL_USER, settings.SENTINEL_PASSWORD))
print('sentinelsat query -s %s -e %s coords %s q %s' % (start, end, coords, self.query))
if self.query:
query = dict([i.split('=') for i in self.query.split(',')])
api.query(coords, start, end, **query)
else:
api.query(coords, start, end)
features = api.get_footprints()['features']
print('%s features found' % len(features))
for feature in features:
product_id = feature['properties']['product_id']
try:
Scene.objects.get(product=product_id)
print('Scene of product %s already exists' % product_id)
except Scene.DoesNotExist:
print('Creating scene with data: %s' % feature)
scene = Scene.objects.create(
product=product_id,
identifier=feature['properties']['identifier'],
date=datetime.strptime(
feature['properties']['date_beginposition'],
'%Y-%m-%dT%H:%M:%S.%fZ'
),
polarisation=feature['properties']['polarisationmode'],
orbit_direction=feature['properties']['orbitdirection'],
sensor_mode=feature['properties']['sensoroperationalmode'],
product_type=feature['properties']['producttype'],
sat=feature['properties']['platformname'],
geom=Polygon(feature['geometry']['coordinates'][0]))
print('Scene of product %s created' % product_id)
scenes_created.append(scene)
return scenes_created
示例5: test_get_products_size
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
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
示例6: test_footprints
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
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)
示例7: test_footprints_s1
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
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)
示例8: test_SentinelAPI_wrong_credentials
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
def test_SentinelAPI_wrong_credentials():
api = SentinelAPI(
"wrong_user",
"wrong_password"
)
api.query('0 0,1 1,0 1,0 0', datetime(2015, 1, 1), datetime(2015, 1, 2))
assert api.content.status_code == 401
with pytest.raises(ValueError):
api.get_products_size()
api.get_products()
示例9: test_SentinelAPI_connection
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
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
示例10: test_footprints_s2
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
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)
示例11: test_s2_cloudcover
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
def test_s2_cloudcover():
api = SentinelAPI(**_api_auth)
api.query(
get_coordinates('tests/map.geojson'),
"20151219", "20151228",
platformname="Sentinel-2",
cloudcoverpercentage="[0 TO 10]"
)
assert len(api.get_products()) == 3
assert api.get_products()[0]["id"] == "6ed0b7de-3435-43df-98bf-ad63c8d077ef"
assert api.get_products()[1]["id"] == "37ecee60-23d8-4ec2-a65f-2de24f51d30e"
assert api.get_products()[2]["id"] == "0848f6b8-5730-4759-850e-fc9945d42296"
示例12: test_SentinelAPI_connection
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
def test_SentinelAPI_connection():
api = SentinelAPI(**_api_auth)
api.query(**_small_query)
assert api.url.startswith(
'https://scihub.copernicus.eu/apihub/search?format=json&rows={rows}'.format(
rows=api.page_size
)
)
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
示例13: test_s2_cloudcover
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
def test_s2_cloudcover():
api = SentinelAPI(
environ.get('SENTINEL_USER'),
environ.get('SENTINEL_PASSWORD')
)
api.query(
get_coordinates('tests/map.geojson'),
"20151219", "20151228",
platformname="Sentinel-2",
cloudcoverpercentage="[0 TO 10]"
)
assert len(api.get_products()) == 2
assert api.get_products()[0]["id"] == "37ecee60-23d8-4ec2-a65f-2de24f51d30e"
assert api.get_products()[1]["id"] == "0848f6b8-5730-4759-850e-fc9945d42296"
示例14: test_get_products_size
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
def test_get_products_size():
api = SentinelAPI(**_api_auth)
api.query(
get_coordinates('tests/map.geojson'),
"20151219", "20151228", platformname="Sentinel-2"
)
assert api.get_products_size() == 63.58
# reset products
api.products = []
# load new very small query
api.load_query("S1A_WV_OCN__2SSH_20150603T092625_20150603T093332_006207_008194_521E")
assert len(api.get_products()) > 0
# Rounded to zero
assert api.get_products_size() == 0
示例15: test_get_products_invalid_json
# 需要导入模块: from sentinelsat.sentinel import SentinelAPI [as 别名]
# 或者: from sentinelsat.sentinel.SentinelAPI import query [as 别名]
def test_get_products_invalid_json():
api = SentinelAPI("mock_user", "mock_password")
with requests_mock.mock() as rqst:
rqst.get(
'https://scihub.copernicus.eu/apihub/search?format=json&rows=15000&q=(beginPosition:[2015-12-19T00:00:00Z TO 2015-12-28T00:00:00Z]) AND (footprint:"Intersects(POLYGON((-66.2695312 -8.0592296,-66.2695312 0.7031074,-57.3046875 0.7031074,-57.3046875 -8.0592296,-66.2695312 -8.0592296)))") AND (platformname:Sentinel-2)',
text="Invalid JSON response", status_code=200
)
api.query(
area=get_coordinates("tests/map.geojson"),
initial_date="20151219",
end_date="20151228",
platformname="Sentinel-2"
)
with pytest.raises(ValueError) as val_err:
api.get_products()
assert val_err.value.message == "API response not valid. JSON decoding failed."