o
    Dfi                     @   s\  d Z ddlZddlmZmZmZ ddlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZ ddlmZ dd Z d	d
 Z!dd Z"dd Z#dd Z$dd Z%dd Z&dd Z'dd Z(dd Z)dd Z*dd Z+dd  Z,d!d" Z-d#d$ Z.d%d& Z/d'd( Z0d)d* Z1e#e$e%e&e'e(e)e*e+e,e-e.e/e0d+Z2d,e1iZ3d-d. Z4d/d0 Z5d1d2 Z6d3d4 Z7d5d6 Z8d7d8 Z9d9d: Z:d;d< Z;d=d> Z<d?d@ Z=dAdB Z>dCdD Z?dEdF Z@dGdH ZAdIdJ ZBdKdL ZCdMdN ZDi dOe5dPe6dQe7dRe7dSe8dTe9dUe9dVe:dWe;dXe;dYe<dZe=d[e>d\e>d]e?d^e@d_eAd`eBiZEeCeCeCeCeDdaZFdS )bz
This module contains mappings necessary to convert from
a CRS to a CF-1.8 compliant projection.

http://cfconventions.org/cf-conventions/cf-conventions.html#appendix-grid-mappings

    N)Datum	EllipsoidPrimeMeridian)AlbersEqualAreaConversionAzimuthalEquidistantConversion GeostationarySatelliteConversion HotineObliqueMercatorBConversion#LambertAzimuthalEqualAreaConversion"LambertConformalConic1SPConversion"LambertConformalConic2SPConversion%LambertCylindricalEqualAreaConversion*LambertCylindricalEqualAreaScaleConversionMercatorAConversionMercatorBConversionOrthographicConversionPolarStereographicAConversionPolarStereographicBConversionPoleRotationNetCDFCFConversionSinusoidalConversionStereographicConversionTransverseMercatorConversionVerticalPerspectiveConversion)CustomDatumCustomEllipsoidCustomPrimeMeridian)CRSErrorc                 C   s  |  d}|r|dvrzt|W S  ty   Y nw d }|  d}zt|p'd|  d|  d|  d|  dd	}W n tyO   |rM|dvrMt|}Y nw d }|  d
}zt|p\d| d d}W n tyw   |ru|dvrut|}Y nw |s||rt	|pd|pd|pddS d S )Nhorizontal_datum_name)	undefinedunknownreference_ellipsoid_namer   semi_major_axissemi_minor_axisinverse_flatteningearth_radius)namer    r!   r"   radiusprime_meridian_namelongitude_of_prime_meridian)r$   	longitudezWGS 84	Greenwich)r$   	ellipsoidprime_meridian)
getr   	from_namer   r   r   r   KeyErrorr   r   )	cf_params
datum_namer*   ellipsoid_namer+   r&    r2   J/home/ubuntu/webapp/venv/lib/python3.10/site-packages/pyproj/crs/_cf1x8.py_horizontal_datum_from_params$   sR   






r4   c                 C   s6   t | ts| S | d}t|dkrdd |D S | S )z=
    Attempt to convert string to list if it is a string
    ,   c                 S   s   g | ]}t | qS r2   )floatstrip).0svalr2   r2   r3   
<listcomp>X   s    z'_try_list_if_string.<locals>.<listcomp>)
isinstancestrsplitlen)	input_str	val_splitr2   r2   r3   _try_list_if_stringP   s   

rB   c                 C   s@   t | } zt| }d }W ||fS  ty   | \}}Y ||fS w )N)rB   r7   	TypeError)standard_parallelfirst_parallelsecond_parallelr2   r2   r3   _get_standard_parallels\   s   
rG   c              
   C   sH   t | d \}}t||pd| dd| dd| dd| dddS )zX
    http://cfconventions.org/cf-conventions/cf-conventions.html#_albers_equal_area
    rD           latitude_of_projection_originlongitude_of_central_meridianfalse_eastingfalse_northinglatitude_first_parallellatitude_second_parallellatitude_false_originlongitude_false_origineasting_false_originnorthing_false_origin)rG   r   r,   r/   rE   rF   r2   r2   r3   _albers_conical_equal_areaf   s   



rU   c                 C   0   t | dd| dd| dd| dddS )[
    http://cfconventions.org/cf-conventions/cf-conventions.html#azimuthal-equidistant
    rI   rH   longitude_of_projection_originrK   rL   latitude_natural_originlongitude_natural_originrK   rL   )r   r,   r/   r2   r2   r3   _azimuthal_equidistantw      



r]   c              
   C   sn   z| d }W n t y   ddd| d   }Y nw t|| d | dd| d	d| d
d| dddS )_
    http://cfconventions.org/cf-conventions/cf-conventions.html#_geostationary_projection
    sweep_angle_axisyx)rb   ra   fixed_angle_axisperspective_point_heightrI   rH   rX   rK   rL   )r`   satellite_heightrZ   r[   rK   rL   )r.   lowerr   r,   )r/   r`   r2   r2   r3   _geostationary   s   



rg   c                 C   rV   )b
    http://cfconventions.org/cf-conventions/cf-conventions.html#lambert-azimuthal-equal-area
    rI   rH   rX   rK   rL   rY   )r	   r,   r\   r2   r2   r3   _lambert_azimuthal_equal_area   r^   ri   c              
   C   st   t | d \}}|dur&t||| dd| dd| dd| dddS t|| dd| dd| ddd	S )
X
    http://cfconventions.org/cf-conventions/cf-conventions.html#_lambert_conformal
    rD   NrI   rH   rJ   rK   rL   rM   rY   )rG   r   r,   r
   rT   r2   r2   r3   _lambert_conformal_conic   s$   






rk   c                 C   sd   d| v rt | d | dd| dd| dddS t| dd| dd| dd| dddS )	e
    http://cfconventions.org/cf-conventions/cf-conventions.html#_lambert_cylindrical_equal_area
    !scale_factor_at_projection_originrJ   rH   rK   rL   )scale_factor_natural_originr[   rK   rL   rD   rN   r[   rK   rL   )r   r,   r   r\   r2   r2   r3   _lambert_cylindrical_equal_area   s   





rp   c                 C   sn   d| v rt | dd| dd| dd| dd| d dS t| dd| dd| dd| dddS )	O
    http://cfconventions.org/cf-conventions/cf-conventions.html#_mercator
    rm   rD   rH   rX   rK   rL   rZ   r[   rK   rL   rn   ro   )r   r,   r   r\   r2   r2   r3   	_mercator   s    


	



rs   c                 C   s:   t | d | d | d d| dd| dd| ddd	S )
W
    http://cfconventions.org/cf-conventions/cf-conventions.html#_oblique_mercator
    rI   rX   azimuth_of_central_linerH   rm         ?rK   rL   )latitude_projection_centrelongitude_projection_centreazimuth_initial_line!angle_from_rectified_to_skew_gridscale_factor_on_initial_lineeasting_projection_centrenorthing_projection_centre)r   r,   r\   r2   r2   r3   _oblique_mercator   s   

r~   c                 C   rV   )S
    http://cfconventions.org/cf-conventions/cf-conventions.html#_orthographic
    rI   rH   rX   rK   rL   rY   )r   r,   r\   r2   r2   r3   _orthographic   r^   r   c              	   C   sb   d| v rt | d | d | dd| dddS t| d | d | dd| dd| dd	d
S )Y
    http://cfconventions.org/cf-conventions/cf-conventions.html#polar-stereographic
    rD   %straight_vertical_longitude_from_polerK   rH   rL   )latitude_standard_parallellongitude_originrK   rL   rI   rm   rv   rr   )r   r,   r   r\   r2   r2   r3   _polar_stereographic  s    



r   c                 C   s&   t | dd| dd| dddS )Q
    http://cfconventions.org/cf-conventions/cf-conventions.html#_sinusoidal
    rX   rH   rK   rL   )r[   rK   rL   )r   r,   r\   r2   r2   r3   _sinusoidal  s
   


r   c              	   C   :   t | dd| dd| dd| dd| dddS )	T
    http://cfconventions.org/cf-conventions/cf-conventions.html#_stereographic
    rI   rH   rX   rK   rL   rm   rv   rr   )r   r,   r\   r2   r2   r3   _stereographic"     



r   c              	   C   r   )	Z
    http://cfconventions.org/cf-conventions/cf-conventions.html#_transverse_mercator
    rI   rH   rJ   rK   rL    scale_factor_at_central_meridianrv   rr   )r   r,   r\   r2   r2   r3   _transverse_mercator1  r   r   c              	   C   s6   t | d | dd| dd| dd| dddS )Z
    http://cfconventions.org/cf-conventions/cf-conventions.html#vertical-perspective
    rd   rI   rH   rX   rK   rL   )viewpoint_heightlatitude_topocentric_originlongitude_topocentric_originrK   rL   )r   r,   r\   r2   r2   r3   _vertical_perspective@  s   


r   c                 C   s   t | d | d | dddS )S
    http://cfconventions.org/cf-conventions/cf-conventions.html#_rotated_pole
    grid_north_pole_latitudegrid_north_pole_longitudenorth_pole_grid_longituderH   )r   r   r   )r   r,   r\   r2   r2   r3   _rotated_latitude_longitudeO  s
   
r   )albers_conical_equal_areaazimuthal_equidistantgeostationarylambert_azimuthal_equal_arealambert_conformal_coniclambert_cylindrical_equal_areamercatoroblique_mercatororthographicpolar_stereographic
sinusoidalstereographictransverse_mercatorvertical_perspectiverotated_latitude_longitudec                 C   s,   i }| j D ]}|j||j dd< q|S )N _)paramsvaluer$   rf   replace)	operation
param_dictparamr2   r2   r3   _to_dictp  s   
r   c                 C   s6   t | }d|d |d f|d |d |d |d dS )	zY
    http://cfconventions.org/cf-conventions/cf-conventions.html#_albers_equal_area

    r   !latitude_of_1st_standard_parallel!latitude_of_2nd_standard_parallellatitude_of_false_originlongitude_of_false_origineasting_at_false_originnorthing_at_false_origingrid_mapping_namerD   rI   rJ   rK   rL   r   
conversionr   r2   r2   r3   !_albers_conical_equal_area__to_cfw  s   r   c                 C   (   t | }d|d |d |d |d dS )rW   r   latitude_of_natural_originlongitude_of_natural_originrK   rL   r   rI   rX   rK   rL   r   r   r2   r2   r3   _azimuthal_equidistant__to_cf     r   c                 C   sT   t | }d}| j dddrd}d||d |dd	|d
 |d |d dS )r_   ra   r   r   z	(sweep_x)rb   r   re   r   rH   r   rK   rL   )r   r`   rd   rI   rX   rK   rL   )r   method_namerf   r   endswithr,   )r   r   r`   r2   r2   r3   _geostationary__to_cf  s   
r   c                 C   r   )rh   r   r   r   rK   rL   r   r   r   r2   r2   r3   $_lambert_azimuthal_equal_area__to_cf  r   r   c                 C   sf   t | }| j dr#d|d |d f|d |d |d |d d	S d|d
 |d |d |d dS )rj   z(2sp)r   r   r   r   r   r   r   r   r   r   rK   rL   r   rD   rJ   rK   rL   r   r   rf   r   r   r2   r2   r3   _lambert_conformal_conic__to_cf  s"   r   c                 C   r   )rl   r   r   r   rK   rL   r   r   r   r2   r2   r3   &_lambert_cylindrical_equal_area__to_cf  r   r   c                 C   sf   t | }| j dddr#d|d |d |d |d |d	 d
S d|d |d |d |d dS )rq   r   r   z(variant_a)r   r   r   rK   rL   scale_factor_at_natural_origin)r   rD   rX   rK   rL   rm   r   )r   rD   rX   rK   rL   )r   r   rf   r   r   r   r2   r2   r3   _mercator__to_cf  s"   r   c                 C   sJ   t | }|d dkrtd d|d |d |d |d |d	 |d
 dS )rt   rz   r   zDangle from rectified to skew grid parameter lost in conversion to CFr   latitude_of_projection_centrelongitude_of_projection_centreazimuth_of_initial_liner{   easting_at_projection_centrenorthing_at_projection_centre)r   rI   rX   ru   rm   rK   rL   )r   warningswarnr   r2   r2   r3   _oblique_mercator__to_cf  s   r   c                 C   r   )r   r   r   r   rK   rL   r   r   r   r2   r2   r3   _orthographic__to_cf  r   r   c                 C   s^   t | }| j drd|d |d |d |d dS d|d |d	 |d |d |d
 dS )r   z(variant b)r   latitude_of_standard_parallellongitude_of_originrK   rL   )r   rD   r   rK   rL   r   r   r   )r   rI   r   rK   rL   rm   r   r   r2   r2   r3   _polar_stereographic__to_cf  s   r   c                 C   "   t | }d|d |d |d dS )r   r   r   rK   rL   )r   rX   rK   rL   r   r   r2   r2   r3   _sinusoidal__to_cf5  s   r   c                 C   .   t | }d|d |d |d |d |d dS )r   r   r   r   rK   rL   r   )r   rI   rX   rK   rL   rm   r   r   r2   r2   r3   _stereographic__to_cfB     r   c                 C   r   )r   r   r   r   rK   rL   r   )r   rI   rJ   rK   rL   r   r   r   r2   r2   r3   _transverse_mercator__to_cfQ  r   r   c                 C   r   )r   r   r   latitude_of_topocentric_originlongitude_of_topocentric_originrK   rL   )r   rd   rI   rX   rK   rL   r   r   r2   r2   r3   _vertical_perspective__to_cf`  r   r   c                 C   s&   t | }d|d |d d |d dS )r   r   o_lat_plon_0   o_lon_pr   r   r   r   r   r   r2   r2   r3   "_rotated_latitude_longitude__to_cfo  s   
r   c                 C   r   )z
    http://cfconventions.org/cf-conventions/cf-conventions.html#_rotated_pole

    https://github.com/OSGeo/PROJ/pull/2835
    r   z/grid_north_pole_latitude_(netcdf_cf_convention)z0grid_north_pole_longitude_(netcdf_cf_convention)z0north_pole_grid_longitude_(netcdf_cf_convention)r   r   r   r2   r2   r3   _pole_rotation_netcdf__to_cf}  s   r   albers_equal_areamodified_azimuthal_equidistantz!geostationary_satellite_(sweep_x)z!geostationary_satellite_(sweep_y)r   zlambert_conic_conformal_(2sp)zlambert_conic_conformal_(1sp)r   zmercator_(variant_a)zmercator_(variant_b)z#hotine_oblique_mercator_(variant_b)r   zpolar_stereographic_(variant_a)zpolar_stereographic_(variant_b)r   r   r   r   )zproj ob_tran o_proj=longlatzproj ob_tran o_proj=lonlatzproj ob_tran o_proj=latlonzproj ob_tran o_proj=latlongz$pole rotation (netcdf cf convention))G__doc__r   pyproj._crsr   r   r   pyproj.crs.coordinate_operationr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   pyproj.crs.datumr   r   r   pyproj.exceptionsr   r4   rB   rG   rU   r]   rg   ri   rk   rp   rs   r~   r   r   r   r   r   r   r   _GRID_MAPPING_NAME_MAP!_GEOGRAPHIC_GRID_MAPPING_NAME_MAPr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _INVERSE_GRID_MAPPING_NAME_MAP)_INVERSE_GEOGRAPHIC_GRID_MAPPING_NAME_MAPr2   r2   r2   r3   <module>   s    T,
	

