def init_database(db, exp, samp, sweep=None): """ Initializes a new database with exp and sample names and creates a new measurement if a sweep is set. Parameters --------- db: The desired path of the new database. exp: The experiment name. sample: The sample name. sweep=None: Optional weep object for creating new runs for existing sweeps """ if '.db' not in db: db = f'{db}.db' if f'{os.environ["MeasureItHome"]}\\Databases\\' in db: initialise_or_create_database_at(db) else: initialise_or_create_database_at(os.environ['MeasureItHome'] + '\\Databases\\' + db) qc.new_experiment(exp, samp) if sweep is not None: sweep._create_measurement()
def export_db_to_txt(db_fn, exp_name=None, sample_name=None): """ Prints all experiment and sample names to the console. """ if '.db' in db_fn: initialise_or_create_database_at(os.environ['MeasureItHome'] + '\\Databases\\' + db_fn) else: initialise_or_create_database_at(os.environ['MeasureItHome'] + '\\Databases\\' + db_fn + '.db') experiments = [] for exp in qc.dataset.experiment_container.experiments(): if exp_name is None or exp.name is exp_name: experiments.append(exp) newpath = os.environ[ 'MeasureItHome'] + '\\Origin Files\\' + exp.name if not os.path.exists(newpath): os.makedirs(newpath) count = 0 for exp in experiments: print("exp name: " + exp.name) if sample_name is None or exp.sample_name is sample_name: print("sample name: " + exp.sample_name) write_sample_to_txt(exp, count) count += 1
def __set_qcodes(self): initialise_or_create_database_at(self.__database) self.station = Station() #### instruments needs change # A dummy instrument dac with two parameters ch1 and ch2 self.dac = DummyInstrument('dac', gates=['amp']) # A dummy instrument dmm with two parameters ch1 and Ch2 self.dmm = DummyInstrument('dmm', gates=['v1']) #These are the parameters which come ready to use from the intruments drivers #dac.add_parameter('amp',label='Amplitude', unit="V", get_cmd=None, set_cmd=None) self.dac.add_parameter('freq', label='Frequency', unit="Hz", get_cmd=None, set_cmd=None) #puts current time in a string to facilitate control of the samples #makes the sample name now = datetime.now() now = now.strftime("%Y-%m-%d_%H-%M-%S") print(now) #the experiment is a unit of data inside the database it's made #out self.exp = load_or_create_experiment(experiment_name=self.__exp_name, sample_name=now) self.dmm.v1 = dmm_parameter('dmm_v1', self.dac)
def start(self): """ Sets the database to the values given at initialization, then calls the callback function """ initialise_or_create_database_at(self.db) qc.new_experiment(name=self.exp, sample_name=self.samp) if self.callback is not None and callable(self.callback): self.callback()
def create_database(self, filename, experiment_name, sample_name): #database.initialise_database() initialise_or_create_database_at(filename) try: experiment = exc.load_experiment_by_name(name=experiment_name, sample=sample_name) except ValueError: experiment = exc.new_experiment(name=experiment_name, sample_name=sample_name) print('new_experiment')
def init_qcodes(data_dir, db_name): qc.config["core"]["db_location"] = data_dir assert os.path.isdir(data_dir), "'{}' Is not a Directory".format(data_dir) ls= os.listdir(data_dir) A = [re.findall(db_name, st.replace(".db", "")) for st in ls] i = 0 for a in A: if len(a)>0: if a[0]+".db" in ls: i+=1 assert i>0, "'{0}' not found in '{1}' \n These exist: {2}".format(db_name, data_dir, ls) initialise_or_create_database_at("{0}/{1}".format(data_dir, db_name) + ".db" )
def setup_save(self): save_data_ui = SaveDataGUI(self, self.db, self.exp_name, self.sample_name) if save_data_ui.exec_(): (self.db, self.exp_name, self.sample_name) = save_data_ui.get_save_info() try: initialise_or_create_database_at(self.db) qc.new_experiment(self.exp_name, self.sample_name) self.db_set = True return True except Exception as e: self.show_error('Error', "Error opening up database. Try again.", e) return False else: return False
def create_local_dbase_in(folder_name='general', db_name='experiments.db', data_dir='D:/Data'): """ Initialise or create a QCoDeS database in D:/Data/folder_name/db_name If the directory does not exist, it is created. Set the QCoDeS database location to point to the specified database. Inputs: folder_name (str): Name of the subfolder in D:/Data where db is stored. Can also be a path to a subfolder, e.g. general/sample1 leads to db in D:/Data/general/sample1 db_name (str): Name of database, including .db data_dt (str): Parent folder for all database files. """ dest_dir = Path(data_dir, folder_name) if not dest_dir.exists(): dest_dir.mkdir(parents=True) dest_path = Path(dest_dir, db_name) initialise_or_create_database_at(dest_path) config['core']['db_location'] = dest_path
def set_database(self): """ Sets the loaded database information for each sweep before running. Database information must be previously loaded using the 'load_database_info' method. Creates path for database and begins a new QCoDeS experiment. """ # Grab the next database file name if self.database is None: return db = "" if isinstance(self.database, str): db = self.database elif isinstance(self.database, deque): db = self.database.popleft() # Grab the next sample name sample = "" if isinstance(self.sample_name, str): sample = self.sample_name elif isinstance(self.sample_name, deque): sample = self.sample_name.popleft() # Grab the next experiment name exp = "" if isinstance(self.exp_name, str): exp = self.exp_name elif isinstance(self.exp_name, deque): exp = self.exp_name.popleft() # Initialize the database try: initialise_or_create_database_at(os.environ['MeasureItHome'] + '\\Databases\\' + db + '.db') qc.new_experiment(name=exp, sample_name=sample) except: print("Database info loaded incorrectly!")
def new_database( db_name: str, db_folder: Optional[str] = None, ) -> str: """ Ceate new database and initialise it """ if db_folder is None: db_folder = nt.config["db_folder"] if db_name[-2:] != "db": db_name += ".db" path = os.path.join(db_folder, db_name) qc.initialise_or_create_database_at(path) # add label columns db_conn = connect(path) with atomic(db_conn) as conn: add_meta_data(conn, 0, {"original_guid": 0}) for label in nt.config["core"]["labels"]: add_meta_data(conn, 0, {label: 0}) return path
def load_database(self): def check_existing_ds(ds): for old_ds in self.datasets: if str(ds['run id']) == str(old_ds['run id']) and str(ds['exp name']) == str(old_ds['exp name']) \ and str(ds['sample name']) == str(old_ds['sample name']) and str(ds['db']) == str(old_ds['db']): return False return True gui = SaveDataGUI(self) if gui.exec_(): (db, exp_name, sample_name) = gui.get_save_info() initialise_or_create_database_at(db) exps = experiments() new_datasets = 0 for exp in exps: for ds in exp.data_sets(): if len(exp_name) == 0 or ds.exp_name == exp_name: if len(sample_name ) == 0 or ds.sample_name == sample_name: new_ds = {} new_ds['run id'] = ds.run_id new_ds['exp name'] = ds.exp_name new_ds['sample name'] = ds.sample_name new_ds['db'] = ds.path_to_db if check_existing_ds(new_ds) is True: self.datasets.append(new_ds) new_datasets += 1 self.update_datasets() if new_datasets == 0: self.show_error( 'Error', 'No (new) data sets found with the specified experiment and sample name!' )
def empty_db_path(tmp_path): db_path = str(tmp_path / 'some.db') initialise_or_create_database_at(db_path) yield db_path