In [29]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
import datetime as dt
In [30]:
import sunradiation as sun
import weatherfeed as wf
import emoncmsfeed as getfeeds
In [31]:
coords_grenoble = (45.1973288, 5.7139923)
startday = pd.to_datetime('12/07/2017', format='%d/%m/%Y').tz_localize('Europe/Paris')
lastday = pd.to_datetime('24/07/2017', format='%d/%m/%Y').tz_localize('Europe/Paris')
J'utilise l'API de DarkSky (https://darksky.net).
In [32]:
# routine pour construire automatiquement un dataframe pandas:
# télécharge les données en ligne
weatherdata = wf.buildmultidayDF(startday, lastday, coords_grenoble )
Ce sont des données heure par heure. Pour avoir une meillieur précision avec les données mesurées et le flux solaire, on augmente artificiellment la fréquence à 15min:
In [34]:
weatherdata = weatherdata.resample('15min').interpolate('linear')
In [35]:
weatherdata['temperature'].plot(figsize=(14, 3), color='r' ); plt.ylabel('°C');
Routine permettant d'obtenir :
Il n'y a pas la radiation diffuse, mais prend en compte la couverture nuageuse ( $ 0.75*c^3.4 $ ... )
In [36]:
sundata = sun.buildmultidayDF( coords_grenoble, weatherdata.index, cloudCover = weatherdata['cloudCover'] )
In [37]:
sundata['I0'].plot(figsize=(14, 3)); plt.ylabel('W/m2');
In [38]:
# surface (m2), sigma (deg), azimuth (deg)
windows = { 'bastille':(1.2*0.8, 37, 50) ,
'cuisine':(0.3*0.72 *2, 90, 50 ),
'chambre':(0.3*0.72 *2, 90, 180+50),
'vercors':(0.6*0.8 * 2, 37, 180+50) }
In [39]:
sunFlux_dict = {}
for k, values in windows.items():
sunFlux_dict['flux_'+k] = values[0] * sun.projectDF( values[1], values[2], sundata )
flux_tot = pd.DataFrame( sunFlux_dict )
In [40]:
flux_tot.plot(figsize=(14, 3)); plt.ylabel('W');
In [41]:
# Somme
weatherdata['flux_tot'] = flux_tot.sum(axis=1)
weatherdata['flux_tot'].plot( figsize=(14, 3) ); plt.ylabel('W');
Rq: C'est le flux 'brut' reçu par les surfaces. Il faut ensuite prendre en compte la réflexion, l'absorption et la ré-émission ... ceci étant décrit par un facteur multiplicatif entre 0 et 1, noté facteur_g. wiipedia
Au minimum, on a $facteur_g = 0.76$ pour un double vitrage. Il y a aussi l'absorption par le cadre (et les rideaux) et la transmision par conduction, et re-émissions.
In [42]:
# Vitesse du vent
weatherdata['windSpeed'].plot(figsize=(14, 2)); plt.ylabel('m/s');
In [43]:
# Pluie
weatherdata['precipIntensity'].plot(figsize=(14, 2)); plt.ylabel('mm / h');
In [44]:
parser = lambda d: pd.to_datetime( int( d ), unit='s' )
In [45]:
Tmesure = pd.read_csv('./data_weektest/3.csv', sep=',', index_col=0, parse_dates=True, \
header=None, names=['T_int',], date_parser=parser)
# Resample
Tmesure = Tmesure.resample('15min').mean()
In [46]:
Tmesure.plot( figsize=(14, 3) ); plt.ylabel('°C');
In [47]:
# Remove some data
mask_start = pd.to_datetime( '14/07/2017 12:00' ).tz_localize('Europe/Paris')
mask_end = pd.to_datetime( '24/07/2017 12:00' ) .tz_localize('Europe/Paris')
mask = (Tmesure.index < mask_start) | (Tmesure.index > mask_end )
Tmesure['T_int'].loc[mask] = np.nan
In [48]:
Tmesure.plot( figsize=(14, 3) ); plt.ylabel('°C');
In [49]:
# Merge
weatherdata['T_int'] = Tmesure['T_int']
In [50]:
weatherdata.to_pickle( 'weektest_data.pck' )
In [51]:
plt.figure( figsize=(14, 5) )
plt.subplot( 2, 1, 1 )
plt.plot(weatherdata['T_int'] , ':k')
plt.plot(weatherdata['temperature'], alpha=0.4);
plt.subplot( 2, 1, 2 )
plt.plot(weatherdata['flux_tot'] , 'r');
In [53]:
filename = 'data_weektest/'+'history_export_2017-07-24T18_14_12.csv'
In [94]:
data = pd.read_csv(filename, sep=';' , header=10)
data.index = pd.to_datetime( data[['Year', 'Month', 'Day', 'Hour', 'Minute']] )
data = data.drop( ['Year', 'Month', 'Day', 'Hour', 'Minute'], axis=1 )
In [95]:
data.columns
Out[95]:
In [97]:
plt.figure( figsize=(14, 5) )
clouCover_blue = data['Total cloud cover [sfc]'] / 100
clouCover_blue.plot()
weatherdata['cloudCover'].plot()
Out[97]:
In [82]:
surf_tot = sum( [ w[0] for w in windows.values() ] )
In [83]:
approx_rad = data['Shortwave Radiation - backwards [sfc]'] * surf_tot / 2
In [84]:
plt.figure( figsize=(14, 5) )
plt.plot( approx_rad, 'r')
weatherdata['flux_tot'].plot()
Out[84]:
In [67]:
plt.figure( figsize=(14, 5) )
data['Temperature [2 m above gnd]'].plot()
weatherdata['temperature'].plot()
Out[67]:
In [ ]:
weatherdata.precipIntensity
In [69]:
plt.figure( figsize=(14, 5) )
data['Total Precipitation [sfc]'].plot()
weatherdata['precipIntensity'].plot()
Out[69]:
In [86]:
plt.figure( figsize=(14, 5) )
data['Relative humidity [2 m above gnd]'].plot()
Out[86]:
In [113]:
cloudcover_blue = data['Total cloud cover [sfc]'].resample('15min').interpolate() / 100
In [114]:
sundata = sun.buildmultidayDF( coords_grenoble, weatherdata.index, cloudCover = cloudcover_blue )
In [118]:
sundata['I0'].plot(figsize=(14, 3)); plt.ylabel('W/m2');
data['Shortwave Radiation - backwards [sfc]'].plot()
Out[118]:
In [116]:
cloudcover_blue
Out[116]:
In [ ]: