Skip to content

Commit

Permalink
Rename everything to brainmapper and explicitly support old cellfinde…
Browse files Browse the repository at this point in the history
…r directories
  • Loading branch information
adamltyson committed Jan 4, 2024
1 parent 4e0d384 commit 490c8b4
Show file tree
Hide file tree
Showing 36 changed files with 1,425 additions and 99 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
from pathlib import Path
from typing import Callable, List, Optional, Tuple, Union
from typing import Callable, Dict, List, Optional, Tuple, Union

import bg_space as bgs
from napari.types import LayerDataTuple
Expand All @@ -14,22 +14,25 @@
PathOrPaths = Union[List[os.PathLike], os.PathLike]


def is_wholebrain_cell_dir(path: os.PathLike) -> bool:
def is_brainmapper_dir(path: os.PathLike) -> bool:
"""
Determines whether a path is to a BrainGlobe workflows whole brain
Determines whether a path is to a BrainGlobe brainmapper whole brain
cell detection (previously cellfinder) output directory.
"""
path = os.path.abspath(path)
if os.path.isdir(path):
filelist = os.listdir(path)
else:
return False
if "cellfinder.json" in filelist:
if "brainmapper.json" in filelist:
return True
# for backwards compatibility
elif "cellfinder.json" in filelist:
return True
return False


def wholebrain_cell_read_dir(path: PathOrPaths) -> Optional[Callable]:
def brainmapper_read_dir(path: PathOrPaths) -> Optional[Callable]:
"""A basic implementation of the napari_get_reader hook specification.
Parameters
Expand All @@ -43,12 +46,23 @@ def wholebrain_cell_read_dir(path: PathOrPaths) -> Optional[Callable]:
If the path is a recognized format, return a function that accepts the
same path or list of paths, and returns a list of layer data tuples.
"""
if isinstance(path, str) and is_wholebrain_cell_dir(path):
if isinstance(path, str) and is_brainmapper_dir(path):
return reader_function
else:
return None


def get_metadata(directory: Path) -> Dict:
try:
with open(directory / "brainmapper.json") as json_file:
metadata = json.load(json_file)
# for backwards compatibility
except FileNotFoundError:
with open(directory / "cellfinder.json") as json_file:
metadata = json.load(json_file)
return metadata


def reader_function(
path: os.PathLike,
point_size: int = 15,
Expand Down Expand Up @@ -78,10 +92,9 @@ def reader_function(
layer_type=="image" if not provided
"""

print("Loading whole brain cell detection directory")
print("Loading brainmapper directory")
path = Path(os.path.abspath(path))
with open(path / "cellfinder.json") as json_file:
metadata = json.load(json_file)
metadata = get_metadata(path)

layers: List[LayerDataTuple] = []

Expand Down
8 changes: 4 additions & 4 deletions brainglobe_napari_io/napari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ contributions:
title: Brainreg Read Directory Atlas Space
python_name: brainglobe_napari_io.brainreg.reader_dir_atlas_space:brainreg_read_dir_atlas_space

- id: brainglobe-napari-io.workflows_wholebrain_cell_read_dir
title: Workflows Whole Brain Cell Detection Read Directory
python_name: brainglobe_napari_io.workflows.wholebrain_cell_reader_dir:wholebrain_cell_read_dir
- id: brainglobe-napari-io.brainmapper_read_dir
title: Brainmapper Read Directory
python_name: brainglobe_napari_io.brainmapper.brainmapper_reader_dir:brainmapper_read_dir

- id: brainglobe-napari-io.cellfinder_read_xml
title: Cellfinder Read XML
Expand All @@ -34,7 +34,7 @@ contributions:
- '*.tiff'
accepts_directories: true

- command: brainglobe-napari-io.workflows_wholebrain_cell_read_dir
- command: brainglobe-napari-io.brainmapper_read_dir
filename_patterns:
- '*.tif'
accepts_directories: true
Expand Down
1 change: 1 addition & 0 deletions tests/data/brainmapper_output/brainmapper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"signal_planes_paths": ["2"], "background_planes_path": ["4"], "output_dir": "output", "signal_ch_ids": null, "background_ch_id": null, "registration_config": "cellfinder.conf.custom", "voxel_sizes": ["5", "2.31", "2.31"], "network_voxel_sizes": [5, 1, 1], "no_detection": false, "no_classification": false, "no_register": false, "no_analyse": false, "no_figures": false, "start_plane": 0, "end_plane": -1, "save_planes": false, "outlier_keep": false, "artifact_keep": false, "max_cluster_size": 100000, "soma_diameter": 16, "ball_xy_size": 6, "ball_z_size": 15, "ball_overlap_fraction": 0.6, "log_sigma_size": 0.2, "n_sds_above_mean_thresh": 10, "soma_spread_factor": 1.4, "trained_model": "model.h5", "model_weights": null, "network_depth": "50", "batch_size": 64, "cube_width": 50, "cube_height": 50, "cube_depth": 20, "save_empty_cubes": false, "n_free_cpus": 8, "max_ram": null, "save_csv": false, "debug": false, "sort_input_file": false, "no_models": false, "model": "resnet50_tv", "heatmap_smooth": 100, "mask_figures": true, "install_path": ".cellfinder", "download_path": "tmp", "no_amend_config": false, "atlas": "allen_mouse_100um", "orientation": "prs", "backend": "niftyreg", "affine_n_steps": 6, "affine_use_n_steps": 5, "freeform_n_steps": 6, "freeform_use_n_steps": 4, "bending_energy_weight": 0.95, "grid_spacing": -10, "smoothing_sigma_reference": -1.0, "smoothing_sigma_floating": -1.0, "histogram_n_bins_floating": 128, "histogram_n_bins_reference": 128, "paths": {"output_dir": "output_dir", "registration_output_folder": "output_dir/brainreg_output", "metadata_path": "output/brainmapper.json", "registration_metadata_path": "output_dir/brainreg_output/brainreg.json"}}
Loading

0 comments on commit 490c8b4

Please sign in to comment.