# ---------------------------------------------------------------------- # ExtractValidLines (5) proc ExtractValidLines {lowerBound upperBound noData} { upvar currentLine currentLine upvar lineCounter lineCounter upvar 4 validLineList validLineList incr lineCounter foreach value $currentLine { if [expr $value == $noData] {continue} ;# -9999.0 == -9999 if [expr $value < $lowerBound || $value > $upperBound] {continue} lappend validLineList $lineCounter } } # ExtractValidLines - end # ---------------------------------------------------------------------- # ExtractLineSamples (5) proc ExtractLineSamples {lineSize lowerBound upperBound noData} { upvar currentLine currentLine upvar 4 lineXfrequencyArray lineXfrequencyArray upvar lineCounter lineCounter upvar 4 sampleValueList sampleValueList incr lineCounter if [info exists lineXfrequencyArray($lineCounter)] { for {set i 1} {$i <= $lineXfrequencyArray($lineCounter)} {incr i} { while 1 { set sortedColumn [expr int(rand()*$lineSize)] while {$sortedColumn == 0} { set sortedColumn [expr int(rand()*$lineSize)] } set value [lindex $currentLine [expr $sortedColumn - 1]] if [expr $value != $noData && $lowerBound <= $value && $value <= $upperBound] {break} } lappend sampleValueList $value } } } # ExtractLineSamples - end # ---------------------------------------------------------------------- # ExtractValidLineRecursively (3) proc ExtractValidLineRecursively {lowerBound upperBound} { upvar var var upvar savedVar savedVar upvar headerLines headerLines upvar lineCounter lineCounter # headerArray array set headerArray [join $headerLines] catch {set lineSize $headerArray(ncols)} catch {set lineSize $headerArray(NCOLS)} catch {set nRows $headerArray(nrows)} catch {set nRows $headerArray(NROWS)} catch {set noData $headerArray(NODATA_VALUE)} catch {set noData $headerArray(NODATA_value)} set lineAction "ExtractValidLines $lowerBound $upperBound $noData" if [ProcessLines $lineAction] {return 1} return 0 } # ExtractValidLineRecursively - end # ---------------------------------------------------------------------- # ExtractRandomSampleRecursively (3) proc ExtractRandomSampleRecursively {lowerBound upperBound} { upvar var var upvar savedVar savedVar upvar headerLines headerLines upvar lineCounter lineCounter # headerArray array set headerArray [join $headerLines] catch {set lineSize $headerArray(ncols)} catch {set lineSize $headerArray(NCOLS)} catch {set nRows $headerArray(nrows)} catch {set nRows $headerArray(NROWS)} catch {set noData $headerArray(NODATA_VALUE)} catch {set noData $headerArray(NODATA_value)} set lineAction "ExtractLineSamples $lineSize $lowerBound $upperBound $noData" if [ProcessLines $lineAction] {return 1} return 0 } # ExtractRandomSampleRecursively - end # ---------------------------------------------------------------------- # ExtractRandomSample (1) proc ExtractRandomSample {filePath resultRepository sampleSize randomSeed lowerBound upperBound} { set argv 0 set initial [clock milliseconds] set filePath0 ../../../../../$resultRepository/doc/[file rootname [file tail $filePath]](sample)($sampleSize)($randomSeed)($lowerBound-$upperBound).txt file delete $filePath0 set filePath1 ../../../../../$resultRepository/doc/[file rootname [file tail $filePath]](extrated_sample)($sampleSize)($randomSeed)($lowerBound-$upperBound).asc file delete $filePath1 set contentType {} lappend contentType "date = [clock format [clock seconds] -format %Y-%m-%d]" lappend contentType "localtime = [clock format [clock seconds] -format %H:%M:%S]" lappend contentType "file path = $filePath" lappend contentType "action = ExtractRandomSampleRecursively" lappend contentType "sampleSize = $sampleSize" lappend contentType "randomSeed = $randomSeed" source ../../../../../urlib.net/www/2021/07.02.22.22/doc/GetSizeRecursively.tcl source ../../../../../urlib.net/www/2021/07.02.22.22/doc/TurnCellSquareRecursively.tcl set action "ExtractValidLineRecursively $lowerBound $upperBound" ProcessRecursively $filePath $action set numberOfValidLines [llength $validLineList] expr srand($randomSeed) while {$sampleSize} { set sortedLine [lindex $validLineList [expr int(rand()*$numberOfValidLines) - 1]] while {$sortedLine == 0} { set sortedLine [lindex $validLineList [expr int(rand()*$numberOfValidLines) - 1]] } incr lineXfrequencyArray($sortedLine) incr sampleSize -1 } set action "ExtractRandomSampleRecursively $lowerBound $upperBound" ProcessRecursively $filePath $action Store sampleValueList $filePath1 set final [clock milliseconds] lappend contentType {} lappend contentType [DisplayProcessingTime [expr $final - $initial]] set contentType [join $contentType \n] puts $contentType Store contentType $filePath0 } # ExtractRandomSample - end # ---------------------------------------------------------------------- if $argv { # usage examples console show source ../../../../../dpi.inpe.br/banon/1998/08.02.08.56/doc/utilities1.tcl ;# Store and StoreArray set imageDirectory ../../../../../urlib.net/www/2021/07.14.21.56/doc set resultRepository urlib.net/www/2021/07.14.21.56 set switchNumber 5 switch $switchNumber 1 { set filePath $imageDirectory/arquivo_masc-Teste_.txt ;# data set sampleSize 100 set randomSeed 183305 set lowerBound 0 set upperBound 3552.935059 } 2 { set filePath $imageDirectory/_masc_distCanaArAbertaAgua_MB2016F5x5_GRR.txt } 3 { set filePath $imageDirectory/MCP_masc-dist-agua-aberta-cana_GRR.txt ;# 14 s } 4 { set filePath $imageDirectory/SP_masc-dist-agua-aberta-cana_GRR.txt ;# 1 mn and 59 s - 731581396 } 5 { set filePath $imageDirectory/MCP_mascara-distancia-presenca-agua-area-aberta-cana-F5x5_32723.asc ;# processing time = 15 s; image size = 90600705 set sampleSize 1000 set randomSeed 7919 set lowerBound 0 set upperBound 9000 } 6 { set filePath $imageDirectory/MPO_mascara25-uniao-hidrografia-area-aberta-MapBiomas_32723.asc ;# processing time = 15 s; image size = 90600705 } 7 { set filePath $imageDirectory/MCP_mascara-porcentagem-formacao-florestal-F7x7_32723.asc set sampleSize 1000 set sampleSize 8000 set randomSeed 183305 set lowerBound 0 set upperBound 100 } 8 { set filePath $imageDirectory/MPO_mascara-distancia-presenca-agua-area-aberta-cana-F5x5_32723.asc set sampleSize 1000 set randomSeed 183305 set lowerBound 0 set upperBound 9000 set fileSequence [list $filePath] } ExtractRandomSample $filePath $resultRepository $sampleSize $randomSeed $lowerBound $upperBound } # Previous textual results if 0 { }