Пример #1
0
    def getone(self):
        """ Method to get the next result from the query

            Parameters
            ----------
            None

            Returns
            -------
            LineData object containing the transition data
        """
        res = self.cursor.fetchone()

        if self.ishfs:
            return LineData(frequency=res[0],
                            transition=res[1],
                            linestrength=res[2],
                            energies=[res[3], res[4]])
        formula = str(res[0])
        return LineData(formula=formula,
                        name=str(res[1]),
                        frequency=res[2],
                        uid=utils.getplain(formula) + "_%.5f" % res[2],
                        energies=[res[5], res[6]],
                        linestrength=res[4],
                        mass=utils.getmass(formula),
                        transition=str(res[3]),
                        plain=utils.getplain(formula),
                        isocount=utils.isotopecount(formula),
                        hfnum=res[7])
Пример #2
0
    def getall(self):
        """ Method to get all results from the query

            Parameters
            ----------
            None

            Returns
            -------
            List of LineData objects, one for each transition

        """
        results = self.cursor.fetchall()
        output = []
        if self.ishfs:
            for res in results:
                output.append(LineData(frequency=res[0], transition=str(res[1]), linestrength=res[2],
                                       energies=[res[3], res[4]]))
        else:
            for res in results:
                formula = str(res[0])
                output.append(LineData(formula=formula, name=str(res[1]), frequency=res[2], uid=utils.getplain(formula) + "_%.5f" % res[2],
                                       energies=[res[5], res[6]], linestrength=res[4], mass=utils.getmass(formula), transition=str(res[3]),
                                       plain=utils.getplain(formula), isocount=utils.isotopecount(formula),
                                       hfnum=res[7]))
        return output
Пример #3
0
    def getone(self):
        """ Method to get the next result from the query

            Parameters
            ----------
            None

            Returns
            -------
            LineData object containing the transition data
        """
        res = self.cursor.fetchone()

        if self.ishfs:
            return LineData(frequency=res[0], transition=res[1], linestrength=res[2],
                            energies=[res[3], res[4]])
        formula = str(res[0])
        return LineData(formula=formula, name=str(res[1]), frequency=res[2], uid=utils.getplain(formula) + "_%.5f" % res[2],
                        energies=[res[5], res[6]], linestrength=res[4], mass=utils.getmass(formula), transition=str(res[3]),
                        plain=utils.getplain(formula), isocount=utils.isotopecount(formula), hfnum=res[7])
Пример #4
0
    def getall(self):
        """ Method to get all results from the query

            Parameters
            ----------
            None

            Returns
            -------
            List of LineData objects, one for each transition

        """
        results = self.cursor.fetchall()
        output = []
        if self.ishfs:
            for res in results:
                output.append(
                    LineData(frequency=res[0],
                             transition=str(res[1]),
                             linestrength=res[2],
                             energies=[res[3], res[4]]))
        else:
            for res in results:
                formula = str(res[0])
                output.append(
                    LineData(formula=formula,
                             name=str(res[1]),
                             frequency=res[2],
                             uid=utils.getplain(formula) + "_%.5f" % res[2],
                             energies=[res[5], res[6]],
                             linestrength=res[4],
                             mass=utils.getmass(formula),
                             transition=str(res[3]),
                             plain=utils.getplain(formula),
                             isocount=utils.isotopecount(formula),
                             hfnum=res[7]))
        return output
Пример #5
0
    def splatalogue(self, minfreq, maxfreq, rrlevelstr, allowExotics):
        """ Method to search through the slsearch database. Search options must already
            have been set. Returns a formatted list of transitions, each item in the list
            is another list containing the following:

            #. Chemical formula

            #. Name

            #. Rest frequency

            #. Unique identifier

            #. Lower state energy in K

            #. Upper state energy in K

            #. Linestrength in D^2

            #. Mass of molecule (rough)

            #. Transition quantum numbers

            #. Cleanly formatted chemical formula for display purposes

            #. Number of non-standard isotopes in the molecule

            Parameters
            ----------
            rrlevelstr : str
                String representation of how deep to search for recombination lines. Possibilities
                are:

                + `off`      no recombination lines are allowed in the results.
                + `shallow`  only H and He, alpha and beta lines are allowed in the results.
                + `deep`     any recombination line is allowed in the results.

            allowExotics : bool
                Whether or not to allow exotic atoms in the molecules (e.g Ti)

            Returns
            -------
            A list of LineData objects, with each containing the data for a single transition.

        """
        possible = []
        # initialize the interface class
        sp = Splatalogue.Splatalogue(**self.sp_kw)
        # do the search
        results = sp.query_lines(minfreq, maxfreq)
        # get the results
        lines = results.readlines()
        # the top row is the column headings as one long string
        # split the string into its individual components
        header = lines[0].split(":")
        # the indexes of the data are not guaranteed, so search for each needed one
        # by its known name, if splatalogue changes the column headings this will
        # break
        sidx = header.index("Species")
        cidx = header.index("Chemical Name")
        fidx = header.index("Freq-GHz")
        bfidx = header.index("Meas Freq-GHz")
        qidx = header.index("Resolved QNs")
        stidx = header.index(
            "S<sub>ij</sub>&#956;<sup>2</sup> (D<sup>2</sup>)")
        elidx = header.index("E_L (K)")
        euidx = header.index("E_U (K)")
        # remove the header row so the rest can be iterated over
        del lines[0]
        # make sure all of the indexes are found
        if min(sidx, cidx, fidx, qidx, stidx, elidx, euidx, bfidx) < 0:
            raise Exception("Missing data")  # need a better message
        # iterate over all the results
        for line in lines:
            # sploit into columns
            row = line.split(":")
            # see which frequency we have, prefering the 'Freq-GHz' column
            if not row[fidx]:
                freq = float(row[bfidx])
            else:
                freq = float(row[fidx])
            # process the result, dropping if needed
            if not utils.isexotic(row[sidx] or allowExotics):
                if (not "RECOMBINATION" in row[cidx].upper() \
                   or ("RECOMBINATION" in row[cidx].upper()
                      and (rrlevelstr == "DEEP" or ("H" in row[sidx] \
                          and ("alpha" in row[sidx] or "beta" in row[sidx]))))) \
                   and not self.checktier1overlap(row[fidx]):
                    possible.append(
                        LineData(
                            formula=row[sidx],
                            name=row[cidx],
                            frequency=freq,
                            uid=utils.getplain(row[sidx]) + "_%.5f" % freq,
                            energies=[float(row[elidx]),
                                      float(row[euidx])],
                            linestrength=float(row[stidx]),
                            mass=utils.getmass(row[sidx]),
                            transition=row[qidx],
                            plain=utils.getplain(row[sidx]),
                            isocount=utils.isotopecount(row[sidx])))

        return possible
Пример #6
0
    def slsearch(self, rrlevelstr, allowExotics):
        """ Method to search through the slsearch database. Search options must already
            have been set. Returns a formatted list of transitions, each item in the list
            is another list containing the following:

            #. Chemical formula

            #. Name

            #. Rest frequency

            #. Unique identifier

            #. Lower state energy in K

            #. Upper state energy in K

            #. Linestrength in D^2

            #. Mass of molecule (rough)

            #. Transition quantum numbers

            #. Cleanly formatted chemical formula for display purposes

            #. Number of non-standard isotopes in the molecule

            Parameters
            ----------
            rrlevelstr : str
                String representation of how deep to search for recombination lines. Possibilities
                are:

                + `off`      no recombination lines are allowed in the results.
                + `shallow`  only H and He, alpha and beta lines are allowed in the results.
                + `deep`     any recombination line is allowed in the results.

            allowExotics : bool
                Whether or not to allow exotic atoms in the molecules (e.g Ti)

            Returns
            -------
            A list of LineData objects, with each containing the data for a single transition.

        """
        try:
            from slsearch import slsearch
            import taskinit
        except:
            logging.info(
                "WARNING: No CASA, slsearch is not available, no line identificaiton possible."
            )
            raise
        if "outfile" not in self.sls_kw:
            # @todo should really use tempfile, or $$; this is an accident in waiting
            # also, in the same namespace if a seed is the same, the accident is guarenteed; see genspec.py)
            flname = "/tmp/slsearch.%i" % (int(random.random() * 1000))
            utils.remove(flname)
            self.sls_kw["outfile"] = flname
        # do the search
        #print self.sls_kw
        #print flname
        slsearch(**self.sls_kw)
        # open the table and get the contents
        tb = taskinit.tbtool()
        tb.open(self.sls_kw["outfile"])
        numrows = tb.nrows()
        possible = []
        # convert the results to a list
        for row in range(numrows):
            species = tb.getcell("SPECIES", row)
            name = tb.getcell("CHEMICAL_NAME", row)
            freq = float(tb.getcell("FREQUENCY", row))
            qn = tb.getcell("QUANTUM_NUMBERS", row)
            linestr = float(tb.getcell("SMU2", row))
            el = float(tb.getcell("EL", row))
            eu = float(tb.getcell("EU", row))
            # only add it to the output list if it does not contain an exotic atom,
            # or if exotics are allowed
            if not utils.isexotic(species or allowExotics):
                if (not "RECOMBINATION" in name.upper() \
                   or ("RECOMBINATION" in name.upper()
                      and (rrlevelstr == "DEEP" or ("H" in species \
                          and ("alpha" in species or "beta" in species))))) \
                   and not self.checktier1overlap(freq):
                    possible.append(
                        LineData(formula=species,
                                 name=name,
                                 frequency=freq,
                                 uid=utils.getplain(species) + "_%.5f" % freq,
                                 energies=[el, eu],
                                 linestrength=linestr,
                                 mass=utils.getmass(species),
                                 transition=qn,
                                 plain=utils.getplain(species),
                                 isocount=utils.isotopecount(species)))
        tb.close()
        # remove the temporary table
        utils.remove(self.sls_kw["outfile"])
        return possible
Пример #7
0
    def splatalogue(self, minfreq, maxfreq, rrlevelstr, allowExotics):
        """ Method to search through the slsearch database. Search options must already
            have been set. Returns a formatted list of transitions, each item in the list
            is another list containing the following:

            #. Chemical formula

            #. Name

            #. Rest frequency

            #. Unique identifier

            #. Lower state energy in K

            #. Upper state energy in K

            #. Linestrength in D^2

            #. Mass of molecule (rough)

            #. Transition quantum numbers

            #. Cleanly formatted chemical formula for display purposes

            #. Number of non-standard isotopes in the molecule

            Parameters
            ----------
            rrlevelstr : str
                String representation of how deep to search for recombination lines. Possibilities
                are:

                + `off`      no recombination lines are allowed in the results.
                + `shallow`  only H and He, alpha and beta lines are allowed in the results.
                + `deep`     any recombination line is allowed in the results.

            allowExotics : bool
                Whether or not to allow exotic atoms in the molecules (e.g Ti)

            Returns
            -------
            A list of LineData objects, with each containing the data for a single transition.

        """
        possible = []
        # initialize the interface class
        sp = Splatalogue.Splatalogue(**self.sp_kw)
        # do the search
        results = sp.query_lines(minfreq, maxfreq)
        # get the results
        lines = results.readlines()
        # the top row is the column headings as one long string
        # split the string into its individual components
        header = lines[0].split(":")
        # the indexes of the data are not guaranteed, so search for each needed one
        # by its known name, if splatalogue changes the column headings this will
        # break
        sidx = header.index("Species")
        cidx = header.index("Chemical Name")
        fidx = header.index("Freq-GHz")
        bfidx = header.index("Meas Freq-GHz")
        qidx = header.index("Resolved QNs")
        stidx = header.index("S<sub>ij</sub>&#956;<sup>2</sup> (D<sup>2</sup>)")
        elidx = header.index("E_L (K)")
        euidx = header.index("E_U (K)")
        # remove the header row so the rest can be iterated over
        del lines[0]
        # make sure all of the indexes are found
        if min(sidx, cidx, fidx, qidx, stidx, elidx, euidx, bfidx) < 0:
            raise Exception("Missing data") # need a better message
        # iterate over all the results
        for line in lines:
            # sploit into columns
            row = line.split(":")
            # see which frequency we have, prefering the 'Freq-GHz' column
            if not row[fidx]:
                freq = float(row[bfidx])
            else:
                freq = float(row[fidx])
            # process the result, dropping if needed
            if not utils.isexotic(row[sidx] or allowExotics):
                if (not "RECOMBINATION" in row[cidx].upper() \
                   or ("RECOMBINATION" in row[cidx].upper()
                      and (rrlevelstr == "DEEP" or ("H" in row[sidx] \
                          and ("alpha" in row[sidx] or "beta" in row[sidx]))))) \
                   and not self.checktier1overlap(row[fidx]):
                    possible.append(LineData(formula=row[sidx], name=row[cidx], frequency=freq,
                                    uid=utils.getplain(row[sidx]) + "_%.5f" % freq,
                                    energies=[float(row[elidx]), float(row[euidx])], linestrength=float(row[stidx]), mass=utils.getmass(row[sidx]),
                                    transition=row[qidx], plain=utils.getplain(row[sidx]),
                                    isocount=utils.isotopecount(row[sidx])))

        return possible
Пример #8
0
    def slsearch(self, rrlevelstr, allowExotics):
        """ Method to search through the slsearch database. Search options must already
            have been set. Returns a formatted list of transitions, each item in the list
            is another list containing the following:

            #. Chemical formula

            #. Name

            #. Rest frequency

            #. Unique identifier

            #. Lower state energy in K

            #. Upper state energy in K

            #. Linestrength in D^2

            #. Mass of molecule (rough)

            #. Transition quantum numbers

            #. Cleanly formatted chemical formula for display purposes

            #. Number of non-standard isotopes in the molecule

            Parameters
            ----------
            rrlevelstr : str
                String representation of how deep to search for recombination lines. Possibilities
                are:

                + `off`      no recombination lines are allowed in the results.
                + `shallow`  only H and He, alpha and beta lines are allowed in the results.
                + `deep`     any recombination line is allowed in the results.

            allowExotics : bool
                Whether or not to allow exotic atoms in the molecules (e.g Ti)

            Returns
            -------
            A list of LineData objects, with each containing the data for a single transition.

        """
        try:
            from slsearch import slsearch
            import taskinit
        except:
            logging.info("WARNING: No CASA, slsearch is not available, no line identificaiton possible.")
            raise
        if "outfile" not in self.sls_kw:
            # @todo should really use tempfile, or $$; this is an accident in waiting
            # also, in the same namespace if a seed is the same, the accident is guarenteed; see genspec.py)
            flname = "/tmp/slsearch.%i" % (int(random.random() * 1000))
            utils.remove(flname)
            self.sls_kw["outfile"] = flname
        # do the search
        #print self.sls_kw
        #print flname
        slsearch(**self.sls_kw)
        # open the table and get the contents
        tb = taskinit.tb
        tb.open(self.sls_kw["outfile"])
        numrows = tb.nrows()
        possible = []
        # convert the results to a list
        for row in range(numrows):
            species = tb.getcell("SPECIES", row)
            name = tb.getcell("CHEMICAL_NAME", row)
            freq = float(tb.getcell("FREQUENCY", row))
            qn = tb.getcell("QUANTUM_NUMBERS", row)
            linestr = float(tb.getcell("SMU2", row))
            el = float(tb.getcell("EL", row))
            eu = float(tb.getcell("EU", row))
            # only add it to the output list if it does not contain an exotic atom,
            # or if exotics are allowed
            if not utils.isexotic(species or allowExotics):
                if (not "RECOMBINATION" in name.upper() \
                   or ("RECOMBINATION" in name.upper()
                      and (rrlevelstr == "DEEP" or ("H" in species \
                          and ("alpha" in species or "beta" in species))))) \
                   and not self.checktier1overlap(freq):
                    possible.append(LineData(formula=species, name=name, frequency=freq,
                                    uid=utils.getplain(species) + "_%.5f" % freq,
                                    energies=[el, eu], linestrength=linestr, mass=utils.getmass(species),
                                    transition=qn, plain=utils.getplain(species),
                                    isocount=utils.isotopecount(species)))
        tb.close()
        # remove the temporary table
        utils.remove(self.sls_kw["outfile"])
        return possible