Skip to content

Instantly share code, notes, and snippets.

@mcejp
Created October 2, 2025 08:39
Show Gist options
  • Select an option

  • Save mcejp/31ba9a4d1ac690df3e10b18b4b10175d to your computer and use it in GitHub Desktop.

Select an option

Save mcejp/31ba9a4d1ac690df3e10b18b4b10175d to your computer and use it in GitHub Desktop.
#!/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