Skip to content
Snippets Groups Projects
Commit 93e2646c authored by Roberto Re's avatar Roberto Re
Browse files

PANDAS.py

parent 771a9535
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import division
__version__ = 20190626
import re
from time import time, sleep
import datetime
from datetime import datetime, timedelta
from datetime import datetime
import io
import sys
from datetime import date
import csv
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
from pandas import read_csv
import seaborn as sns
DEBUG=False
YOUR_PATH = "/dir/your_path"
def PLOT(filepath_=None,title_=None,FLAG_=None):
df = read_csv(filepath_,sep=",", index_col = ['daily'], parse_dates=['daily'],na_values=['-999'])
#No,date,daily,year,month,day,hour,min,PM1,PM2.5,PM10,TEMP,Hum,PRES
if (FLAG_=="PM"):
df = df.drop(['No','date','year','month','day','hour','min','TEMP','Hum','PRES'],axis=1)
if (FLAG_=="RH"):
df = df.drop(['No','date','year','month','day','hour','min','PM1','PM2_5','PM10','TEMP','PRES'],axis=1)
if (FLAG_=="TEMP"):
df = df.drop(['No','date','year','month','day','hour','min','PM1','PM2_5','PM10','Hum','PRES'],axis=1)
df = df.groupby('daily').mean()
if (FLAG_=="PM"):
pd.DataFrame({'PM2_5':100, 'PM10':100}, index=['PM2_5'])
ax = df.plot()
ax.grid()
ratio = 0.6
xleft, xright = ax.get_xlim()
ybottom, ytop = ax.get_ylim()
ax.set_aspect(abs((xright-xleft)/(ybottom-ytop))*ratio)
t0_= '2019-06-01'
now = datetime.utcnow().strftime('%Y-%m-%d')
ax.hlines(8.2,t0_,now, linestyles='dashed',color = 'darkorange')
ax.annotate('Very good',(t0_,6.0),color = 'darkorange')
ax.hlines(16.4,t0_,now, linestyles='dashed',color = 'darkorange')
ax.annotate('Good',(t0_,14.2),color = 'darkorange')
ax.hlines(25.1,t0_,now, linestyles='dashed',color = 'darkorange')
ax.annotate('Fair',(t0_,23.0),color = 'darkorange')
ax.hlines(37.4,t0_,now, linestyles='dashed',color = 'darkorange')
ax.annotate('Poor',(t0_,35.3),color = 'darkorange')
ax.annotate('Very Poor',(t0_,50.0),color = 'darkorange')
fig = ax.get_figure()
ax.set(xlabel="Date",
ylabel="average 24h polveri sottili (g/m3)",
title="Milano Scalo Romana - Air quality category (PM2.5 g/m3)\nTechnical data: PM sensor PM1\PM2.5 10%, PM10 30%");
now = datetime.utcnow().strftime('%Y%m')
filename=YOUR_PATH+"/PM/data/"+now+".png"
fig.savefig(filename)
filepath_ = YOUR_PATH+"pandas.log"
tmp=df.to_string()
OBJ_file_write_avg = open(filepath_, 'w')
OBJ_file_write_avg.write(tmp+"\n")
OBJ_file_write_avg.close()
if (FLAG_=="RH"):
pd.DataFrame({'Hum':100}, index=['Hum'])
ax = df.plot()
ax.grid()
ratio = 0.4
xleft, xright = ax.get_xlim()
ybottom, ytop = ax.get_ylim()
ax.set_aspect(abs((xright-xleft)/(ybottom-ytop))*ratio)
t0_= '2019-06-01'
now = datetime.utcnow().strftime('%Y-%m-%d')
fig = ax.get_figure()
ax.set(xlabel="Date",
ylabel=" Relative Humidity % ",
title="Milano Scalo Romana - Relative Humidity %\n 0%100%(20%80% 3% @25C,0%20% 80%100% @25C 5%)");
now = datetime.utcnow().strftime('%Y%m')
filename=YOUR_PATH+"/PM/data/RH_"+now+".png"
fig.savefig(filename)
filepath_ = YOUR_PATH+"pandas.log"
tmp=df.to_string()
OBJ_file_write_avg = open(filepath_, 'a')
OBJ_file_write_avg.write(tmp+"\n")
OBJ_file_write_avg.close()
if (FLAG_=="TEMP"):
pd.DataFrame({'TEMP':100}, index=['TEMP'])
ax = df.plot()
ax.grid()
ratio = 0.4
xleft, xright = ax.get_xlim()
ybottom, ytop = ax.get_ylim()
ax.set_aspect(abs((xright-xleft)/(ybottom-ytop))*ratio)
t0_= '2019-06-01'
now = datetime.utcnow().strftime('%Y-%m-%d')
fig = ax.get_figure()
ax.set(xlabel="Date",
ylabel=" Temperature C ",
title="Milano Scalo Romana - Temperature C \n -30 70C (0 65C 1.0C)");
now = datetime.utcnow().strftime('%Y%m')
filename=YOUR_PATH+"/PM/data/TEMP_"+now+".png"
fig.savefig(filename)
filepath_ = YOUR_PATH+"pandas.log"
tmp=df.to_string()
OBJ_file_write_avg = open(filepath_, 'a')
OBJ_file_write_avg.write(tmp+"\n")
OBJ_file_write_avg.close()
Str_Anno = datetime.utcnow().strftime('%Y')
filepath_ = YOUR_PATH+"/PM/data/MILANO_SCALO_ROMANA_PARTICULATE_MATTER_annual_series_"+ Str_Anno+".csv"
PLOT(filepath_,"#FCUB","PM")
PLOT(filepath_,"#FCUB","RH")
PLOT(filepath_,"#FCUB","TEMP")
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