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

itkWarningMacro output streams to Jupyter server console (not the notebook) #4690

Open
auneri opened this issue May 21, 2024 · 4 comments
Open
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Comments

@auneri
Copy link

auneri commented May 21, 2024

Description

When using itk inside a jupyter notebook, warnings triggered by itkWarningMacro (and possibly others) are streamed to the server console instead of the notebook.

Steps to Reproduce

directory = pathlib.Path('/path/to/dicom/')
filepaths = sorted(directory.glob('*.dcm'))
del filepaths[2]   # remove an image slice from the list to trigger non-uniform sampling warning
reader = itk.ImageSeriesReader.IF3.New()
reader.SetFileNames(filepaths)
reader.Update()

Expected behavior

The following warning should appear in the notebook:

WARNING: In C:\P\IPP\ITK-source\ITK\Modules\IO\ImageBase\include\itkImageSeriesReader.hxx, line 478
ImageSeriesReader (XXX): Non uniform sampling or missing slices detected,  maximum nonuniformity:XXX

Actual behavior

The warning only appears in the jupyter server console.

Reproducibility

Happens every time.

Versions

Tested on v5.3 and v5.4.

Environment

Tested on Windows 10 and 11.

Additional Information

@auneri auneri added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label May 21, 2024
@blowekamp
Copy link
Member

You may find this SimpleITK Example relevant. A similar approach should be possible with ITK Python:
https://simpleitk.readthedocs.io/en/master/link_Logging_docs.html

@auneri
Copy link
Author

auneri commented May 21, 2024

Thanks, that is indeed very relevant. If I understand it correctly, this solution would require a LoggerBase class implemented on the ITK (C++) side.

I also noticed ITK has TextOutput, LoggerOutput, and FileOutputWindow, all derived from OutputWindow. Only OutputWindow is exposed in Python. I wonder if TextOutput would do the job in this case. Something like:

text = itk.TextOutput.New()  # after TextOutput gets wrapped
itk.OutputWindow.SetInstance(text)

I even tried defining my own TextOutput class in Python, but was not able to overload methods like DisplayText.

@thewtex
Copy link
Member

thewtex commented May 21, 2024

@N-Dekker are your experiences with logging in elastix relevant here?

@N-Dekker
Copy link
Contributor

Sorry, I don't really know. Looks like itkWarningMacro outputs to standard error (std::cerr) by default, as that's what OutputWindow::DisplayText does. Is it not possible to show standard error output directly in a notebook? And why isn't itk::TextOutput available in Python? Again, I don't know 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

No branches or pull requests

4 participants