from radtrans_integrate import radtrans_integrate
from polsynchemis import polsynchemis
import numpy as np
import scipy.integrate

# calculate synchrotron emissivity for given coefficients
def synch_jarho(nu,n,B,T,theta):
    if ((np.isscalar(nu)==False) & (np.isscalar(n)==True)):
        n = n + np.zeros(len(nu))
        B = B + np.zeros(len(nu))
        T = T + np.zeros(len(nu))
        theta = theta + np.zeros(len(nu))
    e = polsynchemis.polsynchth(nu,n,B,T,theta)
    j = e[:,:4]; a = e[:,4:8]; rho = e[:,8:]
    return j,a,rho

def run(x,jarr,aarr,rhoarr,sphstokes=-1,atol=1e-8,rtol=1e-6,max_tau=10):
    if sphstokes==-1:
        method=0
    else:
        method=3
    radtrans_integrate.init_radtrans_integrate_data(method,4,len(x),len(x),max_tau,0.1,atol,rtol,1e-2,100000)
    Karr = (np.append(aarr,rhoarr,axis=1))
    tau = np.append(0.,scipy.integrate.cumtrapz(Karr[:,0],x))
    radtrans_integrate.integrate(x[::-1],jarr[:,:],Karr[:,:],tau,4)
    i = radtrans_integrate.intensity.copy()
    radtrans_integrate.del_radtrans_integrate_data()
    return i

[((13, 8, 13, 47), 'polsynchemis.polsynchemis.polsynchth', 'polsynchemis.polsynchth', ({(13, 32, 13, 34): 'nu', (13, 35, 13, 36): 'n', (13, 37, 13, 38): 'B', (13, 39, 13, 40): 'T', (13, 41, 13, 46): 'theta'}, {}), '(nu, n, B, T, theta)', False, 'from polsynchemis import polsynchemis\n'), ((23, 12, 23, 41), 'numpy.append', 'np.append', (), '', True, 'import numpy as np\n'), ((25, 4, 25, 67), 'radtrans_integrate.radtrans_integrate.integrate', 'radtrans_integrate.integrate', ({(25, 33, 25, 40): 'x[::-1]', (25, 41, 25, 50): 'jarr[:, :]', (25, 51, 25, 60): 'Karr[:, :]', (25, 61, 25, 64): 'tau', (25, 65, 25, 66): '(4)'}, {}), '(x[::-1], jarr[:, :], Karr[:, :], tau, 4)', False, 'from radtrans_integrate import radtrans_integrate\n'), ((26, 8, 26, 43), 'radtrans_integrate.radtrans_integrate.intensity.copy', 'radtrans_integrate.intensity.copy', ({}, {}), '()', False, 'from radtrans_integrate import radtrans_integrate\n'), ((27, 4, 27, 52), 'radtrans_integrate.radtrans_integrate.del_radtrans_integrate_data', 'radtrans_integrate.del_radtrans_integrate_data', ({}, {}), '()', False, 'from radtrans_integrate import radtrans_integrate\n'), ((8, 9, 8, 24), 'numpy.isscalar', 'np.isscalar', ({(8, 21, 8, 23): 'nu'}, {}), '(nu)', True, 'import numpy as np\n'), ((8, 36, 8, 50), 'numpy.isscalar', 'np.isscalar', ({(8, 48, 8, 49): 'n'}, {}), '(n)', True, 'import numpy as np\n')]