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

Update conditions when dataset_description created #28

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions src/niftyone/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ def main() -> None:
out_dir = Path(args.out_dir)
out_dir.mkdir(exist_ok=True, parents=True)

bids.make_dataset_description(out_dir=out_dir)

match args.analysis_level:
case "participant":
bids.make_dataset_description(out_dir=out_dir, overwrite=args.overwrite)
analysis_levels.participant(
bids_dir=args.bids_dir,
out_dir=out_dir,
Expand Down
8 changes: 5 additions & 3 deletions src/niftyone/metadata/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import niftyone


def make_dataset_description(out_dir: Path) -> None:
def make_dataset_description(out_dir: Path, overwrite: bool) -> None:
"""Create dataset_description.json for BIDS dataset."""
description = {
"Name": "NiftyOne",
Expand All @@ -23,5 +23,7 @@ def make_dataset_description(out_dir: Path) -> None:
"License": "LGPL-2.1",
}

with (out_dir / "dataset_description.json").open("w") as f:
json.dump(description, f, indent=4)
ds_fpath = out_dir.joinpath("dataset_description.json")
if not ds_fpath.exists() or overwrite:
with ds_fpath.open("w") as f:
json.dump(description, f, indent=4)
7 changes: 5 additions & 2 deletions tests/unit/niftyone/metadata/test_bids.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import json
from pathlib import Path

import pytest

import niftyone
from niftyone.metadata import bids


def test_make_dataset_description(tmp_path: Path) -> None:
@pytest.mark.parametrize("overwrite", [(True), (False)])
def test_make_dataset_description(tmp_path: Path, overwrite: bool) -> None:
out_dir = tmp_path
bids.make_dataset_description(out_dir=out_dir)
bids.make_dataset_description(out_dir=out_dir, overwrite=overwrite)

# Check file created
json_fpath = out_dir / "dataset_description.json"
Expand Down
Loading