a
    ºb»bÿ  ã                   @   sô  d Z ddlZddlmZmZ ddlZddlmZ e	e	ddgd�d�Z
ejf i e
¤Žejdd	„ ƒƒZdHdd„ZdIdd„Ze d¡ejdddd�ejddddd�ejddd
dd�ejddd�dd„ ƒƒƒƒƒZe d ¡ejd!d"d#d$d�ejd%d&d'd(d�ejd)d*d+d,d�ejd-d.d/ed0d1�ejd2d
d3d4d5�e d6¡e d7¡ejd8d „ ƒƒƒƒƒƒƒƒƒZe d9¡ejd%d:d'd;d�ejdd<edd=d>�ejd?d@eefddAd>�ejd2d
d3d4d5�e dB¡e dC¡e d7¡ejdDd „ ƒƒƒƒƒƒƒƒƒZdEdF„ ZdGek�rðeƒ  dS )Jz
Main CLI to wirecell.plot.
é    N)ÚarioÚ	plottoolsz-hz--help)Zhelp_option_names)Zcontext_settingsc                 C   s   |   t¡ dS )z.
    wirecell-plot command line interface
    N)Zensure_objectÚdict)Úctx© r   ú>/home/yuhw/wc/wire-cell-python-pr-11/wirecell/plot/__main__.pyÚcli   s    r   Tc                 C   s   | r|rdS dS |rdS dS )zÿ
    An opinionated selection of the available colormaps.

    Diverging picks a cmap with central value as white, o.w. zero is
    white.  If color is False then a grayscale is used.

    https://matplotlib.org/stable/tutorials/colors/colormaps.html
    ÚseismicZRedsZGreysr   )Ú	divergingÚcolorr   r   r   Ú	good_cmap   s
    	r   c                 C   sJ   dD ]}|   |¡rtd|ƒ  S qdD ]}|   |¡r&td|ƒ  S q&tƒ S )z9
    Return a good color map for the given data tier
    )ÚorigÚrawT©ZgaussZwienerF)Ú
startswithr   )Útierr   r
   Z
sequentialr   r   r   Ú	tier_cmap%   s    

r   zntier-framesz--cmapr	   zSet the color map)ÚdefaultÚhelpz-oz--outputzntier-frames.pdfzOutput filez-czGive color map as tier=cmap)Zmultipler   Úfileséÿÿÿÿ)Únargsc                 C   s>  |  d¡r td|› �ƒ tj}ntd|› �ƒ tj}dd„ dd„ | D ƒD ƒ}dd„ |D ƒ}tƒ }tƒ }|D ]^}tƒ }	|D ]0}
|
 d	d
¡d  d¡d
d… \}}|	 |¡ qx| 	|¡ |s¾|	}qj| 
|	¡}qjt|ƒ}| ¡  t|ƒ}||ƒ��<}|D �]$}t||ƒD �]\}}tjd
d
d�\}}d}d}| d¡�r:d}d}d|› d|› �}z|| }W nD t�yš   td|› dt|ƒ› �ƒ td | ¡ ¡ƒ Y �qY n0 t||jƒ |jtj|d
d�j j}| |d¡} |j|dd| d�}t |¡ t d¡ t d¡ tj||d� | |¡ �qqòW d  ƒ n1 �s00    Y  dS )z‡
    Plot a number of per tier frames.

    Each file should a "frame file" (an ario stream of
    frame/channels/tickinfo arrays)
    ZpdfzSaving to pdf: zSaving to: c                 S   s   i | ]}|d  |d “qS )r   é   r   )Ú.0Zkvr   r   r   Ú
<dictcomp>I   ó    z ntier_frames.<locals>.<dictcomp>c                 S   s   g | ]}|  d ¡‘qS )ú=)Úsplit)r   Úxr   r   r   Ú
<listcomp>I   r   z ntier_frames.<locals>.<listcomp>c                 S   s   g | ]}t  |¡‘qS r   )r   Úload)r   Úfr   r   r   r   K   r   Ú.r   r   Ú_N)ZnrowsZncolsiçÿÿÿé   r   i'  Zframe_zNo such key "z
".  Have: ú )ZaxisZviridisZequalZnone)ZaspectÚinterpolationÚcmapztime sampleszchannel IDs)Úax)ÚendswithÚprintr   ZPdfPagesZNameSequenceÚlistÚsetr   ÚaddÚappendÚintersectionÚsortÚlenÚzipÚpltZsubplotsr   ÚKeyErrorÚjoinÚkeysÚshapeÚTÚnumpyZmedianÚgetZimshowÚtitleZxlabelZylabelZcolorbarZsavefig)r'   Úoutputr   ZOuterZcmapsZreadersZtiersZidentsÚreaderZmyidsÚkeyÚnameÚidentZntiersÚoutr   Zfigr(   ZvminZvmaxZanameZarrZimr   r   r   Úntier_frames2   s\    
"




rB   Úframez-nz--nameZwavezThe frame plot namez-tz--tagr   zThe frame tagz-uz--unitZADCzThe color unitsz-rz--rangeg      9@zThe color range)r   Útyper   z--interactiveFzrunning in interactive mode)Zis_flagr   r   Údatafiler<   c              	   C   sb   ddl m} t||ƒ}	t |¡}
t |¡�$}|	|
|||||d� W d  ƒ n1 sT0    Y  dS )z)
    Make frame plots of given type.
    r   ©Úframes)ÚinteractiveN)Ú rG   Úgetattrr   r    r   Úpages)r   r?   ÚtagZunitÚrangerH   rE   r<   rG   ÚmodZdatrA   r   r   r   rC   {   s
    

z	wave-compz--tierzorig, gauss, ...z	--channelzwhich channel to check)rD   r   r   z-xz--xrangeztick range of the outputÚ	datafile1Ú	datafile2c           
   
   C   sR   ddl m} t |¡�(}	|j|||	||||d� W d  ƒ n1 sD0    Y  dS )z&
    Compare waveforms from files
    r   rF   )r   ÚchannelÚxrangerH   N)rI   rG   r   rK   Z	wave_comp)
r   r   rQ   rR   rH   rO   rP   r<   rG   rA   r   r   r   rC   ”   s
    
ÿc                   C   s   t tƒ d� d S )N)Úobj)r   r   r   r   r   r   Úmain¬   s    rT   Ú__main__)TT)T)Ú__doc__ZclickZwirecell.utilr   r   r9   Zmatplotlib.pyplotZpyplotr3   r   ZcmddefÚgroupZpass_contextr   r   r   ZcommandÚoptionZargumentrB   ÚfloatrC   ÚintrT   Ú__name__r   r   r   r   Ú<module>   s€   

ÿ
ÿþ@
ÿ
ÿ
ÿÿ
ÿ
ÿÿÿ
ÿ
