<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Get the position of the Sun
il y a une librairie 
Step1:  Remarque
Step2:  Projection sur une surface inclinée
http
Step3:  Verif
<ASSISTANT_TASK:>
Python Code:
map_coords = (45.1973288, 5.7103223) #( 45.166672, 5.71667 ) 
import pysolar.solar as solar
import datetime as dt
d = dt.datetime.now()
#d = dt.datetime(2017, 6, 20, 13, 30, 0, 130320)
solar.get_altitude( *map_coords, d)
solar.get_azimuth(*map_coords, d)
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) ]
Az = np.array( Az )
Az[ Az < -180 ] = Az[ Az < -180 ]+360
plt.plot( Alt )
plt.plot( Az )
plt.plot([0, 24], [0, 0], ':'); plt.ylim([-120, 120]); plt.xlabel('hour of the day');
import pysolar.radiation as radiation
radiation.get_radiation_direct( d, 15 )   # W/m2
Explanation: 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/
End of explanation
from numpy import genfromtxt
horizon_data = genfromtxt('horizon.csv', delimiter=',').T
horizon_data
def isUpperHorizon( azimuth, altitude_deg ):
    h = np.interp(-azimuth, horizon_data[0, :], horizon_data[1, :])
    if h > altitude_deg:
        return 0
    else:
        return 1
isUpperHorizon( 20, 2 )
horizon_data[1, :].max()
Explanation: 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
End of explanation
import math
import pysolar.radiation as radiation
import pysolar.solar as solar
import datetime as dt
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
get_radiation_direct( d, -4 )
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 )
d
import pandas as pd
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' )
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 ]
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é');
d_range.hour + d_range.minute/60
# 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
cosTheta
Explanation: Projection sur une surface inclinée
http://www.a-ghadimi.com/files/Courses/Renewable%20Energy/REN_Book.pdf
page 414
End of explanation
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 ]
plt.plot( Azi, Hor )
plt.plot( Azi, Alt )
plt.ylim([0, 80]);
Azi
Explanation: Verif
End of explanation
<END_TASK>