Skip to content

Commit

Permalink
More fixes due to Band schema numbering change
Browse files Browse the repository at this point in the history
  • Loading branch information
joa-quim committed Dec 19, 2023
1 parent 1694099 commit 231bc4a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/spectral_indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const generic_docs = "
- The second form is more versatile but also more complex to describe.
- `cube`: Is the file name of a 'cube', a multi-layered file normally created with the [`cutcube`](@ref) function.
If this file was created with band descriptions one can use the `bands` or the `bandnames` options.
- `bands`: _cubes_ created with [`cutcube`](@ref) assign descriptions starting with \"Band 1 ...\" an so on
the other bands. So when `bands` is used we search for bands named \"Band band[k]\", where band[k] loops
- `bands`: _cubes_ created with [`cutcube`](@ref) assign descriptions starting with \"Band1 ...\" an so on
the other bands. So when `bands` is used we search for bands named \"Band'band[k]'\", where band[k] loops
over all elements of the `bands` vector. WARNING: the elements order in the vector must be sorted in increasing
wavelength numbers, _i.e._ like the example for the first form.
- `layers`: Use this option when you are certain of the bands order in the cube or the it doesn't have a bands
Expand Down Expand Up @@ -130,7 +130,7 @@ $(generic_docs)
mndwi(green, swir2; kw...) = sp_indices(swir2, green; index="MNDWI", kw...)
mndwi(cube::GMT.GMTimage{UInt16, 3}, bnds; kw...) = sp_indices(cube, find_layers(cube, bnds, 2); index="MNDWI", kw...)
mndwi(cube::String; bands::Vector{Int}=Int[], layers::Vector{Int}=Int[], bandnames::Vector{String}=String[], kw...) =
helper_si_method(cube, "MNDWI"; bands=bands, layers=layers, bandnames=bandnames, defbandnames=["green", "swir 2"], kw...)
helper_si_method(cube, "MNDWI"; bands=bands, layers=layers, bandnames=bandnames, defbandnames=["green", "swir2"], kw...)

# ----------------------------------------------------------------------------------------------------------
"""
Expand Down Expand Up @@ -238,7 +238,7 @@ $(generic_docs)
ndwi2(nir, swir2; kw...) = sp_indices(swir2, nir; index="NDWI2", kw...)
ndwi2(cube::GMT.GMTimage{UInt16, 3}, bnds; kw...) = sp_indices(cube, find_layers(cube, bnds, 2); index="NDWI2", kw...)
ndwi2(cube::String; bands::Vector{Int}=Int[], layers::Vector{Int}=Int[], bandnames::Vector{String}=String[], kw...) =
helper_si_method(cube, "NDWI2"; bands=bands, layers=layers, bandnames=bandnames, defbandnames=["nir", "swir 2"], kw...)
helper_si_method(cube, "NDWI2"; bands=bands, layers=layers, bandnames=bandnames, defbandnames=["nir", "swir2"], kw...)

# ----------------------------------------------------------------------------------------------------------
"""
Expand Down Expand Up @@ -273,7 +273,7 @@ SATVI = ((swir1 - red) / (swir1 + red + L)) * (1.0 + L) - (swir2 / 2.0)
satvi(red, swir2, swir3; kw...) = sp_indices(red, swir2, swir3; index="SATVI", kw...)
satvi(cube::GMT.GMTimage{UInt16, 3}, bnds; kw...) = sp_indices(cube, find_layers(cube, bnds, 3); index="SATVI", kw...)
satvi(cube::String; bands::Vector{Int}=Int[], layers::Vector{Int}=Int[], bandnames::Vector{String}=String[], kw...) =
helper_si_method(cube, "SATVI"; bands=bands, layers=layers, bandnames=bandnames, defbandnames=["red", "swir 1", "swir 2"], kw...)
helper_si_method(cube, "SATVI"; bands=bands, layers=layers, bandnames=bandnames, defbandnames=["red", "swir1", "swir2"], kw...)

# ----------------------------------------------------------------------------------------------------------
"""
Expand Down Expand Up @@ -309,7 +309,7 @@ $(generic_docs)
slavi(red, nir, swir2; kw...) = sp_indices(red, nir, swir2; index="SLAVI", kw...)
slavi(cube::GMT.GMTimage{UInt16, 3}, bnds; kw...) = sp_indices(cube, find_layers(cube, bnds, 3); index="SLAVI", kw...)
slavi(cube::String; bands::Vector{Int}=Int[], layers::Vector{Int}=Int[], bandnames::Vector{String}=String[], kw...) =
helper_si_method(cube, "SLAVI"; bands=bands, layers=layers, bandnames=bandnames, defbandnames=["red", "nir", "swir 2"], kw...)
helper_si_method(cube, "SLAVI"; bands=bands, layers=layers, bandnames=bandnames, defbandnames=["red", "nir", "swir2"], kw...)

# ----------------------------------------------------------------------------------------------------------
function helper_sp_indices(kwargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function find_layers(fname::String; bands::Vector{Int}=Int[], layers::Vector{Int
(all(desc .== "")) && error("This cube file has no band descriptions so cannot use the 'band' or 'bandnames' options.")
(alllayers) && return collect(1:nbands), desc # OK, just return them ALL

(!isempty(bands)) && (bandnames = ["Band $(bands[k])" for k = 1:length(bands)]) # Create a bandnames vector
(!isempty(bands)) && (bandnames = ["Band$(bands[k])" for k = 1:length(bands)]) # Create a bandnames vector
_layers = helper_find_layers(lowercase.(desc), bandnames)
return _layers, desc
end
Expand Down
Binary file modified test/LC08_cube.tiff
Binary file not shown.
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ truecolor(mat2img(rand(UInt16, 16, 16), noconv=1), mat2img(rand(UInt16, 16, 16),
@test RemoteS.assign_description(["AC08_B2.TIF", "AC08_B5.TIF"], String[]) == ["AC08_B2", "AC08_B5"]
@test RemoteS.assign_description(["AC08_B2.TIF", "AC08_B5.TIF"], ["B2", "B5"]) == ["B2", "B5"]

@test reportbands(mat2img(rand(UInt16, 4,4,3), names=["Band 1", "Band 2", "Band 3"]), 3)[1] == "Band 3"
@test reportbands(mat2img(rand(UInt16, 4,4,3), names=["Band 1", "Band 2", "Band 3"]), layers=[1,3]) == ["Band 1", "Band 3"]
@test reportbands(mat2img(rand(UInt16, 4,4,3), names=["Band1", "Band2", "Band3"]), 3)[1] == "Band3"
@test reportbands(mat2img(rand(UInt16, 4,4,3), names=["Band1", "Band2", "Band3"]), layers=[1,3]) == ["Band1", "Band3"]

#sat_tracks(position=true);
#sat_tracks(position=true, tle=["1 27424U 02022A 21245.83760660 .00000135 00000-0 39999-4 0 9997"; "2 27424 98.2123 186.0654 0002229 67.6025 313.3829 14.57107527 28342"]);
Expand All @@ -31,7 +31,7 @@ truecolor("LC08_cube.tiff"); println(" truecolor 1")
truecolor(cube, [3,2,1]); println(" truecolor 2")
truecolor(cube, layers=[3,2,1]); println(" truecolor 3")
println(" reportbands 1")
@test reportbands("LC08_cube.tiff", 2)[1] == "Band 3 - Green [0.53-0.59]"
@test reportbands("LC08_cube.tiff", 2)[1] == "Band3 - Green [0.53-0.59]"
println(" reportbands 2")
reportbands(cube);
println(" subcube")
Expand All @@ -46,8 +46,8 @@ R = subcube("LC08_cube.tiff", bandnames=["red"]); println(" subcube R")
G = subcube("LC08_cube.tiff", bandnames=["green"]); println(" subcube G")
B = subcube("LC08_cube.tiff", bandnames=["blue"]); println(" subcube B")
NIR = subcube("LC08_cube.tiff", bandnames=["nir"]); println(" subcube NIR")
SW1 = subcube("LC08_cube.tiff", bandnames=["swir 1"]); println(" subcube SW1")
SW2 = subcube("LC08_cube.tiff", bandnames=["swir 2"]); println(" subcube SW2")
SW1 = subcube("LC08_cube.tiff", bandnames=["swir1"]); println(" subcube SW1")
SW2 = subcube("LC08_cube.tiff", bandnames=["swir2"]); println(" subcube SW2")
G1 = evi("LC08_cube.tiff"); println(" evi 1")
G2 = evi(B, R, NIR); println(" evi 2")
G3 = evi(cube,[1,3,4]); println(" evi 3")
Expand Down

0 comments on commit 231bc4a

Please sign in to comment.