AllenNeuralDynamics / AllenNeuralDynamics/aind-ophys-nwb

run_capsule.py crashes when SUITE2P_ROI_STATS keys are missing (CaImAn or Suite2p v1.1 extraction)

未關閉
#78 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Jupyter Notebook
星號
1
分支
0
PR 合併指標
30 天內沒有已合併 PR

描述

## Bug

`run_capsule.py` fails on line 958 with a `KeyError` when the extraction file's `rois/` group doesn't contain every key in `SUITE2P_ROI_STATS`:

```python
SUITE2P_ROI_STATS = (
"aspect_ratio",
"compact",
"solidity",
"radius",
"footprint",
)
```

`load_generic_group()` does a plain `f[h5_group][h5_key][:]`, which raises immediately if the key is absent -- and the dict comprehension loading all five (`nwb_ophys`, line ~958) has no error handling around it.

## Root cause

Two extraction configurations no longer produce all five stats:

- **CaImAn-based extraction** (`greedy_roi`/`corr_pnr` init modes, or CNMF/CNMF-E neuropil refinement): `aind-ophys-extraction`'s `extraction.py` sets `keys = []` for these paths -- *none* of the five stats are ever written to `rois/`.
- **Suite2p v1.1** (the recent `aind-ophys-extraction` migration to Suite2p's new `db`/`settings` API): `solidity` is no longer computed by Suite2p's ROI stats at all. The other four (`aspect_ratio`, `compact`, `radius`, `footprint`) are still present.

## Where this shows up

There are two call sites doing this unconditional load, both in `run_capsule.py`:

- `nwb_ophys_single_plane` (~line 558) -- has a broad `try/except` around the whole block (~line 640) that falls back to a bare ROI table on *any* exception, so it doesn't crash, but it silently drops **all** classifier + stats columns even when only one stat (e.g. `solidity`) was actually missing.
- `nwb_ophys` (~line 958) -- has no such wrapper, so it crashes the whole run outright. This is the one reported.

## Suggested fix

Load each stat individually and keep only the ones that actually exist, instead of all-or-nothing:

```python
available_stats = []
suite2p_stats = {}
for stat in SUITE2P_ROI_STATS:
try:
suite2p_stats[stat] = load_generic_group(
file_paths["planes"][plane_name]["extraction_h5"], h5_group="rois", h5_key=stat
)
available_stats.append(stat)
except KeyError:
pass
```

Then build `columns`/`colnames`/`add_roi(**{...})` from `available_stats` instead of the `SUITE2P_ROI_STATS` constant, in both `nwb_ophys` and `nwb_ophys_single_plane`. This means:
- CaImAn-based extraction files get a valid NWB file with zero suite2p-stat columns (instead of crashing).
- Suite2p v1.1 files keep 4 of 5 stat columns (instead of losing all of them via the existing broad fallback, or crashing).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

Start in run_capsule.py at the two call sites named in the issue: nwb_ophys_single_plane around line 558 and nwb_ophys around line 958. Read how SUITE2P_ROI_STATS is loaded through load_generic_group and how columns, colnames, and add_roi are built. Done means missing rois/ stats no longer crash the run, CaImAn files can omit all five stats, and Suite2p v1.1 keeps the four stats it still provides.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
data
Issue 類型
缺陷
難度
3/5
預估耗時
半天
活躍度
冷清
描述清晰度
描述清楚
新手友好度
72/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。