open-AIMS / ADRIA.jl

ADRIA: Adaptive Dynamic Reef Intervention Algorithms. A multi-criteria decision support platform for informing reef restoration and adaptation interventions.
MIT License
18 stars 6 forks source link

Makie spatial plotting maps color vector to each polygon in a multipolygon, leaving white polygons for unmapped shapes #792

Closed Rosejoycrocker closed 3 months ago

Rosejoycrocker commented 3 months ago

The geometry data in a Domain's site data contains a mix of Polygon and Multipolygon types to describe the shape of reef sites/clusters. When plotting maps where a vector (of the same length as the number of sites in the sites data) is used to map to the color a polygon should be filled with, the current viz.map shows many blank polygons, for example:

cycs_2045 = ADRIA.viz.map(
  rs,
  cyclone_scens[timesteps=At(20)];
  opts=Dict(:color_map => Reverse(:lighttest)),
  axis_opts=Dict(:title => "Mean cyclone mortality 2045")
)

Screenshot 2024-07-08 101152

Note any(isnan.(cyclone_scens[timesteps=At(20)])) = false. Plotting instead with Plots.jl gives an error due to a mismatch in the number of polygons and the color mapping vector:

plot(dom.site_data[:,:geom],fill_z=Array(cyclone_scens[timesteps=At(20)]))
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: BoundsError: attempt to access 334-element Vector{Float64} at index [447]

Which is resolved if a sufficiently large colour mapping vector is provided:

plot(dom.site_data[:,:geom],fill_z=rand(1:20,(600,1)))

ex_plots_spatial

This suggests Makie compensates for the mismatched polygons by plotting with no colour fill.

Versions: ADRIA = v0.11.0 GeoMakie = v0.5.10 GraphMakie = v0.6.5 GeoDataFrames = v0.3.9

ConnectedSystems commented 3 months ago

I have a fix for this open (see linked PR above) but just noting that the GeoMakie version you have is pretty old now. The latest version (v0.7.x) introduced some breaking changes so I'm currently using v0.6.5

Rosejoycrocker commented 3 months ago

I have a fix for this open (see linked PR above) but just noting that the GeoMakie version you have is pretty old now. The latest version (v0.7.x) introduced some breaking changes so I'm currently using v0.6.5

Thanks, I'll update