forked from eshook/Forest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
120 lines (78 loc) · 3.25 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# coding: utf-8
# In[ ]:
# %load runforesttestfull.py
#from memory_profiler import profile
from forest import *
from forest.bobs.Bobs import *
import forest.engines.Config
def testit_randomstuff():
# Make an empty Bob
b = Bob()
print(b)
# Make an empty raster dataset
r = Raster(0,0,20,20,10,10,2)
print(r)
def zonalaverage_oldschool(zonefilename, datafilename):
# Read a rasterized Vector dataset as zones
# FIXME: For now it does not read the file
vector = ShapefileNewRead(zonefilename)
print("vector=",vector)
print("data len=",len(vector.data))
# Read a raster dataset as data
# FIXME: For now it does not read the file
raster = GeotiffRead(datafilename)
print("raster=",raster)
print("raster data len",len(raster.data))
# Calculate partial sum of vector and raster
ps = PartialSumRasterize(vector, raster)
print("PartialSum=",ps)
print(ps.data)
zonalaverage = Average(ps)
return zonalaverage
def testit_oldschool(zonefilename, datafilename):
print("starting old school")
zonalaverage = zonalaverage_oldschool(zonefilename, datafilename)
print("ZonalAverage=",zonalaverage)
for zone in sorted(zonalaverage.data):
print(" ",zone,"=",zonalaverage.data[zone])
print("finished old school")
#@profile
def zonalaverage_forest(zonefilename, datafilename):
Config.inputs = []
#output = run_primitive( VectorZoneTest.reg(zonefilename) == RasterDataTest.reg(datafilename) < PartialSum > AggregateSum == Average )
output = run_primitive( ShapefileNewRead.reg(zonefilename) == GeotiffRead.reg(datafilename) < PartialSumRasterize > AggregateSum == Average )
return output
def testit_forest(zonefilename, datafilename):
print("starting forest")
zonalaverage = zonalaverage_forest(zonefilename, datafilename)
print("ZonalAverage=",zonalaverage)
for zone in sorted(zonalaverage.data):
print(" ",zone,"=",zonalaverage.data[zone])
print("finished forest")
# zonefilename = "examples/data/MX_1960_2015_HSLAD_M.shp"
zonefilename = "examples/data/states.shp"
#datafilename = "examples/data/glc2000.tif"
datafilename = "examples/data/prec_1.tif"
#datafilename = "Z:/NISE/Luyi_C/MPC/raster/worldclim/prec/prec_1.tif"
# In[ ]:
# %prun testit_forest(zonefilename,datafilename)
# %lprun -T lprofoutput -f testit_forest testit_forest(zonefilename,datafilename)
# %mprun testit_forest(zonefilename,datafilename)
# import yappi
# yappi.start()
# yappi.get_func_stats().print_all()
# yappi.get_thread_stats().print_all()
# %load_ext line_profiler
# %lprun -f PartialSumRasterize.__call__ testit_forest(zonefilename,datafilename)
# %mprun -f MultiprocessingEngine.run testit_forest(zonefilename,datafilename)
# %mprun -f TileEngine.split testit_forest(zonefilename,datafilename)
# %mprun -f worker testit_forest(zonefilename,datafilename)
# %mprun -f GeotiffReadPrim.__call__ testit_forest(zonefilename,datafilename)
# from memory_profiler import profile
# mprof run --multiprocess testit_forest(zonefilename,datafilename)
def main():
testit_forest(zonefilename,datafilename)
if __name__ == "__main__":
main()
# %debug
# testit_forest(zonefilename,datafilename)