def get_run_from_id(run_id, exp): from RegDB import experiment_info instrument = exp[0:3] exp_runs = experiment_info.experiment_runs(instrument.upper(),exp) run_dict = {int(item['id']): int(item['num']) for item in exp_runs} return run_dict.get(run_id, run_id)
def list_of_runstrings (ins, exp) : """Returns the list of run numbers for specified experiment. """ runs = experiment_info.experiment_runs(ins, exp) lst = [] for rec in runs : lst.append( '%04d'%rec['num'] ) return lst
def get_runs(exp, instrument=None): """ Return DataFrame of runs form RegDB database """ import pandas as pd from RegDB import experiment_info if not instrument: instrument = exp[0:3] runs_list = experiment_info.experiment_runs(instrument.upper(),exp) return pd.DataFrame(runs_list)
def get_runs(exp, instrument=None): """ Return DataFrame of runs form RegDB database """ import pandas as pd from RegDB import experiment_info if not instrument: instrument = exp[0:3] runs_list = experiment_info.experiment_runs(instrument.upper(), exp) return pd.DataFrame(runs_list)
def dict_run_type (ins, exp) : """Returns the dictionary of pairs run:type, for example: {1: 'DATA', 2: 'DATA', 3: 'DATA', 4: 'DATA', 5: 'DATA',...} """ runs = experiment_info.experiment_runs(ins, exp) dict_rt = {} for i,rec in enumerate(runs) : num, type = int(rec['num']), rec['type'] #print i, rec, num, type dict_rt[num] = type return dict_rt
def experiment_guess(*args, **kwargs): """Returns best guess as to what your experiment is based on most recent experiment for which you have been added. Use get_experiments to get a list of all of your experiments. instrument is an optional keyword to narrow the search """ from RegDB import experiment_info if len(args) == 0: global _exp_good_guess global _instrument_good_guess else: _exp_good_guess = None _instrument_good_guess = None instrument = kwargs.get('instrument') if instrument: _exp_good_guess = True return active_experiment(instrument) else: if _instrument_good_guess is None: instrument = instrument_guess() else: instrument = None if instrument and is_in_group('ps-'+instrument) or is_in_psdata(): exp_best = active_experiment(instrument) else: experiments = get_experiments(*args).values()[0] if len(experiments) > 0: nruns = 0 iexp = 0 while nruns == 0 and iexp < len(experiments): exp = experiments[-1-iexp] inst = exp[0:3] runs = experiment_info.experiment_runs(inst.upper(),exp) nruns = len(runs) # print 'tryiing: ',exp,inst,nruns if nruns > 0: exp_best = exp nruns_best = nruns if _instrument_good_guess is True and inst != instrument: nruns = 0 _exp_good_guess = False else: _exp_good_guess = True iexp += 1 if nruns_best == 0: exp_best = _default_exp['exp'] _exp_good_guess = False else: exp_best = _default_exp['exp'] _exp_good_guess = False return exp_best
def get_run_from_id(run_id, exp): import pandas as pd from RegDB import experiment_info instrument = exp[0:3] df = pd.DataFrame(experiment_info.experiment_runs(instrument.upper(),exp)) try: run = df[df['id'] == run_id]['num'].values[0] except: run = None return run
def experiment_guess(*args, **kwargs): """Returns best guess as to what your experiment is based on most recent experiment for which you have been added. Use get_experiments to get a list of all of your experiments. instrument is an optional keyword to narrow the search """ from RegDB import experiment_info if len(args) == 0: global _exp_good_guess global _instrument_good_guess else: _exp_good_guess = None _instrument_good_guess = None instrument = kwargs.get('instrument') if instrument: _exp_good_guess = True return active_experiment(instrument) else: if _instrument_good_guess is None: instrument = instrument_guess() else: instrument = None if instrument and is_in_group('ps-' + instrument) or is_in_psdata(): exp_best = active_experiment(instrument) else: experiments = get_experiments(*args).values()[0] if len(experiments) > 0: nruns = 0 iexp = 0 while nruns == 0 and iexp < len(experiments): exp = experiments[-1 - iexp] inst = exp[0:3] runs = experiment_info.experiment_runs(inst.upper(), exp) nruns = len(runs) # print 'tryiing: ',exp,inst,nruns if nruns > 0: exp_best = exp nruns_best = nruns if _instrument_good_guess is True and inst != instrument: nruns = 0 _exp_good_guess = False else: _exp_good_guess = True iexp += 1 if nruns_best == 0: exp_best = _default_exp['exp'] _exp_good_guess = False else: exp_best = _default_exp['exp'] _exp_good_guess = False return exp_best
def get_run_from_id(run_id, exp): import pandas as pd from RegDB import experiment_info instrument = exp[0:3] df = pd.DataFrame(experiment_info.experiment_runs(instrument.upper(), exp)) try: run = df[df['id'] == run_id]['num'].values[0] except: run = None return run
def experiment_runs (ins, exp) : """Returns the list of dictionaries, one dictionary per run, containing run parameters, for example: {'begin_time_unix': 1375417636, 'end_time_unix': 1375417646, 'num': 1L, 'exper_id': 329L, 'end_time': 1375417646535192694L, 'begin_time': 1375417636042155759L, 'type': 'DATA', 'id': 69762L} """ return experiment_info.experiment_runs(ins, exp)
def run_available(exp, run=None, instrument=None, offline=True, ffb=False, idx=None, path=None, all_streams=False, valid_streams=False): """ Check if run is available Parameters --------- offline : bool Check if offline if True valid_streams : bool Return list of valid streams with non-zero size if True all_streams : bool Return list of all streams if True """ import glob, os from RegDB import experiment_info if not instrument: instrument = exp[0:3] if not run: run = experiment_info.experiment_runs(instrument.upper(),exp)[-1]['num'] if isinstance(exp, str): expNum = experiment_info.name2id(exp) if expNum is None: return False else: expNum = exp try: file_list = experiment_info.get_open_files(expNum,run) except: file_list = [] if not file_list: return False if not path: if ffb: path = os.path.join('/reg/d/ffb',instrument,exp,'xtc') else: path = os.path.join('/reg/d/psdm/',instrument,exp,'xtc') #path = os.path.join(experiment_info.getexp_datapath(expNum),instrument,exp,'xtc') if idx: xtc_files = glob.glob(path+'/index/*.xtc.idx') else: xtc_files = glob.glob(path+'/*.xtc') streams = [] for item in file_list: if idx: name = '{:}/index/e{:}-r{:04}-s{:02}-c{:02}.xtc.idx'.format(path,expNum,item['run'],item['stream'],item['chunk']) else: name = '{:}/e{:}-r{:04}-s{:02}-c{:02}.xtc'.format(path,expNum,item['run'],item['stream'],item['chunk']) if name not in xtc_files: return False else: if valid_streams and os.path.getsize(name): streams.append(item['stream']) elif all_streams: streams.append(item['stream']) if valid_streams or all_streams: return streams else: return True
def run_available(exp, run=None, instrument=None, offline=True, ffb=False, idx=None, path=None, all_streams=False, valid_streams=False): """ Check if run is available Parameters --------- offline : bool Check if offline if True valid_streams : bool Return list of valid streams with non-zero size if True all_streams : bool Return list of all streams if True """ import glob, os from RegDB import experiment_info if not instrument: instrument = exp[0:3] if not run: run = experiment_info.experiment_runs(instrument.upper(), exp)[-1]['num'] if isinstance(exp, str): expNum = experiment_info.name2id(exp) if expNum is None: return False else: expNum = exp try: file_list = experiment_info.get_open_files(expNum, run) except: file_list = [] if not file_list: return False if not path: if ffb: path = os.path.join('/reg/d/ffb', instrument, exp, 'xtc') else: path = os.path.join('/reg/d/psdm/', instrument, exp, 'xtc') #path = os.path.join(experiment_info.getexp_datapath(expNum),instrument,exp,'xtc') if idx: xtc_files = glob.glob(path + '/index/*.xtc.idx') else: xtc_files = glob.glob(path + '/*.xtc') streams = [] for item in file_list: if idx: name = '{:}/index/e{:}-r{:04}-s{:02}-c{:02}.xtc.idx'.format( path, expNum, item['run'], item['stream'], item['chunk']) else: name = '{:}/e{:}-r{:04}-s{:02}-c{:02}.xtc'.format( path, expNum, item['run'], item['stream'], item['chunk']) if name not in xtc_files: return False else: if valid_streams and os.path.getsize(name): streams.append(item['stream']) elif all_streams: streams.append(item['stream']) if valid_streams or all_streams: return streams else: return True