-
Notifications
You must be signed in to change notification settings - Fork 174
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
warn and set projected to False if flip_y_axis is set to True, closes #440 #520
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests are not clear to me, I may be missing something, I will give them another review later.
img = get_data("OSBS_029.png") | ||
r = rio.open(img) | ||
df = m.predict_image(path=img) | ||
gdf = utilities.boxes_to_shapefile(df, root_dir=os.path.dirname(img), projected=False, flip_y_axis=flip_y_axis) | ||
if projected and flip_y_axis: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am missing something. Shouldn't this be if not
( either projected or Flip_y_axis)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I think thats right.
if projected and flip_y_axis:
with pytest.warns(UserWarning):
gdf = utilities.boxes_to_shapefile(
df,
root_dir=os.path.dirname(img),
projected=projected,
flip_y_axis=flip_y_axis)
If the user sets projected to be True and flip_y_axis is True, it should raise a warning. Projected says the boxes are in geographic projection, there is no situation in which you would want to reflect over the y axis and get negative coordinates. The flip_y_axis is only useful in unprojected data and for programs like QGIS that have the origin flipped compared to numpy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bw4sz Make these changes and this will be done.
@@ -388,6 +388,14 @@ def boxes_to_shapefile(df, root_dir, projected=True, flip_y_axis=False): | |||
Returns: | |||
df: a geospatial dataframe with the boxes optionally transformed to the target crs | |||
""" | |||
# Check if the user has set flip_y_axis, but not projected. Warn and confirm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this comment to
# raise a warning if user sets projected to be True and flip_y_axis is True
and remove the () on the if statement
if flip_y_axis and projected:
df, | ||
root_dir=os.path.dirname(img), | ||
projected=projected, | ||
flip_y_axis=flip_y_axis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if statement is not needed
# Test unprojected data, including warning if flip_y_axis is set to True, but projected is False
@pytest.mark.parametrize("flip_y_axis", [True, False])
@pytest.mark.parametrize("projected", [True, False])
def test_boxes_to_shapefile_unprojected(m, flip_y_axis, projected):
img = get_data("OSBS_029.png")
r = rio.open(img)
df = m.predict_image(path=img)
with pytest.warns(UserWarning):
gdf = utilities.boxes_to_shapefile(
df,
root_dir=os.path.dirname(img),
projected=projected,
flip_y_axis=flip_y_axis)
# Confirm that each boxes within image bounds
geom = geometry.box(*r.bounds)
assert all(gdf.geometry.apply(lambda x: geom.intersects(geom)).values)
This is a small PR to add a warning and set projected=True in deepforest.utilities.boxes_to_shapefile when setting flip_y_axis=True.