Skip to content

Add 'Comparative' view in 'Map' pane of the 'Explore' tab #601

Description

@martijn-bollen

Summary

[New feature request]: 'Comparative' view in the 'Map' pane of the 'Explore' tab.This should visualize the spatial density relationship between multiple selected taxa, supporting both Overlap (intersection of ≥ 2 groups) and Difference (subtraction of exactly 2 groups).

1. Problem Statement & Current Status:

The software does not currently visualize spatial density overlaps between species. All Kernel Density Estimations (KDEs) are generated independently.

Objective: Introduce a dynamic, viewport-dependent Comparative tab alongside the existing Composition, Abundance, Density, and Hex grid controls. The resulting analytical surface must dynamically render and recalculate in real-time based on the user's active Leaflet map viewport (zoom level and bounding box).

2. High-Level Architecture & Workflow

UI Layout
When the Comparative tab is active, a sub-selection toggle appears to let users switch analysis modes:

[ Composition ]  [ Abundance ]  [ Density ]  [ Hex grid ]  [[ Comparative ]]
                                                                  |
                                              (o) Overlap   ( ) Difference

State Validation Rules
- Activation Requirement: The Comparative tab stays greyed out with a hover tooltip ("Select multiple taxonomies to compare distributions") unless two or more filter tags are active in the top navigation bar.
- Difference Mode Constraint: The Difference toggle is disabled if (>2) filters are active. It requires exactly two active selections.

3. High-Level Architecture & Workflow

To implement this efficiently within the Leaflet environment, the rendering pipeline must execute the following steps:

1. Viewport Filtering: Upon user zoom or pan, capture the active Leaflet bounding box coordinates. Filter raw point datasets to include only coordinates falling within the visible map window.
2. Dynamic 2D KDE Generation: Generate a continuous 2D Kernel Density Estimation surface for each active species dataset inside the viewport. The grid resolution and bandwidth parameter should dynamically scale to match the current Leaflet zoom level.
3. Density Normalization: Scale each resulting density grid independently so that the sum of all cell values within the visible viewport equals exactly 1.0. This ensures unbiased comparisons regardless of varying point counts between groups.
4. Surface Mathematics Matrix: Apply pixel-by-pixel mathematical operations across the overlapping grids based on the selected UI mode:

  • Mode A: Overlap (N-Species Intersection)
    Evaluate every pixel coordinate (x,y) across all selected species layers simultaneously, extracting only the lowest density value:
    $$\text{Intersection}(x, y) = \min\big(\text{Density}_1(x,y), \text{Density}_2(x,y), \dots, \text{Density}_N(x,y)\big)$$

  • Mode B: Difference (Pairwise Subtraction)
    Subtract the normalized density matrix of the second selected species from the first selected species:
    $$\text{Difference}(x, y) = \text{Density}_1(x,y) - \text{Density}_2(x,y)$$

5. Dynamic Raster Rendering: Project the resulting computational matrix into a continuous map layer and bind it to Leaflet for real-time panning/zooming updates.

3. Expected User Interface & Metrics:

Visual Output & Legends

- Overlap layer: A single sequential heatmap gradient scale. Areas where any single species drops to zero density render as transparent, highlighting localized core intersection bottlenecks.
- Difference layer: A diverging color scale (e.g., Species A Color → White/Transparent → Species B Color). White or transparency signifies equal presence or absolute absence, while deep colors highlight dominant strongholds for either species.

Live Metrics Display
The UI should show a live, viewport-dependent score updating on pan or zoom:

- Overlap Mode: Displays a live continuous overlap score (from 0 to 1) reflecting shared density within the active frame.
- Difference Mode: Displays a relative imbalance ratio index within the frame boundaries.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions