Skip to content
Snippets Groups Projects
Commit 268d1a8c authored by Diego Gomes's avatar Diego Gomes
Browse files

Replace analysistool.py

parent 56498926
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
from datetime import datetime
class AnalysisTool:
......@@ -18,9 +19,9 @@ class AnalysisTool:
def boxplot(self, croptype, save=False):
"""Plot relative deltas of different cropsites for a give croptype"""
"""Plot log deltas of different cropsites for a give croptype"""
colors = ['#134e6f', '#ffa822', '#ff6150', '#1ac0c6']
colors = ['#134e6f', '#ffa822', '#ff6150', '#1ac0c6', '#9e416b']
data = pd.DataFrame(columns=['Date', 'Month', 'Cropsite', 'Delta'])
......@@ -31,7 +32,7 @@ class AnalysisTool:
if croptype in self.data[cropsite]['cropwise'].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']
deltas = self.data[cropsite]['cropwise'][croptype][season]['deltas_log']['MODIS']
months = []
cropsites = []
......@@ -43,24 +44,32 @@ class AnalysisTool:
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'])
df = pd.DataFrame(list(zip(dates, months, cropsites, deltas)), columns=['Date', 'Month', 'Cropsite', 'Delta'])
data = pd.concat([data, df])
months = []
hold = []
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:
if month not in data.values:
hold.append(month)
else:
months += hold
hold = []
months.append(month)
plt.figure(figsize=(10,20))
plt.figure(figsize=(20,10))
axs = sns.boxplot(x='Month', y='Delta', hue='Cropsite', palette=colors, data=data, order=months)
axs.set_title(croptype)
axs.set_ylabel('Relative Difference in Latent Heat Flux [%]')
axs.yaxis.set_major_locator(MultipleLocator(1))
axs.set_ylabel('Sign-adjusted Natural Logarithm of Difference in Latent Heat Flux [sign(W m-2) * ln(|W m-2|)]')
for i in range(int(len(months)/2)):
axs.axvline((i*2)+1, color='black', linestyle='-', linewidth=1120/len(months), alpha=0.05)
try:
axs.axvline(months.index('Jan'), color='lightgrey', linestyle='--')
axs.axvline(months.index('Jan')-0.5, color='lightgrey', linestyle='--')
except ValueError:
pass
axs.axhline(0, color='black', linestyle='-')
......@@ -74,7 +83,7 @@ class AnalysisTool:
def scatterplot(self, croptype, cropsite='all', combine=True, save=False):
"""Plot latent heat values: MODIS vs FLUXNET"""
colors = ['#134e6f', '#ffa822', '#ff6150', '#1ac0c6']
colors = ['#134e6f', '#ffa822', '#ff6150', '#1ac0c6', '#9e416b']
fig, axs = plt.subplots(figsize=(10, 10))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment