def main(): import argparse parser = argparse.ArgumentParser(description='Fit cell from batch to model') parser.add_argument('--wcg_n', type=int, help='wcg rank', default=2) parser.add_argument('--fir_n', type=int, help='FIR ntaps', default=15) args = parser.parse_args() template = '-m lbhb.analysis.rdt.do_fit --wcg_n {wcg_n} --fir_n {fir_n}' executable_path = '/auto/users/bburan/bin/miniconda3/envs/nems-intel/bin/python' for shuffle_phase in (True, False): for shuffle_stream in (True, False): modelname = generate_modelname(args.wcg_n, args.fir_n, shuffle_phase, shuffle_stream) script_path = template.format(wcg_n=args.wcg_n, fir_n=args.fir_n) if shuffle_phase: script_path += ' --shuffle-phase' if shuffle_stream: script_path += ' --shuffle-stream' modelname = hashlib.sha1(modelname.encode('ascii')).hexdigest() for batch in (269, 273): for cell in db.get_batch_cells(batch=batch)['cellid']: db.enqueue_single_model(cell, batch, modelname, force_rerun=True, user='******', executable_path=executable_path, script_path=script_path) print(f'Queued {cell}')
def update_widgets(self): batch = int(self.batchLE.text()) cellmask = self.cellLE.text() modelmask = "%" + self.modelLE.text() + "%" if batch > 0: self.batch = batch else: self.batchLE.setText(str(self.batch)) self.d_cells = nd.get_batch_cells(self.batch, cellid=cellmask) self.d_models = nd.pd_query( "SELECT DISTINCT modelname FROM NarfResults" + " WHERE batch=%s AND modelname like %s" + " ORDER BY modelname", (self.batch, modelmask)) self.cells.clear() for c in list(self.d_cells['cellid']): list_item = qw.QListWidgetItem(c, self.cells) self.models.clear() for m in list(self.d_models['modelname']): list_item = qw.QListWidgetItem(m, self.models) print('updated list widgets')
def update_widgets(self, event): batchmask = int(self.batch) cellmask = self.cell_search_string modelmask = "%" + self.model_search_string + "%" d = nd.get_batch_cells(batchmask, cellid=cellmask) self.cell_list = [Cell(cellid=c) for c in list(d['cellid'])] d = nd.pd_query( "SELECT DISTINCT modelname FROM NarfResults" + " WHERE batch=%s AND modelname like %s" + " ORDER BY modelname", (batchmask, modelmask)) self.model_list = [Model(name=m) for m in list(d['modelname'])] self.selected_cell = "" self.selected_model = "" print('Updated list widgets', event)
if not options['stim']: options['stimfmt'] = 'none' options["batch"] = batch data_path = nems_db.baphy.baphy_data_path(cellid=None, batch=batch, options=options) # regenerate or reload recordings as needed REGEN = False RELOAD = True REFIT = False if REGEN: # load data from baphy files and save to nems format plt.close('all') cell_data = nd.get_batch_cells(batch=batch) cellids = list(cell_data['cellid'].unique()) recordings = [] for cellid in cellids: try: recordings = recordings + [ nems_db.baphy.baphy_load_recording(cellid, batch, options.copy()) ] recordings[-1].save(datapath) except: print("failed on cell {0}".format(cellid)) elif RELOAD: # load data from baphy format cell_data = nd.get_batch_cells(batch=batch)
def load_site_raster(batch, site, options, runclass=None, rawid=None): ''' Load a population raster given batch id, runclass, recording site, and options Input: ------------------------------------------------------------------------- batch ex: batch=301 runclass ex: runclass='PTD' recording site ex: site='TAR010c' options: dict min_isolation (float), default - load all cells above 70% isolation rasterfs (float), default: 100 includeprestim (boolean), default: 1 tag_masks (list of strings), default [], ex: ['Reference'] active_passive (string), default: 'both' ex: 'p' or 'a' **** other options to be implemented **** Output: ------------------------------------------------------------------------- r (numpy array), response matrix (bin x reps x stim x cells) meta (pandas data frame), df with all information from data base about the cells you've loaded (sorted in same order as last dim of r) ''' # Parse inputs try: iso = options['min_isolation'] except: iso = 70 try: options['rasterfs'] except: options['rasterfs'] = 100 try: options['includeprestim'] except: options['includeprestim'] = 1 try: options['tag_masks'] except: pass try: active_passive = options['active_passive'] except: active_passive = 'both' # Define parms dict to be passed to loading function parms = options if 'min_isolation' in parms: del parms['min_isolation'] # not need to find cache file if 'active_passive' in parms: del parms['active_passive'] cfd = db.get_batch_cells(batch=batch, cellid=site, rawid=rawid) cfd = cfd.sort_values( 'cellid' ) # sort the data frame by cellid so it agrees with the r matrix output cfd = cfd[cfd['min_isolation'] > iso] cellids = np.sort(np.unique(cfd[cfd['min_isolation'] > iso] ['cellid'])) # only need list of unique id's # load data for all identified respfiles corresponding to cellids cellcount = len(cellids) a_p = [] # classify as active or passive based on respfile name for i, cid in enumerate(cellids): d = db.get_batch_cell_data(batch, cid, rawid=rawid) respfile = nu.baphy.spike_cache_filename2(d['raster'], parms) for j, rf in enumerate(respfile): rts = nu.io.load_matlab_matrix(rf, key="r") if i == 0: if '_a_' in rf: a_p = a_p + [1] * rts.shape[1] else: a_p = a_p + [0] * rts.shape[1] if j == 0: rt = rts else: rt = np.concatenate((rt, rts), axis=1) if i == 0: r = np.empty((rt.shape[0], rt.shape[1], rt.shape[2], cellcount)) r[:, :, :, 0] = rt else: r[:, :, :, i] = rt if active_passive is 'a': r = r[:, np.array(a_p) == 1, :, :] elif active_passive is 'p': r = r[:, np.array(a_p) == 0, :, :] return r, cfd