Spaces:
Sleeping
Sleeping
Marlin Lee commited on
Commit Β·
5020b99
1
Parent(s): dbd5275
Add nilearn/nibabel/scipy; add get_fmri and beta_std to HTTPDynaDiffLoader
Browse files- Dockerfile +4 -1
- scripts/dynadiff_loader.py +16 -0
Dockerfile
CHANGED
|
@@ -24,7 +24,10 @@ RUN pip install --no-cache-dir \
|
|
| 24 |
google-genai \
|
| 25 |
h5py \
|
| 26 |
timm \
|
| 27 |
-
overcomplete
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# ββ Explorer code βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
COPY scripts/explorer/ /app/scripts/explorer/
|
|
|
|
| 24 |
google-genai \
|
| 25 |
h5py \
|
| 26 |
timm \
|
| 27 |
+
overcomplete \
|
| 28 |
+
nilearn \
|
| 29 |
+
nibabel \
|
| 30 |
+
scipy
|
| 31 |
|
| 32 |
# ββ Explorer code βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 33 |
COPY scripts/explorer/ /app/scripts/explorer/
|
scripts/dynadiff_loader.py
CHANGED
|
@@ -452,6 +452,7 @@ class HTTPDynaDiffLoader:
|
|
| 452 |
self._status = "loading"
|
| 453 |
self._error = ""
|
| 454 |
self._n_samples = None
|
|
|
|
| 455 |
self._lock = threading.Lock()
|
| 456 |
self._nsd_cache: dict[int, list[int]] = {}
|
| 457 |
|
|
@@ -473,6 +474,7 @@ class HTTPDynaDiffLoader:
|
|
| 473 |
self._status = data.get("status", "ok")
|
| 474 |
self._error = data.get("error", "")
|
| 475 |
self._n_samples = data.get("n_samples")
|
|
|
|
| 476 |
return
|
| 477 |
except Exception:
|
| 478 |
_time.sleep(interval)
|
|
@@ -498,8 +500,22 @@ class HTTPDynaDiffLoader:
|
|
| 498 |
with self._lock:
|
| 499 |
return self._n_samples
|
| 500 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 501 |
# ββ remote calls ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 502 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
def sample_idxs_for_nsd_img(self, nsd_img_idx: int) -> list[int]:
|
| 504 |
nsd_idx = int(nsd_img_idx)
|
| 505 |
with self._lock:
|
|
|
|
| 452 |
self._status = "loading"
|
| 453 |
self._error = ""
|
| 454 |
self._n_samples = None
|
| 455 |
+
self._beta_std = None
|
| 456 |
self._lock = threading.Lock()
|
| 457 |
self._nsd_cache: dict[int, list[int]] = {}
|
| 458 |
|
|
|
|
| 474 |
self._status = data.get("status", "ok")
|
| 475 |
self._error = data.get("error", "")
|
| 476 |
self._n_samples = data.get("n_samples")
|
| 477 |
+
self._beta_std = data.get("beta_std")
|
| 478 |
return
|
| 479 |
except Exception:
|
| 480 |
_time.sleep(interval)
|
|
|
|
| 500 |
with self._lock:
|
| 501 |
return self._n_samples
|
| 502 |
|
| 503 |
+
@property
|
| 504 |
+
def beta_std(self):
|
| 505 |
+
with self._lock:
|
| 506 |
+
return self._beta_std
|
| 507 |
+
|
| 508 |
# ββ remote calls ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 509 |
|
| 510 |
+
def get_fmri(self, sample_idx: int) -> 'np.ndarray | None':
|
| 511 |
+
"""Fetch raw fMRI (N_VOXELS,) float32 from the remote endpoint, or None."""
|
| 512 |
+
result = self._post("get_fmri", {"sample_idx": int(sample_idx)})
|
| 513 |
+
raw = result.get("fmri")
|
| 514 |
+
if raw is None:
|
| 515 |
+
return None
|
| 516 |
+
import base64 as _b64
|
| 517 |
+
return np.frombuffer(_b64.b64decode(raw), dtype=np.float32).copy()
|
| 518 |
+
|
| 519 |
def sample_idxs_for_nsd_img(self, nsd_img_idx: int) -> list[int]:
|
| 520 |
nsd_idx = int(nsd_img_idx)
|
| 521 |
with self._lock:
|