In [2]:
%matplotlib inline
import numpy as np
import pandas as pd
import xarray as xr
from matplotlib import pyplot as plt
import seaborn as sns
from datetime import datetime
import datetime
In [3]:
# load the floats data
# ********************
# *** CSV files ***
# ********************
# load CSV output
#plt = plt.figure(8,6)
plt.close('all')
plt.cla() # axis
plt.clf() # figure
plt.show()
freq = 8
pref = 'df_chl_dist_out_OC_'
surf = '_modisa.csv'
infile = pref + str(freq) + 'D' + surf
folder = '../data_collector_modisa_chla9km/df_multidimInterpolation/'
direc = folder + infile
direc
print('in_filename and path:', direc)
df_tmp = pd.read_csv(direc, index_col='index')
df_tmp.sort_values(['id', 'time'])[:20]
Out[3]:
In [4]:
df_tmp['time'] = pd.to_datetime(df_tmp['time']) # ,format='%m/%d/%y %I:%M%p'
df_timed = df_tmp.set_index('time')
# add a new column to the dataset
df_timed['year'] = df_timed.index.year
df_timed[:20]
year_max = df_timed.index.year.max()
year_min = df_timed.index.year.min()
print('year_max', year_max)
print('year_min', year_min)
#print(df_timed)
In [5]:
### Part 1: Plot for the mean of the weekly trends
### Mean
start = year_min
for i in range(0,3):
#plt.subplot(311+i)
plt.figure(figsize=(8,6))
plt.title("mean of the weekly binned Lagrangian rate of change of Chl-a", fontsize=10)
for current_year in range(start, start+5):
mask = df_timed.year == current_year
df_yearly = df_timed[mask]
#print('\n summary statistics of chl_rate_week for the year %d \n' % (current_year) )
#print(df_yearly.chl_rate_week.describe())
axes1=df_yearly.groupby(['week_rotate'])['chl_rate_week'].mean().plot(linestyle="-", linewidth=0.8, label='%d' % current_year )
start = start + 4
axes1.set_ylim(-10, 10)
#axes1.set_title("Year " + str(current_year) + ": Line plot of the weekly data on the rate of change per week of the $Chl_a$ Concentration", fontsize=10)
plt.xlabel('week', fontsize=10)
plt.ylabel('rate of change of the $Chl_a$ in $mg/(m^3 \cdot 7days)$', fontsize=10)
plt.yticks(np.arange(-10, 10, 0.5))
plt.xticks(np.arange(1, 25, 1))
axes1.legend(bbox_to_anchor=(1.15, 1.05))
plt.savefig(str(freq)+"DOC_weekly_mean_" + str(i) +".pdf")
plt.show()
plt.close()
In [6]:
### Part 2: Plot for the median of the weekly trends
### Median
start = year_min
for i in range(0,3):
#plt.subplot(311+i)
plt.figure(figsize=(8,6))
plt.title("median of the weekly binned Lagrangian rate of change of Chl-a", fontsize=10)
for current_year in range(start, start+5):
mask = df_timed.year == current_year
df_yearly = df_timed[mask]
#print('\n summary statistics of chl_rate_week for the year %d \n' % (current_year) )
#print(df_yearly.chl_rate_week.describe())
axes1=df_yearly.groupby(['week_rotate'])['chl_rate_week'].quantile(.50).plot(linestyle="-", linewidth=0.8, label='%d' % current_year )
start = start + 4
axes1.set_ylim(-10, 10)
#axes1.set_title("Year " + str(current_year) + ": Line plot of the weekly data on the rate of change per week of the $Chl_a$ Concentration", fontsize=10)
plt.xlabel('week', fontsize=10)
plt.ylabel('rate of change of the $Chl_a$ in $mg/(m^3 \cdot 7days)$', fontsize=10)
plt.yticks(np.arange(-10, 10, 0.5))
plt.xticks(np.arange(1, 25, 1))
axes1.legend(bbox_to_anchor=(1.15, 1.05))
#plt.savefig(str(freq)+"DOC_weekly_median_" + str(i) +".pdf")
plt.show()
plt.close()
In [7]:
### Part 3: Plot for the 25% quantile of the weekly trends
### 25% quantile
start = year_min
for i in range(0,3):
#plt.subplot(311+i)
plt.figure(figsize=(8,6))
plt.title("25% quantile of the weekly binned Lagrangian rate of change of Chl-a", fontsize=10)
for current_year in range(start, start+5):
mask = df_timed.year == current_year
df_yearly = df_timed[mask]
#print('\n summary statistics of chl_rate_week for the year %d \n' % (current_year) )
#print(df_yearly.chl_rate_week.describe())
axes1=df_yearly.groupby(['week_rotate'])['chl_rate_week'].quantile(.25).plot(linestyle="-", linewidth=0.8, label='%d' % current_year )
start = start + 4
axes1.set_ylim(-10, 10)
#axes1.set_title("Year " + str(current_year) + ": Line plot of the weekly data on the rate of change per week of the $Chl_a$ Concentration", fontsize=10)
plt.xlabel('week', fontsize=10)
plt.ylabel('rate of change of the $Chl_a$ in $mg/(m^3 \cdot 7days)$', fontsize=10)
plt.yticks(np.arange(-10, 10, 0.5))
plt.xticks(np.arange(1, 25, 1))
axes1.legend(bbox_to_anchor=(1.15, 1.05))
#plt.savefig(str(freq)+"DOC_weekly_quantile(25)_" + str(i) +".pdf")
plt.show()
plt.close()
In [8]:
### Part 4: Plot for the 75% quantile of the weekly trends
### 75% quantile
start = year_min
for i in range(0,3):
#plt.subplot(311+i)
plt.figure(figsize=(8,6))
plt.title("75% of the weekly binned Lagrangian rate of change of Chl-a", fontsize=10)
for current_year in range(start, start+5):
mask = df_timed.year == current_year
df_yearly = df_timed[mask]
#print('\n summary statistics of chl_rate_week for the year %d \n' % (current_year) )
#print(df_yearly.chl_rate_week.describe())
axes1=df_yearly.groupby(['week_rotate'])['chl_rate_week'].quantile(.75).plot(linestyle="-", linewidth=0.8, label='%d' % current_year )
start = start + 4
axes1.set_ylim(-10, 10)
#axes1.set_title("Year " + str(current_year) + ": Line plot of the weekly data on the rate of change per week of the $Chl_a$ Concentration", fontsize=10)
plt.xlabel('week', fontsize=10)
plt.ylabel('rate of change of the $Chl_a$ in $mg/(m^3 \cdot 7days)$', fontsize=10)
plt.yticks(np.arange(-10, 10, 0.5))
plt.xticks(np.arange(1, 25, 1))
axes1.legend(bbox_to_anchor=(1.15, 1.05))
#plt.savefig(str(freq)+"DOC_weekly_quantile(75)_" + str(i) +".pdf")
plt.show()
plt.close()
In [9]:
#matplotlib.pyplot.close("all")
plt.close('all')
plt.cla() # axis
plt.clf() # figure
plt.show()
In [ ]: