Skip to content

Commit

Permalink
Merge pull request #253 from ecmwf/feature/raiseGribException
Browse files Browse the repository at this point in the history
Feature/raise grib exception
  • Loading branch information
mathleur authored Nov 14, 2024
2 parents 07131b2 + cdbbfc5 commit 40af1a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions polytope_feature/datacube/backends/fdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from copy import deepcopy
from itertools import product

from ...utility.exceptions import BadRequestError
from ...utility.exceptions import BadGridError, BadRequestError
from ...utility.geometry import nearest_pt
from .datacube import Datacube, TensorIndexTree

Expand Down Expand Up @@ -128,7 +128,15 @@ def get(self, requests: TensorIndexTree, context=None):
printed_list_to_gj = complete_list_complete_uncompressed_requests[::1000]
logging.debug("The requests we give GribJump are: %s", printed_list_to_gj)
logging.info("Requests given to GribJump extract for %s", context)
output_values = self.gj.extract(complete_list_complete_uncompressed_requests, context)
try:
output_values = self.gj.extract(complete_list_complete_uncompressed_requests, context)
except Exception as e:
if "BadValue: Grid hash mismatch" in str(e):
logging.info("Error is: %s", e)
raise BadGridError()
else:
raise e

logging.info("Requests extracted from GribJump for %s", context)
if logging.root.level <= logging.DEBUG:
printed_output_values = output_values[::1000]
Expand Down
5 changes: 5 additions & 0 deletions polytope_feature/utility/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ class UnsliceableShapeError(PolytopeError, KeyError):
def __init__(self, axis):
self.axis = axis
self.message = f"Higher-dimensional shape does not support unsliceable axis {axis.name}."


class BadGridError(PolytopeError, ValueError):
def __init__(self):
self.message = "Data on this grid is not supported by Polytope."

0 comments on commit 40af1a4

Please sign in to comment.