Example Usage of the Field_Protocol_Reader.py Methods¶
Setup¶
Import modules and change current working directory to setup environment:
#!/usr/bin/env python
# -*- coding: utf-8 -*-from __future__ import print_function
from mni2017.field_protocol_reader import field_data, plot_field, create_multiindex_df, create_reasonable_multiindex_df, plot_from_reasonable_df
import os
# change current working directory to folder with field protocol:
path = '/media/thomas/NAS_Data/2017_MNI_campaign/field_data/MULTIPLY'
os.chdir(path)
# initialize field_data class object, load field data in 'MULTIPLY.xlsx
field = field_data(filename='MULTIPLY.xlsx')
UPDATE¶
added create_reasonable_multiindex_df to facilitate working with the actual data [STRIKEOUT:as default option when initializing the class object.]
[STRIKEOUT:One may set the option create_df False if additional .xlsx-files should be added to the class object as this only works with the old procedure.]
[STRIKEOUT:The dataframe can then afterwards be created via create_reasonable_multiindex_df(field.data.items()).]
field_df = create_reasonable_multiindex_df(field.data.items())
field_df
301 (WT) high | ... | 542 (WT) medium | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
BBCH | Chlorophyll measurement 1 [avarage of 10 SPAD Units] | Chlorophyll measurement 2 [avarage of 10 SPAD Units] | Chlorophyll measurement 3 [avarage of 10 SPAD Units] | Chlorophyll measurement 4 [avarage of 10 SPAD Units] | Chlorophyll measurement 5 [avarage of 10 SPAD Units] | Comments | Dry biomass fruit [g] | Dry biomass leaf [g] | Dry biomass stem [g] | ... | Water content total [%] | Water loss fruit [g] | Water loss leaf [g] | Water loss stem [g] | Water loss total [g] | Weather | Wet biomass fruit [g] | Wet biomass leaf [g] | Wet biomass stem [g] | Wet biomass total [g] | |
2017-03-24 | 24.0 | 49.2 | 53.1 | 48.9 | 56.1 | 47.4 | NaN | 0.0 | 4.22 | 0.94 | ... | 75.56 | 0.0 | 9.12 | 0.99 | 10.11 | cloudy | 0.0 | 11.96 | 1.42 | 13.38 |
2017-03-28 | 24.0 | 44.2 | 42.1 | 47.8 | 38.9 | 53.2 | NaN | 0.0 | 6.69 | 7.06 | ... | 80.71 | 0.0 | 10.21 | 2.26 | 12.47 | sunny | 0.0 | 12.78 | 2.67 | 15.45 |
2017-04-05 | 28.0 | 56.4 | 57.5 | 55.6 | 51.3 | 52.1 | NaN | 0.0 | 6.88 | 3.14 | ... | 84.76 | 0.0 | 22.24 | 6.19 | 28.43 | cloudy | 0.0 | 26.45 | 7.09 | 33.54 |
2017-04-10 | 29.0 | 50.1 | 55.9 | 45.5 | 56.2 | 54.6 | NaN | 0.0 | 18.51 | 9.71 | ... | 84.01 | 0.0 | 7.90 | 1.98 | 9.88 | sunny | 0.0 | 9.52 | 2.24 | 11.76 |
2017-04-21 | 31.0 | 40.9 | 53.8 | 44.1 | 56.2 | 48.8 | NaN | 0.0 | 18.75 | 13.54 | ... | 81.70 | 0.0 | 18.06 | 9.85 | 27.91 | cloudy | 0.0 | 22.42 | 11.74 | 34.16 |
2017-05-02 | 31.0 | 47.7 | 46.7 | 42.4 | 37.2 | 47.5 | NaN | 0.0 | 13.13 | 11.48 | ... | 82.55 | 0.0 | 43.87 | 23.58 | 67.45 | cloudy | 0.0 | 53.85 | 27.86 | 81.71 |
6 rows × 705 columns
list(field_df['301 (WT) high']) # List all available values
['BBCH',
'Chlorophyll measurement 1 [avarage of 10 SPAD Units]',
'Chlorophyll measurement 2 [avarage of 10 SPAD Units]',
'Chlorophyll measurement 3 [avarage of 10 SPAD Units]',
'Chlorophyll measurement 4 [avarage of 10 SPAD Units]',
'Chlorophyll measurement 5 [avarage of 10 SPAD Units]',
'Comments',
'Dry biomass fruit [g]',
'Dry biomass leaf [g]',
'Dry biomass stem [g]',
'Dry biomass total [g]',
'Endtime field',
'Estimated share of brown leaf area [%] lower layer',
'Estimated share of brown leaf area [%] upper layer',
'Field overview picture from',
'Field overview picture to',
'Height [cm]',
'LAI file name',
'LAI measurement [cm²]',
'LAT-WGS84',
'LON-WGS84',
'Name',
'Plant count',
'Plants',
'Plants per meter',
'Row orientation [°]',
'Row spacing [cm]',
'Sky cover [x/8]',
'Soil 5cm',
'Soil surface',
'Starttime ESU',
'Starttime field',
'UTM Zone 32 Hochwert',
'UTM Zone 32 Rechtswert',
'Water content fruit [%]',
'Water content leaf [%]',
'Water content stem [%]',
'Water content total [%]',
'Water loss fruit [g]',
'Water loss leaf [g]',
'Water loss stem [g]',
'Water loss total [g]',
'Weather',
'Wet biomass fruit [g]',
'Wet biomass leaf [g]',
'Wet biomass stem [g]',
'Wet biomass total [g]']
field_df['301 (WT) high'][['BBCH', 'Height [cm]']] # Filter the data
BBCH | Height [cm] | |
---|---|---|
2017-03-24 | 24.0 | 12.0 |
2017-03-28 | 24.0 | 10.0 |
2017-04-05 | 28.0 | 28.0 |
2017-04-10 | 29.0 | 32.0 |
2017-04-21 | 31.0 | 37.0 |
2017-05-02 | 31.0 | 39.0 |
# Plot 3 values for field '301 (WT) high':
values = ['BBCH','Height [cm]', 'Chlorophyll measurement 1 [avarage of 10 SPAD Units]']
field_id = '301 (WT) high'
plot_from_reasonable_df(field_df, '301 (WT) high', values)
import matplotlib.pyplot as plt
import pandas as pd
# plot relative development of plant compartments
y = field_df[field_id][['Wet biomass total [g]']]
x = field_df[field_id][[ 'Wet biomass fruit [g]','Wet biomass leaf [g]','Wet biomass stem [g]']]
# make y a Series
y = y.iloc[:,0]
type(y)
# relative biomass:
x_new = x.div(y, axis='index')
# rename columns and plot
x_new.columns = ['wet biomass fruit [%]','wet biomass leaf [%]','wet biomass stem [%]']
x_new.plot(figsize=(10,8), fontsize = 14)
plt.legend(fontsize=14)
plt.grid()
plt.show()