Skip to content

Commit 39a7b76

Browse files
authored
Merge pull request #91 from GenericMappingTools/cutcube-more-err-res
Make cutcube more clear when band names are not found.
2 parents 0c19539 + dc92c04 commit 39a7b76

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/utils.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,16 @@ function truecolor(bandR::T, bandG::T, bandB::T) where {T<:Union{GMTgrid{<:Abstr
123123
@assert size(bandR) == size(bandG) == size(bandB)
124124
n1 = length(bandR); n2 = 2 * n1; n3 = 3 * n1
125125
img = Array{UInt8}(undef, size(bandR,1), size(bandR,2), 3)
126-
mima = isa(bandR, GMTgrid) ? bandR.range[5:6] : GMT.entrema_nan(bndR)
126+
mima = isa(bandR, GMTgrid) ? bandR.range[5:6] : GMT.entrema_nan(bandR)
127127
mima == [0.0,1.0] ? (for k = 1:n1 img[k] = round(UInt8, bandR[k] * 255) end) :
128128
(d = 255.0 / (mima[2] - mima[1]); for k = 1:n1 img[k] = round(UInt8, (bandR[k] - mima[1]) * d) end)
129129

130-
mima = isa(bandG, GMTgrid) ? bandG.range[5:6] : GMT.entrema_nan(bndG)
130+
mima = isa(bandG, GMTgrid) ? bandG.range[5:6] : GMT.entrema_nan(bandG)
131131
n = 0
132132
mima == [0.0,1.0] ? (for k = n1+1:n2 img[k] = round(UInt8, bandG[n+=1] * 255) end) :
133133
(d = 255.0 / (mima[2] - mima[1]); for k = n1+1:n2 img[k] = round(UInt8, (bandG[n+=1] - mima[1]) * d) end)
134134

135-
mima = isa(bandB, GMTgrid) ? bandB.range[5:6] : GMT.entrema_nan(bndB)
135+
mima = isa(bandB, GMTgrid) ? bandB.range[5:6] : GMT.entrema_nan(bandB)
136136
n = 0
137137
mima == [0.0,1.0] ? (for k = n2+1:n3 img[k] = round(UInt8, bandB[n+=1] * 255) end) :
138138
(d = 255.0 / (mima[2] - mima[1]); for k = n2+1:n3 img[k] = round(UInt8, (bandB[n+=1] - mima[1]) * d) end)
@@ -364,8 +364,14 @@ function cutcube(; names::Vector{String}=String[], bands::AbstractVector=Int[],
364364
names = Vector{String}(undef, length(bands))
365365
if isa(bands, Vector{Int})
366366
[names[k] = @sprintf("%s%d%s", template, bands[k], extension) for k = 1:length(bands)]
367-
!isfile(names[1]) && # Landsat uses "B2.TIF" and Sentinel "B02.jp2", try again.
368-
[names[k] = @sprintf("%s%.02d%s", template, bands[k], extension) for k = 1:length(bands)]
367+
if (!isfile(names[1])) # Landsat uses "B2.TIF" and Sentinel "B02.jp2", try again.
368+
n_name = @sprintf("%s%.02d%s", template, bands[1], extension)
369+
if (!isfile(n_name))
370+
error("Neither file name $(names[1]) nor $(n_name) do exist in $(pwd()) Check the file extensions and use the 'extension' option if needed.")
371+
else
372+
[names[k] = @sprintf("%s%.02d%s", template, bands[k], extension) for k = 1:length(bands)]
373+
end
374+
end
369375
else
370376
[names[k] = @sprintf("%s%s", template, bands[k]) for k = 1:length(bands)]
371377
end
@@ -379,10 +385,11 @@ function cutcube(; names::Vector{String}=String[], bands::AbstractVector=Int[],
379385
if (isfile(name))
380386
names[k] = name
381387
else
382-
error("File name $name does not exist. Must stop here.")
388+
name = replace(name, "_ST_B" => "_SR_B") # Revert name change before reporting
389+
error("File name $name does not exist in $(pwd()) Must stop here.")
383390
end
384391
else
385-
error("File name $name does not exist. Must stop here.")
392+
error("File name $name does not exist in $(pwd()) Must stop here.")
386393
end
387394
end
388395
k += 1
@@ -441,7 +448,7 @@ function assign_description(names::Vector{String}, description::Vector{String},
441448
end
442449
else
443450
if (isempty(description))
444-
[desc[k] = splitext(splitdir(names[k])[2])[1] for k = 1:length(names)]
451+
for k = 1:length(names) desc[k] = splitext(splitdir(names[k])[2])[1] end
445452
else
446453
desc = description
447454
end

0 commit comments

Comments
 (0)