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

#6188 Allow user to define own FolderLayout in SaveImage and SaveImaged transforms #6213

Merged
merged 26 commits into from
Mar 24, 2023
Merged

Conversation

MathijsdeBoer
Copy link
Contributor

@MathijsdeBoer MathijsdeBoer commented Mar 21, 2023

Improves issues discussed in #6188 .

Description

As I found out in #6188, SaveImage and SaveImaged provide a fairly rigid way to define the output path. I've made some changes that allow the user to more easily define their own FolderLayout derivative, and pass it to these transforms.
Additionally, I've added a boolean that adds a key "saved_to" to the metadata, so the user can more easily assess where their output actually went.

Finally, and most optionally, I've prepended "meta" to the MetaTensor.__repr__ and MetaTensor.__str__ outputs in an effort to more clearly show to the user that the printed tensor has special properties. This change was made in its own commit, which can be left out if undesired.

Other small changes to documentation formatting, mainly changing:

"""
    ...
    some documentation `code` more docs
    ...
"""

to

"""
    ...
    some documentation ``code`` more docs
    ...
"""

To format these correctly in the docs. Seemed like some people assumed the single backticks would format as code, as opposed to italics.


Test results

./runtests.sh -f -u --net --coverage
results: 1 failure, 2 errors
The failure was related to me changing the MetaTensor.__repr__, fixed the test in a separate commit

./runtests.sh --quick --unittests --disttests
In progress

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

Mathijs de Boer and others added 5 commits March 21, 2023 13:26
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
…d for custom implementations

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Add `savepath_in_metadict`, to include the location of the output image in the metadata

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
monai/data/meta_tensor.py Outdated Show resolved Hide resolved
Mathijs de Boer added 6 commits March 21, 2023 14:54
…d for custom implementations

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Add `savepath_in_metadict`, to include the location of the output image in the metadata

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
This reverts commit 9e1dcd4.
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
wyli pushed a commit that referenced this pull request Mar 21, 2023
…__` for easier identification (#6214)

Discussed in #6213

### Description

Prepends `"meta"` to the `MetaTensor.__repr__` and `MetaTensor.__str__`
output so printing a MetaTensor does not look the exact same as a
regular `torch.Tensor`.

I don't expect this change to cause any breaks, with me running the risk
of invoking [xkcd 1172](https://xkcd.com/1172/).

---

1 failure in `./runtests.sh -f -u --net --coverage`:
```text
======================================================================
FAIL: test_values (tests.test_tciadataset.TestTciaDataset)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\PythonProjects\MONAI-SaveImageFormatting\tests\test_tciadataset.py", line 72, in test_values
    self.assertTrue(
AssertionError: False is not true
```

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [x] New tests added to cover the changes.
- [x] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.

---------

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
@wyli
Copy link
Contributor

wyli commented Mar 22, 2023

could you please update the test case in tests/test_save_imaged.py

@MathijsdeBoer
Copy link
Contributor Author

MathijsdeBoer commented Mar 22, 2023

Will do! (Though I might have accidentally clicked a wrong button on this page)

Edit: Nope, the button did what I expected it to do!

Mathijs de Boer added 2 commits March 22, 2023 22:01
…yout

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
@MathijsdeBoer
Copy link
Contributor Author

I hope it's okay if I didn't rerun the full test suite, and only ran the edited tests. It takes about an hour to do on my work PC, which is considerably more powerful than my personal PC that I used for these last few commits.

monai/transforms/io/array.py Show resolved Hide resolved
monai/transforms/io/array.py Outdated Show resolved Hide resolved
Copy link
Contributor

@KumoLiu KumoLiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contributions! Few comments in line.
You could also run ./runtests.sh --autofix for auto style fixes.

monai/transforms/io/array.py Outdated Show resolved Hide resolved
monai/transforms/io/array.py Outdated Show resolved Hide resolved
monai/transforms/io/array.py Outdated Show resolved Hide resolved
monai/transforms/io/array.py Show resolved Hide resolved
monai/transforms/io/dictionary.py Outdated Show resolved Hide resolved
monai/transforms/io/dictionary.py Outdated Show resolved Hide resolved
monai/transforms/io/dictionary.py Show resolved Hide resolved
monai/transforms/io/dictionary.py Outdated Show resolved Hide resolved
monai/transforms/io/array.py Outdated Show resolved Hide resolved
monai/transforms/io/dictionary.py Show resolved Hide resolved
MathijsdeBoer and others added 3 commits March 23, 2023 11:51
Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: Mathijs de Boer <8137653+MathijsdeBoer@users.noreply.github.com>
Formatting fix in test_save_imaged.py

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
# Conflicts:
#	monai/transforms/io/array.py
#	monai/transforms/io/dictionary.py
Mathijs de Boer and others added 5 commits March 23, 2023 16:33
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
# Conflicts:
#	tests/test_save_imaged.py
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
@wyli
Copy link
Contributor

wyli commented Mar 23, 2023

/build

@MathijsdeBoer
Copy link
Contributor Author

Haha, now I'm starting to get slightly embarrased about the amount of small commits I have to make because I thought I had ran every test, but forgot that one, I'll get to work on fixing that mypy error.

Mathijs de Boer added 2 commits March 24, 2023 00:51
Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I think the current PR's implementation is ok for now, another idea is to set the path string as a property of SaveImage, then after saving we can get the path by saver.last_saved_filename cc @ericspod

@wyli
Copy link
Contributor

wyli commented Mar 24, 2023

/build

@wyli wyli enabled auto-merge (squash) March 24, 2023 19:14
@wyli wyli merged commit c885460 into Project-MONAI:dev Mar 24, 2023
jak0bw pushed a commit to jak0bw/MONAI that referenced this pull request Mar 28, 2023
…aTensor.__str__` for easier identification (Project-MONAI#6214)

Discussed in Project-MONAI#6213

### Description

Prepends `"meta"` to the `MetaTensor.__repr__` and `MetaTensor.__str__`
output so printing a MetaTensor does not look the exact same as a
regular `torch.Tensor`.

I don't expect this change to cause any breaks, with me running the risk
of invoking [xkcd 1172](https://xkcd.com/1172/).

---

1 failure in `./runtests.sh -f -u --net --coverage`:
```text
======================================================================
FAIL: test_values (tests.test_tciadataset.TestTciaDataset)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\PythonProjects\MONAI-SaveImageFormatting\tests\test_tciadataset.py", line 72, in test_values
    self.assertTrue(
AssertionError: False is not true
```

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [x] New tests added to cover the changes.
- [x] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.

---------

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
jak0bw pushed a commit to jak0bw/MONAI that referenced this pull request Mar 28, 2023
…age` and `SaveImaged` transforms (Project-MONAI#6213)

Improves issues discussed in Project-MONAI#6188 .

### Description

As I found out in Project-MONAI#6188, `SaveImage` and `SaveImaged` provide a fairly
rigid way to define the output path. I've made some changes that allow
the user to more easily define their own `FolderLayout` derivative, and
pass it to these transforms.
Additionally, I've added a boolean that adds a key `"saved_to"` to the
metadata, so the user can more easily assess where their output actually
went.

Finally, and most optionally, I've prepended `"meta"` to the
`MetaTensor.__repr__` and `MetaTensor.__str__` outputs in an effort to
more clearly show to the user that the printed tensor has special
properties. This change was made in its own commit, which can be left
out if undesired.

Other small changes to documentation formatting, mainly changing:

```text
"""
    ...
    some documentation `code` more docs
    ...
"""
```

to

```text
"""
    ...
    some documentation ``code`` more docs
    ...
"""
```

To format these correctly in the docs. Seemed like some people assumed
the single backticks would format as `code`, as opposed to _italics_.

---

### Test results

`./runtests.sh -f -u --net --coverage`
results: 1 failure, 2 errors
The failure was related to me changing the `MetaTensor.__repr__`, fixed
the test in a separate commit

`./runtests.sh --quick --unittests  --disttests`
In progress

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [x] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [x] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
jak0bw pushed a commit to jak0bw/MONAI that referenced this pull request Mar 28, 2023
…aTensor.__str__` for easier identification (Project-MONAI#6214)

Discussed in Project-MONAI#6213

### Description

Prepends `"meta"` to the `MetaTensor.__repr__` and `MetaTensor.__str__`
output so printing a MetaTensor does not look the exact same as a
regular `torch.Tensor`.

I don't expect this change to cause any breaks, with me running the risk
of invoking [xkcd 1172](https://xkcd.com/1172/).

---

1 failure in `./runtests.sh -f -u --net --coverage`:
```text
======================================================================
FAIL: test_values (tests.test_tciadataset.TestTciaDataset)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\PythonProjects\MONAI-SaveImageFormatting\tests\test_tciadataset.py", line 72, in test_values
    self.assertTrue(
AssertionError: False is not true
```

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [x] New tests added to cover the changes.
- [x] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.

---------

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
jak0bw pushed a commit to jak0bw/MONAI that referenced this pull request Mar 28, 2023
…age` and `SaveImaged` transforms (Project-MONAI#6213)

Improves issues discussed in Project-MONAI#6188 .

### Description

As I found out in Project-MONAI#6188, `SaveImage` and `SaveImaged` provide a fairly
rigid way to define the output path. I've made some changes that allow
the user to more easily define their own `FolderLayout` derivative, and
pass it to these transforms.
Additionally, I've added a boolean that adds a key `"saved_to"` to the
metadata, so the user can more easily assess where their output actually
went.

Finally, and most optionally, I've prepended `"meta"` to the
`MetaTensor.__repr__` and `MetaTensor.__str__` outputs in an effort to
more clearly show to the user that the printed tensor has special
properties. This change was made in its own commit, which can be left
out if undesired.

Other small changes to documentation formatting, mainly changing:

```text
"""
    ...
    some documentation `code` more docs
    ...
"""
```

to

```text
"""
    ...
    some documentation ``code`` more docs
    ...
"""
```

To format these correctly in the docs. Seemed like some people assumed
the single backticks would format as `code`, as opposed to _italics_.

---

### Test results

`./runtests.sh -f -u --net --coverage`
results: 1 failure, 2 errors
The failure was related to me changing the `MetaTensor.__repr__`, fixed
the test in a separate commit

`./runtests.sh --quick --unittests  --disttests`
In progress

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [x] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [x] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [x] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: Mathijs de Boer <m.deboer-41@umcutrecht.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants