3
_f                 @   s   d Z dd ZdS )a  
**********************************************    
***   Program for the computation of the   ***
***              line profile              ***         
**********************************************
This code is part of the LIFELINE program.

Copyright (C) 2020-2021 University of Liege (Belgium)
Enmanuelle Mossoux (STAR Institute)
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 3 of the License, or any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.

Run: from compute_profile import profile
     p=profile(direct, direct2, ipar, nbr_bin_profile, q1, T, cs_interp, T_cs, energy, M, add, add2)

Read the files created by [r/a]shock[_coriolis].py in direct

# Parameters 
# ==========
direct - directory where the shock characteritics are saved
direct2 - directory where to save files
ipar - index of the binary system for which we read the ray-tracing files
nbr_bin_profile - number of bins in the line profile
q1 - interpolation function of the emissivity
T - tabulated temperatures used to define q1 
cs_interp - interpolation function of the cross-section
T_cs - tabulated temperatures used to define cs_interp
energy - rest energy of the line
M - orbital phase
add[2] - additional name when reading the set of binary systems

# Output
# ======
p - numpy array containing the emission in each bin

# Versions
# ========
v1 - 21/10/19
c       ,      C   sp  dd l }dd l}ddlm} dd lj}t| d t| | d d}xB|j j	 }|}|s\P yt
|d  P W qF tk
r   Y qFX qFW t| d t| | d d}xB|j j	 }|}|sP yt
|d  P W q tk
r   Y qX qW t| d t| | d d}xH|j j	 }|}|s"P yt
|d  P W n tk
rJ   Y nX q
W g }dt| | }t|| d d	}|jd
t|	 d  |jdt|
 d  |jd g }xtt|D ]}|jd |dkr|jt
|d  |}|}n*|jt
|j  |j j	 }|j j	 }dd |D }dd |D }t| d t| d t| | d d}xD|j j	 } | s~P yt
| d  P W n tk
r   Y nX qjW xttt|D ]v}!||! dkr||! d |d k s||! d |d% krqn||j||! d }"|!dkr4|j j	 } | dd d }#| dd d }$dd |#D }#dd |$D }$d}%xvttt|#D ]b}&|#|& t|k r|t|}'n,|#|& t|kr|t|}'n||#|& }'|%|'|$|&   }%qW |j||! |j|%  d|"   r|| ||! |j|%  d|"    ||< qW |j  |jt|d& d t||  d  qW |j  |j  |j  |j  |jd d|	 }(|(|j| d |d |( })t|dkrtd |)d }*d}+n$||j| }*t||j| d  }+|jd|) |* |j|	|	gddgdd! |jd|+ |jd" |jd# |j|| d$  |j  |S )'N    )	constantez/bin_parz.datarz/emiss_part_shock_parz/temp_emiss_parz/line_profile_parwz# Energy (keV) = 
z5# Phases (mean anomaly, radian, M=0 -> conjunction): z8# tangential velocity (km/s) | luminosity (10^27 erg/s)
c             S   s   g | ]}t |qS  )float).0xr   r   8/local/network/htdocs/Lifeline/codes3/compute_profile.py
<listcomp>h   s    zprofile.<locals>.<listcomp>c             S   s   g | ]}t |qS r   )r   )r   r	   r   r   r
   r   i   s    z/ray_tracing_par_binghh!w>      c             S   s   g | ]}t |qS r   )r   )r   r	   r   r   r
   r      s    c             S   s   g | ]}t |qS r   )r   )r   r	   r   r   r
   r      s    g        g      $@ g0O(@g     @@czNo X-ray emissiong      ?g?)r   zEnergy (keV)zNormalized emissionz.pdfr   ) numpymath
constantesr   matplotlib.pyplotpyplotopenstrreadlinesplitr   
ValueErrorwriterangeintappendlenlog10minmaxisfiniteexpclosefigurearrayprintnansumplotylimxlabelylabelsavefig),directdirect2Ziparuseriparnbr_bin_profileq1T	cs_interpT_csenergyMaddadd2npr   r   pltfbinlineZbin1fhistoZhisto1ftemptemp1ZvtangZ	nom_debutZfprofileZemissZibinZfacteurZtemperfRTZligneitempqZtemperRTZfactRTtauZitemp2cssZ
wavelengthwaveZ	y_to_plotZy_limitr   r   r
   profile1   s    
 
 
 


* ,
&0,


rI   N)__doc__rI   r   r   r   r
   <module>-   s   