Checking readability of mseed files (Januka Attanayake)

Hi Januka,

You could simply loop through the files and try to read each one. If it fails, append the file name to a list and continue. At the end you can quarantine (move) the bad files.

Something like this:

from pathlib import Path

import obspy

bad_files = []

for path in Path('path/to/your/files').rglob('*'):
try:
obspy.read(str(path), format='mseed')
except:
bad_files.append(path)

# ... do something with bad files

Derrick

Thanks Derrick, this is exactly what I ended up doing following Richard’s comments.

Januka Attanayake

Research Fellow | Earthquake Seismology
Homepage: https://sites.google.com/site/janukaattanayake

School of Earth Sciences | McCoy Bldg. 200
University of Melbourne | Parkville 3010 VIC
Australia

Hi Januka,

You could simply loop through the files and try to read each one. If it fails, append the file name to a list and continue. At the end you can quarantine (move) the bad files.

Something like this:

from pathlib import Path

import obspy

bad_files = []

for path in Path('path/to/your/files').rglob('*'):
try:
obspy.read(str(path), format='mseed')
except:
bad_files.append(path)

# ... do something with bad files

Derrick