-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCalculations Forest floor
51 lines (43 loc) · 1.65 KB
/
Calculations Forest floor
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
import pandas as pd
import numpy as np
# load and prepare data
#when reading csv files using pandas be sure to use '//' instead of '/' when pasting the pathway
FF_samp=pd.read_csv(LLCS2018FF.csv",
header = 0)
FFash=pd.read_csv(LLCS_FF_ash_2018.csv",
header = 0)
FF_CHN=pd.read_csv(LLCS_2018FF_CHN.csv",
header = 0)
FFmass =pd.DataFrame(FF_samp
.groupby([ 'ws', 'plot', 'ff_layer'])
.agg(
avg_g_cm2=pd.NamedAgg(column="FF_mass_g_cm2", aggfunc="mean") )
)
FFmass=FFmass.reset_index(drop=False)
# merge tables and add columns with calculations
FFdata=(pd.merge(FFmass, FFash, on=['plot','ff_layer']).merge(FF_CHN, on=['plot','ff_layer']))
FFdata['mass_Mg_ha']=FFdata.avg_g_cm2*100
FFdata['C_Mg_ha']=FFdata.c_per*(FFdata.mass_Mg_ha/100)
FFdata['N_Mg_ha']=FFdata.n_per*(FFdata.mass_Mg_ha/100)
# export table
FFdata.to_csv("2018FFdata.csv")
# sum by plot number carbon and nitrogen, average LOI
df2 =pd.DataFrame(FFdata
.groupby(['year','ws', 'plot'])
.agg(
C_Mg_ha_sum=pd.NamedAgg(column="C_Mg_ha", aggfunc="sum"),
N_Mg_ha_sum=pd.NamedAgg(column="N_Mg_ha", aggfunc="sum"),
LOI_avg=pd.NamedAgg(column="loi", aggfunc="mean")
)
)
#export table
df2.to_csv("2018FF_CNsums.csv")
# sum by treatment type carbon and nitrogen
df =pd.DataFrame(FFdata
.groupby(['year','ws', 'treatm'])
.agg(
C_Mg_ha_sum=pd.NamedAgg(column="C_Mg_ha", aggfunc="sum"),
N_Mg_ha_sum=pd.NamedAgg(column="N_Mg_ha", aggfunc="sum")
)
)
df3.to_csv("2018FF_treat_CNsums.csv")