Skip to content

Commit de553c8

Browse files
authored
Merge pull request #89 from GenericMappingTools/fix-some-indices
Fix NDWI and a couple other indices that were wrong. Needed to X -1
2 parents eaff5a8 + 836cd59 commit de553c8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/grid_at_sensor.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ function helper_find_sds(sds::String, info::String, ind_EOLs::Vector{UnitRange{I
167167
((ind = findfirst(":lat", info)) === nothing) && (odeusse = true)
168168
elseif (startswith(sds, "lon"))
169169
((ind = findfirst(":lon", info)) === nothing) && (odeusse = true)
170+
else
171+
odeusse = true
170172
end
171173
end
172174
odeusse && error("The band name -- " * sds * " -- does not exist")
@@ -241,7 +243,7 @@ function get_lon_lat_qual(sds_lon::String, sds_lat::String, qual, inc)
241243
(inc[1] == 0.0) && (dx = diff(G.z[:, round(Int, size(G.z, 1)/2)]); dx = dx[dx .< 10])
242244
lon = G.z[qual]
243245
G = gd2gmt(sds_lat);
244-
(inc[2] == 0.0) && (dy = diff(G.z[round(Int, size(G.z, 2)/2), :]); dy = dy[dy .< 10])
246+
(inc[2] == 0.0) && (dy = diff(G.z[round(Int, size(G.z, 1)/2), :]); dy = dy[dy .< 10])
245247
lat = G.z[qual]
246248
return lon, lat, dx, dy
247249
end

src/spectral_indices.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,15 +693,18 @@ function sp_indices(bnd1, bnd2, bnd3=nothing; index::String="", kwargs...)
693693
# NDBI, LSWI. Normalized difference water index. Gao 1996, Chen 2005; NDWI2 => (nir - swir2)/(nir + swir2)
694694
# Normalized difference red edge index. Gitelson and Merzlyak 1994; (redEdge2 - redEdge1)/(redEdge2 + redEdge1)
695695
# Normalized difference red edge index 2. Barnes et al 2000; (redEdge3 - redEdge1)/(redEdge3 + redEdge1)
696+
697+
# Need to swap bnd1 and bnd2 for indices that are defined as (shorter_cdo - longer_cdo)
698+
_b1, _b2 = (index == "MNDWI" || index == "NBRI" || index == "NDWI" || index == "NDWI2" || index == "NDWI2") ? (bnd2, bnd1) : (bnd1, bnd2)
696699
if (ismask)
697700
@inbounds Threads.@threads for k = 1:mn
698-
t1 = bnd1[k]*i_tmax; t2 = bnd2[k]*i_tmax
701+
t1 = _b1[k]*i_tmax; t2 = _b2[k]*i_tmax
699702
t = (t2 - t1) / (t1 + t2)
700703
(fcomp(t, threshold) && t <= 1) && (mask[k] = 255)
701704
end
702705
else
703706
@inbounds Threads.@threads for k = 1:mn
704-
t1 = bnd1[k]*i_tmax; t2 = bnd2[k]*i_tmax
707+
t1 = _b1[k]*i_tmax; t2 = _b2[k]*i_tmax
705708
t = (t2 - t1) / (t1 + t2)
706709
(t >= -1 && t <= 1) && (img[k] = t)
707710
end

0 commit comments

Comments
 (0)