Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow number of free CPU cores to be set in the GUI #195

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion brainreg/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def misc_parse(parser):
"--n-free-cpus",
dest="n_free_cpus",
type=check_positive_int,
default=4,
default=2,
help="The number of CPU cores on the machine to leave "
"unused by the program to spare resources.",
)
Expand Down
17 changes: 14 additions & 3 deletions brainreg/napari/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def brainreg_register():
smoothing_sigma_floating=1,
histogram_n_bins_floating=128,
histogram_n_bins_reference=128,
n_free_cpus=2,
debug=False,
)

Expand Down Expand Up @@ -212,6 +213,10 @@ def brainreg_register():
value=DEFAULT_PARAMETERS["histogram_n_bins_reference"],
label="histogram_n_bins_reference",
),
n_free_cpus=dict(
value=DEFAULT_PARAMETERS["n_free_cpus"],
label="Free CPU cores",
),
debug=dict(
value=DEFAULT_PARAMETERS["debug"],
label="Debug mode",
Expand Down Expand Up @@ -243,6 +248,7 @@ def widget(
smoothing_sigma_floating: float,
histogram_n_bins_floating: float,
histogram_n_bins_reference: float,
n_free_cpus: int,
debug: bool,
reset_button,
check_orientation_button,
Expand Down Expand Up @@ -333,6 +339,8 @@ def widget(
Number of bins used for the generation of the histograms used
for the calculation of Normalized Mutual Information on the
reference image
n_free_cpus : int
How many CPU cores to leave free
debug: bool
Activate debug mode (save intermediate steps).
check_orientation_button:
Expand Down Expand Up @@ -395,7 +403,7 @@ def get_gui_logging_args():
)

@thread_worker
def run():
def run(n_free_cpus):
paths = Paths(pathlib.Path(registration_output_folder))

niftyreg_args = NiftyregArgs(
Expand Down Expand Up @@ -432,7 +440,10 @@ def run():
scaling,
load_parallel,
) = initialise_brainreg(
atlas_key.value, data_orientation, voxel_sizes
atlas_key.value,
data_orientation,
voxel_sizes,
n_free_cpus=n_free_cpus,
)

additional_images_downsample = get_additional_images_downsample(
Expand Down Expand Up @@ -484,7 +495,7 @@ def run():
f"{paths.registration_output_folder}"
)

worker = run()
worker = run(n_free_cpus)
if not block:
worker.returned.connect(load_registration_as_layers)

Expand Down
5 changes: 3 additions & 2 deletions brainreg/napari/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from tqdm import tqdm


def initialise_brainreg(atlas_key, data_orientation_key, voxel_sizes):
def initialise_brainreg(
atlas_key, data_orientation_key, voxel_sizes, n_free_cpus=2
):
scaling_rounding_decimals = 5
n_free_cpus = 2
atlas = BrainGlobeAtlas(atlas_key)
source_space = bg.AnatomicalSpace(data_orientation_key)

Expand Down
Loading