Debian Codegraph @

test/pytest_getmask.py

raw symbols SCIP
1 ###############################################################################
2 # pytest_getmask.py: getMask
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 args = parser.parse_args()
22
23 try:
24 jim0=jl.createJim(args.input)
25 theStats=jim0.getStats({'function':'max'})
26 # The method getMask sets values within [min,max] to value defined by 'data', else to 'nodata'
27 # The min and max values can be defined as a list
28 jim1=jim0.getMask({'min':1,'max':theStats['max'][0],'nodata':0,'data':1}).pushNoDataValue(1)
29 if jim1.getNvalid()!=87957:
30 print("Failed: nvalid",jim1.getNvalid())
31 throw()
32 if jim1.getNinvalid()!=174187:
33 print("Failed: ninvalid",jim1.getNinvalid())
34 throw()
35 # The min and max values can be defined as a list (min and max values should correspond element wise)
36 # We create a mask with pixel value=1 for pixels within [1,1000] and [2000,maxValue]
37 # Pixels not within those ranges get a no data value 0
38 jim1=jim0.getMask({'min':[1,30],'max':[10,theStats['max'][0]],'nodata':0,'data':1}).setNoDataValue(0)
39 if jim1.getNvalid()!=112924:
40 print("Failed: nvalid",jim1.getNvalid())
41 throw()
42 if jim1.getNinvalid()!=149220:
43 print("Failed: ninvalid",jim1.getNinvalid())
44 throw()
45 jim0.close()
46 jim1.close()
47 print("Success: getMask")
48 except:
49 print("Failed: getMask")
50 jim0.close()