a
    Dfw~                     @  s  d dl mZ d dlZd dlZd dlmZ d dlZd dlZ	d dl
Zd dlmZ d dlmZ d dlmZ d dlmZ zd dlmZ W n ey   edZY n0 zd dlZW n ey   dZY n0 zd dlmZ W n ey   edZY n0 zd dlmZ W n ey   edZY n0 G dd	 d	eZ ej!d
d
dZ"ej!d
d
d
dZ#e$dd e%dej&' D Z(G dd dZ)G dd dZ*dd Z+dd Z,dd Z-dd Z.dd Z/dd Z0d d! Z1dd"d#Z2dd%d&Z3dd)d*Z4d+d, Z5dd0d1Z6d2d3 Z7d4d5 Z8d6d7 Z9ed8d9 d:d;d< Z:d=d> Z;d?d@ Z<dAdB Z=dCdD Z>dEdF Z?ddGdHZ@e"dIdJ ZAe"dKdL ZBe#dMdN ZCe#dOdP ZDe#dQdR ZEe#dSdT ZFe"dUdV ZGe"dWdX ZHe#dYdZ ZIe#d[d\ ZJe"d]d^ ZKe#d_d` ZLe#dadb ZMe"dcdd ZNe#dedf ZOe#dgdh ZPe"didj ZQe#dkdl ZRe#dmdn ZSe#dodp ZTe"dqdr ZUe"dsdt ZVe"dudv ZWe"dwdx ZXe"dydz ZYe"d{d| ZZe"d}d~ Z[e"dd Z\dS )    )annotationsN)getmro)memoize)	DataArray)RaggedDtype)GeometryDtypec                   @  s   e Zd ZdZdS )VisibleDeprecationWarningzVisible deprecation warning.

    By default, python will not show deprecation warnings, so this class
    can be used when a very visible warning is helpful, for example because
    the usage is most likely a user bug.
    N)__name__
__module____qualname____doc__ r   r   ]/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/datashader/utils.pyr   '   s   r   T)nopythonnogil)r   r   parallelc                 C  s   g | ]}t |qS r   )int).0xr   r   r   
<listcomp>4       r   z([0-9]+)\.([0-9]+)\.([0-9]+)c                   @  s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )ExprzBase class for expression-like objects.

    Implements hashing and equality checks. Subclasses should implement an
    ``inputs`` attribute/property, containing a tuple of everything that fully
    defines that expression.
    c                 C  s   t t| |  fS N)hashtype_hashable_inputsselfr   r   r   __hash__@   s    zExpr.__hash__c                 C  s    t | t |u o|  | kS r   )r   r   r   otherr   r   r   __eq__C   s    zExpr.__eq__c                 C  s
   | |k S r   r   r   r   r   r   __ne__G   s    zExpr.__ne__c                 C  s\   g }| j D ]H}t|ttfr,|t| q
t|tjrH||  q
|| q
t|S )zt
        Return a version of the inputs tuple that is suitable for hashing and
        equality comparisons
        )	inputs
isinstancelistsetappendtuplenpZndarraytobytes)r   resultipr   r   r   r   J   s    
zExpr._hashable_inputsN)r	   r
   r   r   r   r!   r"   r   r   r   r   r   r   9   s
   r   c                   @  s*   e Zd ZdZdd Zd	ddZdd ZdS )

DispatcherzSimple single dispatch.c                 C  s
   i | _ d S r   )_lookupr   r   r   r   __init__]   s    zDispatcher.__init__Nc                   sF   |du r fddS t tr8D ]} || q$n
| j< |S )z6Register dispatch of `func` on arguments of type `typ`Nc                   s     | S r   )register)fr   typr   r   <lambda>c   r   z%Dispatcher.register.<locals>.<lambda>)r$   r(   r0   r.   )r   r3   functr   r2   r   r0   `   s    

zDispatcher.registerc                 O  s~   | j }t|}||v r0|| |g|R i |S t|dd  D ]*}||v r@|| |g|R i |  S q@td|d S )N   zNo dispatch for {0} type)r.   r   r   	TypeErrorformat)r   headrestkwargsZlkr3   clsr   r   r   __call__k   s     zDispatcher.__call__)N)r	   r
   r   r   r/   r0   r>   r   r   r   r   r-   [   s   
r-   c                 C  s$   t j| } t| t jo"| t jjv S )zCheck if a datashape is numeric and real.

    Example
    -------
    >>> isrealfloat('int32')
    False
    >>> isrealfloat('float64')
    True
    >>> isrealfloat('string')
    False
    >>> isrealfloat('complex64')
    False
    )	datashape
predicateslaunderr$   UnittypesetsZfloatingdtr   r   r   isrealfloaty   s    rF   c                 C  s$   t j| } t| t jo"| t jjv S )zCheck if a datashape is numeric and real.

    Example
    -------
    >>> isreal('int32')
    True
    >>> isreal('float64')
    True
    >>> isreal('string')
    False
    >>> isreal('complex64')
    False
    )r?   r@   rA   r$   rB   rC   realrD   r   r   r   isreal   s    rH   c                 C  sf   t t| j}|| |d| | |} t| }tj|dd}|| @ }t	|d| j
ddS )aW  nansum where all-NaN values remain NaNs.

    Note: In NumPy <=1.9 NaN is returned for slices that are
    all NaN, while later versions return 0. This function emulates
    the older behavior, which allows using NaN as a missing value
    indicator.

    Parameters
    ----------
    array: Array to sum over
    axis:  Axis to sum over
    r   axis)r%   rangendimremoveinsertZ	transposer)   isnanallwheresum)arrayrJ   TZmissing_valsZ	all_emptyZset_to_zeror   r   r   nansum_missing   s    



rU   c           	      C  sp   | j dd \}}| jdd \}}| | j}| | j}|d |d  |d  }|d |d  |d  }||fS )zCalculate the resolution of xarray.DataArray raster and return it as the
    two-tuple (xres, yres). yres is positive if it is decreasing.
    Nr   r7   )shapedimsvalues)	rasterhwZydimZxdimZxcoordsZycoordsZxresZyresr   r   r   calc_res   s    

r^   c              	   C  s.  |d dk r|   n|  }|d dk r0| n|  }tj }}tj  }}t|d d|gd|d  |gg dg}	ddt|ft| dft| t|ffD ]V\}
}t|	t|
|dg\}}}||k r|}||kr|}||k r|}||kr|}q|d d |d d  }}|| || || || fS )a  Calculate the bounding box of a raster, and return it in a four-element
    tuple: (xmin, ymin, xmax, ymax). This calculation assumes the raster is
    uniformly sampled (equivalent to a flat-earth assumption, for geographic
    data) so that an affine transform (using the "Augmented Matrix" approach)
    suffices:
    https://en.wikipedia.org/wiki/Affine_transformation#Augmented_matrix

    Parameters
    ----------
    xs : numpy.array
        1D NumPy array of floats representing the x-values of a raster. This
        likely originated from an xarray.DataArray or xarray.Dataset object
        (xr.open_rasterio).
    ys : numpy.array
        1D NumPy array of floats representing the y-values of a raster. This
        likely originated from an xarray.DataArray or xarray.Dataset object
        (xr.open_rasterio).
    res : tuple
        Two-tuple (int, int) which includes x and y resolutions (aka "grid/cell
        sizes"), respectively.
    r   r7           )r_   r_         ?)r   r   r`          @)maxminr)   infrS   lendot)xsysresZxboundZyboundZxminZyminZxmaxZymaxZAbZx_Zy_r   y_ZxpadZypadr   r   r   	calc_bbox   s(    
0rl   c                 C  s   t |}t|d }| |  }}|| }| | | || |  } }t| | | t|| |  }	}
|
|	k rz|	|	fS |	|
fS )ai  
    Transform continuous start and end coordinates into array indices.

    Parameters
    ----------
    start : float
        coordinate of the lower bound.
    end : float
        coordinate of the upper bound.
    coords : numpy.ndarray
        coordinate values along the axis.
    res : tuple
        Resolution along an axis (aka "grid/cell sizes")
    ra   )re   absrc   rb   r   )startendcoordsri   sizeZhalfZvminZvmaxspanZsidxZeidxr   r   r   get_indices   s    "rs   c                 C  s<   |r| dd d dd d f } |r8| dd d d d df } | S )N.rW   r   )rS   xflipyflipr   r   r   _flip_array  s
    rv   c                 C  s   |du rt | }| j}|dur*||d  }t|d tjrFtddnd}t|d tjrftddnd}|d |k }|d |k}t|||}|S )a  
    Reorients the array to a canonical orientation depending on
    whether the x and y-resolution values are positive or negative.

    Parameters
    ----------
    raster : DataArray
        xarray DataArray to be reoriented
    res : tuple
        Two-tuple (int, int) which includes x and y resolutions (aka "grid/cell
        sizes"), respectively.
    layer : int
        Index of the raster layer to be reoriented (optional)

    Returns
    -------
    array : numpy.ndarray
        Reoriented 2d NumPy ndarray
    Nr7   r   ns)r^   datar$   r)   Ztimedelta64rv   )r[   ri   ZlayerrS   Zr0zeroZr1zerort   ru   r   r   r   orient_array  s      ry   meanc                   s  | j dd \}}| d||t  d||t  f  t fddtD }|dkrrtj|ddS |dkrtj|ddS |d	krtj|ddS |d
krtj|ddS |dkrtj	|ddS |dkrtj
|ddS |dk rtj|ddS tddS )z3Create downsampled aggregate factor in pixels unitsN   c                   s&   g | ]  fd dt D qS )c                   s$   g | ]} |d d f qS r   r   )r   i)crarrfactorjr   r   r   5  s   z3downsample_aggregate.<locals>.<listcomp>.<listcomp>)rK   )r   r}   r~   )r   r   r   5  s   z(downsample_aggregate.<locals>.<listcomp>rz   r   rI   rR   rb   rc   ZmedianZstdvarzNInvalid 'how' downsample method. Options mean, sum, max, min, median, std, var)rX   r   r)   ZconcatenaterK   ZnanmeanZnansumnanmaxnanminZ	nanmedianZnanstdZnanvar
ValueError)	aggregater~   howrh   rg   concatr   r   r   downsample_aggregate1  s(    ,
r   linear   c                 C  s   t | j}t | j}|dkr4| j| jdk  }|dkrXt |||dddf }n2t jdt || t j	||j
d| dddf }t|||fS )zHelper function similar to np.linspace which return values from aggregate min value to
    aggregate max value in either linear or log space.
    r   r   N)basenumdtype)r)   r   rZ   r   rx   rc   ZlinspaceZlogspacelog1per   r   )r   r   r   Zmax_valZmin_valvalsr   r   r   summarize_aggregate_valuesL  s     
r   c                   s   g  fdd}|S )z&
    simple arg caching decorator
    c                    s,   rd | kr$|  |  fd d < d S )Nr   r7   r   )argsr1   lastr   r   rk   h  s    zhold.<locals>._r   )r1   rk   r   r   r   holdb  s    r   .png. c                 C  sX   ddl m} tj|s"t| |r0|| |} |  tj|||  |rT| S dS )zPGiven a datashader Image object, saves it to a disk file in the requested formatr   )set_backgroundN)	Zdatashader.transfer_functionsr   ospathexistsmkdirZto_pilsavejoin)imgfilenamefmtZ_returnZexport_pathZ
backgroundr   r   r   r   export_imageo  s    

r   c                 C  sv   t | ttfrt| } t |ttfr0t|}tjd }| | d }ttd| tj d | tj }||fS )a  
    Projects the given (longitude, latitude) values into Web Mercator
    coordinates (meters East of Greenwich and meters North of the Equator).

    Longitude and latitude can be provided as scalars, Pandas columns,
    or Numpy arrays, and will be returned in the same form.  Lists
    or tuples will be converted to Numpy arrays.

    Examples:
       easting, northing = lnglat_to_meters(-74,40.71)

       easting, northing = lnglat_to_meters(np.array([-74]),np.array([40.71]))

       df=pandas.DataFrame(dict(longitude=np.array([-74]),latitude=np.array([40.71])))
       df.loc[:, 'longitude'], df.loc[:, 'latitude'] = lnglat_to_meters(df.longitude,df.latitude)
    iRa g     f@Z   g     v@)r$   r%   r(   r)   rS   pilogtan)Z	longitudeZlatitudeZorigin_shiftZeastingZnorthingr   r   r   lnglat_to_meters~  s    


(r   c                 C  st  t | jttjjs<t | jtjjjs<trt | jtj	j
jr| jj}t |tjrX| }trpt |tjrp| }t|}|jjdkr|d}tdt| jj|j}tj||| jjdS | jjdk rt| jdd}|durt|}ttj|dS t | jttfr| jS t r0t | jt r0| jS tj!"| j}|tj#krPtj$n|}|tj$tj%fv rpt|S |S )	zeReturn an object from datashader.datashape.coretypes given a column from a pandas
    dataframe.
    Uobjectz{} * {})r   orderedMtzN)r   )&r$   r   r   pdCategoricalapitypesCategoricalDtypecudfcoredtypescat
categoriesddIndexcomputeZ	to_pandasr)   rS   kindastyper?   dshaper9   re   r   getattrstrOptionDateTimer   r   gpd_GeometryDtypeZCTypeZfrom_numpy_dtypeZobject_stringZ	datetime_)colZpd_categoriesr   Z
cat_dshaper   r   r   r   r   dshape_from_pandas_helper  sJ    



r   c                   s"   t  t fdd jD  S )z=Return a datashape.DataShape object given a pandas dataframe.c                   s   g | ]}|t  | fqS r   r   r   kdfr   r   r     s   z&dshape_from_pandas.<locals>.<listcomp>)re   r?   Recordcolumnsr   r   r   r   dshape_from_pandas  s    r   c                 C  s   t | d  S )Nr   )r(   Z__dask_keys__)r   r<   r   r   r   r4     r   r4   )keyc                   sF    fdd j D } j|dd tjt fdd j D   fS )z;Return a datashape.DataShape object given a dask dataframe.c                   sP   g | ]H}t  | jttjjs6t  | jtjjjrt | j	d ds|qS )ZknownT)
r$   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r     s
   z$dshape_from_dask.<locals>.<listcomp>F)indexc                   s"   g | ]}|t  | d fqS )r   )r   Zget_partitionr   r   r   r   r     s   )r   Z
categorizer?   r   r   )r   Zcat_columnsr   r   r   dshape_from_dask  s    
r   c                   s.   t jt  fddt jt j D  S )z;Return a datashape.DataShape object given a xarray Dataset.c                   s   g | ]}|t  | fqS r   r   r   Zxr_dsr   r   r     s   z.dshape_from_xarray_dataset.<locals>.<listcomp>)r?   r   r   r%   Z	data_varsrp   r   r   r   r   dshape_from_xarray_dataset  s    r   c                 C  s   t | jd d }t j|d< | |dd< t ||jd }t |jd |jd d f}t j|dddf< ||ddddf< t|| dS )aU  
   Converts a set of multiple sequences (eg: time series), stored as a 2 dimensional
   numpy array into a pandas dataframe that can be plotted by datashader.
   The pandas dataframe eventually contains two columns ('x' and 'y') with the data.
   Each time series is separated by a row of NaNs.
   Discussion at: https://github.com/bokeh/datashader/issues/286#issuecomment-334619499

   x_values: 1D numpy array with the values to be plotted on the x axis (eg: time)
   y_values: 2D numpy array with the sequences to be plotted of shape (num sequences X length of
             each sequence)

   r   r7   rW   N)r   rj   )r)   zerosrX   nanZtiler   	DataFrameflatten)Zx_valuesZy_valuesr   rj   r   r   r   !dataframe_from_multiple_sequences  s    
r   c                 C  s  g d}| j |j d|f tjddf }|\}}}t|| ||  dkrZg d}|j dd|f }|jdks|tj}tj| j |dd}|t	|j
dd |j
d }tj|| jd}	t| jdk}
|
s|jd	 }|j ddd	f d	|	|< |	S )
zkHelper for ``datashader.utils.mesh()``. Both arguments are assumed to be
    Pandas DataFrame objects.
    )r   r7   r{   r   Nr{   )r   r{   r7   int64rI   )r      )rZ   r   r)   r   Zcrossitemr   ZtakeZreshapeprodrX   r   r   r   re   repeat)vertices	simplicesZwindingZ	first_triabcZvertex_idxsr   ri   Zverts_have_weightsZ
weight_colr   r   r   _pd_mesh  s     $

"
r   c                 C  sP   t |  | }t| j|j}ttt|d|  d }tj	||d}|S )ziHelper for ``datashader.utils.mesh()``. Both arguments are assumed to be
    Dask DataFrame objects.
    r   )	chunksize)
r   r   rb   Znpartitionsr   r)   ceilre   r   Zfrom_pandas)r   r   ri   Zapprox_npartitionsr   r   r   r   _dd_mesh  s
    r   c                 C  s   |j jd dksJ d|jjdd dd  }|sBJ dt| jdksh|j jd dkshJ d	t| t	j
rt|t	j
rt| |S t| |S )
zMerge vertices and simplices into a triangular mesh, suitable to be
    passed into the ``Canvas.trimesh()`` method via the ``mesh``
    keyword-argument. Both arguments are assumed to be Dask DataFrame
    objects.
    r7   r   zFAt least three vertex columns are required for the triangle definitionNc                 S  s   t | t jS r   )r)   Z
issubdtypeintegerrD   r   r   r   r4   <  r   zmesh.<locals>.<lambda>z^Simplices must be integral. You may consider casting simplices to integers with ".astype(int)"r{   zMIf no vertex weight column is provided, a triangle weight column is required.)rZ   rX   r   ZilocmaprP   re   r   r$   r   r   r   r   )r   r   Zsimplices_all_intsr   r   r   mesh1  s     
r   c                 C  s   |r| |i |S | | S d S r   r   )r5   r   r<   r   r   r   applyL  s    r   c                 C  s   | dkp| dk S )zQ
    Equivalent to isnan for floats, but also numba compatible with integers
    r   r   valr   r   r   isnullS  s    r   c                 C  s   | dkS )zO
    Check for -1 which is equivalent to NaN for some integer aggregations
    rW   r   r   r   r   r   isminus1[  s    r   c                 C  sL   |   } |  }tt| D ](}t| | rt|| s|| | |< qdS )zPFirst of 2 arrays but taking nans into account.
    Return the first array.
    Nravelnbprangere   r   retr    r|   r   r   r   nanfirst_in_placec  s
    r   c                 C  s@   |   } |  }tt| D ]}t|| s|| | |< qdS )zOLast of 2 arrays but taking nans into account.
    Return the first array.
    Nr   r   r   r   r   nanlast_in_placeo  s
    r   c                 C  sv   |   } |  }tt| D ]R}t| | rHt|| sp|| | |< qt|| s|| | | kr|| | |< qdS )zMax of 2 arrays but taking nans into account.  Could use np.nanmax but
    would need to replace zeros with nans where both arrays are nans.
    Return the first array.
    Nr   r   r   r   r   nanmax_in_place{  s    r   c                 C  sv   |   } |  }tt| D ]R}t| | rHt|| sp|| | |< qt|| s|| | | k r|| | |< qdS )zMin of 2 arrays but taking nans into account.  Could use np.nanmin but
    would need to replace zeros with nans where both arrays are nans.
    Accepts 3D (ny, nx, ncat) and 2D (ny, nx) arrays.
    Return the first array.
    Nr   r   r   r   r   nanmin_in_place  s    r   c                 C  s>   t | }t|d |dD ]}| |d  | |< q|| |< |d S )a(  Insert a value into a 1D array at a particular index, but before doing
    that shift the previous values along one to make room. For use in
    ``FloatingNReduction`` classes such as ``max_n`` and ``first_n`` which
    store ``n`` values per pixel.

    Parameters
    ----------
    target : 1d numpy array
        Target pixel array.

    value : float
        Value to insert into target pixel array.

    index : int
        Index to insert at.

    Returns
    -------
    Index beyond insertion, i.e. where the first shifted value now sits.
    r7   rW   )re   rK   )targetvaluer   nr|   r   r   r   shift_and_insert  s
    r   c                 C  sX   t | }d}|D ]B}t|r" qTqt||D ]$}t| | r,|| |< |d } qq,qdS )af  Single pixel implementation of nanfirst_n_in_place.
    ret_pixel and other_pixel are both 1D arrays of the same length.

    Walk along other_pixel a value at a time, find insertion index in
    ret_pixel and shift values along to insert.  Next other_pixel value is
    inserted at a higher index, so this walks the two pixel arrays just once
    each.
    r   r7   N)re   r   rK   Z	ret_pixelZother_pixelr   istartZother_valuer|   r   r   r   _nanfirst_n_impl  s    
r   c           	   	   C  s\   | j \}}}}t|D ]>}t|D ]0}t|D ]"}t| |||f ||||f  q0q$qdS zN3d version of nanfirst_n_in_place_4d, taking arrays of shape (ny, nx, n).
    NrX   r   r   rK   r   	r   r    nynxZncat_nrj   r   r   r   r   r   nanfirst_n_in_place_4d  s
    r  c                 C  sH   | j \}}}t|D ],}t|D ]}t| ||f |||f  q"qdS r   r   r   r    r  r  r  rj   r   r   r   r   nanfirst_n_in_place_3d  s    r  c                 C  sH   t | }d}|D ]2}t|r" qDqt||D ]}t| ||} qq,qdS )ae  Single pixel implementation of nanlast_n_in_place.
    ret_pixel and other_pixel are both 1D arrays of the same length.

    Walk along other_pixel a value at a time, find insertion index in
    ret_pixel and shift values along to insert.  Next other_pixel value is
    inserted at a higher index, so this walks the two pixel arrays just once
    each.
    r   Nre   r   rK   r   r   r   r   r   _nanlast_n_impl  s    
r	  c           	   	   C  s\   | j \}}}}t|D ]>}t|D ]0}t|D ]"}t| |||f ||||f  q0q$qdS r   rX   r   r   rK   r	  r  r   r   r   nanlast_n_in_place_4d  s
    r  c                 C  sH   | j \}}}t|D ],}t|D ]}t| ||f |||f  q"qdS )zM3d version of nanlast_n_in_place_4d, taking arrays of shape (ny, nx, n).
    Nr
  r  r   r   r   nanlast_n_in_place_3d  s    r  c                 C  s`   t | }d}|D ]J}t|r" q\qt||D ],}t| | sH|| | kr,t| ||} qq,qdS )ad  Single pixel implementation of nanmax_n_in_place.
    ret_pixel and other_pixel are both 1D arrays of the same length.

    Walk along other_pixel a value at a time, find insertion index in
    ret_pixel and shift values along to insert.  Next other_pixel value is
    inserted at a higher index, so this walks the two pixel arrays just once
    each.
    r   Nr  r   r   r   r   _nanmax_n_impl  s    
r  c           	   	   C  s\   | j \}}}}t|D ]>}t|D ]0}t|D ]"}t| |||f ||||f  q0q$qdS )a  Combine two max-n arrays, taking nans into account. Max-n arrays are 4D
    with shape (ny, nx, ncat, n) where ny and nx are the number of pixels,
    ncat the number of categories (will be 1 if not using a categorical
    reduction) and the last axis containing n values in descending order.
    If there are fewer than n values it is padded with nans.
    Return the first array.
    NrX   r   r   rK   r  r  r   r   r   nanmax_n_in_place_4d'  s
    	r  c                 C  sH   | j \}}}t|D ],}t|D ]}t| ||f |||f  q"qdS )zL3d version of nanmax_n_in_place_4d, taking arrays of shape (ny, nx, n).
    Nr  r  r   r   r   nanmax_n_in_place_3d7  s    r  c                 C  s`   t | }d}|D ]J}t|r" q\qt||D ],}t| | sH|| | k r,t| ||} qq,qdS )ad  Single pixel implementation of nanmin_n_in_place.
    ret_pixel and other_pixel are both 1D arrays of the same length.

    Walk along other_pixel a value at a time, find insertion index in
    ret_pixel and shift values along to insert.  Next other_pixel value is
    inserted at a higher index, so this walks the two pixel arrays just once
    each.
    r   Nr  r   r   r   r   _nanmin_n_implA  s    
r  c           	   	   C  s\   | j \}}}}t|D ]>}t|D ]0}t|D ]"}t| |||f ||||f  q0q$qdS )a  Combine two min-n arrays, taking nans into account. Min-n arrays are 4D
    with shape (ny, nx, ncat, n) where ny and nx are the number of pixels,
    ncat the number of categories (will be 1 if not using a categorical
    reduction) and the last axis containing n values in ascending order.
    If there are fewer than n values it is padded with nans.
    Return the first array.
    NrX   r   r   rK   r  r  r   r   r   nanmin_n_in_place_4dW  s
    	r  c                 C  sH   | j \}}}t|D ],}t|D ]}t| ||f |||f  q"qdS )zL3d version of nanmin_n_in_place_4d, taking arrays of shape (ny, nx, n).
    Nr  r  r   r   r   nanmin_n_in_place_3dg  s    r  c                 C  sn   |   } |  }tt| D ]J}t| | rHt|| sh|| | |< qt|| s| |  || 7  < qdS )zSum of 2 arrays but taking nans into account.  Could use np.nansum but
    would need to replace zeros with nans where both arrays are nans.
    Return the first array.
    Nr   r   r   r   r   nansum_in_placeq  s    r  c                 C  sZ   |   } |  }tt| D ]8}|| dkr| | dksH|| | | kr|| | |< qdS )zMaximum of 2 arrays of row indexes.
    Row indexes are integers from 0 upwards, missing data is -1.
    Return the first array.
    rW   Nr   rK   re   r   r   r   r   row_max_in_place  s
    (r  c                 C  sZ   |   } |  }tt| D ]8}|| dkr| | dksH|| | | k r|| | |< qdS )zMinimum of 2 arrays of row indexes.
    Row indexes are integers from 0 upwards, missing data is -1.
    Return the first array.
    rW   Nr  r   r   r   r   row_min_in_place  s
    (r  c                 C  s`   t | }d}|D ]J}|dkr" q\qt||D ],}| | dksH|| | kr,t| ||} qq,qdS )ae  Single pixel implementation of row_max_n_in_place.
    ret_pixel and other_pixel are both 1D arrays of the same length.

    Walk along other_pixel a value at a time, find insertion index in
    ret_pixel and shift values along to insert.  Next other_pixel value is
    inserted at a higher index, so this walks the two pixel arrays just once
    each.
    r   rW   Nre   rK   r   r   r   r   r   _row_max_n_impl  s    
r  c           	   	   C  sZ   | j \}}}}t|D ]>}t|D ]0}t|D ]"}t| |||f ||||f  q.q"qdS )zCombine two row_max_n signed integer arrays.
    Equivalent to nanmax_n_in_place with -1 replacing NaN for missing data.
    Return the first array.
    NrX   rK   r  r  r   r   r   row_max_n_in_place_4d  s
    r  c                 C  sF   | j \}}}t|D ],}t|D ]}t| ||f |||f  q qd S r   r  r  r   r   r   row_max_n_in_place_3d  s    r  c                 C  s`   t | }d}|D ]J}|dkr" q\qt||D ],}| | dksH|| | k r,t| ||} qq,qdS )ae  Single pixel implementation of row_min_n_in_place.
    ret_pixel and other_pixel are both 1D arrays of the same length.

    Walk along other_pixel a value at a time, find insertion index in
    ret_pixel and shift values along to insert.  Next other_pixel value is
    inserted at a higher index, so this walks the two pixel arrays just once
    each.
    r   rW   Nr  r   r   r   r   _row_min_n_impl  s    
r  c           	   	   C  sZ   | j \}}}}t|D ]>}t|D ]0}t|D ]"}t| |||f ||||f  q.q"qdS )zCombine two row_min_n signed integer arrays.
    Equivalent to nanmin_n_in_place with -1 replacing NaN for missing data.
    Return the first array.
    NrX   rK   r  r  r   r   r   row_min_n_in_place_4d  s
    r   c                 C  sF   | j \}}}t|D ],}t|D ]}t| ||f |||f  q qd S r   r  r  r   r   r   row_min_n_in_place_3d  s    r!  )NN)rz   )r   r   )r   Tr   r   )N)]
__future__r   r   reinspectr   Znumbar   numpyr)   Zpandasr   Ztoolzr   Zxarrayr   Zdask.dataframeZ	dataframer   Zdatashader.datashaper?   Zdatashader.datatypesr   ImportErrorr   r   	ExceptionZgeopandas.arrayr   r   Zspatialpandas.geometryUserWarningr   ZjitZngjitZngjit_parallelr(   match__version__groupsZnumba_versionr   r-   rF   rH   rU   r^   rl   rs   rv   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r   r   r   r   <module>   s   
	",	
!


+












	



	


	


	







