o
    Nrf                     @   sB   d dl Z d dlZd dlm  mZ dd Zd	ddZd
ddZdS )    Nc           	      C   s|   g }|D ]7}| d}t|dk rtdt|d }t|d }t|d }t| |||d}||t|fg7 }q|S )N.   zNot enough tile info present         )splitlen
IndexErrorinttilesreshapehgfoZformat_dense_tile)	gridZtile_idsZtile_valuesZtile_idpartszxy	ret_array r   _/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/clodius/tiles/npmatrix.pytiles_wrapper   s   
r   c           
      C   s   d}t | j}tt|| td }|dk rdn|}d| | }d| | }|| }|durW|d |d g}|d |d g}	|	d |d  | }|	d |d  | }nddg}| j}	t| jdkrktd| j||||	|d|d	S )
z+
    Get the tileset info for the grid
       r   r   Nr   r   z)Grid's shape is not conducive to plottingfalse)	max_width
max_width1min_posmax_posmax_zoomZmirror_tilesZbins_per_dimension)maxshapemathceillogr	   
ValueError)
r   Zboundsbin_sizemax_dimr   r   r   Zscale_upr   r   r   r   r   tileset_info   s0   
r'   r   c                 C   s<  t | j}tt|| td }|dk rdn|}d||  | }|| }	|| }
t| jd |	| }t| jd |
| }d||  }| |	||
|f }|tt d|jd |  }|tt d|jd |  }||jd  }||jd  }tj|d|fd|ffdtjtjfd}tj	|
|jd d|fdd}tj	|j
|jd d|ddj}tj||dk< |d	ur||	||
|f }tj|d|fd|ffdtjtjfd}tj	|
|jd d|fdd}tj	|j
|jd d|ddj}|| }||jd  }||jd  }tj|d|fd|ffdtjtjfd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   Zconstant)Zconstant_valuesr   )Zaxisg        N)r   r    r!   r"   r#   minnppadnanZnansumr   T)r   r   r   r   Znan_gridr%   r&   r   Z
tile_widthZx_startZy_startZx_endZy_endZ
num_to_sumdataZdivisible_x_widthZdivisible_y_widthZdivisible_x_padZdivisible_y_padabr   Znot_nan_datananbZ
norm_arrayZx_padZy_padr   r   r   r   D   sT   

 "
 "
r   )N)Nr   )	r!   numpyr)   Zclodius.tiles.formatr   formatr   r   r'   r   r   r   r   <module>   s    
(