Skip to content

Commit 77365dd

Browse files
authored
Merge pull request #76 from podaac/release/0.13.1
Release 0.13.1
2 parents dadc2fa + e8494d4 commit 77365dd

File tree

5 files changed

+152
-154
lines changed

5 files changed

+152
-154
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Security
1515

1616

17+
## [0.13.1]
18+
19+
### Added
20+
### Changed
21+
### Deprecated
22+
### Removed
23+
### Fixed
24+
- ** Fix lon and lat check **
25+
Fix the checking of longitude and latitude data for empty granules
26+
### Security
27+
28+
1729
## [0.13.0]
1830

1931
### Added

podaac/lambda_handler/lambda_handler.py

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ def generate_images(local_file, path, config_file, palette_dir, granule_id, vari
4646
"""Function to call in multiprocess to generate images"""
4747
try:
4848
image_gen = tig.TIG(local_file, path, config_file, palette_dir, variables=variables, logger=logger)
49-
if image_gen.are_all_lon_lat_invalid():
50-
raise Exception("Can't generate images for empty granule")
5149
images = image_gen.generate_images(granule_id=granule_id)
5250
conn.send(({'status': 'success', 'data': images}, None))
5351
except Exception as e:

podaac/tig/tig.py

+16-29
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ def generate_images_group(self, image_format='png', world_file=False, granule_id
457457
width_deg = region[3] - region[2]
458458
self.region = Region(region)
459459

460+
if self.are_all_lon_lat_invalid(lon_array, lat_array):
461+
raise Exception("Can't generate images for empty granule")
462+
460463
output_dimensions = (int(height_deg * self.ppd), int(width_deg * self.ppd))
461464
(self.rows, self.cols) = output_dimensions
462465

@@ -573,42 +576,26 @@ def non_nan_neighbors(arr, x, y):
573576

574577
return img_with_neighbor_filled
575578

576-
def are_all_lon_lat_invalid(self):
579+
def are_all_lon_lat_invalid(self, lon, lat):
577580
"""
578-
Checks if all longitude and latitude values in a NetCDF file are invalid.
581+
Checks if all coordinate pairs contain at least one invalid value.
579582
580583
Parameters:
581-
file_path (str): Path to the NetCDF file.
582-
lon_var (str): Name of the longitude variable in the file.
583-
lat_var (str): Name of the latitude variable in the file.
584-
584+
lon (array-like): Array of longitude values.
585+
lat (array-like): Array of latitude values.
585586
Returns:
586-
bool: True if all longitude and latitude values are invalid, False otherwise.
587+
bool: True if all coordinate pairs have at least one invalid value,
588+
False if there exists at least one valid coordinate pair.
587589
"""
588590
try:
589-
with xr.open_dataset(self.input_file) as ds:
590-
591-
lon_var = self.config.get('lonVar')
592-
lat_var = self.config.get('latVar')
593-
594-
if lon_var not in ds.variables or lat_var not in ds.variables:
595-
raise ValueError(f"Missing required variables: '{lon_var}' or '{lat_var}' in the file.")
596-
597-
lon = ds[lon_var]
598-
lat = ds[lat_var]
599-
600-
# Define valid ranges
601-
valid_lon = (lon >= -180) & (lon <= 180)
602-
valid_lat = (lat >= -90) & (lat <= 90)
603-
604-
# Check if all values are invalid
605-
all_invalid_lon = (~valid_lon).all().item()
606-
all_invalid_lat = (~valid_lat).all().item()
607-
608-
return all_invalid_lon and all_invalid_lat
591+
# Define valid ranges
592+
valid_lon_mask = (lon >= -180) & (lon <= 180)
593+
valid_lat_mask = (lat >= -90) & (lat <= 90)
594+
# Check if any pair is completely valid
595+
valid_pairs = valid_lon_mask & valid_lat_mask
596+
return not valid_pairs.any()
609597
except Exception as e:
610-
self.logger.error(f"Error: {e}")
611-
raise e
598+
raise RuntimeError(f"Error checking longitude/latitude validity: {e}") from e
612599

613600
def process_variable(self,
614601
var,

0 commit comments

Comments
 (0)