Repository navigation
Add IMDB.merge_from for incremental event ingest - #9
Conversation
Copies every event of another database (events, realisations, site-event distances, records and IMs) into this one, matching sites by site_id and replacing events that already exist. simulation_db's realtime dataset uses it to merge each new event's single-event upload into the dataset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@claude review |
|
Claude finished @joelridden's task in 5m 57s —— View job Review complete
Findings: 1 (medium severity, confirmed) Posted inline on Everything else held up well under review: the grid/component compatibility checks, re-ingest/delete-then-insert ordering, the id-mapping between source and target int surrogates, and the record-grouping logic that keeps scalar/pSA/FAS/sigma copies exact (verified against |
iterrows and groupby type their keys as Hashable, which ty rejects for .loc lookups and tuple unpacking. Look up record positions in one go and group the IM-presence flags with numpy instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
merge_from updated shared sites with every incoming column, so a single-event file without (say) a vs30 for a station nulled the value for every other event that references that site. Use COALESCE so incoming values still win but a missing one keeps the existing value, and test the value -> NULL case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@claude review |
|
Claude finished @joelridden's task in 2m 44s —— View job Review complete
Findings: 0 No new correctness bugs found. Specifically checked and confirmed correct:
|
lispandfound
left a comment
There was a problem hiding this comment.
Claude point is relevant. Otherwise looks fine.
Why
SeismicNow is getting physics-based simulations of recent NZ earthquakes, served from simulation_db's new realtime dataset. Each new event's results arrive as their own single-event imdb file (plus a waveform
.nc), and simulation_db has to add that event to the one growingrealtime.duckdbwithout rebuilding it. Re-running a simulation has to replace the event cleanly. imdb had no way to copy events between databases, so this adds one.What
IMDB.merge_from(other, replace=True)copies every event inotherinto this database: events, realisations, site-event distances, records and their IMs (scalars, pSA, FAS and sigma).site_id. New sites are added and existing ones are updated with the incoming values.replace=True, an existing event is deleted first, so the latest upload replaces it. Withreplace=False, an existing event is an error.ValueError.add_recordscommits per call. Callers should merge into a copy and swap it in oncevalidate()passes, which is what simulation_db's ingest does.New private helpers:
_grid,_ims_by_recordand_columns. There's no schema change, soSCHEMA_VERSIONstays at 2.Tests
tests/test_merge.pyhas 7 tests: copying, replacing, site updates, grid and component mismatches, and exact round-trips. The full suite passes. simulation_db's realtime ingest tests (239 in total) also pass against this code.🤖 Generated with Claude Code