<s> import laspy <EOL> import numpy as np <EOL> import argparse <EOL> import logging <EOL> class validate ( ) : <EOL> def __init__ ( self ) : <EOL> self . parse_args ( ) <EOL> self . clear_log ( ) <EOL> self . errors = <NUM_LIT:0> <EOL> self . tests = <NUM_LIT:0> <EOL> def parse_args ( self ) : <EOL> parser = argparse . ArgumentParser ( description = """<STR_LIT>""" ) <EOL> parser . add_argument ( "<STR_LIT>" , metavar = "<STR_LIT>" , type = str , nargs = <NUM_LIT:1> , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , metavar = "<STR_LIT>" , type = str , nargs = <NUM_LIT:1> , help = "<STR_LIT>" , default = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , metavar = "<STR_LIT>" , type = float , nargs = <NUM_LIT:1> , help = "<STR_LIT>" , default = <NUM_LIT> ) <EOL> self . args = parser . parse_args ( ) <EOL> def clear_log ( self ) : <EOL> tmp = open ( self . args . log , "<STR_LIT:w>" ) <EOL> tmp . close ( ) <EOL> def bb ( self , inFile , xval , yval , zval ) : <EOL> X_invalid = np . logical_or ( ( inFile . header . min [ <NUM_LIT:0> ] > xval ) , ( inFile . header . max [ <NUM_LIT:0> ] < xval ) ) <EOL> Y_invalid = np . logical_or ( ( inFile . header . min [ <NUM_LIT:1> ] > yval ) , ( inFile . header . max [ <NUM_LIT:1> ] < yval ) ) <EOL> Z_invalid = np . logical_or ( ( inFile . header . min [ <NUM_LIT:2> ] > zval ) , ( inFile . header . max [ <NUM_LIT:2> ] < zval ) ) <EOL> bad_indices = np . where ( np . logical_or ( X_invalid , Y_invalid , Z_invalid ) ) <EOL> return ( bad_indices ) <EOL> def test0 ( self , inFile ) : <EOL> print ( "<STR_LIT>" ) <EOL> if inFile . header . file_signature != "<STR_LIT>" : <EOL> logging . info ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> self . errors += <NUM_LIT:1> <EOL> if self . errors == <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" ) <EOL> self . tests += <NUM_LIT:1> <EOL> def test1 ( self , inFile ) : <EOL> print ( "<STR_LIT>" ) <EOL> bb = zip ( [ "<STR_LIT:X>" , "<STR_LIT:Y>" , "<STR_LIT>" ] , inFile . header . min , inFile . header . max ) <EOL> print ( "<STR_LIT>" ) <EOL> for i in bb : <EOL> print ( "<STR_LIT>" + str ( i ) ) <EOL> bad_indices = self . bb ( inFile , inFile . x , inFile . y , inFile . z ) <EOL> if len ( bad_indices [ <NUM_LIT:0> ] == <NUM_LIT:0> ) : <EOL> print ( "<STR_LIT>" ) <EOL> if len ( bad_indices [ <NUM_LIT:0> ] ) == len ( inFile ) : <EOL> new_bi = self . bb ( inFile , inFile . X , inFile . Y , inFile . Z ) [ <NUM_LIT:0> ] <EOL> if len ( new_bi ) < len ( inFile ) : <EOL> print ( "<STR_LIT>" + str ( len ( new_bi ) ) + "<STR_LIT>" ) <EOL> logging . info ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> logging . info ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" + self . args . log ) <EOL> for i in bad_indices [ <NUM_LIT:0> ] : <EOL> logging . info ( "<STR_LIT>" % i ) <EOL> self . errors += <NUM_LIT:1> <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> self . tests += <NUM_LIT:1> <EOL> def test2 ( self , inFile ) : <EOL> print ( "<STR_LIT>" ) <EOL> actual_max = [ np . max ( vec ) for vec in [ inFile . x , inFile . y , inFile . z ] ] <EOL> actual_min = [ np . min ( vec ) for vec in [ inFile . x , inFile . y , inFile . z ] ] <EOL> header_max = inFile . header . max <EOL> header_min = inFile . header . min <EOL> max_diffs = [ actual_max [ i ] - header_max [ i ] for i in range ( <NUM_LIT:3> ) ] <EOL> min_diffs = [ actual_min [ i ] - header_min [ i ] for i in range ( <NUM_LIT:3> ) ] <EOL> err = <NUM_LIT:0> <EOL> for i in range ( len ( max_diffs ) ) : <EOL> if max_diffs [ i ] > self . args . tol : <EOL> err += <NUM_LIT:1> <EOL> print ( "<STR_LIT>" + [ "<STR_LIT:X>" , "<STR_LIT:Y>" , "<STR_LIT>" ] [ i ] + "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" + str ( actual_max [ i ] ) + "<STR_LIT>" + str ( header_max [ i ] ) ) <EOL> logging . info ( [ "<STR_LIT:X>" , "<STR_LIT:Y>" , "<STR_LIT>" ] [ i ] + "<STR_LIT>" % str ( self . args . tol ) ) <EOL> for i in range ( len ( min_diffs ) ) : <EOL> if min_diffs [ i ] > self . args . tol : <EOL> err += <NUM_LIT:1> <EOL> print ( "<STR_LIT>" + [ "<STR_LIT:X>" , "<STR_LIT:Y>" , "<STR_LIT>" ] [ i ] + "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" + str ( actual_max [ i ] ) + "<STR_LIT>" + str ( header_max [ i ] ) ) <EOL> logging . info ( [ "<STR_LIT:X>" , "<STR_LIT:Y>" , "<STR_LIT>" ] [ i ] + "<STR_LIT>" % str ( self . args . tol ) ) <EOL> if err == <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> self . errors += <NUM_LIT:1> <EOL> print ( "<STR_LIT>" ) <EOL> self . tests += <NUM_LIT:1> <EOL> def test3 ( self , inFile ) : <EOL> print ( "<STR_LIT>" ) <EOL> X_range = np . max ( inFile . x ) - np . min ( inFile . x ) <EOL> Y_range = np . max ( inFile . y ) - np . min ( inFile . y ) <EOL> err = <NUM_LIT:0> <EOL> if X_range > <NUM_LIT> : <EOL> err += <NUM_LIT:1> <EOL> print ( "<STR_LIT>" + str ( X_range ) ) <EOL> logging . info ( "<STR_LIT>" + str ( X_range ) ) <EOL> if Y_range > <NUM_LIT> : <EOL> err += <NUM_LIT:1> <EOL> print ( "<STR_LIT>" + str ( Y_range ) ) <EOL> logging . info ( "<STR_LIT>" + str ( Y_range ) ) <EOL> if err == <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> self . errors += <NUM_LIT:1> <EOL> self . tests += <NUM_LIT:1> <EOL> def validate ( self ) : <EOL> print ( "<STR_LIT>" + self . args . in_file [ <NUM_LIT:0> ] ) <EOL> inFile = laspy . file . File ( self . args . in_file [ <NUM_LIT:0> ] , mode = "<STR_LIT:r>" ) <EOL> self . test0 ( inFile ) <EOL> self . test1 ( inFile ) <EOL> self . test2 ( inFile ) <EOL> self . test3 ( inFile ) <EOL> print ( str ( self . errors ) + "<STR_LIT>" + str ( self . tests ) + "<STR_LIT>" ) <EOL> def main ( ) : <EOL> validator = validate ( ) <EOL> logging . basicConfig ( filename = validator . args . log , level = logging . DEBUG ) <EOL> validator . validate ( ) </s>
