DeepForest
DeepForest copied to clipboard
boxes_to_shapefile should take in absolute path to rgb.
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")
https://github.com/weecology/DeepForest/blob/b612d85bbc9d3f31749653a6f27623a93e6a049a/deepforest/utilities.py#L365
Hi @bw4sz, please review my pull request. Thanks!
A couple of possible ways to avoid or mitigate this being a breaking change older uses of the package:
- 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. - This also relates to #638 and #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).
- If (1) and (2) don't work for some reason then we could at least check the new
rgbargument 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 whereroot_dirwas used positionally.