Add an interactivities plot and add evaluation metrics#67
Merged
rishi-sj-singh merged 6 commits intomainfrom Apr 17, 2026
Merged
Add an interactivities plot and add evaluation metrics#67rishi-sj-singh merged 6 commits intomainfrom
rishi-sj-singh merged 6 commits intomainfrom
Conversation
Add plotly>=5.18 and kaleido to UDef-ARP_conda_env.yml dependencies to enable Plotly visualizations and static image export (via kaleido). This updates the environment to support interactive plotting and image generation.
Compute additional evaluation metrics (MAE, MAE_percent, IoU, agreement, difference) and save them to a .txt alongside the existing PNG output. Generate an interactive Plotly HTML scatter plot (with OLS, Theil–Sen and 1:1 lines, hover info including cell ID, agreement and difference) and write it to disk. Fix a bug using the correct fmask array name (arr_fmask) and adjust gpd.overlay to keep_geom_type=False. Also add required plotly imports and include point IDs for hover/populated customdata.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the Model Assessment outputs by adding an interactive Plotly scatter plot (HTML) with hover tooltips and by computing/writing additional evaluation metrics alongside the existing static plot output.
Changes:
- Add Plotly-based interactive scatter plot export to HTML with per-point hover details.
- Compute and persist additional metrics (MAE, IoU, Agreement, Difference) to a
.txtfile and display IoU on the static plot. - Update GeoPandas overlay behavior and fix a masking bug in deforestation map creation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| model_evaluation.py | Adds Plotly HTML output and new metrics calculations; updates overlay behavior; fixes fmask array usage in a boolean mask. |
| UDef-ARP_conda_env.yml | Adds Plotly (and kaleido) to the conda environment dependencies. |
Comments suppressed due to low confidence (1)
model_evaluation.py:338
- Setting keep_geom_type=False on the overlay can introduce non-area geometries (e.g., LineString/Point results when polygons only touch at boundaries). This function immediately computes area/max_area and divides by max_area, which can yield max_area==0 or skew percentcell, and later code may carry non-polygon geometries forward. Consider filtering thiessen_gdf to Polygon/MultiPolygon geometries (or extracting polygons from GeometryCollections) before computing area/percentcell, or keep keep_geom_type=True and handle GeometryCollection cases explicitly.
thiessen_gdf = gpd.overlay(full_voronoi_grid, area_mask, how="intersection", keep_geom_type=False)
# get area of each polygon
thiessen_gdf["area"] = thiessen_gdf.area
max_area = thiessen_gdf["area"].max()
# using the area, calculate size of cell compared to max
thiessen_gdf["percentcell"] = thiessen_gdf["area"] / max_area
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add a safe branch, e.g., define IoU as 0% when union is 0 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
pins exact package versions Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Replace the temporary diff_arr creation and sum of abs(X - Y) with a direct sum of the already computed distance_arr. This eliminates redundant computation, uses the precomputed per-point distances consistently, and reduces unnecessary memory allocation.
rishi-sj-singh
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After running Model Assessment, three files are automatically saved locally: a PNG graphic, an HTML file, and a metrics.txt file. The HTML file contains an interactive Plotly-powered scatter plot with hover tooltips displaying the ID, Actual value, Predicted value, Agreement, and Difference for each data point. The plot also supports zooming, making it easy to explore high-density regions near the origin.
New statistics:
Calculate MAE
MAE=np.sum(distance_arr)/len(X)
MAE_percent = (MAE / int(grid_area)) * 100
agreement=intersection: Minimum of actual and predicted deforestation for each dot and add them all
agree_arr = [min(X[i],Y[i]) for i in range(len(X))]
agree = np.sum(agree_arr)
union
union_arr = [max(X[i],Y[i]) for i in range(len(X))]
union = np.sum(union_arr)
IoU
iou = agree/union * 100
Calculate the Difference
Absolute value of predicted deforestation minus actual deforestation of each point and add them all
diff_arr=[abs(X[i] - Y[i]) for i in range(len(X))]
difference=np.sum(diff_arr)
IoUon the plot graphic fileIoU,MAE,AgreementandDifferenceto txt fileID,Actual,Predicted,AgreementandDifferencefor each point.