Skip to content

Add an interactivities plot and add evaluation metrics#67

Merged
rishi-sj-singh merged 6 commits intomainfrom
yayao
Apr 17, 2026
Merged

Add an interactivities plot and add evaluation metrics#67
rishi-sj-singh merged 6 commits intomainfrom
yayao

Conversation

@YaoTingYao
Copy link
Copy Markdown
Member

@YaoTingYao YaoTingYao commented Apr 17, 2026

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)

  1. Added IoU on the plot graphic file
  2. Added IoU, MAE, Agreement and Difference to txt file
  3. html file with interactive hover mode with ID, Actual, Predicted, Agreement and Difference for each point.

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 .txt file 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.

Comment thread model_evaluation.py Outdated
Comment thread model_evaluation.py
Comment thread UDef-ARP_conda_env.yml Outdated
Comment thread model_evaluation.py Outdated
@YaoTingYao YaoTingYao requested a review from tawoodard April 17, 2026 17:22
YaoTingYao and others added 2 commits April 17, 2026 13:35
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>
@YaoTingYao YaoTingYao removed the request for review from tawoodard April 17, 2026 17:39
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 rishi-sj-singh merged commit e68edd0 into main Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants