From f3ea036066041fdbce62138760033f55bc7e00a3 Mon Sep 17 00:00:00 2001 From: Carlo Castoldi Date: Thu, 9 Jan 2025 11:25:58 +0100 Subject: [PATCH] add option --decimate-fraction to DevCCF --- .../atlas_scripts/kim_devccf_mouse.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/brainglobe_atlasapi/atlas_generation/atlas_scripts/kim_devccf_mouse.py b/brainglobe_atlasapi/atlas_generation/atlas_scripts/kim_devccf_mouse.py index d1c30f3..055a4a7 100644 --- a/brainglobe_atlasapi/atlas_generation/atlas_scripts/kim_devccf_mouse.py +++ b/brainglobe_atlasapi/atlas_generation/atlas_scripts/kim_devccf_mouse.py @@ -123,7 +123,7 @@ def fetch_ontology(pooch_: pooch.Pooch): return structures def create_meshes(output_path: str|Path, - structures, annotation_volume, root_id): + structures, annotation_volume, root_id, decimate_fraction): if not isinstance(output_path, Path): output_path = Path(output_path) output_path.mkdir(exist_ok=True) @@ -141,7 +141,6 @@ def create_meshes(output_path: str|Path, # Mesh creation closing_n_iters = 2 - decimate_fraction = 0.2 # fraction of the original number of vertices to be kept smooth = True # smooth meshes after creation start = time.time() for node in track( @@ -234,15 +233,26 @@ def _format_action_invocation(self, action): - MRI-MTR MRI Magnetization Transfer Ratio - MRI-T2 MRI T2-weighted -By default, it uses LSFM +By default, LSFM """ +decimate_fraction_help = "fraction of the original number of meshes' vertices to be kept. Must be a number > 0 and <= 1.\nBy default, 0.2" +def decimate_fraction_type(arg): + try: + f = float(arg) + if 0 < f <= 1: + return f + except ValueError: + pass + raise argparse.ArgumentTypeError(f"invalid value: '{arg}' (must be a number > 0 and <= 1)") arg_parser.add_argument("-t", "--timepoints", default=TIMEPOINTS, type=str, nargs="+", choices=TIMEPOINTS, help=timepoints_help) arg_parser.add_argument("-m", "--modality", default="LSFM", type=str, choices=MODALITIES, help=modalities_help) +arg_parser.add_argument("-d", "--decimate-fraction", default=0.2, type=decimate_fraction_type, help=decimate_fraction_help) if __name__ == "__main__": params = vars(arg_parser.parse_args()) timepoints = params["timepoints"] modality = params["modality"] + decimate_fraction = params["decimate-fraction"] atlas_name = f"{ATLAS_NAME}_{modality}" bg_root_dir = DEFAULT_WORKDIR/atlas_name download_dir_path = bg_root_dir/"downloads" @@ -262,7 +272,8 @@ def _format_action_invocation(self, action): meshes_dir_path, structures, annotation_volume, - ROOT_ID + ROOT_ID, + decimate_fraction ) meshes_dict, structures_with_mesh = create_mesh_dict( structures, meshes_dir_path