forked from edinburgh-university-OOSA/active_sensing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictBiomass.py
More file actions
88 lines (64 loc) · 2.09 KB
/
predictBiomass.py
File metadata and controls
88 lines (64 loc) · 2.09 KB
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
'''
A sript to plot histograms
of ground finding error
'''
###########################################
import numpy as np
import argparse
import matplotlib.pyplot as plt
###########################################
# class to hold GEDI metrics
class gediMetrics(object):
###########################################
def __init__(self,filename):
'''Read the file'''
self.RH60,self.RH95,self.lon,self.lat=np.loadtxt=np.loadtxt(filename,usecols=(25,32,106,107),unpack=True, dtype=float,comments='#')
###########################################
def predictBiomass(self,outName):
'''Predict biomass using a hard wired model'''
# filter usable data
useInd=np.where((self.RH60>-100)&(self.RH60<1000)&(self.RH95>-100)&(self.RH95<1000))
# add offsets
offset=20.0
if(len(useInd)>0):
useInd=useInd[0]
# transform
RH60=self.RH60+offset
RH95=self.RH95+offset
# parametric values
RH60RH95=(self.RH60[useInd]+offset)*(self.RH95[useInd]+offset)
# predict
biomass=RH60*0.73074+RH95*0.47493-0.00787*RH60RH95-19.12512
# write to output
f=open(outName,'w')
j=0
for i in useInd:
line=str(self.lon[i])+" "+str(self.lat[i])+" "+str(biomass[j])+"\n"
f.write(line)
j=j+1
f.close()
print("Written to",outName)
# end of gediMetrics class
###########################################
###########################################
# read the command line
def gediCommands():
'''
Read commandline arguments
'''
p = argparse.ArgumentParser(description=("Writes out properties of GEDI waveform files"))
p.add_argument("--input",dest="inName",type=str,help=("Input GEDI metric filename"))
p.add_argument("--output",dest="output",type=str,default='test.txt',help=("Output filename"))
cmdargs = p.parse_args()
return cmdargs
###########################################
# the main block
if __name__ == '__main__':
# read the command line
cmdargs=gediCommands()
inName=cmdargs.inName
output=cmdargs.output
# read data
data=gediMetrics(inName)
# plot it
data.predictBiomass(output)