示例#1
0
    def ingest_levels(self):

        logger.info("Ingesting levels from `{}`.".format(
            self.data_source.short_name))

        for rdr in self.ion_readers:

            atomic_number = rdr.ion.Z
            ion_charge = rdr.ion.Ion - 1

            ion = Ion.as_unique(self.session,
                                atomic_number=atomic_number,
                                ion_charge=ion_charge)

            try:
                bound_levels = rdr.bound_levels
            except ChiantiIonReaderError:
                logger.info("Levels not found for ion {} {}.".format(
                    convert_atomic_number2symbol(atomic_number), ion_charge))
                continue

            logger.info("Ingesting levels for {} {}.".format(
                convert_atomic_number2symbol(atomic_number), ion_charge))

            # ToDo: Determine parity from configuration

            for index, row in bound_levels.iterrows():

                level = Level(ion=ion,
                              data_source=self.data_source,
                              level_index=index,
                              configuration=row["configuration"],
                              term=row["term"],
                              L=row["L"],
                              J=row["J"],
                              spin_multiplicity=row["spin_multiplicity"])

                level.energies = []
                for column, method in [('energy', 'meas'),
                                       ('energy_theoretical', 'theor')]:
                    if row[column] != -1:  # check if the value exists
                        level.energies.append(
                            LevelEnergy(quantity=row[column] * u.Unit("cm-1"),
                                        data_source=self.data_source,
                                        method=method), )
                self.session.add(level)
示例#2
0
    def ingest_levels(self, levels=None):

        if levels is None:
            levels = self.gfall_reader.levels

        # Select ions
        if self.ions is not None:
            levels = levels.reset_index().\
                join(self.ions, how="inner",
                     on=["atomic_number", "ion_charge"]).\
                set_index(["atomic_number", "ion_charge", "level_index"])

        logger.info("Ingesting levels from `{}`.".format(
            self.data_source.short_name))

        for ion_index, ion_levels in levels.groupby(
                level=["atomic_number", "ion_charge"]):

            atomic_number, ion_charge = ion_index
            ion = Ion.as_unique(self.session,
                                atomic_number=atomic_number,
                                ion_charge=ion_charge)

            logger.info("Ingesting levels for {} {}.".format(
                convert_atomic_number2symbol(atomic_number), ion_charge))

            for index, row in ion_levels.iterrows():

                # index: (atomic_number, ion_charge, level_index)
                level_index = index[2]

                ion.levels.append(
                    Level(level_index=level_index,
                          data_source=self.data_source,
                          J=row["j"],
                          energies=[
                              LevelEnergy(quantity=row["energy"] *
                                          u.Unit("cm-1"),
                                          method=row["method"],
                                          data_source=self.data_source)
                          ]))
示例#3
0
    def ingest_ground_levels(self, ground_levels=None):

        if ground_levels is None:
            ground_levels = self.parser.prepare_ground_levels()

        print("Ingesting ground levels from {}".format(
            self.data_source.short_name))

        for index, row in ground_levels.iterrows():
            atomic_number, ion_charge = index

            # Replace nan with None
            row = row.where(pd.notnull(row), None)

            ion = Ion.as_unique(self.session,
                                atomic_number=atomic_number,
                                ion_charge=ion_charge)

            try:
                spin_multiplicity = int(row["spin_multiplicity"])
            except TypeError:  # Raised when the variable is None
                spin_multiplicity = None

            try:
                parity = int(row["parity"])
            except TypeError:  # Raised when the variable is None
                parity = None

            ion.levels.append(
                Level(data_source=self.data_source,
                      configuration=row["configuration"],
                      term=row["term"],
                      L=row["L"],
                      spin_multiplicity=spin_multiplicity,
                      parity=parity,
                      J=row["J"],
                      energies=[
                          LevelEnergy(quantity=0, data_source=self.data_source)
                      ]))
示例#4
0
def foo_engine():
    engine = create_engine(foo_db_url)
    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)
    session = Session(bind=engine)

    # atoms
    h = Atom(atomic_number=1, symbol='H')
    ne = Atom(atomic_number=10, symbol='Ne')

    # data sources
    nist = DataSource(short_name='nist')
    ku = DataSource(short_name='ku')
    ch = DataSource(short_name="chianti")

    # atomic weights
    h.weights = [
        AtomWeight(quantity=1.00784 * u.u, data_source=nist, uncert=4e-3),
        AtomWeight(quantity=1.00811 * u.u, data_source=ku, uncert=4e-3),
    ]

    # ions
    h0 = Ion(atomic_number=1,
             ion_charge=0,
             ionization_energies=[
                 IonizationEnergy(quantity=13.5984 * u.eV,
                                  data_source=nist,
                                  method="th")
             ])

    ne1 = Ion(atomic_number=10,
              ion_charge=1,
              ionization_energies=[
                  IonizationEnergy(quantity=40.96296 * u.eV,
                                   data_source=nist,
                                   method="th"),
                  IonizationEnergy(quantity=40.97 * u.eV,
                                   data_source=nist,
                                   method="m")
              ])

    ne2 = Ion(atomic_number=10,
              ion_charge=2,
              ionization_energies=[
                  IonizationEnergy(quantity=48.839 * u.eV,
                                   data_source=nist,
                                   method="th")
              ])

    # levels
    ne2_lvl0_ku = Level(ion=ne2,
                        data_source=ku,
                        level_index=0,
                        configuration="2s2.2p5",
                        term="2P1.5",
                        L="P",
                        J=1.5,
                        spin_multiplicity=2,
                        parity=1,
                        energies=[
                            LevelEnergy(quantity=0, data_source=ku,
                                        method="m"),
                            LevelEnergy(quantity=0,
                                        data_source=ku,
                                        method="th")
                        ])

    ne2_lvl1_ku = Level(ion=ne2,
                        data_source=ku,
                        level_index=1,
                        configuration="2s2.2p5",
                        term="2P0.5",
                        L="P",
                        J=0.5,
                        spin_multiplicity=2,
                        parity=1,
                        energies=[
                            LevelEnergy(quantity=780.4 * u.Unit("cm-1"),
                                        data_source=ku,
                                        method="m"),
                            LevelEnergy(quantity=780.0 * u.Unit("cm-1"),
                                        data_source=ku,
                                        method="th")
                        ])

    ne2_lvl2_ku = Level(ion=ne2,
                        data_source=ku,
                        level_index=2,
                        configuration="2s2.2p5",
                        term="2D2.5",
                        L="D",
                        J=2.5,
                        spin_multiplicity=2,
                        parity=0,
                        energies=[
                            LevelEnergy(quantity=1366.3 * u.Unit("cm-1"),
                                        data_source=ku,
                                        method="m")
                        ])

    ne2_lvl1_ch = Level(ion=ne2,
                        data_source=ch,
                        level_index=1,
                        configuration="2s2.2p5",
                        term="2P0.5",
                        L="P",
                        J=0.5,
                        spin_multiplicity=2,
                        parity=1,
                        energies=[
                            LevelEnergy(quantity=780.2 * u.Unit("cm-1"),
                                        data_source=ch,
                                        method="m")
                        ])

    # lines
    ne2_line0_ku = Line(
        lower_level=ne2_lvl0_ku,
        upper_level=ne2_lvl1_ku,
        data_source=ku,
        wavelengths=[LineWavelength(quantity=183.571 * u.AA, data_source=ku)],
        a_values=[
            LineAValue(quantity=5.971e-03 * u.Unit("s-1"), data_source=ku)
        ],
        gf_values=[LineGFValue(quantity=8.792e-01, data_source=ku)])

    ne2_line1_ku = Line(
        lower_level=ne2_lvl0_ku,
        upper_level=ne2_lvl2_ku,
        data_source=ku,
        wavelengths=[
            LineWavelength(quantity=18.4210 * u.nm, medium=1, data_source=ku)
        ],
        a_values=[
            LineAValue(quantity=5.587e-03 * u.Unit("s-1"), data_source=ku)
        ],
        gf_values=[LineGFValue(quantity=8.238e-01, data_source=ku)])

    # electron collisions
    ne2_e_col0_ku = ECollision(
        lower_level=ne2_lvl0_ku,
        upper_level=ne2_lvl1_ku,
        data_source=ku,
        bt92_ttype=2,
        bt92_cups=11.16,
        energies=[
            ECollisionEnergy(quantity=0.007108 * u.rydberg, data_source=ku)
        ],
        temp_strengths=[(ECollisionTempStrength(temp=0.0, strength=0.255)),
                        (ECollisionTempStrength(temp=0.07394,
                                                strength=0.266))])

    session.add_all([
        h, ne, nist, ku, ch, h0, ne1, ne2_lvl1_ch, ne2_lvl0_ku, ne2_lvl1_ku,
        ne2_lvl2_ku, ne2_line0_ku, ne2_line1_ku, ne2_e_col0_ku
    ])
    session.commit()
    session.close()
    return engine