Newer
Older
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
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from datetime import datetime
class AnalysisTool:
"""Compare data from different cropsites by croptype"""
def __init__(self):
self.data = {}
def load_cropsite(self, cropsite_object, cropsite_name):
self.data[cropsite_name] = cropsite_object.data
def boxplot(self, croptype):
"""Plot relative deltas of different cropsites for a give croptype"""
data = pd.DataFrame(columns=['Date', 'Month', 'Cropsite', 'Delta'])
start_month = 12
all_months = {}
for cropsite in self.data.keys():
for season in self.data[cropsite]['cropwise'][croptype]:
dates = self.data[cropsite]['cropwise'][croptype][season]['dates']
deltas = self.data[cropsite]['cropwise'][croptype][season]['deltas_rel']['MODIS']
months = []
cropsites = []
first_month = dates[0].month
if first_month < start_month:
start_month = first_month
for date in dates:
months.append(date.strftime('%b'))
cropsites.append(cropsite)
df = pd.DataFrame(list(zip(dates, months, cropsites, np.array(deltas)*100)), columns=['Date', 'Month', 'Cropsite', 'Delta'])
data = pd.concat([data, df])
months = []
for i in range(start_month, start_month + 12):
if i > 12:
i = i - 12
month = datetime.strptime(str(i), '%m').strftime('%b')
if month in data.values:
months.append(month)
plt.figure(figsize=(10,5))
axs = sns.boxplot(x='Month', y='Delta', hue='Cropsite', data=data, order=months)
axs.set_title(croptype)
axs.set_ylabel('Relative Difference in Latent Heat Flux [%]')
axs.axhline(0, color='darkgrey', linestyle='--')
plt.show()