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
Exemple #2
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
Exemple #3
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
Exemple #4
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
Exemple #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_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)
            converged = True
            exploding = False
            try:
                nIter = iterate_ctx(ctx, prd=False, NmaxIter=NmaxIter)
            except ConvergenceError:
                converged = False
                nIter = NmaxIter
            except ExplodingMatrixError:
                converged = False
                exploding = True
                nIter = NmaxIter

            if converged:
                eqPops.update_lte_atoms_Hmin_pops(atmos)
                IwaveCa = ctx.compute_rays(waveCa, [1.0])
                IwaveHa = ctx.compute_rays(waveHa, [1.0])
                return {
                    'IwaveCa': IwaveCa,
                    'IwaveHa': IwaveHa,
                    'eqPops': eqPops,
                    'converged': converged,
                    'nIter': nIter,
                    'atmosData': atmosData,
                    'exploding': exploding
                }
            else:
                return {
                    'converged': converged,
                    'nIter': nIter,
                    'atmosData': atmosData,
                    'exploding': exploding
                }