
    1imI                     <   S r SSKJr  SSKrSSKJr  SSKJr  SSKJr  SSK	J
r
  S	 rS
 rS r\
" S5      S1S j5       r\
" S5      S\R                  \R                   4S j5       r\
" S5      S\R                  \R                   4S j5       r\
" S5      S 5       rS rS r\
" S5      S1S j5       rS rS rS rS rS rS rS rS rS rS r S r!\
" S5      S 5       r"S  r#S! r$S" r%S# r&S$ r'S% r(S& r)S' r*S( r+\
" S5      S) 5       r,S* r-S+ r.S, r/S- r0S. r1S/ r2S0 r3g)2zySolar geometry functions

This module contains the most important functions for calculation of the position of the sun.

   )numeric    N)	constants)	solartime)	radiation)check_aware_dtc                  n   Sn Sn[         R                   R                  [         R                  R                  S9n[         R                  " SS9n[        S5       HY  nUR                  5       n[        XU5      n[        XU5      n[        R                  " X&5      nUS:  a  [        USXgU5        X#-   nM[     g )	Ng>+N.E@g8Q)tzg      ?)hours0   r   UTC)datetimenowtimezoneutc	timedeltarangectimeget_altitudeget_azimuthr   get_radiation_directprint)	latitude_deglongitude_degdthirty_minutes_	timestampaltitude_degazimuth_degpowers	            P/var/www/html/motor_solar_iot/venv/lib/python3.13/site-packages/pysolar/solar.py
solar_testr#      s    LM!2!2!6!67A''4N2YGGI	#LC!,qA..q?1)ULuE     c                     S[         R                  -  S-  U S-
  -  nS[         R                  " SU-  5      -  S[         R                  " U5      -  -
  S[         R                  " U5      -  -
  $ )zQreturns the number of minutes to add to mean solar time to get actual solar time.   g     v@Q   g=
ףp#@gQ@g      ?)mathpisincos)daybs     r"   equation_of_timer.   .   sX    	DGGesRx(A$((1q5/!D488A;$66txx{9JJJr$   c                     SSU -  -  $ )Ngec}4      @ sun_earth_distances    r"   get_aberration_correctionr4   4   s    V0011r$   whenc                 L   [        X05      n[        X05      n[        R                  " U5      n[        R                  " U5      n[        R
                  " U5      n[        R                  " U5      n	[        U	5      n
[        U	5      n[        U	5      n[        U5      n[        U5      n[        U5      n[        XiU5      n[        X5      n[        XU5      n[!        UUU
5      n[#        UUU
5      n[%        UUU5      n['        XNUU5      n[)        UU5      n[+        UX^UU5      nUU4$ )z,Common calculations for altitude and azimuth)get_projected_radial_distanceget_projected_axial_distancestimeget_julian_solar_dayget_julian_ephemeris_dayget_julian_ephemeris_centuryget_julian_ephemeris_millenniumget_geocentric_latitudeget_geocentric_longitudeget_sun_earth_distancer4   "get_equatorial_horizontal_parallaxget_nutationget_apparent_sidereal_timeget_true_ecliptic_obliquityget_apparent_sun_longitude"get_geocentric_sun_right_ascensionget_geocentric_sun_declinationget_local_hour_angle get_parallax_sun_right_ascension get_topocentric_local_hour_angleget_topocentric_sun_declination)r   r   r5   	elevationprojected_radial_distanceprojected_axial_distancejdjdejcejmegeocentric_latitudegeocentric_longituder3   aberration_correctionequatorial_horizontal_parallaxnutationapparent_sidereal_timetrue_ecliptic_obliquityapparent_sun_longitudegeocentric_sun_right_ascensiongeocentric_sun_declinationlocal_hour_angleparallax_sun_right_ascensiontopocentric_local_hour_angletopocentric_sun_declinations                            r"   get_topocentric_positionra   8   sc    !>i V;IT 
	#	#D	)B

(
(
.C

,
,S
1C

/
/
4C1#63C8/456HI%GHZ%["C H7J9#H 88LXmn%GH^`w  zM  &N"!?@VXo  rE  "F+,BMSqr#CD]  @P  Rl  $m #CDTVr#s "AB\^v  Yu  wG  #H&(DDDr$   c                 t    [        XX#5      u  pg[        XU5      n[        XTU5      n	X-   n
[        UX5      nX4$ )zGiven location, time and atmospheric conditions
temperature in Kelvin and pressure in Pascal

returns (azimuth, altitude) of sun in degrees.

Same as a combination of get_azimuth and get_altitude
)ra   get_topocentric_elevation_angleget_refraction_correctionget_topocentric_azimuth_angle)r   r   r5   rL   temperaturepressurer`   r_   topocentric_elevation_anglerefraction_correctionr   r    s               r"   get_positionrj   Y   sd     	!dN > 	((D	F   6h6QS /FL/0L&2QK $$r$   c                 V    [        XX#5      u  pg[        XU5      n[        XTU5      n	X-   $ )ziSee also the faster, but less accurate, get_altitude_fast()
temperature in Kelvin and pressure in Pascal
)ra   rc   rd   )
r   r   r5   rL   rf   rg   r`   r_   rh   ri   s
             r"   r   r   w   sE     	!dN > #B,  nJ  #K5hMhi&>>r$   c                    [         R                  " U5      n[         R                  " [        U5      5      n[         R                  " U 5      n[	        X!5      n[         R
                  " U5      [         R
                  " U5      -  [         R
                  " [         R                  " U5      5      -  n[         R                  " U5      [         R                  " U5      -  n[         R                  " [         R                  " Xx-   5      5      $ N)	r(   tm_ydayradiansget_declinationget_hour_angler+   r*   degreesasin)	r   r   r5   r,   declination_radlatitude_rad
hour_angle
first_termsecond_terms	            r"   get_altitude_fastry      s     ,,t
Cll?3#78O<<-L4J,'$((?*CCdhht||\fOgFhhJ((<(488O+DDK<<		*":;<<r$   c                 d    [        U 5      US   [        R                  " [        X5      5      -  -   $ N	longitude)get_mean_sidereal_timer(   r+   rD   )rO   rR   rW   s      r"   rC   rC      s,    !"%(=IdehIs@t(tttr$   c                     XS   -   U-   $ r{   r1   )rT   rW   ab_corrections      r"   rE   rE      s    ;"77-GGr$   c                 :    [        XX#5      u  pE[        UX5      nU$ rm   )ra   re   )r   r   r5   rL   r`   r_   azimuths          r"   r   r      s/     	!dN > ,,H7G Nr$   c                    [         R                  " U5      n[         R                  " [        U5      5      n[         R                  " U 5      n[         R                  " [	        X!5      5      n[         R                  " [        XU5      5      n[         R                  " [         R                  " U5      * [         R                  " U5      -  [         R                  " U5      -  5      n[         R                  " [         R                  " U5      [         R                  " U5      -  [         R                  " U5      :  S[         R                  " U5      -
  [         R                  " U5      SUS:  -  -   5      $ )N   h  r   )r(   rn   ro   rp   rq   ry   rs   r+   r*   wheretanrr   )	r   r   r5   r,   rt   ru   hour_angle_radaltitude_radazimuth_rads	            r"   get_azimuth_fastr      s    
,,t
Cll?3#78O<<-L\\."EFN<< 1,t TUL))TXXo66.9QQTXT\T\]iTjjkK::dhh~.,1GG488TcKddT\\+66ll;/#q2II r$   c           	          SnSnU HC  nSnU H-  nXVS   [         R                  " US   US   U -  -   5      -  -  nM/     X%U-  -  nX0-  nME     U$ )zcomputes a polynomial with time-varying coefficients from the given constant coefficients array and the current Julian millennium.        g      ?r   r   r&   )r(   r+   )rR   coeffsresultxlinecls          r"   	get_coeffr      sp     FAA11!s
!2333A  	a%	  	r$   c                     [         R                  [        R                  " S[        R                  -  S-  U S-
  -  5      -  $ )zThe declination of the sun is the angle between
Earth's equatorial plane and a line between the Earth and the sun.
The declination of the sun varies between 23.45 degrees and -23.45 degrees,
hitting zero on the equinoxes and peaking on the solstices.
r&   g     v@r'   )r   earth_axis_inclinationr(   r*   r)   )r,   s    r"   rp   rp      s7     ++dhhDGGe8KPSVXPX7Y.ZZZr$   c                     SSU -  -  $ )NgJ+!@i  r1   r2   s    r"   rA   rA      s    D--..r$   c                     [         R                  " U 5      n[         R                  " [         R                  " S[         R                  " U5      -  5      5      $ Ngh֥?)r(   ro   rr   atanr   )latituderu   s     r"   get_flattened_latituder      s6    <<)L<<		*txx/E"EFGGr$   c                     S[        U 5      -  $ N)get_heliocentric_latituderR   s    r"   r>   r>      s    )#...r$   c                 $    [        U 5      S-   S-  $ )Nr   r   )get_heliocentric_longituder   s    r"   r?   r?      s    &s+c1S88r$   c                    [         R                  " U 5      n[         R                  " U5      n[         R                  " U5      n[         R                  " U5      [         R                  " U5      -  n[         R                  " U5      [         R                  " U5      -  [         R                  " U5      -  n[         R                  " Xg-   5      n[         R
                  " U5      $ rm   )r(   ro   r*   r+   rs   rr   )	rZ   rY   rS   apparent_sun_longitude_radtrue_ecliptic_obliquity_radgeocentric_latitude_radar-   deltas	            r"   rG   rG      s    !%.D!E"&,,/F"G"ll+>?()DHH5P,QQA()DHH5P,QQTXT\T\]wTxxAIIaeE<<r$   c                    [         R                  " U 5      n[         R                  " U5      n[         R                  " U5      n[         R                  " U5      [         R                  " U5      -  n[         R                  " U5      [         R                  " U5      -  n[         R                  " U5      n[         R
                  " Xg-
  U5      n	[         R                  " U	5      S-  $ Nr   )r(   ro   r*   r+   r   atan2rr   )
rZ   rY   rS   r   r   r   r   r-   r   alphas
             r"   rF   rF      s    !%.D!E"&,,/F"G"ll+>?+,txx8S/TTA()DHH5P,QQA+,AJJ#E<<$$r$   c                 d    [         R                  " [        U [        R                  5      S-  5      $ N    חA)r(   rr   r   r   heliocentric_latitude_coeffsr   s    r"   r   r      s$    <<	#y'M'MNQTTUUr$   c                 j    [         R                  " [        U [        R                  5      S-  5      S-  $ )Nr   r   )r(   rr   r   r   heliocentric_longitude_coeffsr   s    r"   r   r      s*    <<	#y'N'NORUUVY\\\r$   c                 (    [        X5      nSUS-
  -  $ )Ng      .@g      (@)get_solar_time)r5   r   
solar_times      r"   rq   rq      s    4J:$%%r$   c           
         [         R                  " U 5      n[         R                  " U5      n[         R                  " U5      n[         R                  " U5      n[         R                  " [         R                  " [         R                  " U5      [         R                  " U5      -  [         R
                  " U5      [         R
                  " U5      -  [         R                  " U[         R                  -
  U-
  5      -  -   5      5      $ rm   )r(   ro   rr   acosr+   r*   r)   )topocentric_zenith_angleslopeslope_orientationtopocentric_azimuth_angletza_rad	slope_radso_radtaa_rads           r"   get_incidence_angler      s    ll34GU#I\\+,Fll45G<<		$((7"3dhhy6I"IDHHU^L_bfbjbjkrbsLsvzv~v~  @G  JN  JQ  JQ  @Q  TZ  @Z  w[  M[  #[  \  ]  ]r$   c                     X-   U-
  S-  $ r   r1   )rX   r|   r[   s      r"   rH   rH     s    ".1OOSVVVr$   c                 r    [         R                  " U 5      nSSU S-
  -  -   SU-  U-  SUS-  -
  -  -   nUS-  $ )Ngd1^^q@g9,6ŏv@g   ,BAgKLol9?r   iNr   )r9   get_julian_century)rO   jcsidereal_times      r"   r}   r}     sS    		!	!"	%B!_Y%GH;Y[K[^`K`dehjmuhuduKvvM3r$   c           	        ^ ^
 [         R                  n/ n/ n[         R                  " 5       m
[        U U
4S jS 5       5      n[         R                  n[        [        U5      5       H  nSn[        [        U5      5       H  nXtU   XV   U   -  -  nM     UR                  X   S   X   S   T -  -   [        R                  " [        R                  " U5      5      -  5        UR                  X   S   X   S   T -  -   [        R                  " [        R                  " U5      5      -  5        M     [        U5      S-  [        U5      S-  S	.n	U	$ )
Nc              3   :   >#    U  H  nTU   " T5      v   M     g 7frm   r1   ).0krQ   ps     r"   	<genexpr>get_nutation.<locals>.<genexpr>  s)      
  	
!S		s   )MeanElongationOfMoonMeanAnomalyOfSunMeanAnomalyOfMoonArgumentOfLatitudeOfMoonLongitudeOfAscendingNoder   r   r   r&      g    *A)r|   	obliquity)r   nutation_coefficientsget_aberration_coeffslistaberration_sin_termsr   lenappendr(   r*   ro   r+   sum)rQ   abcdnutation_longnutation_obliquer   yisigmaxyjrW   r   s   `         @r"   rB   rB     s.   **DM'')A

	A 	&&A3t9s1vAtad1g~%G  	dgajDGAJ,<=$,,W^J_A``atwqzC/?!@DHHT\\ZaMbDc cd  "-0;3O_K`akKklHOr$   c                    U n[         R                  " U5      n[         R                  " U5      n[         R                  " U5      nSU-  [         R                  " U5      -  [         R                  " U5      -  n[         R                  " U5      U[         R                  " U5      -  [         R                  " U5      -  -
  n	[         R                  " X5      n
[         R
                  " U
5      $ r   )r(   ro   r*   r+   r   rr   )rM   rV   r]   r\   prdehp_radlha_radgsd_radr   r-   parallaxs              r"   rI   rI   .  s    
#Cll9:Gll+,Gll56G
S488G$$txx'88A	'	S488G#44txx7HH	HAzz!H<<!!r$   c                     [         R                  " [        U5      5      n[         R                  " U5      n[         R                  " U5      U [         R                  " U5      -  [        R
                  -  -   $ rm   )r(   ro   r   r+   r   earth_radiusrL   r   flattened_latitude_radru   s       r"   r7   r7   8  sT    !\\*@*JK<<)L88*+y488L;Q/QT]TjTj/jkkr$   c                     [         R                  " [        U5      5      n[         R                  " U5      nS[         R                  " U5      -  U [         R                  " U5      -  [        R
                  -  -   $ r   )r(   ro   r   r*   r   r   r   s       r"   r8   r8   =  sZ    !\\*@*JK<<)L!788IQ]H^<^ajawaw<wxxr$   c                 <    [        U [        R                  5      S-  $ r   )r   r   sun_earth_distance_coeffsr   s    r"   r@   r@   B  s    S)==>DDr$   c           	          SnSnUnU S-  S-  nSU-  S-  [         R                  " [         R                  " USUS-   -  -   5      5      -  n[         R                  " US	X4-   -  :  Xg-  S
5      nU$ )Ng4?g	h"?gp=
ף@gRQ?g     @g      N@g$@gq=
ףp@g      r   )r(   r   ro   r   )	rg   rf   rh   
sun_radiusatmos_refracttear   r-   del_es	            r"   rd   rd   E  s     JM
%C 	54At#dhht||C4tCT<U/V&WWAJJsdJ$>??ub"E Lr$   c                     [         R                  " U5      S-  [         R                  " U5      -   SU -  -   [        [         R                  " U5      5      -   S-  $ )zfreturns solar time in hours for the specified longitude and time, accurate only to the nearest minute.<      )r(   tm_hourtm_minr.   rn   )r   r5   s     r"   r   r   Z  sR     \\$"$t{{4'881};LLO_`d`l`lmq`rOss
r$   c                    [         R                  " U 5      n[         R                  " U5      n[         R                  " U5      n[         R                  " U5      n[         R                  " U5      [         R                  " U5      -  [         R                  " U5      [         R                  " U5      -  -
  nS[         R
                  " [         R                  " Xg5      5      -   S-  $ )z2West is negative, East is positive, Masters p. 395g     f@r   )r(   ro   r*   r+   r   rr   r   )r_   r   r`   tlha_radru   tsd_radr   r-   s           r"   re   re   g  s    ||89H<<)Lll67GATXXl33dhhw6G$((S_J`6``ADLLA!122c99r$   c           	         [         R                  " U 5      n[         R                  " U5      n[         R                  " U5      n[         R                  " [         R                  " [         R                  " U5      [         R                  " U5      -  [         R
                  " U5      [         R
                  " U5      -  [         R
                  " U5      -  -   5      5      $ rm   )r(   ro   rr   rs   r*   r+   )r   r`   r_   ru   r   r   s         r"   rc   rc   p  s    <<)Lll67G||89H<<		488L#9DHHW<M#MQUQYQYZfQgjnjrjrszj{Q{  C  G  G  HP  Q  RQ  #Q  R  S  Sr$   c                 
    X-
  $ rm   r1   )r]   r^   s     r"   rJ   rJ   v  s    ::r$   c                 &   [         R                  " U 5      nUn[         R                  " U5      n[         R                  " U5      n[         R                  " U5      n	[         R                  " U5      U[         R                  " U5      -  -
  [         R                  " U5      -  n
[         R                  " U5      U[         R                  " U5      -  [         R                  " U	5      -  -
  n[         R                  " [         R
                  " X5      5      $ rm   )r(   ro   r*   r+   rr   r   )r\   rN   rV   r^   r]   r   padr   psra_radr   r   r-   s               r"   rK   rK   y  s    ll56G
"Cll9:G||89Hll+,G	'	S488G#44	48JJAS488G#44txx7HHIA<<

1())r$   c                 R    [        X4U5      n[        XX&5      n[        X4U5      nXx-   $ rm   )rG   rI   rF   )	rM   rV   r]   rZ   rY   rS   gsdpsragsras	            r"   #get_topocentric_sun_right_ascensionr    s4    
()?Zm
nC+,Egw}D-.D_rsD;r$   c                 >    [        XU5      nSU-
  [        X4U5      -
  $ )NZ   )rc   rd   )r   r`   r_   rg   rf   r   s         r"   get_topocentric_zenith_angler    s&    
)(Qm
nC8/sKKKr$   c                     U S-  nSSU-  -
  SUS-  -  -
  SUS-  -  -   SUS	-  -  -
  S
US-  -  -
  SUS-  -  -
  SUS-  -  -   SUS-  -  -   SUS-  -  -   SUS-  -  -   nUS-  US   -   $ )Ng      $@gJ+י@gHzH@g?r&   g     =@r   gq=
ףI@r   g=
ףp5o@   gfffffC@   g{Gz@   gQ;@   g)\(@	   g@
   r0   r   r1   )rR   rW   umean_obliquitys       r"   rD   rD     s    DA'A+.$a-@GaSTfDTUqAv~!q&*-2Q!V^=@DqAvOqAv~a-),017N<N V#x'<<<r$   )r   )4__doc__ r   r(   r   r   r   r9   r   tzinfo_checkr   r#   r.   r4   ra   standard_temperaturestandard_pressurerj   r   ry   rC   rE   r   r   r   rp   rA   r   r>   r?   rG   rF   r   r   rq   r   rH   r}   rB   rI   r7   r8   r@   rd   r   re   rc   rJ   rK   r  r  rD   r1   r$   r"   <module>r     s  $
       (K2 E E@ >?(==%77% %: @A(==)JeJe
? 
? = =uH  "[/H/9	%V] & &]W@"l
y
E* 
 
:S;*L=r$   