def load(self, db_mol_weights=True):
        self.debug('******************************* LOAD Spec')
        if db_mol_weights:
            # get the molecular weights from the database
            dbm = IsotopeDatabaseManager(application=self.application,
                                         warn=False)
            self.db = dbm
            if dbm.isConnected():
                self.info('loading molecular_weights from database')
                mws = dbm.db.get_molecular_weights()
                # convert to a dictionary
                m = dict([(mi.name, mi.mass) for mi in mws])
                self.spectrometer.molecular_weights = m

        if not self.spectrometer.molecular_weights:
            import csv
            # load the molecular weights dictionary
            p = os.path.join(paths.spectrometer_dir, 'molecular_weights.csv')
            if os.path.isfile(p):
                self.info('loading "molecular_weights.csv" file')
                with open(p, 'U') as f:
                    reader = csv.reader(f, delimiter='\t')
                    args = [[l[0], float(l[1])] for l in reader]
                    self.spectrometer.molecular_weights = dict(args)
            else:
                self.info('writing a default "molecular_weights.csv" file')
                # make a default molecular_weights.csv file
                from pychron.spectrometer.molecular_weights import MOLECULAR_WEIGHTS as mw

                with open(p, 'U') as f:
                    writer = csv.writer(f, delimiter='\t')
                    data = [a for a in mw.itervalues()]
                    data = sorted(data, key=lambda x: x[1])
                    for row in data:
                        writer.writerow(row)
                self.spectrometer.molecular_weights = mw

        #config = self.get_configuration(path=os.path.join(paths.spectrometer_dir, 'detectors.cfg'))
        #for name in config.sections():
        #    relative_position = self.config_get(config, name, 'relative_position', cast='float')
        #    color = self.config_get(config, name, 'color', default='black')
        #    default_state = self.config_get(config, name, 'default_state', default=True, cast='boolean')
        #    isotope = self.config_get(config, name, 'isotope')
        #    kind = self.config_get(config, name, 'kind', default='Faraday', optional=True)
        #    self.spectrometer.add_detector(name=name,
        #                                   relative_position=relative_position,
        #                                   color=color,
        #                                   active=default_state,
        #                                   isotope=isotope,
        #                                   kind=kind)
        self.spectrometer.load()

        return True
    def load(self, db_mol_weights=True):
        self.debug('******************************* LOAD Spec')
        if db_mol_weights:
            # get the molecular weights from the database
            dbm = IsotopeDatabaseManager(application=self.application,
                                         warn=False)
            self.db = dbm
            if dbm.isConnected():
                self.info('loading molecular_weights from database')
                mws = dbm.db.get_molecular_weights()
                # convert to a dictionary
                m = dict([(mi.name, mi.mass) for mi in mws])
                self.spectrometer.molecular_weights = m

        if not self.spectrometer.molecular_weights:
            import csv
            # load the molecular weights dictionary
            p = os.path.join(paths.spectrometer_dir, 'molecular_weights.csv')
            if os.path.isfile(p):
                self.info('loading "molecular_weights.csv" file')
                with open(p, 'U') as f:
                    reader = csv.reader(f, delimiter='\t')
                    args = [[l[0], float(l[1])] for l in reader]
                    self.spectrometer.molecular_weights = dict(args)
            else:
                self.info('writing a default "molecular_weights.csv" file')
                # make a default molecular_weights.csv file
                from pychron.spectrometer.molecular_weights import MOLECULAR_WEIGHTS as mw

                with open(p, 'U') as f:
                    writer = csv.writer(f, delimiter='\t')
                    data = [a for a in mw.itervalues()]
                    data = sorted(data, key=lambda x: x[1])
                    for row in data:
                        writer.writerow(row)
                self.spectrometer.molecular_weights = mw

        #config = self.get_configuration(path=os.path.join(paths.spectrometer_dir, 'detectors.cfg'))
        #for name in config.sections():
        #    relative_position = self.config_get(config, name, 'relative_position', cast='float')
        #    color = self.config_get(config, name, 'color', default='black')
        #    default_state = self.config_get(config, name, 'default_state', default=True, cast='boolean')
        #    isotope = self.config_get(config, name, 'isotope')
        #    kind = self.config_get(config, name, 'kind', default='Faraday', optional=True)
        #    self.spectrometer.add_detector(name=name,
        #                                   relative_position=relative_position,
        #                                   color=color,
        #                                   active=default_state,
        #                                   isotope=isotope,
        #                                   kind=kind)
        self.spectrometer.load()

        return True
Exemple #3
0
    def load(self, db_mol_weights=True):
        spec = self.spectrometer
        mftable = spec.magnet.mftable

        self.debug('******************************* LOAD Spec')
        if db_mol_weights:
            # get the molecular weights from the database
            # dbm = IsotopeDatabaseManager(application=self.application,
            #                              warn=False)
            dbm = self.application.get_service(
                'pychron.database.isotope_database_manager.IsotopeDatabaseManager'
            )
            if dbm and dbm.is_connected():
                self.info('loading molecular_weights from database')
                mws = dbm.db.get_molecular_weights()
                # convert to a dictionary
                m = dict([(mi.name, mi.mass) for mi in mws])
                spec.molecular_weights = m
                mftable.db = dbm.db

        if not spec.molecular_weights:
            import csv
            # load the molecular weights dictionary
            p = os.path.join(paths.spectrometer_dir, 'molecular_weights.csv')
            if os.path.isfile(p):
                self.info('loading "molecular_weights.csv" file')
                with open(p, 'U') as f:
                    reader = csv.reader(f, delimiter='\t')
                    args = [[l[0], float(l[1])] for l in reader]
                    spec.molecular_weights = dict(args)
            else:
                self.info('writing a default "molecular_weights.csv" file')
                # make a default molecular_weights.csv file
                from pychron.spectrometer.molecular_weights import MOLECULAR_WEIGHTS as mw

                with open(p, 'U') as f:
                    writer = csv.writer(f, delimiter='\t')
                    data = [a for a in mw.itervalues()]
                    data = sorted(data, key=lambda x: x[1])
                    for row in data:
                        writer.writerow(row)
                spec.molecular_weights = mw

        self.spectrometer.load()
        mftable.spectrometer_name = self.spectrometer.name

        return True
Exemple #4
0
    def load(self, db_mol_weights=True):
        spec = self.spectrometer
        mftable = spec.magnet.mftable

        self.debug("******************************* LOAD Spec")
        if db_mol_weights:
            # get the molecular weights from the database
            # dbm = IsotopeDatabaseManager(application=self.application,
            #                              warn=False)
            dbm = self.application.get_service("pychron.database.isotope_database_manager.IsotopeDatabaseManager")
            if dbm and dbm.is_connected():
                self.info("loading molecular_weights from database")
                mws = dbm.db.get_molecular_weights()
                # convert to a dictionary
                m = dict([(mi.name, mi.mass) for mi in mws])
                spec.molecular_weights = m
                mftable.db = dbm.db

        if not spec.molecular_weights:
            import csv

            # load the molecular weights dictionary
            p = os.path.join(paths.spectrometer_dir, "molecular_weights.csv")
            if os.path.isfile(p):
                self.info('loading "molecular_weights.csv" file')
                with open(p, "U") as f:
                    reader = csv.reader(f, delimiter="\t")
                    args = [[l[0], float(l[1])] for l in reader]
                    spec.molecular_weights = dict(args)
            else:
                self.info('writing a default "molecular_weights.csv" file')
                # make a default molecular_weights.csv file
                from pychron.spectrometer.molecular_weights import MOLECULAR_WEIGHTS as mw

                with open(p, "U") as f:
                    writer = csv.writer(f, delimiter="\t")
                    data = [a for a in mw.itervalues()]
                    data = sorted(data, key=lambda x: x[1])
                    for row in data:
                        writer.writerow(row)
                spec.molecular_weights = mw

        self.spectrometer.load()
        mftable.spectrometer_name = self.spectrometer.name

        return True