Created
October 2, 2025 08:39
-
-
Save mcejp/31ba9a4d1ac690df3e10b18b4b10175d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import os | |
| from pyhdf.SD import SD, SDC | |
| import tqdm | |
| def check_hdf4_file(path): | |
| try: | |
| hdf = SD(path, SDC.READ) | |
| datasets = hdf.datasets().keys() | |
| for name in datasets: | |
| ds = hdf.select(name) | |
| _ = ds[:] # force a full read | |
| ds.endaccess() | |
| hdf.end() | |
| return True, None | |
| except Exception as e: | |
| return False, str(e) | |
| def main(directory): | |
| oks, errors = 0, 0 | |
| for fname in tqdm.tqdm(os.listdir(directory)): | |
| if fname.lower().endswith(".hdf"): | |
| path = os.path.join(directory, fname) | |
| ok, err = check_hdf4_file(path) | |
| if ok: | |
| oks += 1 | |
| else: | |
| print(f"[ERROR] {fname}: {err}") | |
| errors += 1 | |
| print(f"{oks=} {errors=}") | |
| if __name__ == "__main__": | |
| main(".") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment