def cmo_synth_lte(atmosData):
    with open(os.devnull, 'w') as f:
        with redirect_stdout(f):
            atmos = Atmosphere(ScaleType.Geometric,
                               depthScale=atmosData['height'],
                               temperature=atmosData['temp'],
                               vlos=atmosData['vlos'],
                               vturb=4000 * np.ones_like(atmosData['height']))

            aSet = RadiativeSet([
                H_3_atom(),
                C_atom(),
                O_atom(),
                Si_atom(),
                Al_atom(),
                CaII_atom(),
                Fe_atom(),
                He_atom(),
                MgII_atom(),
                N_atom(),
                Na_atom(),
                S_atom()
            ])
            aSet.set_active('Ca')

            spect = aSet.compute_wavelength_grid()

            atmos.convert_scales(Pgas=atmosData['pgas'])
            atmos.quadrature(5)

            eqPops = aSet.iterate_lte_ne_eq_pops(atmos)
            ctx = LwContext(atmos, spect, eqPops, conserveCharge=False)
            iterate_ctx(ctx, eqPops, prd=False)
            Iwave = ctx.compute_rays(wave, [1.0])
            return Iwave
def synth_halpha(atmos, dopplerLines=False):
    atmos.convert_scales()
    atmos.quadrature(5)

    Hatom = H_6_doppler if dopplerLines else H_6_atom
    aSet = lw.RadiativeSet([
        Hatom(),
        C_atom(),
        O_atom(),
        Si_atom(),
        Al_atom(),
        CaII_atom(),
        Fe_atom(),
        He_9_atom(),
        MgII_atom(),
        N_atom(),
        Na_atom(),
        S_atom()
    ])
    aSet.set_active('H')
    spect = aSet.compute_wavelength_grid()

    eqPops = aSet.compute_eq_pops(atmos)
    ctx = lw.Context(atmos, spect, eqPops, Nthreads=8)
    iterate_ctx(ctx)
    Iwave = ctx.compute_rays(wave, [1.0], stokes=False)
    return ctx, Iwave
Beispiel #3
0
    def inner():
        atmos = Atmosphere(ScaleType.Geometric,
                           depthScale=atmosData['height'],
                           temperature=atmosData['temp'],
                           vlos=atmosData['vlos'],
                           vturb=4000 * np.ones_like(atmosData['height']))

        aSet = RadiativeSet([
            H_3_atom(),
            C_atom(),
            O_atom(),
            Si_atom(),
            Al_atom(),
            CaII_atom(),
            Fe_atom(),
            He_atom(),
            MgII_atom(),
            N_atom(),
            Na_atom(),
            S_atom()
        ])
        aSet.set_active('Ca')

        spect = aSet.compute_wavelength_grid()

        atmos.convert_scales(Pgas=atmosData['pgas'])
        atmos.quadrature(5)

        mols = MolecularTable()
        eqPops = aSet.iterate_lte_ne_eq_pops(mols, atmos)
        ctx = LwContext(atmos, spect, eqPops, conserveCharge=False)
        iterate_ctx(ctx, prd=False)
        eqPops.update_lte_atoms_Hmin_pops(atmos)
        Iwave = ctx.compute_rays(wave, [1.0])
        return Iwave
Beispiel #4
0
def synth_8542(atmos, backgroundProvider=None):
    atmos.convert_scales()
    atmos.quadrature(5)
    aSet = lw.RadiativeSet([
        H_6_atom(),
        C_atom(),
        O_atom(),
        Si_atom(),
        Al_atom(),
        CaII_atom(),
        Fe_atom(),
        He_9_atom(),
        MgII_atom(),
        N_atom(),
        Na_atom(),
        S_atom()
    ])
    aSet.set_active('Ca')
    spect = aSet.compute_wavelength_grid()

    eqPops = aSet.compute_eq_pops(atmos)
    ctx = lw.Context(atmos,
                     spect,
                     eqPops,
                     Nthreads=8,
                     backgroundProvider=backgroundProvider)
    iterate_ctx(ctx)
    eqPops.update_lte_atoms_Hmin_pops(atmos)
    Iwave = ctx.compute_rays(wave, [atmos.muz[-1]], stokes=False)
    return ctx, Iwave
Beispiel #5
0
def cmo_synth(atmosData, crsw=None):
    with open(os.devnull, 'w') as f:
        with redirect_stdout(f):
            if crsw is not None:
                crsw = crsw()
            atmos = Atmosphere(ScaleType.Geometric,
                               depthScale=atmosData['height'],
                               temperature=atmosData['temp'],
                               vlos=atmosData['vlos'],
                               vturb=4000 * np.ones_like(atmosData['height']))

            aSet = RadiativeSet([
                H_3_atom(),
                C_atom(),
                O_atom(),
                Si_atom(),
                Al_atom(),
                CaII_atom(),
                Fe_atom(),
                He_atom(),
                MgII_atom(),
                N_atom(),
                Na_atom(),
                S_atom()
            ])
            aSet.set_active('H', 'Ca')

            spect = aSet.compute_wavelength_grid()

            atmos.convert_scales(Pgas=atmosData['pgas'])
            atmos.quadrature(5)

            mols = MolecularTable()
            eqPops = aSet.iterate_lte_ne_eq_pops(mols, atmos)
            ctx = LwContext(atmos,
                            spect,
                            eqPops,
                            conserveCharge=True,
                            initSol=InitialSolution.Lte,
                            crswCallback=crsw)
            iterate_ctx(ctx, prd=False)
            eqPops.update_lte_atoms_Hmin_pops(atmos)
            Iwave = ctx.compute_rays(wave, [1.0])
            return Iwave
def synth_line(atmos, conserve, useNe=True, prd=False):
    atmos.convert_scales()
    atmos.quadrature(5)
    aSet = lw.RadiativeSet([
        H_6_atom(),
        C_atom(),
        O_atom(),
        Si_atom(),
        Al_atom(),
        CaII_atom(),
        Fe_atom(),
        He_9_atom(),
        MgII_atom(),
        N_atom(),
        Na_atom(),
        S_atom()
    ])
    aSet.set_active('H', 'Ca', 'Mg')
    spect = aSet.compute_wavelength_grid()

    molPaths = [get_default_molecule_path() + m + '.molecule' for m in ['H2']]
    mols = lw.MolecularTable(molPaths)

    if useNe:
        eqPops = aSet.compute_eq_pops(atmos, mols)
    else:
        eqPops = aSet.iterate_lte_ne_eq_pops(atmos, mols)
    ctx = lw.Context(atmos,
                     spect,
                     eqPops,
                     ngOptions=NgOptions(0, 0, 0),
                     hprd=False,
                     conserveCharge=conserve,
                     Nthreads=8)
    ctx.depthData.fill = True
    start = time.time()
    iterate_ctx(ctx, atmos, eqPops, prd=prd, updateLte=False)
    end = time.time()
    print('%.2f s' % (end - start))
    eqPops.update_lte_atoms_Hmin_pops(atmos)
    Iwave = ctx.compute_rays(wave, [atmos.muz[-1]], stokes=False)
    return ctx, Iwave
Beispiel #7
0
def cmo_synth_given(atmosData):
    with open(os.devnull, 'w') as f:
        with redirect_stdout(f):
            at = get_global_atomic_table()
            atmos = Atmosphere(ScaleType.Geometric,
                               depthScale=atmosData['height'],
                               temperature=atmosData['temp'],
                               vlos=atmosData['vlos'],
                               vturb=4000 * np.ones_like(atmosData['height']),
                               ne=atmosData['ne'],
                               nHTot=(atmosData['density'] /
                                      (at.weightPerH * Const.Amu)))

            aSet = RadiativeSet([
                H_3_atom(),
                C_atom(),
                O_atom(),
                Si_atom(),
                Al_atom(),
                CaII_atom(),
                Fe_atom(),
                He_atom(),
                MgII_atom(),
                N_atom(),
                Na_atom(),
                S_atom()
            ])
            aSet.set_active('Ca')

            spect = aSet.compute_wavelength_grid()

            atmos.convert_scales()
            atmos.quadrature(5)

            mols = MolecularTable()
            eqPops = aSet.iterate_lte_ne_eq_pops(mols, atmos)
            ctx = LwContext(atmos, spect, eqPops, conserveCharge=False)
            iterate_ctx(ctx, prd=False)
            Iwave = ctx.compute_rays(wave, [1.0])
            return Iwave
def cmo_synth(atmosData, crsw=None, NmaxIter=1000):
    with open(os.devnull, 'w') as f:
        with redirect_stdout(f):
            if crsw is not None:
                crsw = crsw()
            atmos = Atmosphere(ScaleType.Geometric,
                               depthScale=atmosData['height'],
                               temperature=atmosData['temp'],
                               vlos=atmosData['vlos'],
                               vturb=4000 * np.ones_like(atmosData['height']))

            aSet = RadiativeSet([
                H_6_atom(),
                C_atom(),
                O_atom(),
                Si_atom(),
                Al_atom(),
                CaII_atom(),
                Fe_atom(),
                He_atom(),
                MgII_atom(),
                N_atom(),
                Na_atom(),
                S_atom()
            ])
            aSet.set_active('H', 'Ca')

            spect = aSet.compute_wavelength_grid()

            atmos.convert_scales(Pgas=atmosData['pgas'])
            atmos.quadrature(5)

            eqPops = aSet.iterate_lte_ne_eq_pops(atmos)
            ctx = lw.Context(atmos,
                             spect,
                             eqPops,
                             conserveCharge=False,
                             initSol=InitialSolution.Lte,
                             crswCallback=crsw)
            converged = True
            exploding = False
            try:
                nIter = iterate_ctx(ctx,
                                    eqPops,
                                    prd=False,
                                    NmaxIter=NmaxIter,
                                    nr=True)
            except ConvergenceError:
                converged = False
                nIter = NmaxIter
            except ExplodingMatrixError:
                converged = False
                exploding = True
                nIter = NmaxIter

            if converged:
                eqPops.update_lte_atoms_Hmin_pops(atmos)
                Iwave = ctx.compute_rays(wave, [1.0])
                return {
                    'Iwave': Iwave,
                    'eqPops': eqPops,
                    'converged': converged,
                    'nIter': nIter,
                    'atmosData': atmosData,
                    'exploding': exploding
                }
            else:
                return {
                    'converged': converged,
                    'nIter': nIter,
                    'atmosData': atmosData,
                    'exploding': exploding
                }
Beispiel #9
0
coarse = fal_sampler(2, outer=True)
fine = fal_sampler(4)
coarse.quadrature(5)
fine.quadrature(5)
aSet = lw.RadiativeSet([
    H_6_atom(),
    C_atom(),
    O_atom(),
    Si_atom(),
    Al_atom(),
    CaII_atom(),
    Fe_atom(),
    He_9_atom(),
    MgII_atom(),
    N_atom(),
    Na_atom(),
    S_atom()
])
aSet.set_active('Ca')
spect = aSet.compute_wavelength_grid()

coarseEqPops = aSet.compute_eq_pops(coarse)
fineEqPops = aSet.compute_eq_pops(fine)
trueEqPops = aSet.compute_eq_pops(fine)

coarseCtx = lw.Context(coarse,
                       spect,
                       coarseEqPops,
                       ngOptions=lw.NgOptions(0, 0, 0),
                       conserveCharge=False,
                       initSol=lw.InitialSolution.Lte,
Beispiel #10
0
def synth_8542(atmos, conserve, useNe, wave):
    '''
    Synthesise a spectral line for given atmosphere with different
    conditions.

    Parameters
    ----------
    atmos : lw.Atmosphere
        The atmospheric model in which to synthesise the line.
    conserve : bool
        Whether to start from LTE electron density and conserve charge, or
        simply use from the electron density present in the atomic model.
    useNe : bool
        Whether to use the electron density present in the model as the
        starting solution, or compute the LTE electron density.
    wave : np.ndarray
        Array of wavelengths over which to resynthesise the final line
        profile for muz=1.

    Returns
    -------
    ctx : lw.Context
        The Context object that was used to compute the equilibrium
        populations.
    Iwave : np.ndarray
        The intensity at muz=1 for each wavelength in `wave`.
    '''
    # Configure the atmospheric angular quadrature
    atmos.quadrature(5)
    # Configure the set of atomic models to use.
    aSet = lw.RadiativeSet([
        H_6_atom(),
        C_atom(),
        O_atom(),
        Si_atom(),
        Al_atom(),
        CaII_atom(),
        Fe_atom(),
        He_9_atom(),
        MgII_atom(),
        N_atom(),
        Na_atom(),
        S_atom()
    ])
    # Set H and Ca to "active" i.e. NLTE, everything else participates as an
    # LTE background.
    aSet.set_active('H', 'Ca')
    # Compute the necessary wavelength dependent information (SpectrumConfiguration).
    spect = aSet.compute_wavelength_grid()

    # Either compute the equilibrium populations at the fixed electron density
    # provided in the model, or iterate an LTE electron density and compute the
    # corresponding equilibrium populations (SpeciesStateTable).
    if useNe:
        eqPops = aSet.compute_eq_pops(atmos)
    else:
        eqPops = aSet.iterate_lte_ne_eq_pops(atmos)

    # Configure the Context which holds the state of the simulation for the
    # backend, and provides the python interface to the backend.
    # Feel free to increase Nthreads to increase the number of threads the
    # program will use.
    ctx = lw.Context(atmos, spect, eqPops, conserveCharge=conserve, Nthreads=1)
    start = time.time()
    # Iterate the Context to convergence
    iterate_ctx(ctx)
    end = time.time()
    print('%.2f s' % (end - start))
    # Update the background populations based on the converged solution and
    # compute the final intensity for mu=1 on the provided wavelength grid.
    eqPops.update_lte_atoms_Hmin_pops(atmos)
    Iwave = ctx.compute_rays(wave, [atmos.muz[-1]], stokes=False)
    return ctx, Iwave
def make_fal_context(velShift=0.0):
    atmos = Falc82()
    atmos.vlos[:] = velShift
    atmos.convert_scales()
    atmos.quadrature(5)
    aSet = lw.RadiativeSet([H_6_atom(), C_atom(), O_atom(), Si_atom(), Al_atom(), CaII_atom(), Fe_atom(), He_9_atom(), MgII_atom(), N_atom(), Na_atom(), S_atom()])
    aSet.set_active('H', 'Ca')
    spect = aSet.compute_wavelength_grid()

    eqPops = aSet.compute_eq_pops(atmos)

    ctx = lw.Context(atmos, spect, eqPops, ngOptions=NgOptions(0,0,0), Nthreads=1)
    return ctx