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

Feat/qupath #209

Merged
merged 14 commits into from
Jan 5, 2024
Merged

Feat/qupath #209

merged 14 commits into from
Jan 5, 2024

Conversation

swaradgat19
Copy link
Contributor

No description provided.

@swaradgat19
Copy link
Contributor Author

@kaczmarj I believe the pytorch test is failing because I'm importing from paquo.projects import QuPathProject inside the make_qupath_project function and it does not identify QuPathProject in the add_image_and_geojson function.

Copy link
Member

@kaczmarj kaczmarj left a comment

Choose a reason for hiding this comment

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

looks great @swaradgat19 ! i left a few requests for changes but overall, really great. thanks

pyproject.toml Outdated Show resolved Hide resolved
wsinfer/cli/infer.py Outdated Show resolved Hide resolved
wsinfer/qupath.py Outdated Show resolved Hide resolved
wsinfer/qupath.py Outdated Show resolved Hide resolved
wsinfer/qupath.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@kaczmarj kaczmarj marked this pull request as ready for review January 3, 2024 13:56
@kaczmarj
Copy link
Member

kaczmarj commented Jan 3, 2024

flake8 is complaining:

 wsinfer/qupath.py:9:18: F821 undefined name 'QuPathProject'

@swaradgat19
Copy link
Contributor Author

flake8 is complaining:

 wsinfer/qupath.py:9:18: F821 undefined name 'QuPathProject'

@kaczmarj Instead of type QuPathProject in the add_image_and_geojson function, we can use object type like this:

def add_image_and_geojson(
    qupath_proj: object,
    *,
    image_path: Path | str,
    geojson_path: Path | str,
) -> None:
# rest of the code

It is not recognizing QuPathProject inside add_image_and_geojson since we're importing QuPathProject (basically paquo) in another function (make_qupath_project)

Do you think this would be a good idea?

@kaczmarj
Copy link
Member

kaczmarj commented Jan 3, 2024

@kaczmarj Instead of type QuPathProject in the add_image_and_geojson function, we can use object type like this:

def add_image_and_geojson(
    qupath_proj: object,
    *,
    image_path: Path | str,
    geojson_path: Path | str,
) -> None:
# rest of the code

It is not recognizing QuPathProject inside add_image_and_geojson since we're importing QuPathProject (basically paquo) in another function (make_qupath_project)

Do you think this would be a good idea?

i suggest we remove the type, so it's def add_image_and_geojson(qupath_proj, ...)

@swaradgat19
Copy link
Contributor Author

@kaczmarj I believe not specifying a type is causing an issue:

wsinfer/qupath.py:8: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]

This was in the styles ci test

@kaczmarj
Copy link
Member

kaczmarj commented Jan 3, 2024

kaczmarj I believe not specifying a type is causing an issue:

wsinfer/qupath.py:8: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]

This was in the styles ci test

i see... so instead of importing paquo inside of the function, let's import it globally inside of a try/except block. something like this...

try:
    from paquo.projects import QuPathProject
    HAS_PAQUO = True
except Exception:
    HAS_PAQUO = False   

and in the command-line interface, if the user passes --qupath, let's check that HAS_PAQUO is True. if it's not, we should error before any processing is done.

@swaradgat19
Copy link
Contributor Author

swaradgat19 commented Jan 3, 2024

@kaczmarj

Sure. So I'm setting the HAS_PAQUO variable globally like you suggested. Inside the make_qupath_project function, I'm doing the following:

def make_qupath_project(wsi_dir: Path, results_dir: Path) -> None:
    if not HAS_PAQUO:
        print(
            """Cannot find QuPath.
QuPath is required to use this functionality but it cannot be found.
If QuPath is installed, please use define the environment variable
PAQUO_QUPATH_DIR with the location of the QuPath installation.
If QuPath is not installed, please install it from https://qupath.github.io/."""
        )
        sys.exit(1)
    else:
        print("Found QuPath successfully!")
        QUPATH_PROJECT_DIRECTORY = results_dir / "model-outputs-qupath"
        # add image and geojson using paquo

@kaczmarj
Copy link
Member

kaczmarj commented Jan 3, 2024

that looks good. feel free to push a commit with the changes

@swaradgat19
Copy link
Contributor Author

I think its failing because even though the paquo import is global, I'm specifically calling the make_qupath_project function in the infer.py file, which is why it is not recognizing the global paquo import. I'm thinking of handling the import in the infer.py file itself.

For example:

    if qupath:
        #handle paquo import using try-except and if successful, call make_qupath_project function
       make_qupath_project(wsi_dir, results_dir)

@kaczmarj
Copy link
Member

kaczmarj commented Jan 4, 2024

here are the errors.

we will have to add paquo.projects to mypy's ignored list in pyproject.toml. i guess paquo doesn't ship with types.

the other type errors seem to be new and i think unrelated to this pull request. let me work on fixing those in a separate branch. once i make the fix and i merge it into main, i will ask you to merge main into your branch.

wsinfer/qupath.py:8: error: Cannot find implementation or library stub for module named "paquo.projects"  [import-not-found]
wsinfer/qupath.py:8: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
wsinfer/patchlib/patch.py:56: error: Incompatible types in assignment (expression has type "Mat | ndarray[Any, dtype[generic]]", variable has type "ndarray[Any, dtype[signedinteger[Any]]]")  [assignment]
wsinfer/patchlib/patch.py:68: error: Unsupported operand types for * ("ndarray[Any, dtype[generic]]" and "ndarray[Any, dtype[floating[Any]]]")  [operator]
wsinfer/patchlib/patch.py:118: error: Incompatible return value type (got "tuple[Any, Sequence[ndarray[Any, dtype[generic]]], ndarray[Any, dtype[signedinteger[Any]]]]", expected "tuple[Any, Sequence[ndarray[Any, dtype[signedinteger[Any]]]], ndarray[Any, dtype[signedinteger[Any]]]]")  [return-value]
wsinfer/patchlib/segment.py:50: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[generic]]", variable has type "ndarray[Any, dtype[unsignedinteger[_8Bit]]]")  [assignment]
wsinfer/patchlib/segment.py:63: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[generic]]", variable has type "ndarray[Any, dtype[unsignedinteger[_8Bit]]]")  [assignment]
wsinfer/patchlib/segment.py:66: error: Incompatible types in assignment (expression has type "Mat | ndarray[Any, dtype[generic]]", variable has type "ndarray[Any, dtype[unsignedinteger[_8Bit]]]")  [assignment]

@kaczmarj
Copy link
Member

kaczmarj commented Jan 4, 2024

@swaradgat19 - i merged main into your branch

@kaczmarj
Copy link
Member

kaczmarj commented Jan 4, 2024

now the remaining errors are

wsinfer/qupath.py:8: error: Cannot find implementation or library stub for module named "paquo.projects"  [import-not-found]
wsinfer/qupath.py:8: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

to fix that, look at pyproject.toml. there should be a section where we tell mypy what to ignore. add paquo.* there

@swaradgat19
Copy link
Contributor Author

@kaczmarj

I'm currently ignoring the qupath_proj type. I tried setting the type to object but that did not work. I just used # type: ignore. Still waiting for it to pass.

Sorry for the unnecessary commits!

@kaczmarj
Copy link
Member

kaczmarj commented Jan 5, 2024

make

    try:
        from paquo.projects import QuPathProject

        HAS_PAQUO = True
    except Exception:
        HAS_PAQUO = False

top-level in qupath.py. (in other words, take it out of the function)

then, use QuPathProject as the type for qupath_proj.

also remove the type: ignore comment on the same line as qupath_proj

@swaradgat19
Copy link
Contributor Author

@kaczmarj

My bad. I changed it because a global import wasn't working and I was running into issues. The issue was somewhere else. Changing it.

@swaradgat19
Copy link
Contributor Author

Looks good! Should I work on the tests for this feature as well?

@kaczmarj kaczmarj merged commit 2abd323 into SBU-BMI:main Jan 5, 2024
11 checks passed
@kaczmarj
Copy link
Member

kaczmarj commented Jan 5, 2024

great! i merged it into main. thanks very much @swaradgat19 !

Looks good! Should I work on the tests for this feature as well?

yes, that would be great

@swaradgat19
Copy link
Contributor Author

So I'm thinking of modifying the test_cli_run_with_registered_models test with additional the qupath argument. Should I instead make a new test?

@kaczmarj
Copy link
Member

kaczmarj commented Jan 5, 2024 via email

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.

2 participants