Debian Codegraph @

test/pytest_setthreshold.py

raw symbols SCIP
1 ###############################################################################
2 # pytest_setthreshold.py: setThreshold to create mask
3 # Author(s): [email protected]
4 # Copyright (c) 2016-2019 European Union (Joint Research Centre)
5 # License EUPLv1.2
6 #
7 # This file is part of jiplib
8 ###############################################################################
9
10 # History
11 # 2017/10/24 - Created by Pieter Kempeneers ([email protected])
12 # Change log
13
14
15 import argparse
16 import os
17 import jiplib as jl
18
19 parser=argparse.ArgumentParser()
20 parser.add_argument("-input","--input",help="Path of the input file",dest="input",required=True,type=str)
21 parser.add_argument("-min","--min",help="min value for threshold",dest="min",required=True,type=int)
22 parser.add_argument("-max","--max",help="max value for threshold",dest="max",required=True,type=int)
23 args = parser.parse_args()
24
25 jim0=jl.createJim(args.input)
26 if(args.min==0 and args.max==1):
27 try:
28 jim0=jim0.pushNoDataValue(1)
29 # Create binary mask where all values not within [0,1[ are set to 1 (i.e., all pixel values > 0 are set to 1)
30 jim0=jim0.setThreshold({'min':args.min,'max':args.max})
31 if jim0.getNvalid()!=87957:
32 print("Failed: nvalid")
33 throw()
34 if jim0.getNinvalid()!=174187:
35 print("Failed: ninvalid")
36 throw()
37 print("Success: masking")
38 except:
39 print("Failed: masking")
40 elif(args.min==10 and args.max==50):
41 try:
42 jim0=jim0.pushNoDataValue(0)
43 jim1=jim0.setThreshold({'min':10,'max':50})
44 theStats=jim1.getStats({'function':['min','max'],'nodata':0})
45 print(theStats)
46 if theStats['min'][0]!=10:
47 print("Failed: min",theStats['min'])
48 throw()
49 if theStats['max'][0]!=50:
50 print("Failed: max",theStats['max'])
51 throw()
52 jim1=jim0.setThreshold({'min':10,'max':50,'value':100}).clearNoData()
53 theStats=jim1.getStats({'function':['min','max']})
54 if theStats['min'][0]!=0:
55 print("Failed: min",theStats['min'])
56 throw()
57 if theStats['max'][0]!=100:
58 print("Failed: max",theStats['max'])
59 throw()
60 print("Success: masking")
61 except:
62 print("Failed: masking")
63 else:
64 try:
65 jim0=jim0.pushNoDataValue(0)
66 jim1=jim0.setThreshold({'min':args.min,'max':args.max})
67 theStats=jim1.getStats({'function':['min','max'],'nodata':0})
68 print(theStats)
69 print("Success: masking")
70 except:
71 print("Failed: masking")
72 jim1.close()
73 jim0.close()