Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boxes_to_shapefile should take in absolute path to rgb. #516

Open
bw4sz opened this issue Oct 15, 2023 · 2 comments
Open

boxes_to_shapefile should take in absolute path to rgb. #516

bw4sz opened this issue Oct 15, 2023 · 2 comments
Assignees
Labels
API This tag is used for small improvements to the readability and usability of the python API. Feature Request New feature or request good first issue Good for newcomers

Comments

@bw4sz
Copy link
Collaborator

bw4sz commented Oct 15, 2023

Issue (#368) highlights that the boxes_to_shapefile is looking for an image_path column. This isn't flexible enough.

Instead we want a 'rgb' argument that is the full path. Use this test:

from deepforest import main
from deepforest import get_data
from deepforest import utilities
import os
import rasterio as rio
import numpy as  np

raster_path = get_data("OSBS_029.tif")
r = rio.open(raster_path)
df = r.read()

rolled_df = np.rollaxis(df, 0,3)

m = main.deepforest()
m.use_release()

boxes = m.predict_tile(image=rolled_df, patch_size=1500)

shp = utilities.boxes_to_shapefile(boxes, rgb=raster_path, projected=True)
shp.to_file("~/Downloads/boxes.shp")

def boxes_to_shapefile(df, root_dir, projected=True, flip_y_axis=False):

@bw4sz bw4sz added Feature Request New feature or request good first issue Good for newcomers API This tag is used for small improvements to the readability and usability of the python API. labels Oct 15, 2023
@weecology weecology deleted a comment from juangueher Nov 29, 2023
@Om-Doiphode
Copy link
Contributor

Hi @bw4sz, please review my pull request. Thanks!

@ethanwhite
Copy link
Member

A couple of possible ways to avoid or mitigate this being a breaking change older uses of the package:

  1. One option when deprecating positional args is to replace the function with one with a new name and then deprecate the old function. This might actually be the best solution here since then we wouldn't be rushed into 2.0. Possible names include reproject_boxes, boxes_to_projection, boxes_to_original_projection.
  2. This also relates to Understanding the issue #608 #638 and Outputs should attach geometry if available #608. So one option is to move the officially supported behavior to inside the relevant functions with an option argument to maintain projection when present. We then deprecate the function instructing the user to use the optional argument to the relevant function (and since this is now internal we avoid future issues with user facing changes).
  3. If (1) and (2) don't work for some reason then we could at least check the new rgb argument to see if it includes a filename. If it doesn't then perform the previous behavior and throw a deprecation warning. This would at least prevent breaking code where root_dir was used positionally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API This tag is used for small improvements to the readability and usability of the python API. Feature Request New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants