Skip to content

Package snomed mapping as a totalsegmentator package resource#325

Merged
wasserth merged 2 commits into
wasserth:masterfrom
jcfr:package-totalsegmentator_snomed_mapping-csv
Jul 3, 2024
Merged

Package snomed mapping as a totalsegmentator package resource#325
wasserth merged 2 commits into
wasserth:masterfrom
jcfr:package-totalsegmentator_snomed_mapping-csv

Conversation

@jcfr

@jcfr jcfr commented Jun 27, 2024

Copy link
Copy Markdown
Contributor

To retrieve the location after installing totalsegmentator, the following may be done:

from importlib.metadata import distribution
from pathlib import Path


def _lookup(path: str, optional: bool = False) -> Path | None:
    """Support editable installation by looking up path using distribution API."""
    files = distribution("idc_index_data").files
    if files is not None:
        for _file in files:
            if str(_file) == path:
                return Path(str(_file.locate())).resolve(strict=True)
    if optional:
        return None

    msg = f"Failed to lookup '{path}`."
    raise FileNotFoundError(msg)


TOTALSEGMENTATOR_SNOMED_MAPPING_FILEPATH: Path | None = _lookup("resources/totalsegmentator_snomed_mapping.csv")

We could also look into adding the code above directly into totalsegmentator/__init__.py

cc: @fedorov @lassoan

@jcfr

jcfr commented Jun 27, 2024

Copy link
Copy Markdown
Contributor Author

For reference, here is the output reported when building the wheel locally:

@fedorov

fedorov commented Jun 27, 2024

Copy link
Copy Markdown
Contributor

Very cool, thank you @jcfr! 🥇

@wasserth for the background, the motivation for this is to make it easier to reuse this mapping by the users of the package. Currently, there is a duplicate out-of-sync mapping in SlicerTotalSegmentator extension. Jointly with #324 we are trying to consolidate and remove duplication to simplify maintenance.

@wasserth

wasserth commented Jul 2, 2024

Copy link
Copy Markdown
Owner

Thanks for this PR. This sounds reasonable. I am not very familiar with adding data files to the package.
I read that when doing include_package_data=True, setuptools will include the files specified in MANIFEST.in in the package distribution. But in this case there is no MANIFEST.in file. So how does setuptools know that it has to add the snomed csv file?

@jcfr jcfr force-pushed the package-totalsegmentator_snomed_mapping-csv branch from 40d4409 to 9a79e24 Compare July 2, 2024 20:31
@jcfr

jcfr commented Jul 2, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for the review 🙏

But in this case there is no MANIFEST.in file. So how does setuptools know that it has to add the snomed csv file?

This was on oversight1, the settings in setup.py was updated.

Footnotes

  1. While experimenting, I did not removed a previously created directory (TotalSegmentator.egg-info) which led me to over simplify the approach.

@wasserth

wasserth commented Jul 3, 2024

Copy link
Copy Markdown
Owner

This looks better. Thank you!

@wasserth wasserth merged commit db66607 into wasserth:master Jul 3, 2024
Ruijie-Ysp pushed a commit to Ruijie-Ysp/TotalSegmentator that referenced this pull request Mar 19, 2026
…omed_mapping-csv

Package snomed mapping as a totalsegmentator package resource
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.

3 participants