Skip to content

[bug]: Graincrop __str__ method fails when skeleton is None #1396

Description

@SylviaWhittle

Checklist

  • Run using the main branch to check if the issue persists. Instructions on how to do this can be found here.
  • Find the offending file in the output. If processing halts, re-run analysis with topostats --core 1 process.
  • Describe the bug.
  • Include the configuration file.
  • Copy of the log-file from running with topostats --log-level debug <command>.
  • The exact command that failed. This is what you typed at the command line, including any options.
  • TopoStats version, this is reported by topostats --version
  • Operating System and Python Version

Describe the bug

I encountered a badly processed grain in minicircle.spm from a bad config, where a skeleton is not produced.

This resulted in a crash when trying to print(grain_crop).

Copy of the log-file from running with topostats --log-level debug <command>

<class 'NoneType'>
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[24], [line 31](vscode-notebook-cell:?execution_count=24&line=31)
     29 skeleton = grain_crop.skeleton
     30 print(type(skeleton))
---> [31](vscode-notebook-cell:?execution_count=24&line=31) print(f"Grain {grain_index}: {grain_crop}")

File ~/src/TopoStats/topostats/classes.py:186, in GrainCrop.__str__(self)
    174 def __str__(self) -> str:
    175     """
    176     Representation function for useful statistics for the class.
    177 
   (...)
    181         Set of formatted statistics on matched branches.
    182     """
    183     return (
    184         f"filename : {self.filename}\n"
    185         f"image shape : {self.image.shape}\n"
--> [186](https://file+.vscode-resource.vscode-cdn.net/Users/sylvi/src/TopoStats/dev-scripts/__marimo__/session/~/src/TopoStats/topostats/classes.py:186)         f"skeleton shape : {self.skeleton.shape}\n"
    187         f"mask shape : {self.mask.shape}\n"
    188         f"padding : {self.padding}\n"
    189         f"thresholds : {self.thresholds}\n"
    190         f"threshold method : {self.threshold_method}\n"
    191         f"threshold index : {self.threshold_idx}\n"
    192         f"bounding box coords : {self.bbox}\n"
    193         f"pixel to nm scaling : {self.pixel_to_nm_scaling}\n"
    194         f"number of nodes : {len(self.nodes)}"
    195     )

AttributeError: 'NoneType' object has no attribute 'shape'

Include the configuration file

N/A

To Reproduce

No response

TopoStats Version

Git main branch

Python Version

3.11

Operating System

MacOS M1/M2 (post-2021)

Python Packages

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions