Skip to content

added project argument to predict_tile for geo-coordinates#1250

Open
musaqlain wants to merge 2 commits intoweecology:mainfrom
musaqlain:feature-predict-tile-projection
Open

added project argument to predict_tile for geo-coordinates#1250
musaqlain wants to merge 2 commits intoweecology:mainfrom
musaqlain:feature-predict-tile-projection

Conversation

@musaqlain
Copy link
Copy Markdown
Contributor

@musaqlain musaqlain commented Dec 27, 2025

addresses Issue #608. Previously, predict_tile returned pixel coordinates even if the input was a georeferenced raster. This PR adds an optional project=False argument to allow users to request map coordinates directly.

  • updated predict_tile in src/deepforest/main.py to accept project (bool).
  • if project=True, the results are converted to a GeoDataFrame using utilities.image_to_geo_coordinates.
  • added test_predict_tile_projected to tests/test_main.py to verify that setting project=True returns a GeoDataFrame with valid CRS and map coordinates (UTM).

Closes #608

AI-Assisted Development

I utilized AI for sanity checking code logic and conducting an assisted review to identify potential missing resets and schema constraints.

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

Copy link
Copy Markdown
Member

@ethanwhite ethanwhite left a comment

Choose a reason for hiding this comment

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

Sorry this got lost in the queue @musaqlain. Everything looks really good. I've requested a couple of small changes to the docstring.

My one bigger question is what happens if someone sets project=True and passes a path to a non-georeferenced file. It would be good to make sure that we fail informatively in this case, which might happen automatically or might require a new check either in the new if project: block or in image_to_geo_coordinates

Comment thread src/deepforest/main.py
- "batch" loads the entire image into GPU memory and creates views of an image as batch, requires in the entire tile to fit into GPU memory. CPU parallelization is possible for loading images.
- "window" loads only the desired window of the image from the raster dataset. Most memory efficient option, but cannot parallelize across windows.
crop_model: a deepforest.model.CropModel object to predict on crops
project (bool): If True, return a geopandas.GeoDataFrame with geometry column projected to the image CRS. Defaults to False.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's not standard to declare the defaults in docstring so let's remove "Defaults to False." here.

Comment thread src/deepforest/main.py

Returns:
pd.DataFrame or tuple: Predictions dataframe or (predictions, crops) tuple
pd.DataFrame or tuple: Predictions dataframe or (predictions, crops) tuple. If project=True, returns a geopandas.GeoDataFrame.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Change to "Predictions dataframe, geopandas.GeoDataFrame, or (predictions, crops) tuple." since I don't think it's standard to describe logic here, and we already have two possible types and we're not describing the difference between them

@ethanwhite ethanwhite added the Awaiting author contribution Waiting on the issue author to do something before proceeding label Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Awaiting author contribution Waiting on the issue author to do something before proceeding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Outputs should attach geometry if available

2 participants