Skip to content

Commit

Permalink
[FIX] close #340 and #355
Browse files Browse the repository at this point in the history
  • Loading branch information
zihuaihuai committed Sep 25, 2024
1 parent 1f3068f commit ad85244
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 8 additions & 2 deletions brainstat/context/histology.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ def read_histology_profile(
)

with h5py.File(histology_file, "r") as h5_file:
profiles = h5_file.get(template)[...]
if template == "fslr32k":
profiles = h5_file.get("fs_LR_64k")[...]
else:
profiles = h5_file.get(template)[...]
if civet_template:
fsaverage_surface = fetch_template_surface("fsaverage")
civet_surface = fetch_template_surface(civet_template)
Expand Down Expand Up @@ -191,7 +194,10 @@ def download_histology_profiles(

data_dir = Path(data_dir) if data_dir else data_directories["BIGBRAIN_DATA_DIR"]
data_dir.mkdir(parents=True, exist_ok=True)
output_file = data_dir / ("histology_" + template + ".h5")
if template == "fslr32k":
output_file = data_dir / "histology_fslr32k.h5"
else:
output_file = data_dir / ("histology_" + template + ".h5")

url = read_data_fetcher_json()["bigbrain_profiles"][template]["url"]

Expand Down
10 changes: 9 additions & 1 deletion brainstat/tests/test_histology.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Unit tests for the histology module."""
import pytest
import requests
import numpy as np

from brainstat._utils import read_data_fetcher_json

from brainstat.context.histology import read_histology_profile
parametrize = pytest.mark.parametrize
json = read_data_fetcher_json()

Expand All @@ -19,3 +20,10 @@ def test_urls(template):
"""
r = requests.head(json["bigbrain_profiles"][template]["url"])
assert r.status_code == 200


def test_histology_profiles_is_ndarray():
histology_profiles = read_histology_profile(template="fslr32k")

# Assert that histology_profiles is an ndarray
assert isinstance(histology_profiles, np.ndarray), "histology_profiles should be a NumPy ndarray"
2 changes: 1 addition & 1 deletion brainstat/tests/test_mesh_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ def test_nifti_input():
edg = mesh_edges(nifti)

assert edg.shape[1] == 2
assert np.amax(edg) <= nifti.get_data().sum() - 1
assert np.amax(edg) <= nifti.get_fdata().sum() - 1

0 comments on commit ad85244

Please sign in to comment.