-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjules_tools.py
executable file
·46 lines (36 loc) · 1.27 KB
/
jules_tools.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
############################################
# Series of tools for jules post processing
############################################
#############################################
# nee_from_jules_output:
# Calculate the NEE from jules output:
# (npp * frac) - sum(resp_s)
# or:
# npp_gb - resp_s
# or:
# any combination of the above
#
#############################################
def nee_from_jules_output(filename,\
l_npp_gb=False,l_resp_s_gb=False,\
frac=None):
import netCDF4 as nc
import numpy as np
inf=nc.Dataset(filename,'r')
tsteps=len(inf.dimensions['time'])
if (l_npp_gb==False):
# load frac if in file
if (frac==None):
frac=inf.variables['frac'][:].squeeze()
# else populate from static input vector
else:
frac = np.array([ frac for i in range(tsteps) ])
npp=inf.variables['npp'][:]. squeeze()
npp_gb = np.sum( npp * frac, axis=1 )
else:
npp_gb = inf.variables['npp_gb'][:]. squeeze()
if (l_resp_s_gb==False):
resp_s=inf.variables['resp_s'][:]. squeeze()
resp_s_gb = np.sum( resp_s, axis=1 )
else:
resp_s_gb = inf.variables['resp_s_gb'][:]. squeeze()