@@ -391,7 +391,7 @@ function cutcube(; names::Vector{String}=String[], bands::AbstractVector=Int[],
391
391
(MTL != = nothing ) && (MTL = [" MTL=" * join (MTL, " \n " )])
392
392
393
393
# Little parsing of the -R string but does not test if W < E & S < N
394
- (region === nothing ) && (region = grdinfo (names[1 ], C= true )[1 : 4 ]) # Swallow the entire region
394
+ (region === nothing ) && (region:: Vector{Float64} = grdinfo (names[1 ], C= true )[1 : 4 ]) # Swallow the entire region
395
395
_region:: String = isa (region, String) ? region :
396
396
@sprintf (" %.12g/%.12g/%.12g/%.12g" , region[1 ], region[2 ], region[3 ], region[4 ])
397
397
startswith (_region, " -R" ) && (_region = _region[3 : end ]) # Tolerate a region that starts with "-R"
@@ -535,7 +535,9 @@ function parse_lsat8_file(fname::String; band::Int=0, layer::Int=0, mtl::String=
535
535
meta = GMT. Gdal. GDALGetMetadata (ds. ptr, C_NULL )
536
536
if (nbands > 1 )
537
537
desc = Vector {String} (undef,0 )
538
- [append! (desc, [GMT. Gdal. GDALGetDescription (GMT. Gdal. GDALGetRasterBand (ds. ptr, bd))]) for bd = 1 : nbands]
538
+ for bd = 1 : nbands
539
+ append! (desc, [GMT. Gdal. GDALGetDescription (GMT. Gdal. GDALGetRasterBand (ds. ptr, bd))])
540
+ end
539
541
else
540
542
desc = [" " ]
541
543
end
@@ -557,7 +559,7 @@ function parse_lsat8_file(fname::String; band::Int=0, layer::Int=0, mtl::String=
557
559
pars = read_mtl (fname, mtl) # No 'band' here because it's suposed to be findable in 'fname'
558
560
band_layer = 0
559
561
end
560
- band_layer, pars
562
+ band_layer, pars, nbands
561
563
end
562
564
563
565
# ----------------------------------------------------------------------------------------------------------
@@ -567,10 +569,10 @@ function helper_dns(fname::String, band::Int, bandname::String, bandnames::Strin
567
569
(bandname == " " && bandnames != " " ) && (bandname = bandnames) # Accept singular and plural name
568
570
if (bandname != " " )
569
571
layers, = find_layers (fname, bandnames= [bandname])
570
- band_layer, pars = parse_lsat8_file (fname, layer= layers[1 ], mtl= mtl)
572
+ band_layer, pars, = parse_lsat8_file (fname, layer= layers[1 ], mtl= mtl)
571
573
(band_layer != layers[1 ]) && error (" Internal error. $band_layer and $(layers[1 ]) should be equal." )
572
574
else
573
- band_layer, pars = parse_lsat8_file (fname, band= band, mtl= mtl)
575
+ band_layer, pars, = parse_lsat8_file (fname, band= band, mtl= mtl)
574
576
end
575
577
band_layer, pars
576
578
end
@@ -606,7 +608,7 @@ T = dn2temperature(cube, band=10)
606
608
```
607
609
"""
608
610
function dn2temperature (fname:: String ; band:: Int = 0 , mtl:: String = " " , save:: String = " " )
609
- band_layer, pars = parse_lsat8_file (fname, band= band, mtl= mtl)
611
+ band_layer, pars, = parse_lsat8_file (fname, band= band, mtl= mtl)
610
612
(pars. band < 10 ) && throw (ArgumentError (" Brightness temperature is only for bands 10 or 11. Not this one: $(pars. band) " ))
611
613
I, indNaN, o = helper1_sats (fname, band_layer)
612
614
@inbounds Threads. @threads for k = 1 : size (I,1 )* size (I,2 )
@@ -683,8 +685,11 @@ function dn2aux(fname::String, fun::String; band::Int=0, bandname::String="", ba
683
685
helper_dns_op (I, fact_x, fact_a, indNaN, o)
684
686
end
685
687
688
+ _band_layer, _pars, n_bands = parse_lsat8_file (fname, band= band, mtl= mtl) # Cannot repeat 'pars' else Box.core
689
+ (_band_layer == 0 && n_bands == 1 ) && (band:: Int = _pars. band)
690
+
686
691
helper_fun = (fun == " radiance" ) ? inn_helper_rad : inn_helper_ref # Which helper function to use.
687
- if (band == 0 && bandname == " " && bandnames == " " )
692
+ if (band == 0 && bandname == " " && bandnames == " " ) # Reading a cube
688
693
bdnames = reportbands (fname)
689
694
if (fun == " reflect" )
690
695
((ind = findfirst (contains .(bdnames, " Band 10" ))) != = nothing ) && (deleteat! (bdnames, ind))
@@ -715,7 +720,7 @@ Computes the radiance-at-surface of Landsat8 band using the COST model.
715
720
$dns_doc
716
721
"""
717
722
function reflectance_surf (fname:: String ; band:: Int = 0 , mtl:: String = " " , save:: String = " " )
718
- band_layer, pars = parse_lsat8_file (fname, band= band, mtl= mtl)
723
+ band_layer, pars, = parse_lsat8_file (fname, band= band, mtl= mtl)
719
724
(pars. band >= 10 ) && error (" Computing Surface Reflectance for Thermal bands is not defined." )
720
725
I, indNaN, o = helper1_sats (fname, band_layer)
721
726
0 commit comments