question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Repr should not load the image

See original GitHub issue

🚀 Feature

Changing the way __repr__ gives an representation of the image.

Motivation

Debuggers call __repr__ to give a preview of the python object.

Pitch When having torchio Images that have not been loaded and the debugger calls __repr__ to give a preview of the python object, due to the attributes embedded in the returned string, __repr__ will always load the image.

That can, however, alter the program flow in ways that make it difficult to debug as the usual python program would not load the image at that point and it wouldn’t be necessary to do so, if it weren’t for the debugger.

The proposed change therefore is to have a __repr__ like this:


def __repr__(self) -> str:
    if self._loaded:
        ... # current repr logic since we can safely access all attributes of the image if it was loaded.
    else:
        return f"{self.__class__.__name__}(path: {self.path})"

I think in such cases it is better to have the image path instead of just loading the image just for this preview

Alternatives We could keep it as is and just state this somewhere in the docs. I am afraid, however, that this won’t be helpful for most people since it’s quite involved with debugger internals (I had to dig a bit through debugger sources on my own).

Additional context

cc @fepegar

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fepegarcommented, Aug 12, 2022

Yes but you cannot do that for DICOM data. So it is kind of inconsistent 😃

Or rather “this functionality is not supported for DICOM files”. I think it should work for things like NRRD too. Why in the world would someone use DICOM in a research setting anyway? 😄

1reaction
justusschockcommented, Aug 12, 2022

You can read metadata from the NIfTI header very quickly without loading the image data.

Yes but you cannot do that for DICOM data. So it is kind of inconsistent 😃

I can’t reproduce your behavior, it’s very strange:

That is indeed very strange. I really have no idea on why it behaves like this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

r - Rmarkdown - cannot render image in html report when ...
It works fine locally, which means I think the issue is to do with the relative file path. Short example made for ease:...
Read more >
Resolve the "Images Not Showing on Website" Error [2022]
At first, you can just launch Repairit and go to its 'Photo Repair' section from the sidebar. Click on the Add icon to...
Read more >
ExtentReport - 3 | Solve the images are not loading ... - YouTube
1.How to solve the images are not loading in extent report ?2.How to solve the addScreenCapture does not working?3.
Read more >
Add an external image to a paginated report (Report Builder)
External images can be on a report server in native mode or any other Web site, including a report server in SharePoint integrated...
Read more >
Image not showing in Power BI Report
We are loading the images through the image button in PowerBI Desktop and have tried png, jpeg and giff. None is working. Does...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found