a
    1$ei                     @   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 ZDe5e6e7e7e8e9e9e:e;e;e<e=e>e>e?e@eAeBdOZEeCeCeCeCeDdPZFdS )Qz
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}|r6|dvr6zt|W S  ty4   Y n0 d }|  d}z2t|pNd|  d|  d|  d|  dd	}W n( ty   |r|dvrt|}Y n0 d }|  d
}zt|pd| d d}W n( ty   |r|dvrt|}Y n0 |s|rt	|pd|pd|pddS d S )NZhorizontal_datum_name)	undefinedunknownZreference_ellipsoid_namer   semi_major_axissemi_minor_axisinverse_flatteningZearth_radius)namer   r   r    Zradiusprime_meridian_nameZlongitude_of_prime_meridian)r!   Z	longitudezWGS 84Z	Greenwich)r!   	ellipsoidprime_meridian)
getr   	from_namer   r   r   r   KeyErrorr   r   )	cf_paramsZ
datum_namer#   Zellipsoid_namer$   r"    r)   M/var/www/html/django/DPS/env/lib/python3.9/site-packages/pyproj/crs/_cf1x8.py_horizontal_datum_from_params$   sH    





r+   c                 C   s6   t | ts| S | d}t|dkr2dd |D S | S )z=
    Attempt to convert string to list if it is a string
    ,   c                 S   s   g | ]}t | qS r)   )floatstrip).0Zsvalr)   r)   r*   
<listcomp>X       z'_try_list_if_string.<locals>.<listcomp>)
isinstancestrsplitlen)Z	input_strZ	val_splitr)   r)   r*   _try_list_if_stringP   s    

r7   c                 C   s<   t | } zt| }d }W n ty2   | \}}Y n0 ||fS )N)r7   r.   	TypeError)standard_parallelfirst_parallelsecond_parallelr)   r)   r*   _get_standard_parallels\   s    r<   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
    r9           latitude_of_projection_originlongitude_of_central_meridianfalse_eastingfalse_northinglatitude_first_parallelZlatitude_second_parallelZlatitude_false_originZlongitude_false_originZeasting_false_originZnorthing_false_origin)r<   r   r%   r(   r:   r;   r)   r)   r*   _albers_conical_equal_areaf   s    



rE   c                 C   s0   t | dd| dd| dd| dddS )[
    http://cfconventions.org/cf-conventions/cf-conventions.html#azimuthal-equidistant
    r>   r=   longitude_of_projection_originr@   rA   latitude_natural_originlongitude_natural_originr@   rA   )r   r%   r(   r)   r)   r*   _azimuthal_equidistantw   s    



rL   c              
   C   sn   z| d }W n( t y4   ddd| d   }Y n0 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)rP   rO   Zfixed_angle_axisperspective_point_heightr>   r=   rG   r@   rA   )rN   satellite_heightrI   rJ   r@   rA   )r'   lowerr   r%   )r(   rN   r)   r)   r*   _geostationary   s    



rT   c                 C   s0   t | dd| dd| dd| dddS )b
    http://cfconventions.org/cf-conventions/cf-conventions.html#lambert-azimuthal-equal-area
    r>   r=   rG   r@   rA   rH   )r	   r%   rK   r)   r)   r*   _lambert_azimuthal_equal_area   s    



rV   c              
   C   st   t | d \}}|durLt||| 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
    r9   Nr>   r=   r?   r@   rA   rB   rH   )r<   r   r%   r
   rD   r)   r)   r*   _lambert_conformal_conic   s$    






rX   c                 C   sd   d| v r4t | 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_originr?   r=   r@   rA   )scale_factor_natural_originrJ   r@   rA   r9   rC   rJ   r@   rA   )r   r%   r   rK   r)   r)   r*   _lambert_cylindrical_equal_area   s    





r]   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
    rZ   r9   r=   rG   r@   rA   rI   rJ   r@   rA   r[   r\   )r   r%   r   rK   r)   r)   r*   	_mercator   s     


	



r`   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
    r>   rG   azimuth_of_central_liner=   rZ         ?r@   rA   )Zlatitude_projection_centreZlongitude_projection_centreZazimuth_initial_line!angle_from_rectified_to_skew_gridscale_factor_on_initial_lineZeasting_projection_centreZnorthing_projection_centre)r   r%   rK   r)   r)   r*   _oblique_mercator   s    

rf   c                 C   s0   t | dd| dd| dd| dddS )S
    http://cfconventions.org/cf-conventions/cf-conventions.html#_orthographic
    r>   r=   rG   r@   rA   rH   )r   r%   rK   r)   r)   r*   _orthographic   s    



rh   c              	   C   sb   d| v r0t | 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
    r9   %straight_vertical_longitude_from_poler@   r=   rA   )Zlatitude_standard_parallelZlongitude_originr@   rA   r>   rZ   rc   r_   )r   r%   r   rK   r)   r)   r*   _polar_stereographic  s     



rk   c                 C   s&   t | dd| dd| dddS )Q
    http://cfconventions.org/cf-conventions/cf-conventions.html#_sinusoidal
    rG   r=   r@   rA   )rJ   r@   rA   )r   r%   rK   r)   r)   r*   _sinusoidal  s
    


rm   c              	   C   s:   t | dd| dd| dd| dd| dddS )	T
    http://cfconventions.org/cf-conventions/cf-conventions.html#_stereographic
    r>   r=   rG   r@   rA   rZ   rc   r_   )r   r%   rK   r)   r)   r*   _stereographic"  s    



ro   c              	   C   s:   t | dd| dd| dd| dd| dddS )	Z
    http://cfconventions.org/cf-conventions/cf-conventions.html#_transverse_mercator
    r>   r=   r?   r@   rA    scale_factor_at_central_meridianrc   r_   )r   r%   rK   r)   r)   r*   _transverse_mercator1  s    



rr   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
    rQ   r>   r=   rG   r@   rA   )viewpoint_heightZlatitude_topocentric_originZlongitude_topocentric_originr@   rA   )r   r%   rK   r)   r)   r*   _vertical_perspective@  s    


ru   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_longituder=   )rw   rx   ry   )r   r%   rK   r)   r)   r*   _rotated_latitude_longitudeO  s
    
rz   )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!   rS   replace)Z	operationZ
param_dictparamr)   r)   r*   _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_namer9   r>   r?   r@   rA   r   
conversionr   r)   r)   r*   !_albers_conical_equal_area__to_cfw  s    r   c                 C   s(   t | }d|d |d |d |d dS )rF   r|   latitude_of_natural_originlongitude_of_natural_originr@   rA   r   r>   rG   r@   rA   r   r   r)   r)   r*   _azimuthal_equidistant__to_cf  s    r   c                 C   sT   t | }d}| j dddr(d}d||d |dd	|d
 |d |d dS )rM   rO   r   r   z	(sweep_x)rP   r}   rR   r   r=   r   r@   rA   )r   rN   rQ   r>   rG   r@   rA   )r   method_namerS   r   endswithr%   )r   r   rN   r)   r)   r*   _geostationary__to_cf  s    
r   c                 C   s(   t | }d|d |d |d |d dS )rU   r~   r   r   r@   rA   r   r   r   r)   r)   r*   $_lambert_azimuthal_equal_area__to_cf  s    r   c                 C   sf   t | }| j drFd|d |d f|d |d |d |d d	S d|d
 |d |d |d dS )rW   z(2sp)r   r   r   r   r   r   r   r   r   r   r@   rA   r   r9   r?   r@   rA   r   r   rS   r   r   r)   r)   r*   _lambert_conformal_conic__to_cf  s"    r   c                 C   s(   t | }d|d |d |d |d dS )rY   r   r   r   r@   rA   r   r   r   r)   r)   r*   &_lambert_cylindrical_equal_area__to_cf  s    r   c                 C   sf   t | }| j dddrFd|d |d |d |d |d	 d
S d|d |d |d |d dS )r^   r   r   z(variant_a)r   r   r   r@   rA   scale_factor_at_natural_origin)r   r9   rG   r@   rA   rZ   r   )r   r9   rG   r@   rA   )r   r   rS   r   r   r   r)   r)   r*   _mercator__to_cf  s"    r   c                 C   sJ   t | }|d dkrtd d|d |d |d |d |d	 |d
 dS )ra   rd   r   zDangle from rectified to skew grid parameter lost in conversion to CFr   Zlatitude_of_projection_centreZlongitude_of_projection_centreZazimuth_of_initial_linere   Zeasting_at_projection_centreZnorthing_at_projection_centre)r   r>   rG   rb   rZ   r@   rA   )r   warningswarnr   r)   r)   r*   _oblique_mercator__to_cf  s    r   c                 C   s(   t | }d|d |d |d |d dS )rg   r   r   r   r@   rA   r   r   r   r)   r)   r*   _orthographic__to_cf  s    r   c                 C   s^   t | }| j dr8d|d |d |d |d dS d|d |d	 |d |d |d
 dS )ri   z(variant b)r   Zlatitude_of_standard_parallelZlongitude_of_originr@   rA   )r   r9   rj   r@   rA   r   r   r   )r   r>   rj   r@   rA   rZ   r   r   r)   r)   r*   _polar_stereographic__to_cf  s    r   c                 C   s"   t | }d|d |d |d dS )rl   r   r   r@   rA   )r   rG   r@   rA   r   r   r)   r)   r*   _sinusoidal__to_cf5  s    r   c                 C   s.   t | }d|d |d |d |d |d dS )rn   r   r   r   r@   rA   r   )r   r>   rG   r@   rA   rZ   r   r   r)   r)   r*   _stereographic__to_cfB  s    r   c                 C   s.   t | }d|d |d |d |d |d dS )rp   r   r   r   r@   rA   r   )r   r>   r?   r@   rA   rq   r   r   r)   r)   r*   _transverse_mercator__to_cfQ  s    r   c                 C   s.   t | }d|d |d |d |d |d dS )rs   r   rt   Zlatitude_of_topocentric_originZlongitude_of_topocentric_originr@   rA   )r   rQ   r>   rG   r@   rA   r   r   r)   r)   r*   _vertical_perspective__to_cf`  s    r   c                 C   s&   t | }d|d |d d |d dS )rv   r   Zo_lat_pZlon_0   Zo_lon_pr   rw   rx   ry   r   r   r)   r)   r*   "_rotated_latitude_longitude__to_cfo  s    
r   c                 C   s"   t | }d|d |d |d dS )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   r)   r)   r*   _pole_rotation_netcdf__to_cf}  s    r   )Zalbers_equal_areaZ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   Zpyproj._crsr   r   r   Zpyproj.crs.coordinate_operationr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   Zpyproj.crs.datumr   r   r   Zpyproj.exceptionsr   r+   r7   r<   rE   rL   rT   rV   rX   r]   r`   rf   rh   rk   rm   ro   rr   ru   rz   Z_GRID_MAPPING_NAME_MAPZ!_GEOGRAPHIC_GRID_MAPPING_NAME_MAPr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Z_INVERSE_GRID_MAPPING_NAME_MAPZ)_INVERSE_GEOGRAPHIC_GRID_MAPPING_NAME_MAPr)   r)   r)   r*   <module>   s   T,
