-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from JoshuaBillson/mnf
Made CairoMakie an Extension
- Loading branch information
Showing
16 changed files
with
107 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module RemoteSensingToolboxMakieExt | ||
|
||
using RemoteSensingToolbox, CairoMakie, Rasters, Statistics | ||
using Pipe: @pipe | ||
import Tables | ||
|
||
function RemoteSensingToolbox.plot_signatures(bandset::Type{<:AbstractBandset}, raster::AbstractRasterStack, shp, label::Symbol; colors=Makie.wong_colors()) | ||
# Create Figure | ||
fig = Figure(resolution=(1000,500)) | ||
|
||
# Create Axis | ||
ax = Axis( | ||
fig[1,1], | ||
xlabel="Wavelength (nm)", | ||
ylabel="Reflectance", | ||
xlabelfont=:bold, | ||
ylabelfont=:bold, | ||
xlabelpadding=10.0, | ||
ylabelpadding=10.0, | ||
) | ||
|
||
# Plot Signatures | ||
RemoteSensingToolbox.plot_signatures!(ax, bandset, raster, shp, label; colors=colors) | ||
|
||
# Add Legend | ||
Legend(fig[1,2], ax, "Classification") | ||
|
||
# Return Figure | ||
return fig | ||
end | ||
|
||
function RemoteSensingToolbox.plot_signatures!(ax, bandset::Type{<:AbstractBandset}, raster::AbstractRasterStack, shp, label::Symbol; colors=Makie.wong_colors()) | ||
# Extract Signatures | ||
extracted = @pipe RemoteSensingToolbox.extract_signatures(raster, shp, label) |> RemoteSensingToolbox.fold_rows(mean, _, :label) | ||
|
||
# Plot Signatures | ||
RemoteSensingToolbox.plot_signatures!(ax, bandset, extracted, :label, colors) | ||
end | ||
|
||
function RemoteSensingToolbox.plot_signatures!(ax, bandset::Type{<:AbstractBandset}, sigs, labelcolumn::Symbol, colors) | ||
# Extract Signatures | ||
cols = Tables.columnnames(sigs) | ||
bs = filter(x -> x in cols, bands(bandset)) | ||
sig_matrix = hcat([Tables.getcolumn(sigs, b) for b in bs]...) | ||
|
||
# Plot Signatures | ||
xs = [wavelength(bandset, b) for b in bs] | ||
labels = Tables.getcolumn(sigs, labelcolumn) | ||
for i in 1:size(sig_matrix,1) | ||
lines!(ax, xs, sig_matrix[i,:], label=labels[i]; color=colors[i]) | ||
end | ||
end | ||
|
||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,3 @@ | ||
function _rasterize(shp, to, fill) | ||
Rasters.rasterize(last, shp, to=to, fill=fill, verbose=false, progress=false) | ||
end | ||
|
||
function _sort_signature(bandset::Type{<:AbstractBandset}, reflectances::Vector{<:Number}, bands::Vector{Symbol}) | ||
sorted = @pipe zip(wavelength.(bandset, bands), reflectances) |> collect |> sort(_, by=first) | ||
return (first.(sorted), last.(sorted)) | ||
end | ||
|
||
function _plot_signatures!(ax, bandset::Type{<:AbstractBandset}, sigs::Matrix{<:AbstractFloat}, bands::Vector{Symbol}, labels; colors=wong_colors(), kwargs...) | ||
# Check Arguments | ||
(size(sigs, 2) != length(bands)) && throw(ArgumentError("Length of signatures ($(size(sigs, 2))) must be equal to number of bands ($(length(bands)))!")) | ||
(size(sigs, 1) != length(labels)) && throw(ArgumentError("Number of signatures ($(size(sigs, 1))) must be equal to number of labels ($(length(labels)))")) | ||
|
||
# Plot Signatures | ||
for i in 1:size(sigs,1) | ||
_plot_signature!(ax, bandset, sigs[i,:], bands, label=labels[i]; color=colors[i], kwargs...) | ||
end | ||
end | ||
|
||
function _plot_signature!(ax, bandset::Type{<:AbstractBandset}, signature::Vector{<:AbstractFloat}, bands::Vector{Symbol}; kwargs...) | ||
# Check Arguments | ||
(length(signature) != length(bands)) && throw(ArgumentError("Length of signatures ($(length(sigs))) must be equal to number of bands ($(length(bands)))!")) | ||
|
||
# Sort Bands In Ascending Order | ||
x, y = _sort_signature(bandset, signature, bands) | ||
|
||
# Plot Signature | ||
lines!(ax, x, y; kwargs...) | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
[deps] | ||
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" | ||
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" | ||
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" | ||
Pipe = "b98c9c47-44ae-5843-9183-064241ee97a0" | ||
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4" | ||
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROJCS["WGS_1984_UTM_Zone_11N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-117.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]] |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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