From b86a6b8bc6cc6a31b269551cd5e58fc834d80750 Mon Sep 17 00:00:00 2001 From: sfmig <33267254+sfmig@users.noreply.github.com> Date: Fri, 31 May 2024 17:54:21 +0100 Subject: [PATCH] Try with config file --- benchmarks/benchmarks/brainglobe_atlasapi.py | 35 ++++++++++++++----- .../brainglobe_atlasapi/create_mouse_atlas.py | 6 ++-- .../configs/brainglobe_atlasapi_large.json | 3 ++ .../configs/brainglobe_atlasapi_small.json | 3 ++ 4 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 brainglobe_workflows/configs/brainglobe_atlasapi_large.json create mode 100644 brainglobe_workflows/configs/brainglobe_atlasapi_small.json diff --git a/benchmarks/benchmarks/brainglobe_atlasapi.py b/benchmarks/benchmarks/brainglobe_atlasapi.py index 43443ec9..288dc344 100644 --- a/benchmarks/benchmarks/brainglobe_atlasapi.py +++ b/benchmarks/benchmarks/brainglobe_atlasapi.py @@ -1,3 +1,7 @@ +import json +import os +from pathlib import Path + from brainglobe_workflows.brainglobe_atlasapi.create_mouse_atlas import ( create_mouse_atlas, ) @@ -6,14 +10,27 @@ class TimeBenchmark: # Timing attributes timeout = 3600 # default: 60 s - version = ( - None # benchmark version. Default:None (i.e. hash of source code) - ) - warmup_time = 0.1 # seconds - rounds = 2 - repeat = 0 - sample_time = 0.01 # default: 10 ms = 0.01 s; - min_run_count = 2 # default:2 + + def setup(self): + # read input config: environment variable if it exists, else default + input_config_path = os.getenv( + "ATLAS_CONFIG_PATH", + default=str( + Path(__file__).parents[2] + / "brainglobe_workflows" + / "configs" + / "brainglobe_atlasapi_small.json" + ), + ) + + assert Path(input_config_path).exists() + + # read as dict + with open(input_config_path) as cfg: + config_dict = json.load(cfg) + + # pass dict to class + self.config = config_dict def time_create_mouse_atlas(self): - create_mouse_atlas() + create_mouse_atlas(**self.config) diff --git a/brainglobe_workflows/brainglobe_atlasapi/create_mouse_atlas.py b/brainglobe_workflows/brainglobe_atlasapi/create_mouse_atlas.py index 980e6a31..a52f96b3 100644 --- a/brainglobe_workflows/brainglobe_atlasapi/create_mouse_atlas.py +++ b/brainglobe_workflows/brainglobe_atlasapi/create_mouse_atlas.py @@ -1,10 +1,10 @@ from brainglobe_atlasapi import BrainGlobeAtlas -def create_mouse_atlas(): - atlas = BrainGlobeAtlas("allen_mouse_100um") +def create_mouse_atlas(atlas_name): + atlas = BrainGlobeAtlas(atlas_name) print(atlas.atlas_name) if __name__ == "__main__": - create_mouse_atlas() + create_mouse_atlas("allen_mouse_100um") diff --git a/brainglobe_workflows/configs/brainglobe_atlasapi_large.json b/brainglobe_workflows/configs/brainglobe_atlasapi_large.json new file mode 100644 index 00000000..a999d569 --- /dev/null +++ b/brainglobe_workflows/configs/brainglobe_atlasapi_large.json @@ -0,0 +1,3 @@ +{ + "atlas_name": "allen_mouse_10um" +} diff --git a/brainglobe_workflows/configs/brainglobe_atlasapi_small.json b/brainglobe_workflows/configs/brainglobe_atlasapi_small.json new file mode 100644 index 00000000..a41a627a --- /dev/null +++ b/brainglobe_workflows/configs/brainglobe_atlasapi_small.json @@ -0,0 +1,3 @@ +{ + "atlas_name": "allen_mouse_100um" +}