Skip to content

Fix path_length silently ignored in CalculateImageStats - #393

Merged
animmosmith merged 4 commits into
mainfrom
363-path-length-not-propagated
Jul 29, 2026
Merged

Fix path_length silently ignored in CalculateImageStats#393
animmosmith merged 4 commits into
mainfrom
363-path-length-not-propagated

Conversation

@animmosmith

Copy link
Copy Markdown
Collaborator

Summary

  • CalculateImageStats.__call__ read the configured path_length via getattr(data['settings']['general'], 'path_length', 40). Since data['settings']['general'] is a plain dict, getattr never finds the key (dicts don't expose their contents as attributes), so this always silently returned the default 40 regardless of what was configured in config.toml. This affects the volume concentration (vc) and sample_volume outputs.
  • Every existing test happened to use path_length=40.0, so the bug produced no test failures.
  • Fixed by using plain dict access (general.get('path_length', 40)), consistent with how PerClassConcentration already reads it.
  • Added a regression test using a non-default path_length (123.0) that fails against the old code and passes against the fix.

This closes out #363, which asked for imx/imy (CCD pixel dimensions) to be propagated into nc_vc_from_stats — that part was already fixed by #369 for the related/duplicate issue #366, which derives imx/imy from the actual raw image shape rather than threading them through config. This PR fixes the path_length regression that #369 introduced along the way.

Test plan

  • New regression test fails on the pre-fix code, passes after the fix
  • pytest pyopia/tests/test_pipeline.py passes (4 passed)
  • flake8 shows no new issues

data['settings']['general'] is a plain dict, so
getattr(general, 'path_length', 40) always returned the default,
silently ignoring any path_length configured in config.toml when
calculating volume concentration (vc) and sample_volume. Every
existing test happened to use path_length=40, masking the bug.

Use general.get('path_length', 40) instead, and add a regression
test with a non-default path_length to catch this in future.

Fixes #363
@animmosmith
animmosmith requested a review from nepstad June 18, 2026 15:10
@animmosmith animmosmith added the bug Something isn't working label Jul 28, 2026
@animmosmith animmosmith self-assigned this Jul 28, 2026
@animmosmith
animmosmith requested a review from emlynjdavies July 28, 2026 15:39
animmosmith added a commit that referenced this pull request Jul 28, 2026
animmosmith added a commit that referenced this pull request Jul 28, 2026
* add 'pyopia --version' command

* bump version (merge PR #393 first)

* adjust version

---------

Co-authored-by: Alex Nimmo Smith <animmosmith@users.noreply.github.com>

@emlynjdavies emlynjdavies left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good - need to bump version in init file.

@animmosmith
animmosmith merged commit bdd5301 into main Jul 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority-high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix to propagate H and V pixelcount of the CCD to the nv_to_vc_stats routine for correct volume cconcetration calculations.

2 participants