├── CITATION.cff ├── README.md ├── LICENSE ├── vertical_differencing_colorbar.py ├── vertical_differencing_histogram.py └── vertical_differencing.pl /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use this software, please cite it as below." 3 | authors: 4 | - family-names: "Chelsea" 5 | given-names: "Scott" 6 | orcid: https://orcid.org/0000-0002-3884-4693 7 | title: "On-Demand vertical differencing implemented in OpenTopography" 8 | version: 1.1.0 9 | date-released: 2020-08-06 10 | repository-code: "https://github.com/OpenTopography/Vertical_Differencing" 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![NSF-1948997](https://img.shields.io/badge/NSF-1948997-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1948997) 2 | [![NSF-1948994](https://img.shields.io/badge/NSF-1948994-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1948994) 3 | [![NSF-1948857](https://img.shields.io/badge/NSF-1948857-blue.svg)](https://nsf.gov/awardsearch/showAward?AWD_ID=1948857) 4 | 5 | Vertical differencing in OpenTopography 6 | 7 | Author: Chelsea Scott 8 | 9 | At its core, vertical differencing utilizes gdal_calc. https://gdal.org/programs/gdal_calc.html 10 | 11 | gdal_calc -A compare.tif -B reference.tif --outfile=diff.tif --calc="B-A" --NoDataValue=-9999 12 | 13 | vertical_differencing.pl - script that generates vertical differencing products as available in OpenTopography (hillshade images, histograms, etc.) 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 The Regents of the University of California 2 | 3 | Permission to use, copy, modify, and distribute this software and its documentation 4 | for educational, research and non-profit purposes, without fee, and without a written 5 | agreement is hereby granted, provided that the above copyright notice, this 6 | paragraph and the following three paragraphs appear in all copies. 7 | 8 | Permission to make commercial use of this software may be obtained 9 | by contacting: 10 | Technology Transfer Office 11 | 9500 Gilman Drive, Mail Code 0910 12 | University of California 13 | La Jolla, CA 92093-0910 14 | (858) 534-5815 15 | invent@ucsd.edu 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE REGENTS OF THE UNIVERSITY OF CALIFORNIA AND 18 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 19 | NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. 21 | IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 22 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vertical_differencing_colorbar.py: -------------------------------------------------------------------------------- 1 | #!/opt/python/bin/python -u 2 | 3 | ############################################################################################# 4 | # LICENSE 5 | # 6 | # Copyright (c) 2007 The Regents of the University of California# 7 | # 8 | # Permission to use, copy, modify, and distribute this software and its documentation 9 | # for educational, research and non-profit purposes, without fee, and without a written 10 | # agreement is hereby granted, provided that the above copyright notice, this 11 | # paragraph and the following three paragraphs appear in all copies. 12 | # 13 | # Permission to make commercial use of this software may be obtained 14 | # by contacting: 15 | # Technology Transfer Office 16 | # 9500 Gilman Drive, Mail Code 0910 17 | # University of California 18 | # La Jolla, CA 92093-0910 19 | # (858) 534-5815 20 | # invent@ucsd.edu 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE REGENTS OF THE UNIVERSITY OF CALIFORNIA AND 23 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | # NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | # PARTICULAR PURPOSE ARE DISCLAIMED. 26 | # IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | ############################################################################################# 34 | 35 | ############################################################################################# 36 | # USAGE: 37 | # 38 | # python3 vertical_differencing_colorbar.py 39 | # Example: python3 vertical_differencing_colorbar.py 4.91 m colorbar.png 40 | # 41 | ############################################################################################# 42 | 43 | import sys 44 | import matplotlib 45 | matplotlib.use('Agg') 46 | import matplotlib.pyplot as plt 47 | 48 | if len(sys.argv) != 4: 49 | print ("\n\nMissing parameters:") 50 | print ("Usage: python3 vertical_differencing_colorbar.py ") 51 | print ("Example: python3 vertical_differencing_colorbar.py 4.91 m colorbar.png\n\n") 52 | exit(0) 53 | 54 | stddevVal = float(sys.argv[1]) 55 | unit = sys.argv[2] 56 | file_png = sys.argv[3] 57 | 58 | print ('stddevVal =', stddevVal) 59 | print ('unit =', unit) 60 | print ('file_png =', file_png) 61 | 62 | fig, ax = plt.subplots(figsize=(6, 1)) 63 | 64 | #Try to get the figsize by a ratio of 400 / 450 65 | #fig, ax = plt.subplots(figsize=(6, 6.75)) 66 | 67 | fig.subplots_adjust(bottom=0.5) 68 | cmap = matplotlib.cm.bwr_r 69 | 70 | print (cmap) 71 | 72 | norm = matplotlib.colors.Normalize(vmin=-stddevVal, vmax=stddevVal) 73 | cb1 = matplotlib.colorbar.ColorbarBase(ax, cmap=cmap, norm=norm, orientation='horizontal') 74 | cb1.set_label('Vertical difference (' + unit + ')') 75 | 76 | #fig.tight_layout() 77 | #fig.show() 78 | 79 | plt.savefig(file_png) 80 | plt.close(fig) 81 | 82 | 83 | -------------------------------------------------------------------------------- /vertical_differencing_histogram.py: -------------------------------------------------------------------------------- 1 | #!/opt/python/bin/python -u 2 | 3 | ############################################################################################# 4 | # LICENSE 5 | # 6 | # Copyright (c) 2007 The Regents of the University of California# 7 | # 8 | # Permission to use, copy, modify, and distribute this software and its documentation 9 | # for educational, research and non-profit purposes, without fee, and without a written 10 | # agreement is hereby granted, provided that the above copyright notice, this 11 | # paragraph and the following three paragraphs appear in all copies. 12 | # 13 | # Permission to make commercial use of this software may be obtained 14 | # by contacting: 15 | # Technology Transfer Office 16 | # 9500 Gilman Drive, Mail Code 0910 17 | # University of California 18 | # La Jolla, CA 92093-0910 19 | # (858) 534-5815 20 | # invent@ucsd.edu 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE REGENTS OF THE UNIVERSITY OF CALIFORNIA AND 23 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | # NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | # PARTICULAR PURPOSE ARE DISCLAIMED. 26 | # IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | ############################################################################################# 34 | 35 | ############################################################################################# 36 | # USAGE: 37 | # 38 | # Usage: python3 histogram.py 39 | # Example: python3 histogram.py vertical_differencing_3.xyz histogram.png 10 0.5 40 | # 41 | ############################################################################################# 42 | 43 | import sys 44 | import numpy as np 45 | import matplotlib 46 | matplotlib.use('Agg') 47 | import matplotlib.pyplot as plt 48 | 49 | # main 50 | 51 | if len(sys.argv) != 6: 52 | print ("\n\nMissing parameters:") 53 | print ("Usage: python3 histogram.py ") 54 | print ("Example: python3 histogram.py vertical_differencing_3.xyz histogram.png 10 0.5 \n\n") 55 | exit(0) 56 | 57 | file_xyz = sys.argv[1] 58 | file_png = sys.argv[2] 59 | bind_val = int(sys.argv[3]) 60 | mlod = float(sys.argv[4]) 61 | unit = sys.argv[5] 62 | 63 | print ('Input file xyz =', file_xyz) 64 | print ('Output file png =', file_png) 65 | print ('bind_val =', bind_val) 66 | print ('mlod =', mlod) 67 | print ('unit =', unit) 68 | 69 | topo2 = np.loadtxt(file_xyz) 70 | dh = np.array(topo2) 71 | dh = dh[np.logical_and(dh>-9000,dh<9000)] 72 | 73 | #Try to get the figsize by a ratio of 400 / 450 74 | fig, ax = plt.subplots(figsize=(6, 6.75)) 75 | n, bins, patches = ax.hist(dh,bins=range(-bind_val, bind_val),facecolor='blue', alpha=0.5) 76 | 77 | if mlod < 0: 78 | ax.set_title("Vertical Differencing") 79 | else: 80 | max_counts = max(n) 81 | plt.plot([-mlod,-mlod], [0, max_counts], 'r-') 82 | plt.plot([mlod,mlod], [0, max_counts], 'r-') 83 | ax.set_title("Vertical Differencing: Error threshold = " + str(mlod) + " " + unit) 84 | 85 | 86 | ax.set_xlabel('Vertical difference (' + unit + ')') 87 | ax.set_ylabel('Counts') 88 | 89 | fig.tight_layout() 90 | #plt.show() 91 | 92 | plt.savefig(file_png) 93 | plt.close(fig) 94 | -------------------------------------------------------------------------------- /vertical_differencing.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | ############################################################################################# 4 | # LICENSE 5 | # 6 | # Copyright (c) 2007 The Regents of the University of California# 7 | # 8 | # Permission to use, copy, modify, and distribute this software and its documentation 9 | # for educational, research and non-profit purposes, without fee, and without a written 10 | # agreement is hereby granted, provided that the above copyright notice, this 11 | # paragraph and the following three paragraphs appear in all copies. 12 | # 13 | # Permission to make commercial use of this software may be obtained 14 | # by contacting: 15 | # Technology Transfer Office 16 | # 9500 Gilman Drive, Mail Code 0910 17 | # University of California 18 | # La Jolla, CA 92093-0910 19 | # (858) 534-5815 20 | # invent@ucsd.edu 21 | # 22 | # THIS SOFTWARE IS PROVIDED BY THE REGENTS OF THE UNIVERSITY OF CALIFORNIA AND 23 | # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 24 | # NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | # PARTICULAR PURPOSE ARE DISCLAIMED. 26 | # IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | ############################################################################################# 34 | 35 | ############################################################################################# 36 | # REQUIRES: 37 | # GDAL installed 38 | # imagemagik installed 39 | # 40 | # USAGE: 41 | # 42 | # vertical_differencing.pl 43 | # -i1 44 | # -i2 45 | # -o 46 | # -mlod 47 | # -se 48 | # 49 | # All parameters are mandatory, and may be presented in any order 50 | # 51 | ############################################################################################# 52 | 53 | use strict; 54 | use Time::HiRes qw(gettimeofday); #provides millisecond-level+ timing 55 | use Scalar::Util qw(looks_like_number); 56 | use JSON; 57 | use POSIX qw/ceil/; 58 | 59 | # set the PATH to find gdal binaries 60 | my $gdal_location = "/gdal/bin/"; 61 | my $histogram_py_location = "vertical_differencing_histogram.py"; 62 | my $colorbar_py_location = "vertical_differencing_colorbar.py"; 63 | 64 | my $time = gettimeofday(); 65 | 66 | #set the following to the path for the las2dem location 67 | my $output_name = "output"; 68 | my $input_ref_file = ""; 69 | my $input_cmp_file = ""; 70 | 71 | my $mlod = -1; 72 | my $surveyError = 0; 73 | 74 | my $x1 = undef; 75 | my $y1 = undef; 76 | my $x2 = undef; 77 | my $y2 = undef; 78 | my $bind; 79 | my $unit = "m"; 80 | 81 | sub startsWith { 82 | return index($_[0], $_[1]) == 0; 83 | } 84 | 85 | #this function encapsulates executing a command-line program, printing of stdout from 86 | #a `` system call, and proper handling of the status code. 87 | sub executeString { 88 | #execute line passed to function eg: 'cat myfile.txt' 89 | #redirect output to stderr to stdout 90 | my $cmd = "$_[0] 2>&1"; 91 | my @status = `$cmd`; 92 | print "\n>>cmd: $cmd\n"; 93 | 94 | #stdout has been captured in the @status array 95 | #the status code returned by the system call is stored in $? 96 | if($? != 0) { 97 | die "An error ($?) occured during processing. Aborting...\n"; 98 | } 99 | 100 | my $errorMessage = undef; 101 | 102 | foreach my $s(@status) { 103 | print "\t$s"; 104 | 105 | # work around in case, the error returned as stdout, not stderr 106 | if (index(lc($s), "error") >= 0) { 107 | $errorMessage = $s; 108 | } 109 | } 110 | 111 | if(defined $errorMessage) { 112 | die "An error occured during processing: $errorMessage\n"; 113 | } 114 | } 115 | 116 | sub getXYBound { 117 | my $fileName = $_[0]; 118 | 119 | my $gdal_cmd = $gdal_location . "gdalinfo -json " . $fileName ; 120 | print "\ngdal $gdal_cmd\n"; 121 | 122 | my $json_output = `$gdal_cmd 2>&1`; 123 | 124 | print "\njson: $json_output.\n"; 125 | 126 | my $data = decode_json($json_output); 127 | 128 | my $minx = undef; 129 | my $miny = undef; 130 | my $maxx = undef; 131 | my $maxy = undef; 132 | my $pixel_size = undef; 133 | my $dimensions = undef; 134 | 135 | if (defined $data->{cornerCoordinates}->{lowerLeft}) { 136 | my @lowerLeft = @{$data->{cornerCoordinates}->{lowerLeft}}; 137 | $minx = $lowerLeft[0]; 138 | $miny = $lowerLeft[1]; 139 | } 140 | 141 | if (defined $data->{cornerCoordinates}->{upperRight}) { 142 | my @upperRight = @{$data->{cornerCoordinates}->{upperRight}}; 143 | $maxx = $upperRight[0]; 144 | $maxy = $upperRight[1]; 145 | } 146 | 147 | return ($minx, $miny, $maxx, $maxy); 148 | } 149 | 150 | sub max { 151 | return $_[0] >= $_[1] ? $_[0] : $_[1]; 152 | } 153 | 154 | sub min { 155 | return $_[0] >= $_[1] ? $_[1] : $_[0]; 156 | } 157 | 158 | sub make_histogram { 159 | my $input_tif = $_[0]; 160 | my $output_xyz = $_[1]; 161 | my $output3_xyz = $_[2]; 162 | my $output_png = $_[3]; 163 | my $cur_mlod = $_[4]; 164 | 165 | print ("\n-------------------------------------------------\n"); 166 | print ("\nMaking histogram\n"); 167 | print ("\nMake a text file with the differencing results \n"); 168 | executeString($gdal_location . "gdal_translate -of XYZ " . $input_tif . " " . $output_xyz); 169 | 170 | print ("\nExtract the third column \n"); 171 | executeString("awk '{\$1=\$2=\"\"; print \$0}' " . $output_xyz . " > " . $output3_xyz); 172 | 173 | print ("\nMaking histogram with python\n"); 174 | my $histogram_cmd = "python3 " . $histogram_py_location . " " . $output3_xyz . " " . $output_png . " " . $bind . " " . $cur_mlod . " " . $unit; 175 | executeString($histogram_cmd); 176 | } 177 | 178 | 179 | my $num_argv = $#ARGV + 1; 180 | 181 | for(my $i = 0; $i < $num_argv; $i++) { 182 | if($ARGV[$i] eq "-i1") { 183 | $input_ref_file = $ARGV[$i+1]; 184 | } 185 | 186 | if($ARGV[$i] eq "-i2") { 187 | $input_cmp_file = $ARGV[$i+1]; 188 | } 189 | 190 | if($ARGV[$i] eq "-o") { 191 | $output_name = $ARGV[$i+1]; 192 | } 193 | 194 | if($ARGV[$i] eq "-mlod") { 195 | $mlod = $ARGV[$i+1]; 196 | } 197 | 198 | if($ARGV[$i] eq "-se") { 199 | $surveyError = 1; 200 | } 201 | 202 | if($ARGV[$i] eq "-unit") { 203 | $unit = $ARGV[$i+1]; 204 | } 205 | } 206 | 207 | if(!(-e $input_ref_file)) { 208 | die("Input ref file must be specified"); 209 | } 210 | 211 | if(!(-e $input_cmp_file)) { 212 | die("Input cmp file must be specified"); 213 | } 214 | 215 | my @status; 216 | 217 | my @bound_ref = getXYBound("reference.tif"); 218 | my @bound_cmp = getXYBound("compare.tif"); 219 | 220 | #$minx, $miny, $maxx, $maxy 221 | print ("\n\tx1: " . $bound_ref[0] . "\n\ty1: " . $bound_ref[1] . "\n\tx2: " . $bound_ref[2] . "\n\ty2: " . $bound_ref[3]); 222 | print ("\n\n\tx3: " . $bound_cmp[0] . "\n\ty3: " . $bound_cmp[1] . "\n\tx4: " . $bound_cmp[2] . "\n\ty4: " . $bound_cmp[3]); 223 | print "\n\n"; 224 | 225 | $x1 = max($bound_ref[0], $bound_cmp[0]); 226 | $y1 = min($bound_ref[1], $bound_cmp[1]); 227 | $x2 = min($bound_ref[2], $bound_cmp[2]); 228 | $y2 = max($bound_ref[3], $bound_cmp[3]); 229 | 230 | if ($bound_ref[0] != $x1 || $bound_ref[1] != $y1 || $bound_ref[2] != $x2 || $bound_ref[3] != $y2) { 231 | my $ref_cropCmd = $gdal_location . "gdalwarp -te " . $x1 . " " . $y1 . " " . $x2 . " " . $y2 . " " . $input_ref_file . " reference_crop.tif"; 232 | print "\nrefrence will be cropped\n" . $ref_cropCmd; 233 | executeString($ref_cropCmd); 234 | $input_ref_file = "reference_crop.tif"; 235 | } 236 | 237 | if ($bound_cmp[0] != $x1 || $bound_cmp[1] != $y1 || $bound_cmp[2] != $x2 || $bound_cmp[3] != $y2) { 238 | my $cmp_cropCmd = $gdal_location . "gdalwarp -te " . $x1 . " " . $y1 . " " . $x2 . " " . $y2 . " compare.tif compare_crop.tif"; 239 | print "\ncompare will be cropped\n" . $cmp_cropCmd; 240 | executeString($cmp_cropCmd); 241 | $input_cmp_file = "compare_crop.tif"; 242 | } 243 | 244 | print ("\n\tx1: " . $x1 . "\n\ty1: " . $y1 . "\n\tx2: " . $x2 . "\n\ty2: " . $y2 . "\n"); 245 | 246 | executeString("python " . $gdal_location . "gdal_calc.py -A " . $input_cmp_file . " -B " . $input_ref_file . " --outfile=" . $output_name . ".tif --calc=\"B-A\" --NoDataValue=-9999"); 247 | print ("\nCreate differencing from refrence and compare tif \n"); 248 | 249 | print ("\n-------------------------------------------------\n"); 250 | print ("\nMake PNG file: vertical_differencing.png\n"); 251 | 252 | #generatePng ($output_name . ".tif", "vertical_differencing.png"); 253 | my $thumbFile = "tmb_vertical_differencing.png"; 254 | 255 | executeString($gdal_location . "gdal_translate -stats " . $output_name . ".tif temp_" . $output_name . ".tif"); 256 | print ("\nCreate temp tif with metadata \n"); 257 | 258 | print ("\nCreate color file \n"); 259 | my $gdal_cmd = $gdal_location . "gdalinfo temp_" . $output_name . ".tif"; 260 | print "\n $gdal_cmd\n"; 261 | 262 | my $output = `$gdal_cmd 2>&1`; 263 | 264 | my $statistics_stddev; 265 | my $statistics_mean; 266 | 267 | foreach my $line (split /[\r\n]+/, $output) { 268 | $line =~ s/^\s+|\s+$//g; 269 | if (startsWith($line, "STATISTICS_STDDEV") ) { 270 | my @tokens = split("=", $line); 271 | $statistics_stddev = $tokens[1]; 272 | #print ("\n>>line: " . $line . "\n"); 273 | print ("\n>>statistics_stddev: " . $statistics_stddev . "\n"); 274 | } 275 | 276 | if (startsWith($line, "STATISTICS_MEAN") ) { 277 | my @tokens = split("=", $line); 278 | $statistics_mean = $tokens[1]; 279 | #print ("\n>>line: " . $line . "\n"); 280 | print ("\n>>statistics_mean: " . $statistics_mean . "\n"); 281 | } 282 | } 283 | 284 | my $value = (2 * $statistics_stddev) + abs($statistics_mean); 285 | print ("\n>>value: " . $value . "\n"); 286 | 287 | my $stddevVal = sprintf("%.1f", $value); 288 | $bind = ceil(abs($statistics_mean) + (4*$statistics_stddev)); 289 | 290 | open(my $fh, '>', "color.txt") or die "Could not open file 'color.txt' $!"; 291 | print $fh "-9999 gray\n"; 292 | print $fh "-" . $value . " red\n"; 293 | print $fh "0 white\n"; 294 | print $fh $value . " blue\n"; 295 | close $fh; 296 | 297 | if ($mlod > 0) { 298 | open(my $fh2, '>', "color2.txt") or die "Could not open file 'color2.txt' $!"; 299 | print $fh2 "-9999 gray\n"; 300 | print $fh2 "-" . $value . " red\n"; 301 | print $fh2 "0 white\n"; 302 | print $fh2 $value . " blue\n"; 303 | print $fh2 "9999 black\n"; 304 | close $fh2; 305 | } 306 | 307 | 308 | print ("\nMake the tiff file with the col.txt color palette.\n"); 309 | executeString($gdal_location . "gdaldem color-relief temp_" . $output_name . ".tif color.txt temp2_" . $output_name . ".tif"); 310 | 311 | print ("\nImageMagick: create main PNG file\n"); 312 | executeString("convert temp2_" . $output_name . ".tif vertical_differencing.png"); 313 | 314 | print ("\nImageMagick: Create thumbnail 400 x 400 of main image.\n"); 315 | executeString("convert -resize 400x400 vertical_differencing.png " . $thumbFile); 316 | 317 | make_histogram ( 318 | $output_name . ".tif", 319 | "vertical_differencing.xyz", 320 | "vertical_differencing_3.xyz", 321 | "histogram.png", 322 | -1); 323 | 324 | print ("\nMake colorbar with python \n"); 325 | my $colorbar_cmd = "python3 " . $colorbar_py_location . " " . $stddevVal . " " . $unit . " colorbar_blue_white_red.png"; 326 | executeString($colorbar_cmd); 327 | 328 | 329 | `mv $input_ref_file output.reference.tif`; 330 | `mv $input_cmp_file output.compare.tif`; 331 | 332 | if ($mlod > 0) { 333 | print ("\n-------------------------------------------------\n"); 334 | print ("\nMake Error Detection \n"); 335 | 336 | my $gdal_calc_cmd1 = "python " . $gdal_location . "gdal_calc.py -A " . $output_name . ".tif --outfile=abs.tif --calc=\"abs(A)\" --NoDataValue=-9999"; 337 | executeString($gdal_calc_cmd1); 338 | print ("\n" . $gdal_calc_cmd1 . "\n"); 339 | 340 | my $gdal_calc_cmd2 = "python " . $gdal_location . "gdal_calc.py -A " . $output_name . ".tif -B abs.tif --outfile=e1.tif --calc=\"A*(B>=" . $mlod . ")\" --NoDataValue=-9999"; 341 | executeString($gdal_calc_cmd2); 342 | print ("\n" . $gdal_calc_cmd2 . "\n"); 343 | 344 | my $gdal_calc_cmd3 = "python " . $gdal_location . "gdal_calc.py -A e1.tif -B abs.tif --outfile=errUserMinDet.tif --calc=\"(B<" . $mlod . ")*+9999+A\" --NoDataValue=-9999"; 345 | executeString($gdal_calc_cmd3); 346 | print ("\n" . $gdal_calc_cmd3 . "\n"); 347 | 348 | print ("\nMake the tiff file with the col.txt color palette.\n"); 349 | executeString($gdal_location . "gdaldem color-relief errUserMinDet.tif color2.txt out_errUserMinDet.tif "); 350 | 351 | print ("\nImageMagick: create main PNG file\n"); 352 | executeString("convert out_errUserMinDet.tif out_errUserMinDet.png"); 353 | 354 | print ("\nImageMagick: Create thumbnail 400 x 400 of main image.\n"); 355 | executeString("convert -resize 400x400 out_errUserMinDet.png tmb_out_errUserMinDet.png"); 356 | 357 | make_histogram ( 358 | "errUserMinDet.tif", 359 | "errUserMinDet.xyz", 360 | "errUserMinDet_3.xyz", 361 | "histogram_mlod.png", 362 | $mlod); 363 | } 364 | 365 | print "\nCompressing output...\n"; 366 | 367 | my $cmd = "tar -cvf " . $output_name. ".tar --remove-files " . $output_name . ".tif output.reference.tif output.compare.tif 2>/dev/null"; 368 | 369 | # tar cvf some.tar file1 file2 file3 370 | print ("\n" . $cmd); 371 | @status = `$cmd`; 372 | 373 | $cmd = "gzip " . $output_name . ".tar 2>/dev/null"; 374 | print ("\n" . $cmd); 375 | @status = `$cmd`; 376 | 377 | print "\n\nCleaning up...\n"; 378 | @status = `rm *.tif`; 379 | 380 | print "Process Completed.\n"; 381 | $time = gettimeofday() - $time; 382 | print "Total time taken: $time seconds\n"; 383 | --------------------------------------------------------------------------------