コード例 #1
0
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
コード例 #2
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
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
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
                }
コード例 #6
0
    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,
                       Nthreads=8)
fineCtx = lw.Context(fine,
                     spect,
                     fineEqPops,
                     ngOptions=lw.NgOptions(0, 0, 0),
                     conserveCharge=False,
                     initSol=lw.InitialSolution.Lte,
                     Nthreads=8)
trueCtx = lw.Context(fine,
                     spect,
                     trueEqPops,
                     ngOptions=lw.NgOptions(0, 0, 0),
                     conserveCharge=False,
コード例 #7
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
コード例 #8
0
    CaII_atom(),
    Fe_atom(),
    He_atom(),
    Mg_atom(),
    N_atom(),
    Na_atom(),
    S_atom()
])
aSet.set_active('Ca')
spect = aSet.compute_wavelength_grid()

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

baseEqPops = aSet.compute_eq_pops(baseAtmos)
baseCtx = lw.Context(baseAtmos, spect, baseEqPops, Nthreads=8)
eqPopses = [aSet.compute_eq_pops(a) for a in atmoses]
ctxs = [lw.Context(a, spect, e, Nthreads=8) for a, e in zip(atmoses, eqPopses)]

eta1 = 1e-1
eta2 = 5e-4
nu1 = 2
nu2 = 4

Rc = 1.0
count = 0
global nIter
nIter = [0 for f in ctxs]
start = time.time()
for i in range(nu2):
    ctxs[-1].formal_sol_gamma_matrices()
コード例 #9
0
    He_9_atom(),
    MgII_atom(),
    N_atom(),
    Na_atom(),
    S_atom()
])
aSet.set_active(AtomName)
spect = aSet.compute_wavelength_grid()

eqPops = [aSet.compute_eq_pops(atmos) for atmos in falHeirarchy]

ctx = [
    lw.Context(atmos,
               spect,
               pops,
               ngOptions=lw.NgOptions(0, 0, 0),
               conserveCharge=False,
               initSol=lw.InitialSolution.Lte,
               Nthreads=8) for atmos, pops in zip(falHeirarchy, eqPops)
]

Nested = False
mgStart = time.time()
global nIter
nIter = [0 for f in falHeirarchy]
if Nested:
    # Full multigrid V-cycle
    # NOTE(cmo): Initial guess on coarsest grid
    for i in range(100):
        dJ = ctx[0].formal_sol_gamma_matrices()
        delta = stat_equil(ctx[0])