From 6a2a66f9adab06d83ce94627d21ef0a32153dc70 Mon Sep 17 00:00:00 2001 From: Syed R Rizvi Date: Wed, 3 Jul 2024 09:10:43 -0400 Subject: [PATCH] Add utility to validate COG files for HyBIG service --- util/validate_cog_for_hybig.py | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 util/validate_cog_for_hybig.py diff --git a/util/validate_cog_for_hybig.py b/util/validate_cog_for_hybig.py new file mode 100644 index 0000000..6fb4dcf --- /dev/null +++ b/util/validate_cog_for_hybig.py @@ -0,0 +1,37 @@ +import rioxarray +import argparse + +def validate_cog(file_path): + try: + # Open the COG file using rioxarray + dataset = rioxarray.open_rasterio(file_path) + + # Check if CRS is defined + if dataset.rio.crs is None: + print(f"COG file {file_path} does not have a defined CRS.") + return False + + # Check the number of bands + num_bands = dataset.rio.count + if num_bands not in [1, 3, 4]: + print(f"COG file {file_path} has {num_bands} bands. Expected 1, 3, or 4 bands.") + return False + + print(f"COG file {file_path} is valid.") + return True + + except Exception as e: + print(f"Error validating COG file {file_path}: {e}") + return False + +if __name__ == "__main__": + # Define command line arguments + parser = argparse.ArgumentParser(description="Validate a Cloud-Optimized GeoTIFF (COG) file for HyBIG service requirements.") + parser.add_argument('file', type=str, help="Path to the COG file") + + # Parse command line arguments + args = parser.parse_args() + + # Call the validation function + validate_cog(args.file) +