
    tf                     <    d dl Z d dlZd dlmc mZ d ZddZddZy)    Nc                 0   g }|D ]  }|j                  d      }t        |      dk  rt        d      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hgfoformat_dense_tile)	gridtile_idstile_valuestile_idpartszxy	ret_arrays	            `/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/clodius/tiles/npmatrix.pytiles_wrapperr      s    K Fc"u:>;<<aMaMaM$1a(00"6	$"8"8"CDEEF     c                    d}t        | j                        }t        j                  t        j                  ||z        t        j                  d      z        }|dk  rdn|}d|z  |z  }d|z  |z  }||z  }|1|d   |d   g}|d   |d   g}	|	d   |d   z
  |z  }|	d   |d   z
  |z  }nddg}| j                  }	t        | j                        dkD  rt        d| j                        ||||	|d|dS )	z+
    Get the tileset info for the grid
       r   r   r   r   z)Grid's shape is not conducive to plottingfalse)	max_width
max_width1min_posmax_posmax_zoommirror_tilesbins_per_dimension)maxshapemathceillogr   
ValueError)
r   boundsbin_sizemax_dimr%   r!   r"   scale_upr#   r$   s
             r   tileset_infor2      s    H$**oGyy'H"45CDHqLqhHX(Ih)J7"H!9fQi(!9fQi( QZ'!*,8	aj71:-9
a&**
4::DdjjQQ & r   c                    t        | j                        }t        j                  t        j                  ||z        t        j                  d      z        }|dk  rdn|}d||z
  z  |z  }||z  }	||z  }
t        | j                  d   |	|z         }t        | j                  d   |
|z         }d||z
  z  }| |	||
|f   }|t        j                  t        d|j                  d         |z        z  }|t        j                  t        d|j                  d         |z        z  }||j                  d   z
  }||j                  d   z
  }t        j                  |d|fd|ffdt        j                  t        j                  f      }t        j                  |j                  |j                  d   d|f      d      }t        j                  |j                  j                  |j                  d   d|      d      j                  }t        j                  ||dk(  <   |||	||
|f   }t        j                  |d|fd|ffdt        j                  t        j                  f      }t        j                  |j                  |j                  d   d|f      d      }t        j                  |j                  j                  |j                  d   d|      d      j                  }||z  }||j                  d   z
  }||j                  d   z
  }t        j                  |d|fd|ffdt        j                  t        j                  f      S )	aR  
    Return tiles at the given positions.

    Parameters
    -----------
    grid: np.array
        An nxn array containing values
    z: int
        The zoom level (0 corresponds to most zoomed out)
    x: int
        The x tile position
    y: int
        The y tile position
    bin_size: int
        The number of values per bin
    r   r   r   constant)constant_valuesr	   )axisg        )r(   r)   r*   r+   r,   minnppadnannansumr   T)r   r   r   r   nan_gridr/   r0   r%   
tile_widthx_starty_startx_endy_end
num_to_sumdatadivisible_x_widthdivisible_y_widthdivisible_x_paddivisible_y_padabr   not_nan_datananb
norm_arrayx_pady_pads                               r   r   r   D   s   " $**oGyy'H"45CDHqLqhH x!|$x/J*nG*nG

1w34E

1w34Ex!|$Jwu},-D #TYYs1djjm/Dz/Q%RR"TYYs1djjm/Dz/Q%RR'$**Q-7O'$**Q-7O

_	?34(		A 			!))QWWQZZ89BA		!##++aggaj"jAJLLI"$&&Ii3
  wu} <=VV!A#78VVRVV,	
 YYrzz288A;J"?@qIYYrtt||BHHQKZHqQSS

*	 yq))Eyq))E66
UaZ (	 r   )N)Nr   )	r*   numpyr8   clodius.tiles.formatr   formatr   r   r2    r   r   <module>rU      s"      # #(%PSr   