B
    }d                 @   sL   d Z ddlmZ ddlmZ ddlmZ ddlmZ dZ	G d	d
 d
eZ
dS )zCoherence plots
    )OrderedDict   )Plot)label_to_latex   )Spectrumz&Joseph Areeda <joseph.areeda@ligo.org>c                   sh   e Zd ZdZdZdZ fddZe fddZ fdd	Z	d
d Z
dd Zdd Z fddZ  ZS )	CoherencezYPlot coherence between a reference time series and one
    or more other time series
    	coherencer   c                sB   t  j|| | jjp| jd | _d| jkr>| jdd | _d S )Nr   ,)super__init__argsrefZ	chan_listref_chansplit)selfr   kwargs)	__class__ _/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/gwpy/cli/coherence.pyr   '   s    
zCoherence.__init__c                s   t  |}|jddd |S )Nz--refz7Reference channel against which others will be compared)help)r   arg_channelsadd_argument)clsparsergroup)r   r   r   r   .   s    zCoherence.arg_channelsc                s>   |j d krd|_ |j dkr2|js&d|_|js2d|_t |S )NZlinearr   g?)ZyscaleZyminZymaxr   _finalize_arguments)r   r   )r   r   r   r   5   s    

zCoherence._finalize_argumentsc             C   s   dS )zText for y-axis label
        r   r   )r   r   r   r   
get_ylabel?   s    zCoherence.get_ylabelc             C   s   d| j  S )zFStart of default super title, first channel is appended to it
        zCoherence: )r   )r   r   r   r   get_suptitleD   s    zCoherence.get_suptitlec          	   C   s  | j }t|j}|j}| dd||f  |dk	r:||9 }| dd| j  t }xX| jD ]N}|j}y||| |j	j
< W qZ tk
r   t ||< ||| |j	j
< Y qZX qZW t| j| jd}| }g | _x|D ]}|| | j}	x|| D ]t}
|| |
 }|j|	|||jd}|
}t| jdkr8|d	|jj 7 }| jrHt|}|j||d
 | j| qW qW |jdkr|jsd| |_|S )z9Generate the coherence plot from all time series
        r   z-Calculating spectrum secpfft: %s, overlap: %sN   zReference channel: )figsizedpi)	fftlengthoverlapwindowr   z, )labellog)r   floatZsecpfftr#   r&   r   r   Z
timeseriesspanZchannelnameKeyErrorr   r    r!   ZgcaZspectrapopr	   r$   len
start_listepochZgpsZusetexr   plotappendZxscaleZxmin)r   r   r"   r#   groupsZseriessegr/   ZaxZreftsr)   Zcohr%   r   r   r   	make_plotI   sF    



zCoherence.make_plotc                s    t   }|dk	r|d |S )z)Create a legend for this product
        NzCoherence with:)r   
set_legend	set_title)r   leg)r   r   r   r4   }   s    

zCoherence.set_legend)__name__
__module____qualname____doc__actionZMIN_DATASETSr   classmethodr   r   r   r   r3   r4   __classcell__r   r   )r   r   r      s   
4r   N)r:   collectionsr   r/   r   Zplot.texr   Zspectrumr   
__author__r   r   r   r   r   <module>   s   