Fix RangeIndex crash in script 07 seismic load

When load_usgs returns an empty DataFrame it has a RangeIndex, causing
resample("1D") to throw TypeError. Guard with an isinstance check and
fall back to a zero series so the rest of the pipeline continues.

Also aligns expected usgs-dir path with what script 06 wrote.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
root 2026-04-24 00:45:07 +02:00
parent 1832f73f74
commit 14a108d71a

View file

@ -338,12 +338,15 @@ def load_cr_and_seismic(
# --- Seismic metric ---
events = load_usgs(start_year, end_year, usgs_dir)
events = events.loc[study_start:study_end]
events = events[events["mag"] >= min_mag]
daily_mw = events["mag"].resample("1D").sum()
daily_mw = daily_mw.reindex(
pd.date_range(study_start, study_end, freq="D"), fill_value=0.0
)
full_day_index = pd.date_range(study_start, study_end, freq="D")
if events.empty or not isinstance(events.index, pd.DatetimeIndex):
logger.warning("No USGS events loaded for %s%s; seismic series will be zeros", study_start, study_end)
daily_mw = pd.Series(0.0, index=full_day_index)
else:
events = events.loc[study_start:study_end]
events = events[events["mag"] >= min_mag]
daily_mw = events["mag"].resample("1D").sum()
daily_mw = daily_mw.reindex(full_day_index, fill_value=0.0)
seismic_bin = _bin_series(daily_mw, study_start, bin_days, agg="sum").fillna(0.0)
seismic_bin = seismic_bin.reindex(ref_index, fill_value=0.0)