Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility to validate COGs' compatibility with HyBIG #21

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions util/validate_cog_for_hybig.py
Original file line number Diff line number Diff line change
@@ -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)