Skip to content

Commit 4e0863b

Browse files
ewagnerecosml-admin
ewagner
authored andcommitted
Updating package files
1 parent 5ffd3a2 commit 4e0863b

14 files changed

+5069
-0
lines changed

PLSR_model_evaluation_report.xlsx

10.9 KB
Binary file not shown.

apply_PLSR_coeffs.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Mon Nov 26 14:29:10 2018
4+
5+
@author: zwang896
6+
7+
Applying ASD fresh spectra models and predict traits
8+
"""
9+
10+
import numpy as np, os,pandas as pd,glob
11+
12+
#-----------------define inout and output
13+
outdir = 'D:/test/output/'
14+
plsrDir = 'D:/test/coefficients/'
15+
specCSV = 'D:/test/test_spectra.csv'
16+
17+
plsrCSVs = glob.glob(plsrDir+'*.csv')
18+
plsrCSVs = sorted(plsrCSVs)
19+
20+
df_spec = pd.read_csv(specCSV, sep=',')
21+
spec = df_spec.iloc[:,0:2151].values
22+
23+
#---------------vector normalization
24+
spec_len = np.tile(np.linalg.norm(spec, axis=1), (spec.shape[1], 1))
25+
spec = spec/spec_len.T
26+
27+
#---------------5nm resampling
28+
wl_step = 5
29+
wl = np.arange(350,2501)
30+
spec = spec[:,0::wl_step]
31+
wl = wl[0::wl_step]
32+
33+
#----------------appyling PLSR coefficients
34+
df_all=pd.DataFrame()
35+
df_all=df_spec.iloc[:,2151:]
36+
37+
for plsrCSV in plsrCSVs:
38+
trait_model = pd.read_csv(plsrCSV, sep=',', index_col=0).values
39+
intercept = trait_model[:, 0]
40+
coefficients = np.array(trait_model[:, list(np.arange(1, trait_model.shape[1]))])
41+
42+
traitPred = np.einsum('jl,ml->jm',spec,coefficients, optimize='optimal')
43+
traitPred = traitPred + intercept
44+
traitPred_mean = traitPred.mean(axis=1)
45+
traitPred_std = traitPred.std(axis=1,ddof=1)
46+
47+
trait = os.path.basename(plsrCSV)[14:-4]
48+
df_all[trait+'_mean'] = traitPred_mean
49+
df_all[trait+'_std'] = traitPred_std
50+
51+
#----------------write predicted traits to csv
52+
outfile = os.path.join(outdir,os.path.basename(specCSV)[:-4]+'_traits.csv')
53+
df_all.to_csv(outfile)

coefficients/PLSR_raw_coef_Carbon.csv

+501
Large diffs are not rendered by default.

coefficients/PLSR_raw_coef_Carotenoid_area.csv

+501
Large diffs are not rendered by default.

coefficients/PLSR_raw_coef_Carotenoid_mass.csv

+501
Large diffs are not rendered by default.

coefficients/PLSR_raw_coef_Cellulose.csv

+501
Large diffs are not rendered by default.

coefficients/PLSR_raw_coef_Chlorophyllab_area.csv

+501
Large diffs are not rendered by default.

coefficients/PLSR_raw_coef_Chlorophyllab_mass.csv

+501
Large diffs are not rendered by default.

coefficients/PLSR_raw_coef_Fiber.csv

+501
Large diffs are not rendered by default.

coefficients/PLSR_raw_coef_LMA_gm2_V2.csv

+501
Large diffs are not rendered by default.

coefficients/PLSR_raw_coef_Lignin.csv

+501
Large diffs are not rendered by default.

coefficients/PLSR_raw_coef_Nitrogen.csv

+501
Large diffs are not rendered by default.

output/sample_results.csv

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
,sample_id,Carbon_mean,Carbon_std,Carotenoid_area_mean,Carotenoid_area_std,Carotenoid_mass_mean,Carotenoid_mass_std,Cellulose_mean,Cellulose_std,Chlorophyllab_area_mean,Chlorophyllab_area_std,Chlorophyllab_mass_mean,Chlorophyllab_mass_std,Fiber_mean,Fiber_std,LMA_gm2_V2_mean,LMA_gm2_V2_std,Lignin_mean,Lignin_std,Nitrogen_mean,Nitrogen_std
2+
0,sample_1,52.3092069602,1.26855142525,161.270009237,8.82692805479,881.311840857,89.4154982596,2.55836683574,1.61789827305,652.270615909,27.2613778985,5970.65691612,469.045440737,22.0749698735,4.93547616027,62.6207399326,8.05210275164,10.3145542589,4.14721982408,2.7684241229,0.251827221871
3+
1,sample_2,49.640218138,1.29392487234,145.260679035,7.62493883188,873.21020191,76.0677377237,5.21288224249,1.49148426045,546.990335136,24.9053065567,5739.3660338,432.557897992,27.277664893,4.46234772175,58.350221029,7.8131393889,12.9276500101,3.93899520858,2.20993918673,0.24194709589

test_spectra.csv

+3
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)