
    rbiz              	           d Z ddlZddlmZ ddlmZmZ ddlmZ dedefdZ	dedefd	Z
 G d
 dej                  Z G d de          Zdedeeef         fdZddededeeef         fdZdededefdZdS )z&
Utility functions used within pyproj
    N)array)Enumauto)Anyvaluereturnc                     | | k    p| du S )z'
    Check if value is NaN or None
    N r   s    \/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/pyproj/utils.pyis_nullr      s    
 E>*Ud]*    c                     t          |                                           } | dv rdS | dv rdS t          d|  d          )z
    https://docs.python.org/3.9/distutils/apiref.html#distutils.util.strtobool

    Here since distutils is deprecated.

    Convert a string representation of truth to True or False.
    )yyesttrueon1T)nnoffalseoff0Fzinvalid truth value: '')strlower
ValueErrorr   s    r   	strtoboolr       sW     JJE444t555u
6e666
7
77r   c                       e Zd ZdZd ZdS )NumpyEncoderz1
    Handle numpy types when dumping to JSON
    c                 ,   	 |                                 S # t          $ r Y nw xY w	 |j        j        dk    rt	          |          S |j        j        dk    rt          |          S n# t          $ r Y nw xY wt          j                            | |          S )Nr   i)	tolistAttributeErrordtypekindfloatintjsonJSONEncoderdefault)selfobjs     r   r-   zNumpyEncoder.default(   s    	::<< 	 	 	D		y~$$Szz!y~$$3xx % 	 	 	D	''c222s#    
##A& A& &
A32A3N)__name__
__module____qualname____doc__r-   r
   r   r   r"   r"   #   s-         3 3 3 3 3r   r"   c                   b    e Zd ZdZ e            Z e            Z e            Z e            ZdS )DataTypezA
    Data type for copy to buffer and convertback operations
    N)	r0   r1   r2   r3   r   FLOATLISTTUPLEARRAYr
   r   r   r5   r5   8   sF          DFFE466DDFFEDFFEEEr   r5   xxxc                     	 t          dt          |           f          t          j        fS # t          $ r t          d          dw xY w)a  
    Prepares scalar for PROJ C-API:
    - Makes a copy because PROJ modifies buffer in place
    - Make sure dtype is double as that is what PROJ expects
    - Makes sure object supports Python Buffer API

    Parameters
    -----------
    xxx: float or 0-d numpy array

    Returns
    -------
    tuple[Any, DataType]
        The copy of the data prepared for the PROJ API & Python Buffer API.
    dzinput must be a scalarN)r   r)   r5   r6   	Exception	TypeError)r:   s    r   _copytobuffer_return_scalarr?   C   sR     <S5::-(((.88 < < <011t;<s	   ), AFinplacec                    t          | d          s8t          | d          r(t          | j                  r|                                 } t          | d          r?| j        dk    rt	          |           S |                     dd|           t          j        fS t          j        }t          | t                    r|r| j
        dk    rt          d|           } nst          | t                    rt          d|           } t          j        }nAt          | t                    rt          d|           } t          j        }nt	          |           S | |fS )a  
    Prepares data for PROJ C-API:
    - Makes a copy because PROJ modifies buffer in place
    - Make sure dtype is double as that is what PROJ expects
    - Makes sure object supports Python Buffer API

    If the data is a numpy array, it ensures the data is in C order.

    Parameters
    ----------
    xxx: Any
        A scalar, list, tuple, numpy.array,
        pandas.Series, xaray.DataArray, or dask.array.Array.
    inplace: bool, default=False
        If True, will return the array without a copy if it
        meets the requirements of the Python Buffer API & PROJ C-API.

    Returns
    -------
    tuple[Any, DataType]
        The copy of the data prepared for the PROJ API & Python Buffer API.
    hardmask	__array__shaper
   r<   C)ordercopy)hasattrcallablerC   rD   r?   astyper5   r9   
isinstancer   typecodelistr7   tupler8   )r:   r@   	data_types      r   _copytobufferrP   Y   s?   8 C$$C%% S]##
 mmoo sG L9?? /s333zz#S7{z;;X^KKI#u 
0 	"#,#--S//C	C		 0CooM			C		 0CooN		*3///	>r   rO   inxc                     | t           j        k    r|d         S | t           j        k    r|                                S | t           j        k    rt          |          S |S )Nr   )r5   r6   r7   r%   r8   rN   )rO   rQ   s     r   _convertbackrS      sQ    HN""1vHM!!zz||HN""SzzJr   )F)r3   r+   r   enumr   r   typingr   boolr   r    r,   r"   r5   rN   r?   rP   rS   r
   r   r   <module>rW      s                        +3 +4 + + + +8S 8T 8 8 8 8 3 3 3 3 34# 3 3 3*    t   <S <U5(?-C < < < <,6 6s 6T 6eCM6J 6 6 6 6rH 3 3      r   