@@ -578,29 +578,24 @@ def non_nan_neighbors(arr, x, y):
578
578
579
579
def are_all_lon_lat_invalid (self , lon , lat ):
580
580
"""
581
- 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 .
582
582
583
583
Parameters:
584
- file_path (str): Path to the NetCDF file.
585
- lon_var (str): Name of the longitude variable in the file.
586
- lat_var (str): Name of the latitude variable in the file.
587
-
584
+ lon (array-like): Array of longitude values.
585
+ lat (array-like): Array of latitude values.
588
586
Returns:
589
- 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.
590
589
"""
591
590
try :
592
591
# Define valid ranges
593
- valid_lon = (lon >= - 180 ) & (lon <= 180 )
594
- valid_lat = (lat >= - 90 ) & (lat <= 90 )
595
-
596
- # Check if all values are invalid
597
- all_invalid_lon = (~ valid_lon ).all ().item ()
598
- all_invalid_lat = (~ valid_lat ).all ().item ()
599
-
600
- return all_invalid_lon and all_invalid_lat
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 ()
601
597
except Exception as e :
602
- self .logger .error (f"Error: { e } " )
603
- raise e
598
+ raise RuntimeError (f"Error checking longitude/latitude validity: { e } " ) from e
604
599
605
600
def process_variable (self ,
606
601
var ,
0 commit comments