a
    ƒ³b½  ã                   @   s†   d Z ddlmZ ddlmZ ddlZddlmZ ddd„Z	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )zp
Helpers for plot-blobs main command

Exposed functions take a graph return a figure:

  func_<name>(gr) -> fig
é    )ÚunitsNé   )Ú	get_slicec                 C   s   t j| |dd�S )NT)Útight_layout)ÚpltÚsubplots)ÚnrowsÚncols© r
   ú?/home/yuhw/wc/wire-cell-python-pr-11/wirecell/img/plot_blobs.pyr      s    r   c           
      C   sl   t ƒ }| j ¡ D ]0\}}|d dkr&q|d d | }| |¡ qtƒ \}}	|	j|| dd� |	 |¡ |S )NÚcodeÚbÚcornersr   éè  ©Úbins)ÚlistÚnodesÚdataÚappendr   ÚhistÚ	set_label)
ÚgrÚindexÚlabelÚunitÚvalsÚnodeÚndataÚvÚfigÚaxr
   r
   r   Ú_plot_coord   s    

r"   c                 C   s   t | ddtjƒS )Nr   zX [cm]©r"   r   Úcm©r   r
   r
   r   Úplot_x   ó    r&   c                 C   s   t | ddtjƒS )Nr   zY [cm]r#   r%   r
   r
   r   Úplot_y    r'   r(   c                 C   s   t | ddtjƒS )Né   zZ [cm]r#   r%   r
   r
   r   Úplot_z!   r'   r*   c                 C   s|   t ƒ }| j ¡ D ]8\}}|d dkr&qt| |ƒ}| j| }| |d ¡ qtƒ \}}|jt |¡t	j
 dd� | d¡ |S )z
    Histogram blob times
    r   r   Ústartr   r   zT [us])r   r   r   r   r   r   r   ÚnumpyÚarrayr   Úusr   )r   Útimesr   r   ÚsnodeÚsdatr    r!   r
   r
   r   Úplot_t#   s    



r2   c                 C   sð   d| }t ƒ }t ƒ }| j ¡ D ]n\}}|d dkr4qt| |ƒ}| j| }| |d ¡ t t |d ¡d d …|f ¡t|d ƒ }	| |	¡ qt	ƒ \}
}| 
t |¡tj t |¡tj ¡ | d| ¡ › d�¡ | d¡ | |› d	�¡ |
S )
NÚxyzr   r   r+   r   zBlob <z> vs Tzt [us]z [mm])r   r   r   r   r   r,   Úsumr-   Úlenr   Úscatterr   r.   ÚmmÚ	set_titleÚupperÚ
set_xlabelÚ
set_ylabel)r   ZposindexÚletterÚtimeÚyposr   Úbdatr0   r1   Úyr    r!   r
   r
   r   Ú_plot_tN3   s"    

,
$
rA   c                 C   s
   t | dƒS )Nr   ©rA   r%   r
   r
   r   Úplot_txG   r'   rC   c                 C   s
   t | dƒS )Nr   rB   r%   r
   r
   r   Úplot_tyH   r'   rD   c                 C   s
   t | dƒS )Nr)   rB   r%   r
   r
   r   Úplot_tzI   r'   rE   )r   r   )Ú__doc__Úwirecellr   Úmatplotlib.pyplotÚpyplotr   r,   Ú	converterr   r   r"   r&   r(   r*   r2   rA   rC   rD   rE   r
   r
   r
   r   Ú<module>   s   
