Skip to content

Instantly share code, notes, and snippets.

@rdmtinez
Last active October 13, 2017 12:27
Show Gist options
  • Save rdmtinez/91c90f7f27393885fb791164052baec2 to your computer and use it in GitHub Desktop.
Save rdmtinez/91c90f7f27393885fb791164052baec2 to your computer and use it in GitHub Desktop.
import os
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt, gridspec
from matplotlib.backends.backend_pdf import PdfPages
from collections import OrderedDict
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
wkdir = "C:/Users/MAR8RNG/BOSCH-PROJECTS/1-Humidity/python/condensed_CSVs/"
bse_prm ='premium/'
os.chdir(wkdir+bse_prm)
csv_list = os.listdir(wkdir+bse_prm)
for csv in csv_list:
imei=csv[:-4]
imei
with open(csv) as f:
df = pd.read_csv(f, parse_dates=['DateTime'])
#For iterating over months and obtaining weeks
mon_list = df['Month'].unique()
df.set_index(['Month'], drop=False, inplace=True)
mon_week = OrderedDict()
for m in mon_list:
if m not in mon_week:
mon_week[m] = df.loc[m]['Week'].unique()
#Month-Week (e.g. Dec-52) Selection
df.set_index(['Month', 'Week'], inplace=True)
df.sort_index(inplace=True)
#Save figs as PDFs
with PdfPages(wkdir+'figures/'+imei+'.pdf') as pdf:
#Montly-Weekly plots
for m in mon_list:
#create figure
fig = plt.figure()
#number of weekly plots in fig
nweeks = len(mon_week[m])
#create grid in for figure
grid = gridspec.GridSpec(3, 3)
#plot monthly and position in grid
month=plt.subplot(grid[0,:])
df.loc[m].plot(x='DateTime',
y=['VWC', 'dVWC'],
figsize=(16,9),ax=month, title=m)
n=5
i=1
for w in mon_week[m]:
#plot weekly and position in grid
week=plt.subplot(grid[i,5%n])
df.loc[m, w].plot(x='DateTime',
y=['VWC', 'dVWC'],
ax=week,title=m+'_'+str(w))
#sets up week grid positions
n-=1
if n==2:
i=2
n=5
plt.tight_layout()
pdf.savefig(fig)
plt.close('all')
####don't forget to add labels####
####graph the moving average####
####graph all using the same window####
#save figures as pdfs
#create more space between the figures
#better labels
#create smaller df or only obtain the series to make the algorithm faster
#to do, label maximums
#label y axis
#smooth out the graphs
#arima
#plt.subplot2grid()
#one figure top MONTH
#month
#weeks side by side
#df_sub = create a data frame with daily high low values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment