Beispiel #1
0
def synthetic_phase_shift_cyl(d, lmbda):
    """
    Synthetic phase shift for a cylindrical simulation
    Parameters:
    -----------
      - d [dict]:  dictionary data containing fields (2D ndarrays), at least
          - r: radius array [cm] (must be equidistant)
          - z: height array [cm] (must be equidistant)
          - nele: electron density [cm⁻³]
      - lmbda: probe wavelenght [nm]

    Returns:
    --------
      - phase shift: 2D ndarray
    """
    Ne = d['nele']
    Nc = critical_density(lmbda)

    mu = np.sqrt(1 - Ne / Nc) - 1
    mu[Ne > Nc] = np.nan

    dr = np.diff(d['x'])[0, 0]
    mu_dl = abel(mu, dr) / (2 * lmbda * 1e-9 * 1e2)

    return np.ma.array(mu_dl, mask=np.isnan(mu_dl))
Beispiel #2
0
def synthetic_phase_shift_cyl(d, lmbda):
    """
    Synthetic phase shift for a cylindrical simulation
    Parameters:
    -----------
      - d [dict]:  dictionary data containing fields (2D ndarrays), at least
          - r: radius array [cm] (must be equidistant)
          - z: height array [cm] (must be equidistant)
          - nele: electron density [cm⁻³]
      - lmbda: probe wavelenght [nm]

    Returns:
    --------
      - phase shift: 2D ndarray
    """
    Ne = d['nele']
    Nc = critical_density(lmbda)

    mu = np.sqrt(1 - Ne/Nc) - 1
    mu[Ne>Nc] = np.nan

    dr = np.diff(d['x'])[0,0]
    mu_dl = abel(mu, dr)/(2*lmbda*1e-9*1e2)
    
    return  np.ma.array(mu_dl, mask=np.isnan(mu_dl))
Beispiel #3
0
def test_abel_gaussian():
    n = 500
    r = np.linspace(0, 5., n)
    dr = np.diff(r)[0]
    rc = 0.5 * (r[1:] + r[:-1])
    fr = np.exp(-rc**2)
    Fn = abel(fr, dr=dr)
    Fn_a = np.pi**0.5 * np.exp(-rc**2)
    yield assert_allclose, Fn, Fn_a, 1e-2, 1e-3
Beispiel #4
0
def test_abel_gaussian():
    n = 500
    r = np.linspace(0, 5.0, n)
    dr = np.diff(r)[0]
    rc = 0.5 * (r[1:] + r[:-1])
    fr = np.exp(-rc ** 2)
    Fn = abel(fr, dr=dr)
    Fn_a = np.pi ** 0.5 * np.exp(-rc ** 2)
    yield assert_allclose, Fn, Fn_a, 1e-2, 1e-3
Beispiel #5
0
def synthetic_shadowgraphy_cyl(d, lmbda, L=10, absorption=True, refraction=False):
    """
    Compute angle of refraction for a plasma assuming cylindrical symmetry on an axis
    orthogonal to the propagation axis.

    Parameters:
    -----------
      - d [dict]:  dictionary data containing fields (2D ndarrays), at least
          - r: radius array [cm] (must be equidistant)
          - z: height array [cm] (must be equidistant)
          - dens: solid density [g.cm⁻³]
          - Abar: mean atomic mass [g.mol⁻¹]
          - Zbar: mean ionization
      - lmbda: probe wavelenght [nm]
      - L: distance to detector [cm]
    Returns:
    --------
      - theta: 2D ndarray: refracted angle

    Source: Shlieren and shadowgraph techniques. G.Settles 
    """
    dI = np.ones(d['nele'].shape)
    Ne = d['nele']
    Nc = critical_density(lmbda)

    if refraction:
        # this doesn't seem to work so well

        Ref = 1 - np.sqrt(1 - Ne/Nc)
        Ref[Ne>Nc] = np.nan


        dr = np.diff(d['r'])[0,0]
        Ref_dl = abel(Ref, dr)
        d2Ref_dl = laplace(Ref_dl, dr)
        #pval =  (np.abs(np.gradient(Ref_dl)[0])/dr + np.abs(np.gradient(Ref_dl)[1])/dr)*180/np.pi
        #return d2Ref_dl
        dI0 = 1./(1. + d2Ref_dl)
        dI *= dI0
    if absorption:
        from scipy.constants import c
        nu_ei = 3e-6*d['nele']*d['Zbar']*10/d['tele']**(3./2)
        nu_ei = 1.0
        print(Nc)
        kernel = nu_ei*(Ne/Nc)/(c*(1 - Ne/Nc)**0.5)
        dr = np.diff(d['r'])[0,0]
        print(dr)
        kappa = kernel
        #kappa = abel(kernel, dr)
        dI0 = kappa#np.exp(-kappa)
        dI *= dI0
    return dI
Beispiel #6
0
def test_abel_step():
    n = 800
    r = np.linspace(0, 20, n)
    dr = np.diff(r)[0]
    rc = 0.5 * (r[1:] + r[:-1])
    fr = np.exp(-rc**2)
    #fr += 1e-1*np.random.rand(n)
    #    plt.plot(rc,fr,'b', label='Original signal')
    F = abel(fr, dr=dr)
    F_a = (np.pi)**0.5 * fr.copy()

    F_i = abel(F, dr=dr, inverse=True, derivative=np.gradient)
    #sys.exit()
    #    plt.plot(rc, F_a, 'r', label='Direct transform [analytical expression]')
    #    mask = slice(None,None,5)
    #    plt.plot(rc[mask], F[mask], 'ko', label='Direct transform [computed]')
    #    plt.plot(rc[mask], F_i[mask],'o',c='orange', label='Direct-inverse transform')
    #yield assert_allclose, fr, F_i, 5e-3, 1e-6, 'Test that direct>inverse Abel equals the original data'
    #yield assert_allclose, F_a, F, 5e-3, 1e-6, 'Test direct Abel transforms failed!'

    yield assert_allclose, fr, F_i, 5e-2, 1e-6, 'Test that direct>inverse Abel equals the original data'
    yield assert_allclose, F_a, F, 5e-3, 1e-6, 'Test direct Abel transforms failed!'
Beispiel #7
0
def test_abel_step():
    n = 800
    r = np.linspace(0, 20, n)
    dr = np.diff(r)[0]
    rc = 0.5 * (r[1:] + r[:-1])
    fr = np.exp(-rc ** 2)
    # fr += 1e-1*np.random.rand(n)
    #    plt.plot(rc,fr,'b', label='Original signal')
    F = abel(fr, dr=dr)
    F_a = (np.pi) ** 0.5 * fr.copy()

    F_i = abel(F, dr=dr, inverse=True, derivative=np.gradient)
    # sys.exit()
    #    plt.plot(rc, F_a, 'r', label='Direct transform [analytical expression]')
    #    mask = slice(None,None,5)
    #    plt.plot(rc[mask], F[mask], 'ko', label='Direct transform [computed]')
    #    plt.plot(rc[mask], F_i[mask],'o',c='orange', label='Direct-inverse transform')
    # yield assert_allclose, fr, F_i, 5e-3, 1e-6, 'Test that direct>inverse Abel equals the original data'
    # yield assert_allclose, F_a, F, 5e-3, 1e-6, 'Test direct Abel transforms failed!'

    yield assert_allclose, fr, F_i, 5e-2, 1e-6, "Test that direct>inverse Abel equals the original data"
    yield assert_allclose, F_a, F, 5e-3, 1e-6, "Test direct Abel transforms failed!"
Beispiel #8
0
def synthetic_radiography_cyl(d,
                              species,
                              nu,
                              spect_ip,
                              hdf5_backend='pickle',
                              transform=None):
    """
    Postprocess simulation to produce Xray
    
    Parameters:
    -----------
      - d [dict]:  data with all the fields
      - species [dict]: of species
      - nu [ndarray]: array of frequences [eV]
      - spect_ip [ndarray]: normalized spectra on ip
      - hdf5_backend: pytables or h5py
      - transform: a optional function
          def transform(d, op):
              # do something with d, op
              return d, op

    Returns:
    --------
      - trans [ndarray]: transmissions
    """
    spect_ip = spect_ip[np.newaxis, np.newaxis, :]
    dnu = np.diff(nu)[0]
    nu = nu  #[np.newaxis, np.newaxis, :]
    species_keys = sorted(species.keys())

    # projected density
    dr = np.diff(d['r'])[0, 0]
    pd = {key: abel(d['dens'] * d[key], dr) for key in species}
    # getting the opacitoy
    op = {
        key: hedp.opacity.henke.cold_opacity(species[key], pd[key], nu,
                                             hdf5_backend)
        for key in species
    }
    #if 'tube' in op:
    #    op['tube'][550:700,:37] = 1e-9

    if transform is not None:
        d, op = transform(d, op)

    op_int = hedp.math.add_multiple(*[op[key] for key in species])
    tm = np.sum(spect_ip * np.exp(-op_int), axis=-1) * dnu
    return tm
Beispiel #9
0
def synthetic_radiography_cyl(d, species, nu, spect_ip, hdf5_backend='pickle', transform=None):
    """
    Postprocess simulation to produce Xray
    
    Parameters:
    -----------
      - d [dict]:  data with all the fields
      - species [dict]: of species
      - nu [ndarray]: array of frequences [eV]
      - spect_ip [ndarray]: normalized spectra on ip
      - hdf5_backend: pytables or h5py
      - transform: a optional function
          def transform(d, op):
              # do something with d, op
              return d, op

    Returns:
    --------
      - trans [ndarray]: transmissions
    """
    spect_ip = spect_ip[np.newaxis, np.newaxis, :]
    dnu = np.diff(nu)[0]
    nu = nu#[np.newaxis, np.newaxis, :]
    species_keys = sorted(species.keys())

    # projected density
    dr = np.diff(d['r'])[0,0]
    pd = {key: abel(d['dens']*d[key], dr) for key in species}
    # getting the opacitoy
    op = {key: hedp.opacity.henke.cold_opacity(species[key], pd[key], nu, hdf5_backend) for key in species}
    #if 'tube' in op:
    #    op['tube'][550:700,:37] = 1e-9

    if transform is not None:
        d, op = transform(d, op)


    op_int  = hedp.math.add_multiple(*[op[key] for key in species])
    tm = np.sum(spect_ip * np.exp(-op_int), axis=-1)*dnu
    return tm
Beispiel #10
0
def test_abel_zeros():
    # just a sanity check
    n = 64
    x = np.zeros((n, n))
    assert (abel(x, inverse=False) == 0).all()
Beispiel #11
0
def test_abel_zeros():
    # just a sanity check
    n = 64
    x = np.zeros((n, n))
    assert (abel(x, inverse=False) == 0).all()