
    R1iH*                         d Z ddlmZmZmZmZmZmZmZ ddl	m
Z
 ddlmZmZ ddlmZ  eg d      Zedddf   Z eg d	      Zedddf   Zd
 Zd Zd Zd Zd Zd ZddZd Zd ZeeeeeeeeeeeeeeedZy)u  Routines for computing magnitudes.

Planetary routines adapted from:

https://arxiv.org/pdf/1808.01973.pdf

Which links to:

https://sourceforge.net/projects/planetary-magnitudes/

Which has directories with three successive versions of their magnitude
computation, the most recent of which provides the files on which this
Python code is based:

Ap_Mag_V3.f90
Ap_Mag_Output_V3.txt
Ap_Mag_Input_V3.txt

* ``r`` planet’s distance from the Sun.
* ``delta`` from Earth?
* ``ph_ang`` illumination phase angle (degrees)

    )arrayclipexplog10nansinwhere   )RAD2DEG)angle_between	length_of)_target_name)g Y?g1*?gs"?N)gmn_"˿g`@!gkпc                 L   | j                   }t        j                  |      }|t        |      }t	        d|z        | j
                  j                  j                  }| j                  j                  }||z   }t        |      }t        |      }t        ||      t        z  }	|t        u rat        |j                        dkD  rt        }
nt        }
t        |
|      }|t        z  dz
  }t        |
|      }|t        z  dz
  } ||||	||      S |t         u rat        |j                        dkD  rt"        }
nt$        }
t        |
|      }|t        z  dz
  }t        |
|      }|t        z  dz
  } ||||	||      S |t&        u r!| j(                  j*                  } ||||	|      S  ||||	      S )u  Given the position of a planet, return its visual magnitude.

    >>> from skyfield.api import load
    >>> from skyfield.magnitudelib import planetary_magnitude
    >>> ts = load.timescale()
    >>> t = ts.utc(2020, 7, 31)
    >>> eph = load('de421.bsp')
    >>> astrometric = eph['earth'].at(t).observe(eph['jupiter barycenter'])
    >>> print('%.2f' % planetary_magnitude(astrometric))
    -2.73

    The formulae are from `Mallama and Hilton “Computing Apparent
    Planetary Magnitude for the Astronomical Almanac” (2018)
    <https://arxiv.org/pdf/1808.01973.pdf>`_.  Two of the formulae have
    inherent limits:

    * Saturn’s magnitude is unknown and the function will return ``nan``
      (the floating-point value “Not a Number”) if the “illumination
      phase angle” — the angle of the vertex observer-Saturn-Sun —
      exceeds 6.5°.

    * Neptune’s magnitude is unknown and will return ``nan`` if the
      illumination phase angle exceeds 1.9° and the position's date is
      before the year 2000.

    And one formula is not fully implemented (though contributions are
    welcome!):

    * Skyfield does not compute which features on Mars are facing the
      observer, which can introduce an error of ±0.06 magnitude.

    z)cannot compute the magnitude of target %sr
   g     V@)target
_FUNCTIONSgetr   
ValueErrorcenter_barycentricxyzaur   r   r   _saturn_magnitudelenshape_SATURN_POLE_2D_SATURN_POLE_uranus_magnitude_URANUS_POLE_2D_URANUS_POLE_neptune_magnitudetJ)positionr   functionnamesun_to_observerobserver_to_planetsun_to_planetrdeltaph_angpoleasun_sub_latobserver_sub_latyears                  Y/home/cursorai/projects/iching/venv/lib/python3.12/site-packages/skyfield/magnitudelib.pyplanetary_magnituder1   $   s   B __F~~f%HF#DtKLL 115588O!#&88M- A()E=*<=GF$$}""#a'"DD$.'kD($ 23w;-5&+7GHH$$}""#a'"DD$.'kD($ 23w;-5&+7GHH%%zz||5&$//Auf%%    c                     dt        | |z        z  }d|z  d|dz  z  z
  d|dz  z  z   d|dz  z  z
  d	|dz  z  z   d
|dz  z  z
  }d|z   |z   S )N   gP}:3?gšȤZ?   ga	?   gPb>   gn>g!=   gV-㿩r   r(   r)   r*   distance_mag_factorph_ang_factors        r0   _mercury_magnituder=   v   s    eAI..V
vqy
 	!
vqy
 	! vqy
 	! vqy
 		!
 vqy
 	!  ''-77r2   c                     dt        | |z        z  }|dk  }t        |dd      }t        |dd      }t        |dd      }t        |d	d      }t        |d
d      }	|	}
||||fD ]  }|
|z  }
|
|z  }
 d|z   |
z   S )Nr4   gfffffvd@        gb('n@g1{vQgvöEg8)q)8?g7_.?gW];Ǿgrh1C>gK7r   r	   )r(   r)   r*   r;   	conditiona0a1a2a3a4r<   r,   s               r0   _venus_magnituderG      s    eAI..I	y#0	1B	y+}	5B	y+}	5B	y+s	+B	y+s	+BMR^  ''-77r2   c                 P    dt        | |z        z  }d|z  d|dz  z  z   }d|z   |z   S )Nr4   gR\U]Qg̼*?r5   gQr9   r:   s        r0   _earth_magnituderI      s?    eAI..')fai*??M&&66r2   c                     dt        | | z        z  }dt        ||z        z  }||z   }d}||k  }t        |dd      }t        |dd      }	||z  |	|dz  z  z   }
d}d}t        ||k  d	d
      }|||
z   |z   |z   z  }|S )N      @g      I@gIf6?gXgot{!g-;6?r5   r?   gV-grh|׿r@   )r(   r)   r*   r_mag_factordelta_mag_factorr;   geocentric_phase_angle_limitrA   r,   br<   mag_corr_rotmag_corr_orbap_mags                 r0   _mars_magnituderS      s    q1u%LU55=11&)99#' 66IiI.Aii0AJVQY.M* LL 69966JF
!M1L@<OOFMr2   c           	          dt        | |z        z  }d}|dz  }t        ||k  d|z  dz
  |z  dt        d|z  dz   |z  d	z
  |z  d
z
  |z  dz
  |z  dz         z        }t        ||k  d|z   |z   d|z   |z         }|S )Nr4   g      (@g     f@Za/D?VF?8?g      gjtgFx@gX9v?gZd;?g&1?g      ?g
ףp="gB`""r@   )r(   r)   r*   r;   rN   	ph_ang_pir<   rR   s           r0   _jupiter_magnituderX      s    eAI..#' I..	F	W	$.u)#e+y85@IM"#%*+.78:=>
 	
M ..$$}4$$}4F
 Mr2   c                    dt        | | z        z  }dt        ||z        z  }||z   }||z  }	|	dk\  }
|	t        |
dd      z  }t        |
|d      }d}d}||k  ||k  z  }t        |t        |ddt        |t        z        z  z
  d|z  z   d	t        |t        z        z  t	        d
|z        z  z
  dd|z  z
  d|dz  z  z         t        ||kD  | z  dd|z  z   d|dz  z  z   d|dz  z  z
  d|dz  z  z   t
                    }||z   }|S )NrK   r?   g      ?g      @g      ;@g!g333333?g9v?gx&1?g      gfffff!rV   rU   r5   gzG!g,m' 0?gXB߂1?g8D>r6   g_6_y4>r7   )r   r	   r   r   r   r   )r(   r)   r*   r-   earth_sub_latringsrL   rM   r;   product
signs_samesquare_rootsub_lat_geocrN   geocentric_inclination_limitis_within_geocentric_boundsrR   s                    r0   r   r      s    q1u%LU55=11&)99
 M)GCJU:sC88K[#6L $' #'  
/	/77	9  
 # US!788856>Ic,011C4GGH FVO#g	&99		
 	22v> Hv%%619(<<"#$,vqy$89 		
F0 ))FMr2   c                     dt        | |z        z  }t        |      t        |      z   dz  }d|z  }d}d|z   |z   }	|	t        ||kD  d|z  dz   |z  d      z  }	|	S )	Ng      @g       @gyCnKg@gq=
ףpgiTd?guBYz?r?   )r   absr	   )
r(   r)   r*   sun_sub_lat_planetogearth_sub_lat_planetogr;   sub_lat_planetogsub_lat_factorrN   rR   s
             r0   r   r     s    q5y 11014569<= 00N#& ))N:F
e--	F	X	%/ F
 Mr2   c           
          dt        | | z        z  }dt        ||z        z  }||z   }t        dd|dz
  z  z
  dd      }||z  }d}t        ||kD  t        |dk\  |d|z  z   d	|d
z  z  z   t              |      }|S )NrK   g(\g_vOv?g     @g      gffffff?g     @@gkD?g5?r5   )r   r   r	   r   )	r(   r)   r*   r/   rL   rM   r;   rR   rN   s	            r0   r   r     s    q1u%LU55=11&)99 %&D6M22E5AF
!!F#& -- 	FNX&&FAI)==	
 	F Mr2   )   i+  i  i  iW  i  i  i  r
   r5   r7   r4   r8         )T)__doc__numpyr   r   r   r   r   r   r	   	constantsr   	functionsr   r   	naifcodesr   r   r   r   r   r1   r=   rG   rI   rS   rX   r   r   r   r    r2   r0   <module>rr      s   . ; : :  / # 9:q$w'<=q$w'P&d
887
&P&3j: 
							 #
r2   