Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle bad request errors #126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions planet_explorer/gui/pe_dailyimages_search_results_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@

import iso8601
from qgis.core import (
Qgis,
QgsApplication,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsGeometry,
QgsMessageLog,
QgsProject,
QgsRectangle,
QgsWkbTypes,
Expand All @@ -48,6 +50,8 @@
QTreeWidgetItemIterator,
)

from planet.api.exceptions import BadQuery

from ..gui.pe_results_configuration_dialog import (
PlanetNodeMetadata,
ResultsConfigurationDialog,
Expand All @@ -61,6 +65,7 @@

from ..pe_utils import (
PLANET_COLOR,
QGIS_LOG_SECTION_NAME,
SEARCH_AOI_COLOR,
area_coverage_for_image,
create_preview_group,
Expand Down Expand Up @@ -229,19 +234,39 @@ def update_request(self, request, local_filters):
self.tree.clear()
stats_request = {"interval": "year"}
stats_request.update(self._request)
resp = self._p_client.stats(stats_request).get()
self._total_count = sum([b["count"] for b in resp["buckets"]])
if self._total_count:
response = self._p_client.quick_search(
self._request,
page_size=TOP_ITEMS_BATCH,
sort=" ".join(self.sort_order()),

try:
resp = self._p_client.stats(stats_request).get()
self._total_count = sum([b["count"] for b in resp["buckets"]])
if self._total_count:
response = self._p_client.quick_search(
self._request,
page_size=TOP_ITEMS_BATCH,
sort=" ".join(self.sort_order()),
)
self._response_iterator = response.iter()
self.load_more()
self._set_widgets_visibility(True)
else:
self._set_widgets_visibility(False)

except BadQuery as bq:
QgsMessageLog.logMessage(
f"Exception during search, "
f"the search parameters are invalid."
f"Error details {bq}.",
QGIS_LOG_SECTION_NAME,
Qgis.Critical,
)

iface.messageBar().pushMessage(
"Planet Explorer",
"Encountered a problem during search, "
"Make sure search parameters are valid. "
"See logs for details",
level=Qgis.Critical,
duration=10,
)
self._response_iterator = response.iter()
self.load_more()
self._set_widgets_visibility(True)
else:
self._set_widgets_visibility(False)

@waitcursor
def load_more(self):
Expand Down
48 changes: 20 additions & 28 deletions planet_explorer/pe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,36 +286,28 @@ def create_preview_vector_layer(image):
QgsField("sort_order", QVariant.String),
]

prop_dates = [
'acquired',
'published',
'updated'
]
prop_int = [
'anomalous_pixels'
]
prop_dates = ["acquired", "published", "updated"]
prop_int = ["anomalous_pixels"]
prop_double = [
'clear_confidence_percent',
'clear_percent',
'cloud_cover',
'cloud_percent',
'ground_control_ratio', # Only SkySat
'gsd',
'heavy_haze_percent',
'light_haze_percent',
'pixel_resolution',
'satellite_azimuth',
'shadow_percent',
'snow_ice_percent',
'sun_azimuth',
'sun_elevation',
'view_angle',
'visible_confidence_percent',
'visible_percent'
]
prop_boolean = [
'ground_control' # Only PlanetScope
"clear_confidence_percent",
"clear_percent",
"cloud_cover",
"cloud_percent",
"ground_control_ratio", # Only SkySat
"gsd",
"heavy_haze_percent",
"light_haze_percent",
"pixel_resolution",
"satellite_azimuth",
"shadow_percent",
"snow_ice_percent",
"sun_azimuth",
"sun_elevation",
"view_angle",
"visible_confidence_percent",
"visible_percent",
]
prop_boolean = ["ground_control"] # Only PlanetScope

for prop in image["properties"]:
# Determines the field types
Expand Down
8 changes: 6 additions & 2 deletions planet_explorer/tests/test_daily_imagery.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,9 @@ def test_aoi_bb_from_layer(layer_dir, expected_coordinates):
),
],
)
def test_aoi_from_multiple_polygons(qtbot, pe_qgis_iface, layer_dir, expected_coordinates, perform_selection):
def test_aoi_from_multiple_polygons(
qtbot, pe_qgis_iface, layer_dir, expected_coordinates, perform_selection
):
"""Tests the filter for the AOI read from no selection and a
selection on a layer loaded in QGIS. AOI calculated from each polygon.
"""
Expand Down Expand Up @@ -794,7 +796,9 @@ def test_aoi_from_multiple_polygons(qtbot, pe_qgis_iface, layer_dir, expected_co
),
],
)
def test_bb_aoi_from_multiple_polygons(qtbot, pe_qgis_iface, layer_dir, expected_coordinates):
def test_bb_aoi_from_multiple_polygons(
qtbot, pe_qgis_iface, layer_dir, expected_coordinates
):
"""Tests the filter for the AOI read from on the bounding box of a layer
loaded in QGIS. AOI calculated using a bounding box covering all polygons.
"""
Expand Down