Skip to content

Commit

Permalink
remove GIN download from setup_cache (it's done in CellfinderConfig now)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfmig committed Apr 22, 2024
1 parent 1a26f9a commit 36bfc1a
Showing 1 changed file with 64 additions and 31 deletions.
95 changes: 64 additions & 31 deletions benchmarks/cellfinder_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import shutil
from pathlib import Path

import pooch
from brainglobe_utils.IO.cells import save_cells
from cellfinder.core.main import main as cellfinder_run
from cellfinder.core.tools.IO import read_with_dask
Expand Down Expand Up @@ -81,18 +80,18 @@ class TimeBenchmarkPrepGIN:
# Custom attributes
input_config_path = str(DEFAULT_JSON_CONFIG_PATH_CELLFINDER)

def setup_cache(
self,
):
def setup_cache(self):

Check warning on line 83 in benchmarks/cellfinder_core.py

View check run for this annotation

Codecov / codecov/patch

benchmarks/cellfinder_core.py#L83

Added line #L83 was not covered by tests
"""
Download the input data from the GIN repository to the local
directory specified in the default_config.json
directory specified in the default_config.json.
Notes
-----
The `setup_cache` method only performs the computations once
per benchmark round and then caches the result to disk [1]_. It cannot
be parametrised [2]_.
be parametrised [2]_. Therefore, if we sweep across different input
JSON files, we need to ensure all data for all configs is made
available with this setup function.
[1] https://asv.readthedocs.io/en/latest/writing_benchmarks.html#setup-and-teardown-functions
Expand All @@ -108,15 +107,6 @@ def setup_cache(
config_dict = json.load(cfg)
config = CellfinderConfig(**config_dict)

# Download data with pooch
_ = pooch.retrieve(
url=config.data_url,
known_hash=config.data_hash,
path=config._install_path,
progressbar=True,
processor=pooch.Unzip(extract_dir=config.data_dir_relative),
)

# Check paths to input data should now exist in config
assert Path(config._signal_dir_path).exists()
assert Path(config._background_dir_path).exists()
Expand All @@ -129,12 +119,7 @@ def setup(self):
"""

# Run setup
cfg = setup_cellfinder_workflow(
[
"--config",
self.input_config_path,
]
)
cfg = setup_cellfinder_workflow(self.input_config_path)

Check warning on line 122 in benchmarks/cellfinder_core.py

View check run for this annotation

Codecov / codecov/patch

benchmarks/cellfinder_core.py#L122

Added line #L122 was not covered by tests

# Save configuration as attribute
self.cfg = cfg
Expand Down Expand Up @@ -162,7 +147,7 @@ class TimeFullWorkflow(TimeBenchmarkPrepGIN):
A base class for timing benchmarks for the cellfinder workflow.
"""

def time_workflow_from_cellfinder_run(self):
def time_workflow(self):

Check warning on line 150 in benchmarks/cellfinder_core.py

View check run for this annotation

Codecov / codecov/patch

benchmarks/cellfinder_core.py#L150

Added line #L150 was not covered by tests
run_workflow_from_cellfinder_run(self.cfg)


Expand All @@ -177,10 +162,10 @@ class TimeReadInputDask(TimeBenchmarkPrepGIN):
"""

def time_read_signal_with_dask(self):
read_with_dask(self.cfg._signal_dir_path)
read_with_dask(str(self.cfg._signal_dir_path))

Check warning on line 165 in benchmarks/cellfinder_core.py

View check run for this annotation

Codecov / codecov/patch

benchmarks/cellfinder_core.py#L165

Added line #L165 was not covered by tests

def time_read_background_with_dask(self):
read_with_dask(self.cfg._background_dir_path)
read_with_dask(str(self.cfg._background_dir_path))

Check warning on line 168 in benchmarks/cellfinder_core.py

View check run for this annotation

Codecov / codecov/patch

benchmarks/cellfinder_core.py#L168

Added line #L168 was not covered by tests


class TimeDetectCells(TimeBenchmarkPrepGIN):
Expand All @@ -198,13 +183,37 @@ def setup(self):
# basic setup
TimeBenchmarkPrepGIN.setup(self)

# add input data as arrays to config
self.signal_array = read_with_dask(self.cfg._signal_dir_path)
self.background_array = read_with_dask(self.cfg._background_dir_path)
# add input data as arrays to the config
self.signal_array = read_with_dask(str(self.cfg._signal_dir_path))
self.background_array = read_with_dask(

Check warning on line 188 in benchmarks/cellfinder_core.py

View check run for this annotation

Codecov / codecov/patch

benchmarks/cellfinder_core.py#L187-L188

Added lines #L187 - L188 were not covered by tests
str(self.cfg._background_dir_path)
)

def time_cellfinder_run(self):
cellfinder_run(
self.signal_array, self.background_array, self.cfg.voxel_sizes
self.signal_array,
self.background_array,
self.cfg.voxel_sizes,
self.cfg.start_plane,
self.cfg.end_plane,
self.cfg.trained_model,
self.cfg.model_weights,
self.cfg.model,
self.cfg.batch_size,
self.cfg.n_free_cpus,
self.cfg.network_voxel_sizes,
self.cfg.soma_diameter,
self.cfg.ball_xy_size,
self.cfg.ball_z_size,
self.cfg.ball_overlap_fraction,
self.cfg.log_sigma_size,
self.cfg.n_sds_above_mean_thresh,
self.cfg.soma_spread_factor,
self.cfg.max_cluster_size,
self.cfg.cube_width,
self.cfg.cube_height,
self.cfg.cube_depth,
self.cfg.network_depth,
)


Expand All @@ -215,12 +224,36 @@ def setup(self):
TimeBenchmarkPrepGIN.setup(self)

# add input data as arrays to config
self.signal_array = read_with_dask(self.cfg._signal_dir_path)
self.background_array = read_with_dask(self.cfg._background_dir_path)
self.signal_array = read_with_dask(str(self.cfg._signal_dir_path))
self.background_array = read_with_dask(

Check warning on line 228 in benchmarks/cellfinder_core.py

View check run for this annotation

Codecov / codecov/patch

benchmarks/cellfinder_core.py#L227-L228

Added lines #L227 - L228 were not covered by tests
str(self.cfg._background_dir_path)
)

# detect cells
self.detected_cells = cellfinder_run(
self.signal_array, self.background_array, self.cfg.voxel_sizes
self.signal_array,
self.background_array,
self.cfg.voxel_sizes,
self.cfg.start_plane,
self.cfg.end_plane,
self.cfg.trained_model,
self.cfg.model_weights,
self.cfg.model,
self.cfg.batch_size,
self.cfg.n_free_cpus,
self.cfg.network_voxel_sizes,
self.cfg.soma_diameter,
self.cfg.ball_xy_size,
self.cfg.ball_z_size,
self.cfg.ball_overlap_fraction,
self.cfg.log_sigma_size,
self.cfg.n_sds_above_mean_thresh,
self.cfg.soma_spread_factor,
self.cfg.max_cluster_size,
self.cfg.cube_width,
self.cfg.cube_height,
self.cfg.cube_depth,
self.cfg.network_depth,
)

def time_save_cells(self):
Expand Down

0 comments on commit 36bfc1a

Please sign in to comment.