In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

Get the position of the Sun

il y a une librairie : PySolar !

http://pysolar.org/
http://docs.pysolar.org/en/latest/

 pip install pysolar


Rq: voir aussi une app js en ligne: http://suncalc.net/


In [2]:
map_coords = (45.1973288, 5.7103223) #( 45.166672, 5.71667 )

In [3]:
import pysolar.solar as solar
import datetime as dt

In [16]:
d = dt.datetime.now()
#d = dt.datetime(2017, 6, 20, 13, 30, 0, 130320)

In [18]:
solar.get_altitude( *map_coords, d)


/home/etienne/Projets/thermique_appart/py3/lib/python3.5/site-packages/pysolar/time.py:105: UserWarning: I don't know about leap seconds after 2015
  (leap_seconds_base_year + len(leap_seconds_adjustments) - 1)
Out[18]:
15.048516489446936

In [19]:
solar.get_azimuth(*map_coords, d)


/home/etienne/Projets/thermique_appart/py3/lib/python3.5/site-packages/pysolar/time.py:105: UserWarning: I don't know about leap seconds after 2015
  (leap_seconds_base_year + len(leap_seconds_adjustments) - 1)
Out[19]:
-253.0659505266616

In [20]:
Alt = [ solar.get_altitude(*map_coords, dt.datetime(2017, 12, 21, h, 0, 0, 0)) for h in range(0, 24) ]
Az = [ solar.get_azimuth(*map_coords, dt.datetime(2017, 12, 21, h, 0, 0, 0)) for h in range(0, 24) ]


/home/etienne/Projets/thermique_appart/py3/lib/python3.5/site-packages/pysolar/time.py:105: UserWarning: I don't know about leap seconds after 2015
  (leap_seconds_base_year + len(leap_seconds_adjustments) - 1)

In [13]:
Az = np.array( Az )

Az[ Az < -180 ] = Az[ Az < -180 ]+360

In [14]:
plt.plot( Alt )
plt.plot( Az )
plt.plot([0, 24], [0, 0], ':'); plt.ylim([-120, 120]); plt.xlabel('hour of the day');



In [21]:
import pysolar.radiation as radiation

In [23]:
radiation.get_radiation_direct( d, 15 )   # W/m2


Out[23]:
484.0580091484929

Remarque: Le flux solaire au dessus de l'atmosphère est de F = 1 360,8 W/m2

https://fr.wikipedia.org/wiki/Constante_solaire

Avec l'horizon


In [12]:
from numpy import genfromtxt

In [13]:
horizon_data = genfromtxt('horizon.csv', delimiter=',').T

In [14]:
horizon_data


Out[14]:
array([[-180.    , -179.5   , -179.    , ...,  179.    ,  179.5   ,  180.    ],
       [   6.6451,   14.0111,   14.4924, ...,   12.8084,   13.0535,
          13.5404]])

In [53]:
def isUpperHorizon( azimuth, altitude_deg ):
    h = np.interp(-azimuth, horizon_data[0, :], horizon_data[1, :])

    if h > altitude_deg:
        return 0
    else:
        return 1

In [54]:
isUpperHorizon( 20, 2 )


Out[54]:
1

In [55]:
horizon_data[1, :].max()


Out[55]:
15.9122

Projection sur une surface inclinée

http://www.a-ghadimi.com/files/Courses/Renewable%20Energy/REN_Book.pdf

page 414


In [56]:
import math
import pysolar.radiation as radiation
import pysolar.solar as solar
import datetime as dt

In [57]:
def get_radiation_direct(d, alt):
    if alt>0:
        return radiation.get_radiation_direct( d, alt )   # W/m2
    else:
        return 0
    
def get_flux_surface( coords, date, sigma, phi_C ):
    # Surface orientation :
    # sigma : deg, vertical angle of the surface, ref. to the horizontal
    # phi_C : deg, azimuth, relative to south, with positive values in the southeast direction and negative values in
    # the southwest
    
    # Sun position
    phi_S_deg = solar.get_azimuth( *coords, date ) # deg, azimuth of the sun,relative to south
    beta_deg = solar.get_altitude( *coords, date ) # deg, altitude angle of the sun
    
    I0 = get_radiation_direct( d, beta_deg )   # W/m2
    I0 = I0* isUpperHorizon( phi_S_deg, beta_deg )
    
    beta = beta_deg*math.pi/180  # rad
    phi_S = phi_S_deg*math.pi/180  #rad
    sigma = sigma*math.pi/180
    phi_C = phi_C*math.pi/180
    
    cosTheta = math.cos(beta)*math.cos( phi_S - phi_C )*math.sin( sigma ) + math.cos( sigma )*math.sin( beta )
    
    if cosTheta >0 :
        Isurf = I0*cosTheta   # flux projeté, W/m2
    else:
        Isurf = 0  # mais diffuse... 
        
    return Isurf

def get_flux_total( coords, date ):
    # Sun position
    beta_deg = solar.get_altitude( *coords, date ) # deg, altitude angle of the sun
    
    I0 = get_radiation_direct( d, beta_deg )   # W/m2
        
    return I0

In [58]:
get_radiation_direct( d, -4 )


Out[58]:
0

In [59]:
d = dt.datetime(2017, 6, 22, 11, 0, 0, 0)
sigma = 37
phi_C = 50

F = get_flux_surface( map_coords, d, sigma, phi_C )
print( F )


814.1677834421273
/home/etienne/Projets/thermique_appart/py3/lib/python3.5/site-packages/pysolar/time.py:105: UserWarning: I don't know about leap seconds after 2015
  (leap_seconds_base_year + len(leap_seconds_adjustments) - 1)

In [66]:
d


Out[66]:
datetime.datetime(2017, 6, 22, 11, 0)

In [60]:
import pandas as pd

In [61]:
start =  dt.datetime(2017, 6, 22, 0, 0, 0, 0)
end =  dt.datetime(2017, 6, 22, 23, 59, 0, 0)

d_range = pd.date_range( start=start, end=end, freq='5min' )

In [62]:
F_tot = [ get_flux_total(map_coords, d ) for d in d_range ]
F_est = [ get_flux_surface(map_coords, d, sigma, phi_C ) for  d in d_range ]
F_ouest = [ get_flux_surface(map_coords, d, sigma, phi_C+180 ) for d in d_range ]
F_sud = [ get_flux_surface(map_coords, d, 90, phi_C-90 ) for d in d_range ]


/home/etienne/Projets/thermique_appart/py3/lib/python3.5/site-packages/pysolar/time.py:105: UserWarning: I don't know about leap seconds after 2015
  (leap_seconds_base_year + len(leap_seconds_adjustments) - 1)

In [63]:
x = d_range.hour + d_range.minute/60

plt.figure(figsize=(12, 5))
plt.plot( x, F_est )
plt.plot( x, F_ouest )
plt.plot( x, F_sud )
plt.plot( x, F_tot, 'k:' )
plt.xlabel('hour of the day');
plt.ylabel('flux solaire projeté');



In [64]:
d_range.hour + d_range.minute/60


Out[64]:
Float64Index([            0.0, 0.0833333333333,  0.166666666667,
                         0.25,  0.333333333333,  0.416666666667,
                          0.5,  0.583333333333,  0.666666666667,
                         0.75,
              ...
                23.1666666667,           23.25,   23.3333333333,
                23.4166666667,            23.5,   23.5833333333,
                23.6666666667,           23.75,   23.8333333333,
                23.9166666667],
             dtype='float64', length=288)

In [ ]:
# Sun position
phi_S = solar.get_azimuth( *map_coords, d ) # deg, azimuth of the sun,relative to south
beta = solar.get_altitude( *map_coords, d ) # deg, altitude angle of the sun

I0 = radiation.get_radiation_direct( d, 65 )   # W/m2

cosTheta = math.cos(beta)*math.cos( phi_S - phi_C )*math.sin( sigma ) + math.cos( sigma )*math.sin( beta )

Isurf = I0*cosTheta   # flux projeté, W/m2

In [ ]:
cosTheta

Verif


In [51]:
Azi = np.array( [ solar.get_azimuth( *map_coords, d ) for d in d_range ] )

Azi[ Azi < -180 ] = Azi[ Azi < -180 ]+360

Alt = [ solar.get_altitude( *map_coords, d ) for d in d_range ]
Hor = [ np.interp(-a, horizon_data[0, :], horizon_data[1, :]) for a in Azi ]


/home/etienne/Projets/thermique_appart/py3/lib/python3.5/site-packages/pysolar/time.py:105: UserWarning: I don't know about leap seconds after 2015
  (leap_seconds_base_year + len(leap_seconds_adjustments) - 1)

In [65]:
plt.plot( Azi, Hor )
plt.plot( Azi, Alt )
plt.ylim([0, 80]);



In [40]:
Azi


Out[40]:
[-156.20139906919525,
 -157.35005412193766,
 -158.50626305301813,
 -159.66977583554535,
 -160.84032129275806,
 -162.01760706071286,
 -163.2013202892822,
 -164.3911284786617,
 -165.58667980207406,
 -166.78760337810354,
 -167.99351127919272,
 -169.20399824350483,
 -170.41864393032074,
 -171.63701366551788,
 -172.85865945476417,
 -174.0831217431234,
 -175.3099312738409,
 -176.53861036636567,
 -177.7686740900823,
 -178.99963314665303,
 -180.23099431445462,
 -181.4622634019026,
 -182.6929465526473,
 -183.92255172060993,
 -185.1505907835824,
 -186.376581627983,
 -187.6000495253354,
 -188.8205282872421,
 -190.03756299230065,
 -191.25071016842116,
 -192.45954034286058,
 -193.66363884596774,
 -194.8626066822876,
 -196.05606193441406,
 -197.2436410398381,
 -198.42499930366728,
 -199.5998111378948,
 -200.76777176092457,
 -201.92859640330153,
 -203.08202176074508,
 -204.22780574979214,
 -205.3657273300792,
 -206.49558683395963,
 -207.61720618938784,
 -208.73042844029828,
 -209.8351170463444,
 -210.93115659567923,
 -212.01845121687666,
 -213.0969251540597,
 -214.16652180272058,
 -215.22720287024498,
 -216.27894807093526,
 -217.32175478073924,
 -218.35563710045278,
 -219.38062477800514,
 -220.39676350304148,
 -221.40411312531432,
 -222.40274793706425,
 -223.39275558242872,
 -224.37423613539914,
 -225.3473017210249,
 -226.31207614437665,
 -227.26869401432361,
 -228.21729977556117,
 -229.15804804547076,
 -230.0911020613853,
 -231.0166340667438,
 -231.93482445221684,
 -232.8458610726451,
 -233.74993909032253,
 -234.64726084030235,
 -235.5380352428814,
 -236.42247714088387,
 -237.30080786331342,
 -238.17325403644872,
 -239.04004821067826,
 -239.90142833164504,
 -240.7576373794493,
 -241.6089235017755,
 -242.45554017641382,
 -243.2977459489847,
 -244.1358040988407,
 -244.96998346809346,
 -245.80055763313987,
 -246.62780580004198,
 -247.45201260666448,
 -248.27346808370476,
 -249.09246809097948,
 -249.90931478949653,
 -250.72431671027516,
 -251.5377887549974,
 -252.35005333117527,
 -253.16143988772149,
 -253.97228613463642,
 -254.7829382112492,
 -255.5937510164813,
 -256.4050890192869,
 -257.2173271243097,
 -258.0308511560977,
 -258.84605828870133,
 -259.6633586318204,
 -260.483175239222,
 -261.3059458329814,
 -262.1321235013468,
 -262.9621775850769,
 -263.7965950840915,
 -264.63588216629756,
 -265.4805653218719,
 -266.3311924975839,
 -267.18833548127566,
 -268.05259069172996,
 -268.924581814221,
 -269.804961420037,
 -270.69441283440744,
 -271.5936526205852,
 -272.5034332419655,
 -273.42454541330324,
 -274.35782048548265,
 -275.30413426673204,
 -276.26440916419153,
 -277.2396184191195,
 -278.23078928621516,
 -279.23900652909686,
 -280.2654166470604,
 -281.31123233822086,
 -282.37773661195524,
 -283.46628689825593,
 -284.5783207590459,
 -285.71535953267534,
 -286.8790142434359,
 -288.0709900208732,
 -289.2930905144394,
 -290.5472226930756,
 -291.83540129712713,
 -293.1597520210164,
 -294.5225135893899,
 -295.9260404640481,
 -297.3728012478157,
 -298.86537780810784,
 -300.4064599155375,
 -301.9988366799742,
 -303.6453846646933,
 -305.3490510470962,
 -307.11282981207773,
 -308.9397303546193,
 -310.83274002923986,
 -312.7947733153134,
 -314.82861377341555,
 -316.93684155002234,
 -319.1217483665292,
 -321.3852408082546,
 -323.72873159613414,
 -326.15301923986135,
 -328.6581598781793,
 -331.24333981319705,
 -333.90674685447243,
 -336.6454587568994,
 -339.455349855456,
 -342.3310299966889,
 -345.2658273721938,
 -348.2518228677702,
 -351.2799404332475,
 -354.3400966044012,
 -357.42141068257615,
 -0.5124566423625652,
 -3.601555263857165,
 -6.6770784480643215,
 -9.727750660838922,
 -12.742929491072857,
 -15.712847027596297,
 -18.628798220145057,
 -21.483270737734557,
 -24.270019199406136,
 -26.984077685052057,
 -29.621729311914663,
 -32.18043292345092,
 -34.65872175510006,
 -37.05608519970872,
 -39.37284137292809,
 -41.610006889429286,
 -43.76917087935121,
 -45.85238047061597,
 -47.862033005093,
 -49.80078503690797,
 -51.67147127754052,
 -53.47703643508984,
 -55.22047971280202,
 -56.90480976136834,
 -58.53300800118919,
 -60.107999894094775,
 -61.63263520619154,
 -63.10967079522936,
 -64.54176127356624,
 -65.93145141137421,
 -67.2811719138686,
 -68.59323837487472,
 -69.86985205835981,
 -71.11310140476618,
 -72.32496450130961,
 -73.50731396441779,
 -74.66191989122802,
 -75.79045558240489,
 -76.89450183780895,
 -77.97555154360612,
 -79.03501484022092,
 -80.07422418038863,
 -81.09443868745609,
 -82.09684825040426,
 -83.08257878897291,
 -84.05269528727007,
 -85.0082066336451,
 -85.9500689061274,
 -86.87918861406604,
 -87.79642623564229,
 -88.70259954221655,
 -89.59848623109991,
 -90.48482627354161,
 -91.36232528231761,
 -92.23165591987879,
 -93.09346093326059,
 -93.94835484981775,
 -94.7969256710087,
 -95.63973689150777,
 -96.47732938927635,
 -97.31022274674075,
 -98.13891636083332,
 -98.96389156863881,
 -99.7856120058014,
 -100.60452554763606,
 -101.42106505232698,
 -102.2356491482928,
 -103.04868338386217,
 -103.86056130924004,
 -104.67166505726095,
 -105.48236575562527,
 -106.29302497260619,
 -107.10399447418592,
 -107.91561756648059,
 -108.72822929645776,
 -109.54215671919542,
 -110.3577195524332,
 -111.17523079388872,
 -111.99499685943454,
 -112.81731756629449,
 -113.64248718247222,
 -114.47079378201755,
 -115.30252022498615,
 -116.13794399110157,
 -116.97733708799836,
 -117.82096636582912,
 -118.66909380990722,
 -119.52197634291406,
 -120.37986546988861,
 -121.24300804004173,
 -122.11164524748449,
 -122.98601333207728,
 -123.86634308667743,
 -124.75285944069714,
 -125.64578147567414,
 -126.54532241964648,
 -127.45168912844497,
 -128.3650813971782,
 -129.28569246312315,
 -130.21370763756147,
 -131.14930475223366,
 -132.0926533383443,
 -133.04391388974574,
 -134.0032375953656,
 -134.97076605923348,
 -135.9466304792477,
 -136.93095065316686,
 -137.92383528227458,
 -138.92538027588114,
 -139.9356690307912,
 -140.95477136656177,
 -141.98274257552566,
 -143.01962300829643,
 -144.06543767829794,
 -145.1201953166422,
 -146.1838872793736,
 -147.25648790018784,
 -148.3379527293896,
 -149.42821895700968,
 -150.52720443715907,
 -151.63480689478138,
 -152.7509037688402,
 -153.8753521390306,
 -155.00798812492582]

In [ ]: