Skip to content

Fix data dimension swapping and axis errors#1335

Open
abhayrajjais01 wants to merge 2 commits intoweecology:mainfrom
abhayrajjais01:fix-data-dimensions
Open

Fix data dimension swapping and axis errors#1335
abhayrajjais01 wants to merge 2 commits intoweecology:mainfrom
abhayrajjais01:fix-data-dimensions

Conversation

@abhayrajjais01
Copy link
Contributor

@abhayrajjais01 abhayrajjais01 commented Mar 6, 2026

Description

This PR addresses two dimensionality and shape bugs when preparing and loading data for predictions.

Changes:

  • src/deepforest/datasets/prediction.py: Fixed a bug where height and width bounds were swapped when passed to slidingwindow.generateForSize. rasterio's src.shape returns (height, width), but the variables were passed to the generator in reversed order.
  • src/deepforest/preprocess.py: Fixed a bug where numpy_image.shape[2] was being accessed for the number of bands after the image tensor was already transposed from (H, W, C) to channels-first (C, H, W). It now correctly checks numpy_image.shape[0].

Type of change

  • Bug fix (non-breaking change which fixes an issue)

AI-Assisted Development

  • I used AI tools (e.g., GitHub Copilot, ChatGPT, etc.) in developing this PR
  • I understand all the code I'm submitting
  • I have reviewed and validated all AI-generated code

AI tools used (if applicable):

Gemini

@vickysharma-prog
Copy link
Contributor

Hi @abhayrajjais01,
I noticed the PR description mentions two specific fixes:

  1. Height/width bounds swap in prediction.py
  2. numpy_image.shape[2] issue in preprocess.py
    Quick question — the description seems very similar across Fix data dimension swapping and axis errors #1335, Fix: syntax errors in utility function validations #1336, and Fix dictionary key type mismatch causing KeyError during metrics eval #1337. Are these related fixes split intentionally, or does each PR address a different issue? Just asking since the descriptions match but titles suggest different fixes.
    Also, reproduction steps or a small test case confirming the fix would help with review.
    Thanks!

@abhayrajjais01
Copy link
Contributor Author

abhayrajjais01 commented Mar 6, 2026

Hi @abhayrajjais01, I noticed the PR description mentions two specific fixes:

  1. Height/width bounds swap in prediction.py
  2. numpy_image.shape[2] issue in preprocess.py
    Quick question — the description seems very similar across Fix data dimension swapping and axis errors #1335, Fix: syntax errors in utility function validations #1336, and Fix dictionary key type mismatch causing KeyError during metrics eval #1337. Are these related fixes split intentionally, or does each PR address a different issue? Just asking since the descriptions match but titles suggest different fixes.
    Also, reproduction steps or a small test case confirming the fix would help with review.
    Thanks!

Hi @vickysharma-prog,
Thanks for reviewing!
Yes, the descriptions accidentally matching across those 3 PRs was just a mistake on my end when splitting the fixes into separate branches.

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.34%. Comparing base (ecf3a1c) to head (b262bd5).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1335   +/-   ##
=======================================
  Coverage   87.34%   87.34%           
=======================================
  Files          24       24           
  Lines        2978     2978           
=======================================
  Hits         2601     2601           
  Misses        377      377           
Flag Coverage Δ
unittests 87.34% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

assert ds[1].shape == (3, 300, 300)


def test_TiledRaster_non_square(tmp_path):
Copy link
Contributor

Choose a reason for hiding this comment

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

I’m having difficulty seeing how this test is necessary given the changes made.

# Check that it's 3 bands
bands = numpy_image.shape[2]
# Check that it's 3 bands (image is now channels-first: C x H x W)
bands = numpy_image.shape[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Please take some time to understand this part of the code, you may be able to make more meaningful improvements to the logic.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants