
    tfv                     D    d dl Z d dlZd dlmc mZ ddZddZd Z	ddZy)    Nc                    g }|D ]  }|j                  d      }t        |      dk  rt        d      t        |d         }t        |d         }t	        | |||      j                  d      }||t        j                  |      fgz  } |S )N.   zNot enough tile info present      )splitlen
IndexErrorinttilesreshapectfformat_dense_tile)	arraytile_idsnot_nan_arraytile_valuestile_idpartszx	ret_arrays	            `/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/clodius/tiles/npvector.pytiles_wrapperr      s    K Ec"u:>;<<aMaM%A}5==rC	#"7"7	"BCDDE     c                    t        | j                        }t        j                  t        j                  ||z        t        j                  d      z        }|dk  rdn|}d|z  |z  }||z  }|r|d   g}|d   g}|d   |d   z
  |z  }ndg}| j                  d   g}t        | j                        dkD  rt        d| j                        ||||||dS )z,
    Get the tileset info for the array
    r   r   r   z$The array shape is not a vector type)	max_widthmin_posmax_posmax_zoombins_per_dimension	tile_size)maxshapemathceillogr
   
ValueError)	r   boundsr"   max_dimr!   r   scale_upr   r    s	            r   tileset_infor-      s     %++Gyy',>">?$((1+MNHqLqhHX 22I 7"H!9+!9+ QZ'!*,8	#;;q>"
5;;!?MM0' r   c                    | j                   d   }t        j                  t        j                  ||z        t        j                  d      z        }|dk  rdn|}d||z
  z  |z  }||z  }t	        | j                   d   ||z         }|||fS )a  
    Return the maximum zoom level and data corresponding to the
    zoom level and position of the array.

    Parameters
    ----------
    array: np.array
        The array containing the raw numpy data
    z: int
        The zoom level
    x: int
        The x position
    r   r   )r%   r&   r'   r(   min)	r   r   r   bin_sizer+   r!   
tile_widthx_startx_ends	            r   max_zoom_and_data_boundsr4   >   s     kk!nGyy'H"45CDHqLqhH
 x!|$x/J*nGA* 45E We##r   c                    t        | |||      \  }}}| || }d||z
  z  }	|	t        j                  |j                  d   |	z        z  }
|
|j                  d   z
  }t	        j
                  |d|ffdt        j                  f      }t	        j                  |j                  d|	f      d      }|t	        j                  | ||        }n||| }t	        j
                  |d|fdt        j                  f      }t	        j                  |j                  d|	f      d      }||dz   z  }||j                  d   z
  }t	        j
                  |d|fdt        j                  f      S )a  
    Return tiles at the given positions.

    Parameters
    -----------
    array: np.array
        An nxn array containing values
    z: int
        The zoom level (0 corresponds to most zoomed out)
    x: int
        The x tile position
    not_nan_array: np.array
        An array storing the number of values which are not nan
        in the original array. Can be precalculated for speed.
    bin_size: int
        The number of values per bin
    r   r   constant)constant_valuesr   r   )axis)
r4   r&   r'   r%   nppadnannansumr   isnan)r   r   r   r   r0   r!   r2   r3   data
num_to_sumdivisible_x_widthdivisible_x_padar   not_nan_datana
norm_arrayx_pads                     r   r   r   ^   sZ   $  8q!XNHguDx!|$J #TYYtzz!}z/I%JJ'$**Q-7O
tq/*,j266)TA		!))R$45A>Iwu!566$WU3 
?+j266)
B 2::r:&67a@JZ!^,I yq))E66)q%j:yQQr   )N)Ni   )
r&   numpyr9   clodius.tiles.formatr   formatr   r   r-   r4    r   r   <module>rK      s(      " "&"J$@.Rr   