Skip to content

Commit

Permalink
Merge pull request #360 from MICA-MNI/340-read_histology_profiletempl…
Browse files Browse the repository at this point in the history
…ate=fslr32k-gives-error-in-h5_filegettemplate

340 read histology profiletemplate=fslr32k gives error in h5 filegettemplate
  • Loading branch information
zihuaihuai authored Sep 26, 2024
2 parents 2ad1b3a + 4051c8a commit dad2c29
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 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
4 changes: 2 additions & 2 deletions brainstat/tests/test_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def test_fixed_overload():
assert np.array_equal(fix_add_intercept.m, expected)

# fix_sub = fix01 - fix12
# assert np.array_equal(fix_sub.m, random_data[:, 0][:, None])
# assert np.array_equal(fix_sub.m.to_numpy(), random_data[:, 0][:, None])

# fix_mul = fix01 * fix2
# assert np.array_equal(fix_mul.m, random_data[:, :2] * random_data[:, 2][:, None])
# assert np.array_equal(fix_mul.m.to_numpy(), random_data[:, :2] * random_data[:, 2][:, None])


def test_mixed_init():
Expand Down

0 comments on commit dad2c29

Please sign in to comment.