Skip to content

Commit

Permalink
Add option to pass subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
finsberg committed Oct 12, 2024
1 parent 888278c commit bb18d5a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
16 changes: 9 additions & 7 deletions docs/demo_dolfinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

# First we try to generate the mean shape from the UK Biobank atlas

folder_mean = Path("mean")
subprocess.run(["ukb-atlas", str(folder_mean), "--mesh"])
folder = Path("data")
subdir = "mean"
subprocess.run(["ukb-atlas", str(folder), "--mesh", "--subdir", subdir])

comm = MPI.COMM_WORLD
msh_file = folder_mean / "ED.msh"
msh_file = folder / subdir / "ED.msh"
gmsh.initialize()
gmsh.model.add("Mesh from file")
gmsh.merge(str(msh_file))
Expand Down Expand Up @@ -50,12 +51,13 @@


# Now lets us perturb the mean shape with the second mode

folder_mean = Path("mode_1")
subprocess.run(["ukb-atlas", str(folder_mean), "--mesh", "--mode", "1", "--std", "1.5"])
subdir = "mode_1"
subprocess.run(
["ukb-atlas", str(folder), "--mesh", "--mode", "1", "--std", "1.5", "--subdir", subdir]
)

comm = MPI.COMM_WORLD
msh_file = folder_mean / "ED.msh"
msh_file = folder / subdir / "ED.msh"
gmsh.initialize()
gmsh.model.add("Mesh from file")
gmsh.merge(str(msh_file))
Expand Down
13 changes: 11 additions & 2 deletions src/ukb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def get_parser() -> argparse.ArgumentParser:
type=Path,
help="Directory to save the generated surfaces and meshes.",
)
parser.add_argument(
"--subdir",
type=Path,
default=None,
help="Directory to save the generated surfaces and meshes.",
)
parser.add_argument(
"-a",
"--all",
Expand Down Expand Up @@ -85,8 +91,11 @@ def main(argv: typing.Sequence[str] | None = None) -> int:
default=lambda o: str(o),
)

unique_id = hashlib.md5(args_json.encode()).hexdigest()
outdir = main_outdir / unique_id
if args["subdir"]:
outdir = main_outdir / args["subdir"]
else:
unique_id = hashlib.md5(args_json.encode()).hexdigest()
outdir = main_outdir / unique_id
outdir.mkdir(exist_ok=True, parents=True)

(outdir / "parameters.json").write_text(args_json)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def test_generate_surfaces_mean_healthy(tmp_path):
ukb.cli.main([str(tmp_path)])
ukb.cli.main([str(tmp_path), "--subdir", "."])
assert (tmp_path / "UKBRVLV.h5").exists()
assert (tmp_path / "parameters.json").exists()
for name in ukb.surface.surfaces:
Expand All @@ -17,7 +17,7 @@ def test_generate_surfaces_mean_healthy(tmp_path):
def test_generate_surfaces_non_mean_healthy(tmp_path):
mode = 1
std = 0.3
ukb.cli.main([str(tmp_path), "--mode", str(mode), "--std", str(std)])
ukb.cli.main([str(tmp_path), "--mode", str(mode), "--std", str(std), "--subdir", "."])
assert (tmp_path / "UKBRVLV.h5").exists()
assert (tmp_path / "parameters.json").exists()
params = json.loads((tmp_path / "parameters.json").read_text())
Expand All @@ -32,7 +32,7 @@ def test_generate_surfaces_non_mean_healthy(tmp_path):

@pytest.mark.xfail(reason="I think we have the wrong template")
def test_generate_surfaces_mean_all(tmp_path):
ukb.cli.main([str(tmp_path), "--all"])
ukb.cli.main([str(tmp_path), "--all", "--subdir", "."])
assert (tmp_path / "UKBRVLV_ALL.h5").exists()
assert (tmp_path / "parameters.json").exists()
for name in ukb.surface.surfaces:
Expand Down

0 comments on commit bb18d5a

Please sign in to comment.