Skip to content
filefolderPublic

About

A QuakeML to HDF5 read/write utility for ObsPy earthquake catalog objects

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qmlh5

A QuakeML to HDF5 read/write utility for ObsPy earthquake catalog objects

Large XML catalogs are increasingly difficult to load and share. This utility hopes to alleviate this.

For an example 80,000 event catalog object (with arrivals),

  • writing to h5 now takes < 5 minutes (a 3.3G file)
  • reading the h5 back in takes < 15 minutes

Version 1.4 (29 Nov 2026)

  • read_catalog / read_events / add() now also read SeisComP XML (SCML/SC3ML), QuakeML, or any other ObsPy event format; the format is auto-detected (or force it with format="SCML" etc.). HDF5 and XML files can be mixed in globs.
  • Clearer error when qmlh5.qmlh5() is pointed at a non-HDF5 file
  • Fix cat += qmlh5.qmlh5('file.h5') on an unopened instance
  • lower/upper uncertainty and confidence level are now stored for pick slowness/backazimuth, arrival takeoff angle, amplitude period/scaling time, nodal planes, principal axes, moment tensor, and station magnitudes (previously only uncertainty was kept). Older files still read normally.
  • Errors on values that are exactly 0 (e.g. backazimuth 0°) are no longer dropped
  • starttime/endtime filtering now uses each event's preferred origin (falling back to the first origin when none is set)
  • Comments without a resource ID are read back without one (no random IDs)
  • Warn when event_indices is given with a glob that matches several files
  • Add tests: python -m pytest tests
  • Per-file tqdm progress bar when reading a glob of files or using add() (add() gains a progress= argument)

Version 1.3 (13 Oct 2026)

  • New ways to merge catalogs (e.g. cat += qmlh5.add('202?.h5'))
  • Add mirror functions read_events and write_events to match ObsPy behavior read_catalog and write_catalog still work as before.
  • Make tqdm mandatory

Version 1.2 (25 Sept 2026)

  • Expand query capability, add get_stats() helper, vectorize query_arrivals

Version 1.1 (29 June 2026)

  • add chunking to significantly reduce RAM consumption for writes
  • refactor reading process (fix O(n^2) bug) for >95% speedup
  • add TQDM to show read & write progress
  • add time filter kwargs (e.g. starttime and endtime) to read_events

Version 1.0 (April 26 2026)

  • initial release

How to install (via pip)

$ python3 -m pip install git+https://github.com/filefolder/qmlh5

Usage examples

import qmlh5

cat = qmlh5.read_catalog('huge_ml_catalog.h5')
# cat is an ObsPy catalog object
# (can load multiple files at once via wildcards)

# can also quickly read a specific timerange
cat_2006 = qmlh5.read_catalog('huge_ml_catalog.h5',
                              starttime=UTCDateTime(2006,1,1),
                              endtime=UTCDateTime(2007,1,1))

# SeisComP XML (or QuakeML) is read too, auto-detected — handy for converting
cat = qmlh5.read_catalog('events.scml')          # or format="SCML" to force
qmlh5.write_catalog(cat, 'events.h5')

# you can write this as QML or SCML or whatever obspy supports
cat.write('out.qml',format='QUAKEML')

# OR you can write out again as an hdf5 object
qmlh5.write_catalog(cat,'out.h5')

# Print quick stats
qmlh5.get_stats('huge_ml_catalog.h5')
"""
    qmlh5 stats  huge_ml_catalog.h5
      Origins:               39202
      Latitude range:        -37.0319 to -29.0002°
      Longitude range:       111.7592 to 139.9836°
      Depth range:           -0.49 to 36.42 km
      Horizontal uncertainty:3.899 ± 3.424 km  (n=39200)
      Depth uncertainty:     4.260 ± 3.508 km  (n=39108)
      RMS error:             0.426 ± 0.205 s  (n=39202)
"""

# You can filter BEFORE loading, for speed.
# Otherwise filter using the traditional Catalog object filters as before
with qmlh5.qmlh5("huge_ml_catalog.h5") as q:
    events = q.query_events(
        # bounding box: lat/lon rectangle
        ("query_bbox", dict(min_lat=32, max_lat=37, min_lon=-120, max_lon=-114)),

        # time window: origin time between two dates
        ("query_time", dict(t_start="2006-01-01", t_end="2007-01-01")),

        # magnitude range, optionally restricted to one magnitude type
        ("query_magnitude", dict(min_mag=4.5, max_mag=9.0, mag_type="Mw")),

        # circular (or annular) region around a point, in degrees
        ("query_radius", dict(center_lat=34.05, center_lon=-118.25,
                               max_radius_deg=2.0, min_radius_deg=0.0,
                               invert=False)),

        # arbitrary polygon, as (lat, lon) vertices
        ("query_polygon", dict(vertices=[(40, -10), (40, 30),
                                          (55, 30), (55, -10)],
                                invert=False)),

        # depth range, in metres
        ("query_depth", dict(min_depth_m=0.0, max_depth_m=70_000.0)),

        # number of phases actually used in the location solution
        ("query_arrivals", dict(min_count=10, max_count=None)),

        mode="union",   # nb "union" requires only ONE, "intersection" requires ALL
    )

    cat = q.read_catalog(event_indices=events)

Schema coverage

Every class below is serialized field-for-field against the QuakeML 1.2 BED schema.

Object Fields stored
Event public ID, preferred origin/magnitude/focal-mechanism IDs, event_type, event_type_certainty, descriptions, comments, creation info
EventDescription text, type
Origin time/latitude/longitude/depth (each with 4 error sub-fields), depth_type, time_fixed, epicenter_fixed, reference system / method / earth model IDs, origin_type, region, evaluation mode/status
OriginQuality associated/used phase & station counts, depth phase count, standard error, azimuthal & secondary azimuthal gaps, ground truth level, min/max/median distance
OriginUncertainty horizontal uncertainty (min/max), azimuth of max horizontal uncertainty, preferred description, confidence level
ConfidenceEllipsoid semi-major/minor/intermediate axis lengths, major-axis plunge/azimuth/rotation
CompositeTime year, month, day, hour, minute, second — each with all 4 error sub-fields
Arrival pick ID, phase, time correction, azimuth, distance, takeoff angle (+ errors), time/horizontal-slowness/backazimuth residuals and weights, earth model ID
Pick time (+ 4 errors), waveform ID, filter/method/slowness-method IDs, horizontal slowness & backazimuth (+ errors), onset, phase hint, polarity
Magnitude mag (+ 4 errors), type, origin ID, method ID, station count, azimuthal gap, evaluation
StationMagnitude mag (+ errors), type, amplitude ID, method ID, waveform ID, contributions
StationMagnitudeContribution station magnitude ID, residual, weight
Amplitude generic amplitude (+ 4 errors), type, category, unit, method ID, period (+ uncertainty), SNR, time window, pick ID, waveform ID, filter ID, scaling time (+ uncertainty), magnitude hint
TimeWindow begin, end, reference
FocalMechanism triggering origin ID, nodal planes (strike/dip/rake + uncertainties), principal axes (azimuth/plunge/length + uncertainties), preferred plane, azimuthal gap, station polarity count, misfit, station distribution ratio, method ID, waveform IDs
MomentTensor derived origin ID, moment magnitude ID, scalar moment (+ uncertainty), all six tensor components (+ uncertainties), variance, variance reduction, double couple, CLVD, ISO, Green's function ID, filter ID, source time function (type/duration/rise/decay), method ID, category, inversion type
DataUsed wave type, station count, component count, shortest/longest period
Comment text, resource ID, creation info
CreationInfo agency ID/URI, author/URI, creation time, version
WaveformStreamID network/station/location/channel codes, resource URI

Comment, CreationInfo, and WaveformStreamID instances are deduplicated into shared tables and referenced by integer index from their parent objects.

AI-assisted (far too complex otherwise!), exercise appropriate caution

About

A QuakeML to HDF5 read/write utility for ObsPy earthquake catalog objects

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages