Skip to content

Commit

Permalink
add in check for empty granules
Browse files Browse the repository at this point in the history
  • Loading branch information
sliu008 committed Jan 22, 2025
1 parent 9175e6a commit e7fa6f0
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 81 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ disable=raw-checker-failed,
use-symbolic-message-instead,
too-many-arguments,
too-many-locals,
too-many-positional-arguments
too-many-positional-arguments,
broad-exception-raised
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
Expand Down
27 changes: 27 additions & 0 deletions podaac/forge_py/forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def generate_footprint(lon, lat, strategy=None, is360=False, path=None, **kwargs
if is360:
lon = ((lon + 180) % 360.0) - 180

is_lon_lat_invalid = are_all_lon_lat_invalid(lon, lat)
if is_lon_lat_invalid:
raise Exception("Can't generate footprint for empty granule")

# Dispatch to the correct footprint strategy based on `strategy`
if strategy == "open_cv":
footprint = open_cv_footprint.footprint_open_cv(lon, lat, path=path, **kwargs)
Expand All @@ -164,3 +168,26 @@ def generate_footprint(lon, lat, strategy=None, is360=False, path=None, **kwargs
footprint = remove_small_polygons(footprint, kwargs['min_area'])

return dumps(footprint, trim=True)


def are_all_lon_lat_invalid(lon, lat):
"""
Checks if all longitude and latitude values in a NetCDF file are invalid.
Parameters:
lon (array): longitude values.
lat (array): latitude values.
Returns:
bool: True if all longitude and latitude values are invalid, False otherwise.
"""

# Define valid ranges
valid_lon = (lon >= -180) & (lon <= 180)
valid_lat = (lat >= -90) & (lat <= 90)

# Check if all values are invalid
all_invalid_lon = (~valid_lon).all().item()
all_invalid_lat = (~valid_lat).all().item()

return all_invalid_lon and all_invalid_lat
Loading

0 comments on commit e7fa6f0

Please sign in to comment.