
    1id                        S r SSKJrJr  SSKJr  SSKJrJr  SSKJ	r	  Sr
SrS	rS
rSr\	" S5      S 5       r\	" S5      S 5       r\	" S5      S 5       r\	" S5      S 5       r\	" S5      S 5       r\	" S5      S 5       r\	" S5      \4S j5       r\	" S5      \4S j5       r\	" S5      \R.                  \R0                  \4S j5       r\	" S5      \\R.                  \R0                  4S j5       r\4S jr\	" S5      \\R.                  \R0                  \4S j5       r\	" S5      \\R.                  \R0                  \4S j5       r\	" S5      \\
\\\R.                  \R0                  4S j5       r\	" S5      \\
\\\R.                  \R0                  4S j5       r\	" S5      \\R.                  \R0                  4S j5       r S r!\	" S5      S 5       r"g) a  Additional support functions for solar geometry, astronomy, radiation correlation

:Original author: Simeon Nwaogaidu
:Contact: SimeonObinna.Nwaogaidu AT lahmeyer DOT de

:Additional author: Holger Zebner
:Contact: holger.zebner AT lahmeyer DOT de

:Additional author: Brandon Stafford

    )datetime	timedelta   )numeric)solar	constants)check_aware_dtg       @      ?g     \@m          whenc           	         UR                  5       nUS:w  a  UR                  5       nOSnUR                  5       R                  nUS-  S-  U-
  nS[        R
                  -  U-  S-  nSS[        R                  " U5      -  -
  S	[        R                  " SU-  5      -  -
  S
[        R                  " SU-  5      -  -
  S[        R                  " U5      -  -   S[        R                  " SU-  5      -  -   S[        R                  " SU-  5      -  -   n[        R                  " SSU-  -   5      nSS[        R                  " U5      -  -
  S[        R                  " SU-  5      -  -   S[        R                  " SU-  5      -  -   S[        R                  " SU-  5      -  -
  S[        R                  " U5      -  -
  S[        R                  " SU-  5      -  -   S[        R                  " SU-  5      -  -   S-  nSUS-  -   U-
  n	[        R                  " [        R                  " [        R                  " S5      5      [        R                  " [        R                  " U 5      5      [        R                  " [        R                  " U5      5      -  -  [        R                  " [        R                  " U 5      5      [        R                  " [        R                  " U5      5      -  -
  5      S[        R
                  -  -  n
[        UR                  UR                  UR                  UR                  S9nU[!        X-
  S9-   nU[!        X-   S9-   nU[!        U	S9-   nXU4$ )aq  This function calculates the astronomical sunrise, sunset and sun transit times in local time.

Parameters
----------
latitude_deg : float
    latitude in decimal degree. A geographical term denoting
    the north/south angular location of a place on a sphere.
longitude_deg : float
    longitude in decimal degree. Longitude shows your location
    in an east-west direction,relative to the Greenwich meridian.
when : datetime.datetime
    date and time in any valid timezone, answers will be for same day in same timezone.

Returns
-------
sunrise_time_dt : datetime.datetime
    Sunrise time in local time.
sunset_time_dt : datetime.datetime
    Sunset time in local time.
transit_time_dt:
    Sun transit time in local time.

References
----------
.. [1] http://www.skypowerinternational.com/uploads/documents/7.1415.01.121_cm121_bed-anleitung_engl.pdf
.. [2] http://pysolar.org/
.. [3] https://www.esrl.noaa.gov/gmd/grad/solcalc/solareqns.PDF
.. [4] https://www.sciencedirect.com/science/article/pii/S0038092X11004592
.. [5] https://iris.unipa.it/retrieve/handle/10447/55143/28818/Articolo.pdf

Examples
--------
>>> lat = 50.111512
>>> lon = 8.680506
>>> timezone_local = dateutil.tz.gettz('Europe/Berlin')
>>> now = datetime.now(timezone_local)
>>> sr, ss, tr = sb.get_sunrise_sunset_transit(lat, lon, now)
>>> print('sunrise: ', sr)
>>> print('sunset:', ss)
>>> print('transit:', tr)

Nr   i  g      .@   in  gWx?gjt6@gqS?g m?   g5l/@gKJ̓?g`Y?g/$rq@g̓k?gN@!@gX9v>Y@g33333@g?ܵ|@gq=
ף(@   gd;Oz@gS:)@g     @2@   gZd;OV@)yearmonthdaytzinfo)hours)	utcoffsettotal_seconds	timetupletm_ydaymathpicossinradiansacostanr   r   r   r   r   r   )latitude_deglongitude_degr   
utc_offsetr   SHATTdecl	time_adstTONhasame_daysunrise_timesunset_timetransit_times                  O/var/www/html/motor_solar_iot/venv/lib/python3.13/site-packages/pysolar/util.pyget_sunrise_sunset_transitr1   /   s   Z !JT--/


..

"
"C
t
d
"]
2C	
TWWs	S	 B TXXb\!" txxB''	( dhhq2v&&' dhhrl"# txxB''
( dhhq2v&&' 	  
g3.	/B dhhrl*+ dhhq2v..	/ TXXa"f--. DHHQV,,- dhhrl*
+ dhhq2v../ DHHQV,,-" % , sTz/I
%C IIf-. HHT\\,78HHT\\$/01 l34d+,-
- $''\ $ tyy$**DHHW[WbWbcHi99LYsx88Ki44Ll22    c                      [        XU5      SS $ )zYWrapper for get_sunrise_sunset_transit that returns just the sunrise and the sunset time.r   r   r1   r#   r$   r   s      r0   get_sunrise_sunsetr6      s     	#<EaJKr2   c                      [        XU5      S   $ )zJWrapper for get_sunrise_sunset_transit that returns just the sunrise time.r   r4   r5   s      r0   get_sunrise_timer8           	#<EaHIr2   c                      [        XU5      S   $ )zIWrapper for get_sunrise_sunset_transit that returns just the sunset time.r   r4   r5   s      r0   get_sunset_timer;      r9   r2   c                      [        XU5      S   $ )zJWrapper for get_sunrise_sunset_transit that returns just the transit time.r   r4   r5   s      r0   get_transit_timer=      r9   r2   c                     SS[         R                  " S[         R                  -  U R                  5       R                  S-
  -  5      -  S-  -
  $ )ao  Mean Earth-Sun distance is the arithmetical mean of the maximum and minimum distances
between a planet (Earth) and the object about which it revolves (Sun). However,
the function is used to  calculate the Mean earth sun distance.

Parameters
----------
when : datetime.datetime
    date/time for which to do the calculation

Returns
-------
KD : float
    Mean earth sun distance

References
----------
.. [1] http://sunbird.jrc.it/pvgis/solres/solmod3.htm#clear-sky%20radiation
.. [2] R. aguiar and et al, "The ESRA user guidebook, vol. 2. database", models and exploitation software-Solar
        radiation models, p.113
r   gx&?r   ^   r   )r   r   r   utctimetupler   )r   s    r0   mean_earth_sun_distancerA      sD    . vTWW0A0A0C0K0Kb0P!QRRUXXXXr2   c                    UR                  5       R                  n[        R                  " S[        R                  -  US-
  -  S-  5      n[        R
                  " S[        R                  -  US-
  -  S-  5      n[        R                  " SS[        R                  -  US-
  -  S-  -  5      n[        R
                  " SS[        R                  -  US-
  -  S-  -  5      n[        R                  " [        R                  " U5      5      n	[        R                  " [        R                  " X!5      5      n
[        R
                  " [        R                  " U 5      5      [        R
                  " U	5      -  [        R                  " [        R                  " U 5      5      [        R                  " U	5      -  [        R                  " U
5      -  -   nUS:  a  X;-  SSU-  -   SU-  -   SU-  -   S	U-  -   -  $ S
$ )a+  Equation calculates Extratrestrial radiation. Solar radiation incident outside the earth's
atmosphere is called extraterrestrial radiation. On average the extraterrestrial irradiance
is 1367 Watts/meter2 (W/m2). This value varies by + or - 3 percent as the earth orbits the sun.
The earth's closest approach to the sun occurs around January 4th and it is furthest
from the sun around July 5th.

Parameters
----------
when : datetime.datetime
    date/time for which to do the calculation
latitude_deg : float
    latitude in decimal degree. A geographical term denoting the north/south angular location
    of a place on a sphere.
longitude_deg : float
    longitude in decimal degree. Longitude shows your location in an east-west direction,relative
    to the Greenwich meridian.
SC : float
    The solar constant is the amount of incoming solar electromagnetic radiation per unit area, measured
    on the outer surface of Earth's atmosphere in a plane perpendicular to the rays.It is measured by
    satellite to be roughly 1366 watts per square meter (W/m^2)

Returns
-------
EXTR1 : float
    Extraterrestrial irradiation

References
----------
.. [1] http://solardat.uoregon.edu/SolarRadiationBasics.html
.. [2] Dr. J. Schumacher and et al,"INSEL LE(Integrated Simulation Environment Language)Block reference",p.68

r   r
   g     v@r   gqh ?g>7j?gh㈵T?g{/hG?gZa/?r   )
r@   r   r   r   r   r   r    r   get_declinationget_hour_angle)r#   r$   r   SCr   abbccddfr(   r+   ZAs               r0   extraterrestrial_irradrK      s   D 



%
%C	!dgg+s+U3	4B	!dgg+s+U3	4B	!q477{cCi0%89	:B	!q477{cCi0%89	:B<<--c23D	e**4?	@B	$,,|,	-	>$,,WcJdAehlhphpquhvAvy}  zB  zB  CE  zF  BF  
FBbdghbh27g2-2=2MPX[]P]]^qnqqr2   c                     [         R                  [        R                  " S[        R                  -  U-  U R                  5       R                  S-
  -  5      -  $ )a  The declination of the sun is the angle between Earth's equatorial plane and a line
between the Earth and the sun. It varies between 23.45 degrees and -23.45 degrees,
hitting zero on the equinoxes and peaking on the solstices.

Parameters
----------
when : datetime.datetime
    date/time for which to do the calculation
TY : float
    Total number of days in a year. eg. 365 days per year,(no leap days)

Returns
-------
DEC : float
    The declination of the Sun

References
----------
.. [1] http://pysolar.org/

r   Q   )r   earth_axis_inclinationr   r   r   r@   r   )r   TYs     r0   declination_degreerP     sF    . ++dhhDGGr8JPTPaPaPcPkPkoqOq7r.sssr2   c                     [         R                  " XX%X45      nSS[        R                  " U5      -  -   SSS[        R                  " SU-  5      -
  -  -  -   $ )a  Equation calculates Solar elevation function for clear sky type.

 Parameters
 ----------
 latitude_deg : float
     latitude in decimal degree. A geographical term denoting
     the north/south angular location of a place on a sphere.
 longitude_deg : float
     longitude in decimal degree. Longitude shows your location
     in an east-west direction,relative to the Greenwich meridian.
 when : datetime.datetime
     date/time for which to do the calculation
 temperature : float
     atmospheric temperature in kelvin
pressure : float
     pressure in pascals
 elevation : float
     The elevation of a geographic location is its height above a fixed reference point, often the mean
     sea level.

 Returns
 -------
 SOLALTC : float
     Solar elevation function clear sky

 References
 ----------
 .. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status
         and proposed new approaches", energy 30 (2005), pp 1533 - 1549.

 gq?gAǘ?goŏ1      ?r   r   r   get_altituder   r   r   )r#   r$   r   temperaturepressure	elevationaltitudes          r0   solarelevation_function_clearrY     sY    D !!,d{dH$((8"4568qSWS[S[\]ai\jSkOkHl:mnor2   c                     [         R                  " XX#XE5      nSS[        R                  " U5      -  -   SSS[        R                  " SU-  5      -
  -  -  -   $ )a7  The function calculates solar elevation function for overcast sky type.
This associated hourly overcast radiation model is based on the estimation of the
overcast sky transmittance with the sun directly overhead combined with the application
of an over sky elavation function to estimate the overcast day global irradiation
value at any solar elevation.

Parameters
----------
latitude_deg : float
    latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a
    sphere.
longitude_deg : float
    longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the
    Greenwich meridian.
when : datetime.datetime
    date/time for which to do the calculation
elevation : float
    The elevation of a geographic location is its height above a fixed reference point, often the mean sea level.
temperature : float
    atmospheric temperature in kelvin
pressure : float
    pressure in pascals

Returns
-------
SOLALTO : float
    Solar elevation function overcast

References
----------
.. [1] Prof. Peter Tregenza,"Solar radiation and daylight models", p.89.

.. [2] Also accessible through Google Books: http://tinyurl.com/5kdbwu
    Tariq Muneer, "Solar Radiation and Daylight Models, Second Edition: For the Energy Efficient
    Design of Buildings"

gZ+g{gx&?g\?rR   r   r   rS   )r#   r$   r   rW   rU   rV   rX   s          r0    solarelevation_function_overcastr[   C  sZ    R !!,d{dHGtxx'9:;3RSVZV^V^_`ck_kVlRlKm@noor2   c                 $    SSU -  -   SU -  U -  -   $ )a  Equation calculates the Diffuse_transmittance and the is the Theoretical Diffuse Irradiance on a horizontal
surface when the sun is at the zenith.

Parameters
----------
TL : float
    Linke turbidity factor

Returns
-------
DT : float
    diffuse_transmittance

References
----------
.. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed
        new approaches", energy 30 (2005), pp 1533 - 1549.

x&15K7AD@@߾? )TLs    r0   diffuse_transmittancerb   p  s!    ( 2'7b>R+@ABr2   c                 v    SSU-  -   SU-  U-  -   n[         R                  " XX#XE5      n[        U5      U-  U-  $ )a  Equation calculates diffuse radiation under clear sky conditions.

Parameters
----------
latitude_deg : float
    latitude in decimal degree. A geographical term denoting the north/south angular location of a place on
    a sphere.
longitude_deg : float
    longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the
    Greenwich meridian.
when : datetime.datetime
    date/time for which to do the calculation
elevation : float
    The elevation of a geographic location is its height above a fixed reference point, often the mean sea level.
temperature : float
    atmospheric temperature in kelvin
pressure : float
    pressure in pascals
TL : float
    Linke turbidity factor

Returns
-------
DIFFC : float
    Diffuse Irradiation under clear sky

References
----------
.. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed
        new approaches", energy 30 (2005), pp 1533 - 1549.

r]   r^   r_   )r   rT   rA   )	r#   r$   r   rW   rU   rV   ra   DTrX   s	            r0   diffuse_underclearre     sJ    F v}
%B2)>
?B!!,d{dH"4(2-88r2   c           	      v    SSU-  -   SU-  U-  -   n[        U5      U-  [        R                  " XX#XE5      -  nU$ )a  Function calculates the diffuse radiation under overcast conditions.

Parameters
----------
latitude_deg : float
    latitude in decimal degree. A geographical term denoting the north/south angular location of a place on a
    sphere.
longitude_deg : float
    longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the
    Greenwich meridian.
when : datetime.datetime
    date/time for which to do the calculation
elevation : float
    The elevation of a geographic location is its height above a fixed reference point, often the mean sea level.
temperature : float
    atmospheric temperature in kelvin
pressure : float
    pressure in pascals
TL : float
    Linke turbidity factor

Returns
-------
DIFOC : float
    Diffuse Irradiation under overcast

References
----------
.. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed
        new approaches", energy 30 (2005), pp 1533 - 1549.

r]   r^   r_   )rA   r   rT   )	r#   r$   r   rW   rU   rV   ra   rd   DIFOCs	            r0   diffuse_underovercastrh     sU    F v}
%B2)>
?B%d+((T(3?@E Lr2   c	                     [        U5      n	[        X#5      n
SU	-  [        R                  " SU-  U-  U
-  5      -  [        R                  " [
        R                  " XX&Xx5      5      -  nU$ )av  Equation calculates direct radiation under clear sky conditions.

Parameters
----------
latitude_deg : float
    latitude in decimal degree. A geographical term denoting the north/south angular location of a
    place on a sphere.
longitude_deg : float
    longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the
    Greenwich meridian.
when : datetime.datetime
    date/time for which to do the calculation
TY : float
    Total number of days in a year. eg. 365 days per year,(no leap days)
AM : float
    Air mass. An Air Mass is a measure of how far light travels through the Earth's atmosphere. One air mass,
    or AM1, is the thickness of the Earth's atmosphere. Air mass zero (AM0) describes solar irradiance in space,
    where it is unaffected by the atmosphere. The power density of AM1 light is about 1,000 W/m^2
TL : float
    Linke turbidity factor
elevation : float
    The elevation of a geographic location is its height above a fixed reference point, often the mean
    sea level.
temperature : float
    atmospheric temperature in kelvin
pressure : float
    pressure in pascals

Returns
-------
DIRC : float
    Direct Irradiation under clear

References
----------
.. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed
       new approaches", energy 30 (2005), pp 1533 - 1549.

iW  gGr)rA   rP   r   expr   r   rT   )r#   r$   r   rO   AMra   rW   rU   rV   KDDECDIRCs               r0   direct_underclearro     sr    V 
!	&B
T
%C2IB2!6#!>  !%%*<*<\:>:E+S "TTD
 Kr2   c	                     [        XUX4XV[        R                  [        R                  S9	n	[	        XUU[        R                  [        R                  S9n
X-   nU$ )a  Equation calculates global irradiance under clear sky conditions.

Parameters
----------
latitude_deg : float
    latitude in decimal degree. A geographical term denoting the north/south angular location of a place
    on a sphere.
longitude_deg : float
    longitude in decimal degree. Longitude shows your location in an east-west direction,relative to
    the Greenwich meridian.
when : datetime.datetime
    date/time for which to do the calculation
temperature : float
    atmospheric temperature in kelvin
pressure : float
    pressure in pascals
elevation : float
    The elevation of a geographic location is its height above a fixed reference point, often the
    mean sea level.
TY : float
    Total number of days in a year. eg. 365 days per year,(no leap days)
AM : float
    Air mass. An Air Mass is a measure of how far light travels through the Earth's atmosphere. One air mass,
    or AM1, is the thickness of the Earth's atmosphere. Air mass zero (AM0) describes solar irradiance in
    space, where it is unaffected by the atmosphere. The power density of AM1 light is about 1,000 W/m.

TL : float
    Linke turbidity factor
elevation : float
    The elevation of a geographic location is its height above a fixed reference point, often the mean sea
    level.

Returns
-------
ghic : float
    Global Irradiation under clear sky

References
----------
.. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed
        new approaches", energy 30 (2005), pp 1533 - 1549.

)rU   rV   )ro   r   standard_temperaturestandard_pressurere   )r#   r$   r   rO   rk   ra   rW   rU   rV   rn   DIFFCghics               r0   global_irradiance_clearru     s]    ` l4 b9CaCa)2)D)DFD |D(	8V8V)2)D)DFE LDKr2   c           	      >    S[         R                  " XUX4U5      -  nU$ )aD  Calculated Global is used to compare to the Diffuse under overcast conditions.
Under overcast skies, global and diffuse are expected to be equal due to the absence of the beam
component.

Parameters
----------
latitude_deg : float
    latitude in decimal degree. A geographical term denoting the north/south angular location of a
    place on a sphere.
longitude_deg : float
    longitude in decimal degree. Longitude shows your location in an east-west direction,relative
    to the Greenwich meridian.
when : datetime.datetime
    date/time for which to do the calculation
elevation : float
    The elevation of a geographic location is its height above a fixed reference point, often the
    mean sea level.
temperature : float
    atmospheric temperature in kelvin
pressure : float
    pressure in pascals

Returns
-------
ghioc : float
    Global Irradiation under overcast sky

References
----------
.. [1] S. Younes, R.Claywell and el al, "Quality
        control of solar radiation data: present status
        and proposed new approaches", energy 30
        (2005), pp 1533 - 1549.

i<  )r   rT   )r#   r$   r   rW   rU   rV   ghiocs          r0   global_irradiance_overcastrx   L  s.    N E&&|D$-hI JE Lr2   c                     X-  nU$ )a  Function calculates the Diffuse ratio.

Parameters
----------
DIFF_data : array_like
    Diffuse horizontal irradiation data
ghi_data : array_like
    global horizontal irradiation data array

Returns
-------
K : float
    diffuse_ratio

References
----------
.. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed
        new approaches", energy 30 (2005), pp 1533 - 1549.

r`   )	DIFF_dataghi_dataKs      r0   diffuse_ratior}   y  s    * 	AHr2   c                 &    [        XU5      nX-  nU$ )a  This calculates the clear index ratio.

Parameters
----------
ghi_data : array_like
    global horizontal irradiation data array
when : datetime.datetime
    date/time for which to do the calculation
latitude_deg : float
    latitude in decimal degree. A geographical term denoting the north/south angular location of a place
    on a sphere.
longitude_deg : float
    longitude in decimal degree. Longitude shows your location in an east-west direction,relative to the
    Greenwich meridian.

Returns
-------
KT : float
    Clear index ratio

References
----------
.. [1] S. Younes, R.Claywell and el al,"Quality control of solar radiation data: present status and proposed
        new approaches", energy 30 (2005), pp 1533 - 1549.

)rK   )r{   r#   r$   r   EXTR1KTs         r0   clear_indexr     s    : #<EE

BIr2   N)#__doc__r   r    r   r   r   r   tzinfo_checkr	   
AM_default
TL_default
SC_default
TY_defaultelevation_defaultr1   r6   r8   r;   r=   rA   rK   rP   rq   rr   rY   r[   rb   re   rh   ro   ru   rx   r}   r   r`   r2   r0   <module>r      s  &
   ( 



  s3 s3j K K
 I I
 I I
 I I
 Y Y0 AK *r *rZ ", t t2 S\SqSq-6-H-HWh"p "pH 1BR[RpRp090K0K)p )pX  * C. FW%.%C%CPYPkPkpz%9 %9N IZ(1(F(FS\SnSnr|' 'R %JZUf$-$B$ByOjOj3 3j !+*:[l*3*H*HU^UpUp9 9x +<ILjLj*3*E*E) )X4    r2   