Skip to content

[bug]: grain_statistics.csv : num_crossings now show NaN values when should be 0 #1337

@SylviaWhittle

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

Apologies for being brief, very tight timing.

TLDR: While before the refactor, when there were 0 crossings in a grain, the num_crossings value would be 0 in grain_statistics.csv. Now it is blank, resulting in np.NaNs when loaded with pandas. This is an issue because it plays havoc with plotting and statistical tests.

It is easily remedied in notebooks but it should be solved in the code in TopoStats.

pre-refactor:

grain_width_mean          num_crossings    avg_crossing_confidence
──────────────────────────────────────────────────────────────────
4.773744764128326e-09     4.0              0.38107924047877306
5.242914783670332e-09     2.0              0.08864451467797059
4.913545750037248e-09     4.0              0.14422470589214334
4.423753160624048e-09     0.0
5.728616417748964e-09     4.0              0.12469370334249806
2.8681403277686427e-09    0.0
2.913348687877496e-09     0.0
3.124840290301134e-09     0.0
3.1064815954335514e-09    1.0              0.3045958659627791
2.8993527432466555e-09    0.0
2.8972075675710188e-09    0.0
3.0841143869273333e-09    0.0
2.8623385249027225e-09    1.0              0.07816997614823118
2.8869585027636084e-09    1.0              0.7869694583149466
2.9632845964112094e-09    1.0              0.09486841707328764
2.891921483662744e-09     3.0              0.31374286629983283

post-refactor:

 min_feret                 num_crossings    mean_crossing_confidence
────────────────────────────────────────────────────────────────────
 6.815122304925579e-08     4.0              0.3428346382435419
 8.066171376085668e-08     1.0              0.19311029975809224
 6.212453139492674e-08     3.0              0.42181056066841655
 8.707252204478241e-08     3.0              0.17008668658113066
 6.405904110263782e-08     4.0              0.2243091945330366
 6.367590659299645e-08     2.0              0.2789784821202682
 7.048508650242575e-08     2.0              0.48695289971645206
 5.56190508539147e-08      2.0              0.45224846833227267
 5.9194523538409384e-08    2.0              0.12459912910854043
 7.193149423088672e-08     2.0              0.23692794699086106
 8.146243258698979e-08
 2.5459800025132202e-08
 6.977606016592443e-08     1.0
 5.1255921755292394e-08    1.0              0.24119906614093212
 4.947190094242895e-08     3.0              0.18114883256860656

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

No deviation in logs, superfluous.

Include the configuration file

Standard default config.

To Reproduce

Run topostats, see that the values for crossings are NaN when should be 0.

TopoStats Version

Git main branch

Python Version

3.11

Operating System

MacOS M1/M2 (post-2021)

Python Packages

absl-py==2.4.0
AFMReader==0.0.1
annotated-types==0.7.0
art==6.5
asttokens==2.4.1
astunparse==1.6.3
biopython==1.86
certifi==2026.2.25
charset-normalizer==3.4.5
cheap_repr==0.5.2
contourpy==1.2.1
coverage==7.6.1
cycler==0.12.1
decorator==5.1.1
et_xmlfile==2.0.0
executing==2.0.1
filetype==1.2.0
flatbuffers==25.12.19
fonttools==4.53.1
gast==0.7.0
google-pasta==0.2.0
grpcio==1.78.0
h5py==3.11.0
idna==3.11
igor2==0.5.8
imageio==2.35.1
iniconfig==2.0.0
ipython==8.26.0
jedi==0.19.1
Jinja2==3.1.4
joblib==1.4.2
keras==3.13.2
kiwisolver==1.4.5
lazy_loader==0.4
libclang==18.1.1
llvmlite==0.46.0
loguru==0.7.2
markdown-it-py==4.0.0
MarkupSafe==2.1.5
matplotlib==3.9.2
matplotlib-inline==0.1.7
mdurl==0.1.2
ml_dtypes==0.5.4
namex==0.1.0
networkx==3.3
numba==0.64.0
numpy==2.0.2
numpyencoder==0.3.0
opencv-python==4.10.0.84
openpyxl==3.1.5
opt_einsum==3.4.0
optree==0.19.0
packaging==24.1
pandas==2.2.2
parso==0.8.4
pexpect==4.9.0
pillow==10.4.0
pluggy==1.5.0
prompt_toolkit==3.0.47
protobuf==7.34.0
psutil==5.9.8
ptyprocess==0.7.0
pure_eval==0.2.3
pydantic==2.12.5
pydantic_core==2.41.5
pyfiglet==1.0.2
Pygments==2.18.0
pyparsing==3.1.2
pyspm==0.6.3
pytest==7.4.4
pytest-cov==5.0.0
pytest-github-actions-annotate-failures==0.2.0
pytest-lazy-fixture==0.6.3
pytest-mpl==0.17.0
pytest-regtest==2.1.1
python-dateutil==2.9.0.post0
pytz==2024.1
PyYAML==6.0.2
requests==2.32.5
rich==14.3.3
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.8
schema==0.7.7
scikit-image==0.24.0
scikit-learn==1.5.1
scipy==1.14.0
seaborn==0.13.2
setuptools==82.0.1
six==1.16.0
skan==0.13.1
snoop==0.4.3
stack-data==0.6.3
tensorflow==2.21.0
termcolor==3.3.0
threadpoolctl==3.5.0
tifffile==2024.8.10
toolz==1.1.0
topoly==1.1.0
-e git+ssh://git@github.com/AFM-SPM/TopoStats.git@80543d675064be9c6e86071a4e197bfc5d3c3040#egg=topostats
tqdm==4.66.5
traitlets==5.14.3
ty==0.0.22
typing-inspection==0.4.2
typing_extensions==4.15.0
tzdata==2024.1
urllib3==2.6.3
wcwidth==0.2.13
wheel==0.46.3
wrapt==2.1.2

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions