a
    Nž�d  ã                   @   s    d Z ddlmZ ddlmZ ddlZddlZe d¡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d„ ZdS )zq
Helpers for plot-blobs main command

Exposed functions take a graph return a figure:

  func_<name>(gr) -> fig

é    )ÚunitsNzwirecell.imgé   )Ú	get_slicec                 C   s   t j| |dd�S )NT)Útight_layout)ÚpltÚsubplots)ÚnrowsÚncols© r
   ú9/home/yuhw/wc/wire-cell-python/wirecell/img/plot_blobs.pyr      s    r   c                 C   s´   t ƒ }| j ¡ D ]0\}}|d dkr&q|d d | }| |¡ qtƒ \}}	t |¡}|	j|| dd� |	 |¡ t	| dd ƒ}
|
rŽd|
› d	�}
d
| }|	 
d| ¡ › d|
› �¡ |S )NÚcodeÚbÚcornersr   éè  ©ÚbinsÚnameú (ú)ÚxyzzBlob ú )ÚlistÚnodesÚdataÚappendr   ÚnumpyÚarrayÚhistÚ	set_labelÚgetattrÚ	set_titleÚupper)ÚgrÚindexÚlabelÚunitÚvalsÚnodeÚndataÚvÚfigÚaxÚgnameÚletterr
   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(   ó    r2   c                 C   s   t | ddtjƒS )Nr   zY [cm]r/   r1   r
   r
   r   Úplot_y)   r3   r4   c                 C   s   t | ddtjƒS )Né   zZ [cm]r/   r1   r
   r
   r   Úplot_z*   r3   r6   c           	      C   s¨   t ƒ }| j ¡ D ]8\}}|d dkr&qt| |ƒ}| j| }| |d ¡ qtƒ \}}|jt |¡t	j
 dd� | d¡ t| ddƒ}|r”d	|› d
�}| d|› �¡ |S )z
    Histogram blob times
    r   r   Ústartr   r   zT [us]r   Nr   r   zBlob T )r   r   r   r   r   r   r   r   r   r   Úusr   r   r    )	r"   Útimesr'   r(   ÚsnodeÚsdatr*   r+   r,   r
   r
   r   Úplot_t,   s    



r<   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 ¡ t| dd ƒ}|rØd|› d�}| d	| ¡ › d
|› �¡ | d¡ | |› d�¡ |
S )Nr   r   r   r7   r   r   r   r   zBlob <z> vs T zt [us]z [mm])r   r   r   r   r   r   Úsumr   Úlenr   Úscatterr   r8   Úmmr   r    r!   Ú
set_xlabelÚ
set_ylabel)r"   Zposindexr-   ÚtimeÚyposr'   Úbdatr:   r;   Úyr*   r+   r,   r
   r
   r   Ú_plot_tN@   s(    

,
$
rG   c                 C   s
   t | dƒS )Nr   ©rG   r1   r
   r
   r   Úplot_txW   r3   rI   c                 C   s
   t | dƒS )Nr   rH   r1   r
   r
   r   Úplot_tyX   r3   rJ   c                 C   s
   t | dƒS )Nr5   rH   r1   r
   r
   r   Úplot_tzY   r3   rK   c           %         sÊ  ddl m‰  ddlm} tddƒ\}}dd„ | j ¡ D ƒ}t|ƒdkrNtdƒ‚t	 
d	d„ |D ƒ¡}|dk}|| }|jdkr„td
ƒ‚t	 
dd„ |D ƒ¡tj | }t	 
dd„ |D ƒ¡tj | }	t	 t|ƒddf¡}
t|ƒD ]F\}}t|d ƒD ]0\}}|d |
| | d< |d |
| | d< qðqÜt d|
j› �¡ |
| }
t d|
j› �¡ t dt	 |¡› dt	 |¡› dt	 |¡› �¡ t dt	 |	¡› dt	 |	¡› dt	 |	¡› �¡ d}d}tg d¢g d¢ƒD �]ü\}}|
dd…|dd…f }|
dd…|dd…f }t	 |dd…df |dd…df f¡j}|dd…df |dd…df  }|dd…df |dd…df  }|||  }t	 |¡}|||	  }t	 |¡}t d|j› d|j› d|j› d|j› d |j› d!|	j› �¡ ‡ fd"d„t|||ƒD ƒ}|||d#d$�}| |¡ | || || g¡ t	 |dd…df |f¡j}‡ fd%d„t|||	ƒD ƒ}|||d#d$�} |  |¡ |  || || g¡ |dd…|f \}!}"d&| }#d&| }$|! |¡ |! t	 |dd…df ¡t	 |dd…df | ¡¡ |! t	 |dd…df ¡t	 |dd…df | ¡¡ |! |#¡ |! |$¡ |j ||!d'� |" | ¡ |" t	 |dd…df ¡t	 |dd…df | ¡¡ |" t	 |dd…df ¡t	 |dd…df |	 ¡¡ |" |#¡ |" d(¡ |j | |"d'� �qÆ|S ))z=
    Project blob charge onto each view and along slices
    r   ©Ú	Rectangle)ÚPatchCollectionr5   é   c                 S   s    g | ]\}}|d  dkr|‘qS )r   r   r
   )Ú.0ÚnÚdr
   r
   r   Ú
<listcomp>e   r3   zplot_views.<locals>.<listcomp>zgraph with no blobsc                 S   s   g | ]}|d  ‘qS )Úvalr
   ©rP   r   r
   r
   r   rS   j   r3   zno non-negative blob chargesc                 S   s   g | ]}|d  ‘qS )r7   r
   rU   r
   r
   r   rS   o   r3   c                 S   s   g | ]}|d  ‘qS )Úspanr
   rU   r
   r
   r   rS   p   r3   ÚboundsÚbegÚendr   zwb=zwb[ind]=zt min=z mean=z max=zdt min=g      Ð?g      @)r   r   r5   )r   r5   r   Nzshapes: points=z	, widths=z
, heights=z, qdens=z, t=z, dt=c                    s   g | ]}ˆ |Ž ‘qS r
   r
   ©rP   ÚargsrL   r
   r   rS   �   r3   Úviridis)ÚalphaÚcmapc                    s   g | ]}ˆ |Ž ‘qS r
   r
   rZ   rL   r
   r   rS   –   r3   ÚUVW)r+   zT [ms])!Úmatplotlib.patchesrM   Úmatplotlib.collectionsrN   r   r   r   r>   Ú
ValueErrorr   r   Úsizer   ÚmsÚzerosÚ	enumerateÚlogÚdebugÚshapeÚminÚmeanÚmaxÚzipÚvstackÚTÚ	set_arrayÚset_climÚadd_collectionÚset_xlimÚset_ylimrA   rB   Úcolorbar)%r"   rN   r*   ÚaxesÚblobsZqallÚindÚqÚtÚdtÚwbZiblobÚblobZiboundÚboundr]   ÚcscaleÚp1Úp2Zwb1Zwb2ÚpointsÚwidthsÚheightsZqdensZqmeanZtdensZtmeanÚr1Zpc1ÚtptsÚr2Zpc2Úax1Úax2Úl1Úl2r
   rL   r   Ú
plot_views[   sz    
..(  

:


44


44

rŒ   )r   r   )Ú__doc__Úwirecellr   Úmatplotlib.pyplotÚpyplotr   r   ÚloggingÚ	getLoggerrg   Ú	converterr   r   r.   r2   r4   r6   r<   rG   rI   rJ   rK   rŒ   r
   r
   r
   r   Ú<module>   s"   

