B
    d                 @   s   d dl Z d dlZd dlZd dlZd dlmZ dZdZi Zi Z	dd Z
dd Zd	d
 Zdd ZeeddZdd Zeje_dd ZeeddZdd Zeje_dd ZeeddZdd Zeje_dS )    N)CubicSplinegZڊ?g>c       
   	   C   s   d |t||}yttd |}W n& tk
rN   td |||Y nX t|dD}d|d d  }|| |  d }	|dkr|	j	}	n|d	kr|	j
}	W d
Q R X t||	ddddS )z3Creates a cubic spline for the specified mode data.z{}{}{}zdata/l{}.hdfzunsupported lmn {}{}{}rg-C6?spin reimNr   z
not-a-knotF)ZaxisZbc_typeZextrapolate)formatabspkg_resourcesresource_stream__name__OSError
ValueErrorh5pyFilerealimagr   )
namereimlmnZlmndfilefpxyr   r   W/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/pykerr/qnm.py_create_spline   s    r   c          	   C   sR   y||t ||f }W n6 tk
rL   t| ||||}|||t ||f< Y nX |S )zGets a spline.)r	   KeyErrorr   )r   r   r   r   r   cachespliner   r   r   
_getspline'   s    r!   c             C   s   t | tkrtdtdS )z"Checks that the spin is in bounds.z|spin| must be < {}N)r	   MAX_SPINr   r   )r   r   r   r   
_checkspin1   s    r#   c             C   sV   t |  tdd|||t}tdd|||t}|| d||   }|dk rR|  }|S )a  Returns the dimensionless complex angular frequency of a Kerr BH.

    Parmeters
    ---------
    spin : float
        Dimensionless spin. Must be in [-0.9997, 0.9997].
    l : int
        The l index. Up to l=7 is supported.
    m : int
        The m index. All +/-m for the given l are supported.
    n : int
        The overtone number (where n=0 is the fundamental mode). Up to n=7 is
        supported.

    Returns
    -------
    complex :
        The complex angular frequency.
    omegar   r   y              ?r   )r#   r!   _reomega_splines_imomega_splinesZconj)r   r   r   r   ZresplineZimspliner$   r   r   r   	_qnmomega8   s    
r'         c             C   s*   t | |||}t|tjr&|tj}|S )N)_npqnmomega
isinstancenumpyndarrayastypecomplex)r   r   r   r   outr   r   r   qnmomegaY   s    r1   c             C   sF   t | tdd|||t}||}|dk r0| }|dtj |  t  S )a'  Returns the QNM frequency for a Kerr black hole.

    Parameters
    ----------
    mass : float
        Mass of the object (in solar masses).
    spin : float
        Dimensionless spin. Must be in [-0.9997, 0.9997].
    l : int
        The l index. Up to l=7 is supported.
    m : int
        The m index. All +/-m for the given l are supported.
    n : int
        The overtone number (where n=0 is the fundamental mode). Up to n=7 is
        supported.

    Returns
    -------
    float :
        The frequency (in Hz) of the requested mode.
    r$   r   r      )r#   r!   r%   r,   piMTSUN)massr   r   r   r   r    Zreomegar   r   r   _qnmfreqb   s    r6      c             C   s,   t | ||||}t|tjr(|tj}|S )N)
_npqnmfreqr+   r,   r-   r.   float)r5   r   r   r   r   r0   r   r   r   qnmfreq   s    r:   c             C   s,   t | tdd|||t}|  t || S )a+  "Returns the QNM damping time for a Kerr black hole.

    Parameters
    ----------
    mass : float
        Mass of the object (in solar masses).
    spin : float
        Dimensionless spin. Must be in [-0.9997, 0.9997].
    l : int
        The l index. Up to l=7 is supported.
    m : int
        The m index. All +/-m for the given l are supported.
    n : int
        The overtone number (where n=0 is the fundamental mode). Up to n=7 is
        supported.

    Returns
    -------
    float :
        The frequency (in Hz) of the requested mode.
    r$   r   )r#   r!   r&   r4   )r5   r   r   r   r   r    r   r   r   _qnmtau   s    r;   c             C   s,   t | ||||}t|tjr(|tj}|S )N)	_npqnmtaur+   r,   r-   r.   r9   )r5   r   r   r   r   r0   r   r   r   qnmtau   s    r=   )osr
   r,   r   Zscipy.interpolater   r"   r4   r%   r&   r   r!   r#   r'   Z
frompyfuncr*   r1   __doc__r6   r8   r:   r;   r<   r=   r   r   r   r   <module>   s.   
