def populatemetadata(): #%% save metadata from google drive if necessairy lastmodify = online_notebook.fetch_lastmodify_time_animal_metadata() with open(dj.config['locations.metadata_surgery_experiment'] + 'last_modify_time.json') as timedata: lastmodify_prev = json.loads(timedata.read()) if lastmodify != lastmodify_prev: print('updating surgery and WR metadata from google drive') dj.config['locations.metadata_surgery_experiment'] df_surgery = online_notebook.fetch_animal_metadata() df_surgery.to_csv(dj.config['locations.metadata_surgery_experiment'] + 'Surgery.csv') IDs = df_surgery['ID'].tolist() for ID in IDs: df_wr = online_notebook.fetch_water_restriction_metadata(ID) if type(df_wr) == pd.DataFrame: df_wr.to_csv( dj.config['locations.metadata_surgery_experiment'] + ID + '.csv') with open( dj.config['locations.metadata_surgery_experiment'] + 'last_modify_time.json', "w") as write_file: json.dump(lastmodify, write_file) print('surgery and WR metadata updated') lastmodify = online_notebook.fetch_lastmodify_time_lab_metadata() with open(dj.config['locations.metadata_lab'] + 'last_modify_time.json') as timedata: lastmodify_prev = json.loads(timedata.read()) if lastmodify != lastmodify_prev: print('updating Lab metadata from google drive') dj.config['locations.metadata_lab'] IDs = ['Experimenter', 'Rig', 'Virus'] for ID in IDs: df_wr = online_notebook.fetch_lab_metadata(ID) if type(df_wr) == pd.DataFrame: df_wr.to_csv(dj.config['locations.metadata_lab'] + ID + '.csv') with open( dj.config['locations.metadata_lab'] + 'last_modify_time.json', "w") as write_file: json.dump(lastmodify, write_file) print('Lab metadata updated') #%% add users df_experimenters = pd.read_csv(dj.config['locations.metadata_lab'] + 'Experimenter.csv') experimenterdata = list() for experimenter in df_experimenters.iterrows(): experimenter = experimenter[1] dictnow = { 'username': experimenter['username'], 'fullname': experimenter['fullname'] } experimenterdata.append(dictnow) print('adding experimenters') for experimenternow in experimenterdata: try: lab.Person().insert1(experimenternow) except dj.errors.DuplicateError: print('duplicate. experimenter: ', experimenternow['username'], ' already exists') #%% add rigs df_rigs = pd.read_csv(dj.config['locations.metadata_lab'] + 'Rig.csv') rigdata = list() for rig in df_rigs.iterrows(): rig = rig[1] dictnow = { 'rig': rig['rig'], 'room': rig['room'], 'rig_description': rig['rig_description'] } rigdata.append(dictnow) print('adding rigs') for rignow in rigdata: try: lab.Rig().insert1(rignow) except dj.errors.DuplicateError: print('duplicate. rig: ', rignow['rig'], ' already exists') #%% add viruses df_viruses = pd.read_csv(dj.config['locations.metadata_lab'] + 'Virus.csv') virusdata = list() serotypedata = list() for virus in df_viruses.iterrows(): virus = virus[1] if type(virus['remarks']) != str: virus['remarks'] = '' dictnow = { 'virus_id': virus['virus_id'], 'virus_source': virus['virus_source'], 'serotype': virus['serotype'], 'username': virus['username'], 'virus_name': virus['virus_name'], 'titer': virus['titer'], 'order_date': virus['order_date'], 'remarks': virus['remarks'] } virusdata.append(dictnow) dictnow = {'serotype': virus['serotype']} serotypedata.append(dictnow) print('adding rigs') for virusnow, serotypenow in zip(virusdata, serotypedata): try: lab.Serotype().insert1(serotypenow) except dj.errors.DuplicateError: print('duplicate serotype: ', serotypenow['serotype'], ' already exists') try: lab.Virus().insert1(virusnow) except dj.errors.DuplicateError: print('duplicate virus: ', virusnow['virus_name'], ' already exists') #%% populate subjects, surgeries and water restrictions print('adding surgeries and stuff') df_surgery = pd.read_csv( dj.config['locations.metadata_surgery_experiment'] + 'Surgery.csv') #%% for item in df_surgery.iterrows(): if item[1]['project'] == dj.config['project'] and ( item[1]['status'] == 'training' or item[1]['status'] == 'sacrificed'): subjectdata = { 'subject_id': item[1]['animal#'], 'cage_number': item[1]['cage#'], 'date_of_birth': item[1]['DOB'], 'sex': item[1]['sex'], 'username': item[1]['experimenter'], } try: lab.Subject().insert1(subjectdata) except dj.errors.DuplicateError: print('duplicate. animal :', item[1]['animal#'], ' already exists') surgeryidx = 1 while 'surgery date (' + str(surgeryidx) + ')' in item[1].keys( ) and item[1]['surgery date (' + str(surgeryidx) + ')'] and type( item[1]['surgery date (' + str(surgeryidx) + ')']) == str: start_time = datetime.strptime( item[1]['surgery date (' + str(surgeryidx) + ')'] + ' ' + item[1]['surgery time (' + str(surgeryidx) + ')'], '%Y-%m-%d %H:%M') end_time = start_time + timedelta( minutes=int(item[1]['surgery length (min) (' + str(surgeryidx) + ')'])) surgerydata = { 'surgery_id': surgeryidx, 'subject_id': item[1]['animal#'], 'username': item[1]['experimenter'], 'start_time': start_time, 'end_time': end_time, 'surgery_description': item[1]['surgery type (' + str(surgeryidx) + ')'] + ':-: comments: ' + str(item[1]['surgery comments (' + str(surgeryidx) + ')']), } try: lab.Surgery().insert1(surgerydata) except dj.errors.DuplicateError: print('duplicate. surgery for animal ', item[1]['animal#'], ' already exists: ', start_time) #checking craniotomies #% cranioidx = 1 while 'craniotomy diameter (' + str( cranioidx) + ')' in item[1].keys() and item[1][ 'craniotomy diameter (' + str(cranioidx) + ')'] and ( type(item[1]['craniotomy surgery id (' + str(cranioidx) + ')']) == int or type(item[1]['craniotomy surgery id (' + str(cranioidx) + ')']) == float): if item[1]['craniotomy surgery id (' + str(cranioidx) + ')'] == surgeryidx: proceduredata = { 'surgery_id': surgeryidx, 'subject_id': item[1]['animal#'], 'procedure_id': cranioidx, 'skull_reference': item[1]['craniotomy reference (' + str(cranioidx) + ')'], 'ml_location': item[1]['craniotomy lateral (' + str(cranioidx) + ')'], 'ap_location': item[1]['craniotomy anterior (' + str(cranioidx) + ')'], 'surgery_procedure_description': 'craniotomy: ' + item[1]['craniotomy comments (' + str(cranioidx) + ')'], } try: lab.Surgery.Procedure().insert1(proceduredata) except dj.errors.DuplicateError: print('duplicate cranio for animal ', item[1]['animal#'], ' already exists: ', cranioidx) cranioidx += 1 #% virusinjidx = 1 while 'virus inj surgery id (' + str( virusinjidx) + ')' in item[1].keys() and item[1][ 'virus inj virus id (' + str(virusinjidx) + ')'] and item[1]['virus inj surgery id (' + str(virusinjidx) + ')']: if item[1]['virus inj surgery id (' + str(virusinjidx) + ')'] == surgeryidx: # ============================================================================= # print('waiting') # timer.sleep(1000) # ============================================================================= if '[' in item[1]['virus inj lateral (' + str(virusinjidx) + ')']: virus_ml_locations = eval( item[1]['virus inj lateral (' + str(virusinjidx) + ')']) virus_ap_locations = eval( item[1]['virus inj anterior (' + str(virusinjidx) + ')']) virus_dv_locations = eval( item[1]['virus inj ventral (' + str(virusinjidx) + ')']) virus_volumes = eval( item[1]['virus inj volume (nl) (' + str(virusinjidx) + ')']) else: virus_ml_locations = [ int(item[1]['virus inj lateral (' + str(virusinjidx) + ')']) ] virus_ap_locations = [ int(item[1]['virus inj anterior (' + str(virusinjidx) + ')']) ] virus_dv_locations = [ int(item[1]['virus inj ventral (' + str(virusinjidx) + ')']) ] virus_volumes = [ int(item[1]['virus inj volume (nl) (' + str(virusinjidx) + ')']) ] for virus_ml_location, virus_ap_location, virus_dv_location, virus_volume in zip( virus_ml_locations, virus_ap_locations, virus_dv_locations, virus_volumes): injidx = len(lab.Surgery.VirusInjection() & surgerydata) + 1 virusinjdata = { 'surgery_id': surgeryidx, 'subject_id': item[1]['animal#'], 'injection_id': injidx, 'virus_id': item[1]['virus inj virus id (' + str(virusinjidx) + ')'], 'skull_reference': item[1]['virus inj reference (' + str(virusinjidx) + ')'], 'ml_location': virus_ml_location, 'ap_location': virus_ap_location, 'dv_location': virus_dv_location, 'volume': virus_volume, 'dilution': item[1]['virus inj dilution (' + str(virusinjidx) + ')'], 'description': 'virus injection: ' + item[1]['virus inj comments (' + str(virusinjidx) + ')'], } try: lab.Surgery.VirusInjection().insert1( virusinjdata) except dj.errors.DuplicateError: print('duplicate virus injection for animal ', item[1]['animal#'], ' already exists: ', injidx) virusinjidx += 1 #% surgeryidx += 1 #% if item[1]['ID']: #df_wr = online_notebook.fetch_water_restriction_metadata(item[1]['ID']) try: df_wr = pd.read_csv( dj.config['locations.metadata_surgery_experiment'] + item[1]['ID'] + '.csv') except: df_wr = None if type(df_wr) == pd.DataFrame: wrdata = { 'subject_id': item[1]['animal#'], 'water_restriction_number': item[1]['ID'], 'cage_number': item[1]['cage#'], 'wr_start_date': df_wr['Date'][0], 'wr_start_weight': df_wr['Weight'][0], } try: lab.WaterRestriction().insert1(wrdata) except dj.errors.DuplicateError: print('duplicate. water restriction :', item[1]['animal#'], ' already exists')
def mockdata(): print('populating with mock data') reload(ccf) reload(lab) reload(experiment) reload(ephys) reload(publication) try: # TODO: these should be loaded in a more 'official' way lab.Person().insert1({ 'username': '******', 'fullname': 'Dave Liu' }, skip_duplicates=True) lab.ModifiedGene().insert1( { 'gene_modification': 'VGAT-Chr2-EYFP Jax', 'gene_modification_description': 'VGAT' }, skip_duplicates=True) lab.ModifiedGene().insert1( { 'gene_modification': 'PV-ires-Cre X Ai32', 'gene_modification_description': 'PV' }, skip_duplicates=True) lab.ModifiedGene().insert1( { 'gene_modification': 'Rosa26 Cag lsl reachR-citrine 1A4 X PV-ires-Cre', 'gene_modification_description': 'reachR PV' }, skip_duplicates=True) # Subject 399752 / dl7 lab.Subject().insert1( { 'subject_id': 399752, 'username': '******', 'cage_number': 145375, 'date_of_birth': '2017-08-03', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 399752, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 399752, 'surgery_id': 1, 'username': '******', 'start_time': '2017-11-03', 'end_time': '2017-11-03', 'surgery_description': 'Headbar anterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 399752, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -4, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 399752, 'water_restriction_number': 'dl7', 'cage_number': 148861, 'wr_start_date': '2017-11-07', 'wr_start_weight': 25 }, skip_duplicates=True) # Subject 397853 / dl14 lab.Subject().insert1( { 'subject_id': 397853, 'username': '******', 'cage_number': 144545, 'date_of_birth': '2017-07-15', 'sex': 'M', 'animal_source': 'Allen Institute' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 397853, 'gene_modification': 'PV-ires-Cre X Ai32' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 397853, 'surgery_id': 1, 'username': '******', 'start_time': '2017-11-20', 'end_time': '2017-11-20', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 397853, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 397853, 'water_restriction_number': 'dl14', 'cage_number': 149595, 'wr_start_date': '2017-11-27', 'wr_start_weight': 24.1 }, skip_duplicates=True) # Subject 400480 / dl15 lab.Subject().insert1( { 'subject_id': 400480, 'username': '******', 'cage_number': 145700, 'date_of_birth': '2017-08-09', 'sex': 'M', 'animal_source': 'Allen Institute' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 400480, 'gene_modification': 'PV-ires-Cre X Ai32' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 400480, 'surgery_id': 1, 'username': '******', 'start_time': '2017-11-21', 'end_time': '2017-11-21', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 400480, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 400480, 'water_restriction_number': 'dl15', 'cage_number': 149598, 'wr_start_date': '2017-11-27', 'wr_start_weight': 27.6 }, skip_duplicates=True) # Subject 406680 / dl20 lab.Subject().insert1( { 'subject_id': 406680, 'username': '******', 'cage_number': 148859, 'date_of_birth': '2017-10-06', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 406680, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 406680, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-04', 'end_time': '2018-01-04', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 406680, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 406680, 'water_restriction_number': 'dl20', 'cage_number': 151282, 'wr_start_date': '2018-01-10', 'wr_start_weight': 22.7 }, skip_duplicates=True) # Subject 408022 / dl21 lab.Subject().insert1( { 'subject_id': 408022, 'username': '******', 'cage_number': 148859, 'date_of_birth': '2017-10-19', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 408022, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 408022, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-05', 'end_time': '2018-01-05', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 408022, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 408022, 'water_restriction_number': 'dl21', 'cage_number': 151283, 'wr_start_date': '2018-01-10', 'wr_start_weight': 21.1 }, skip_duplicates=True) # Subject 408021 / dl22 lab.Subject().insert1( { 'subject_id': 408021, 'username': '******', 'cage_number': 148859, 'date_of_birth': '2017-10-19', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 408021, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 408021, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-15', 'end_time': '2018-01-15', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 408021, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 408021, 'water_restriction_number': 'dl22', 'cage_number': 151704, 'wr_start_date': '2018-01-19', 'wr_start_weight': 21 }, skip_duplicates=True) # Subject 407512 / dl24 lab.Subject().insert1( { 'subject_id': 407512, 'username': '******', 'cage_number': 151629, 'date_of_birth': '2017-10-13', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 407512, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 407512, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-16', 'end_time': '2018-01-16', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 407512, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 407512, 'water_restriction_number': 'dl24', 'cage_number': 151793, 'wr_start_date': '2018-01-22', 'wr_start_weight': 26 }, skip_duplicates=True) # 407513 / dl25 lab.Subject().insert1( { 'subject_id': 407513, 'username': '******', 'cage_number': 148636, 'date_of_birth': '2017-10-13', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 407513, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 407513, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-17', 'end_time': '2018-01-17', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 407513, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 407513, 'water_restriction_number': 'dl25', 'cage_number': 151794, 'wr_start_date': '2018-01-22', 'wr_start_weight': 25.5 }, skip_duplicates=True) # Subject 407986 / dl28 lab.Subject().insert1( { 'subject_id': 407986, 'username': '******', 'cage_number': 152268, 'date_of_birth': '2017-10-18', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 407986, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 407986, 'surgery_id': 1, 'username': '******', 'start_time': '2018-02-01', 'end_time': '2018-02-01', 'surgery_description': 'Headbar anterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 407986, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -4, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 407986, 'water_restriction_number': 'dl28', 'cage_number': 152312, 'wr_start_date': '2018-02-05', 'wr_start_weight': 19.8 }, skip_duplicates=True) # Subject 123457 / tw5 lab.Subject().insert1( { 'subject_id': 123457, 'username': '******', 'cage_number': 145375, 'date_of_birth': '2017-08-03', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 123457, 'water_restriction_number': 'tw5', 'cage_number': 148861, 'wr_start_date': '2017-11-07', 'wr_start_weight': 20.5 }, skip_duplicates=True) # Subject 412330 / tw34 lab.Subject().insert1( { 'subject_id': 412330, 'username': '******', 'cage_number': 154522, 'date_of_birth': '2017-12-05', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 412330, 'water_restriction_number': 'tw34', 'cage_number': 154522, 'wr_start_date': '2018-03-18', 'wr_start_weight': 21.0 }, skip_duplicates=True) # subject 432998 / dl55 lab.Subject().insert1( { 'subject_id': 432998, 'username': '******', 'cage_number': 160920, 'date_of_birth': '2018-07-02', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 432998, 'water_restriction_number': 'dl55', 'cage_number': 160920, 'wr_start_date': '2018-09-05', 'wr_start_weight': 21.0 }, skip_duplicates=True) # Subject 435884 / dl59 lab.Subject().insert1( { 'subject_id': 435884, 'username': '******', 'cage_number': 161908, 'date_of_birth': '2018-08-06', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 435884, 'water_restriction_number': 'dl59', 'cage_number': 154522, 'wr_start_date': '2018-09-30', 'wr_start_weight': 21.0 }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'TRig1', 'room': '2w.334', 'rig_description': 'Training rig 1' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'TRig2', 'room': '2w.334', 'rig_description': 'Training rig 2' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'TRig3', 'room': '2w.334', 'rig_description': 'Training rig 3' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'RRig', 'room': '2w.334', 'rig_description': 'Recording rig' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'Ephys1', 'room': '2w.334', 'rig_description': 'Recording computer' }, skip_duplicates=True) # ---- Brain Location ---- experiment.BrainLocation.insert1( { 'brain_location_name': 'left_alm', 'brain_area': 'ALM', 'hemisphere': 'left', 'skull_reference': 'Bregma' }, skip_duplicates=True) experiment.BrainLocation.insert1( { 'brain_location_name': 'right_alm', 'brain_area': 'ALM', 'hemisphere': 'right', 'skull_reference': 'Bregma' }, skip_duplicates=True) experiment.BrainLocation.insert1( { 'brain_location_name': 'both_alm', 'brain_area': 'ALM', 'hemisphere': 'both', 'skull_reference': 'Bregma' }, skip_duplicates=True) experiment.BrainLocation.insert1( { 'brain_location_name': 'left_medulla', 'brain_area': 'Medulla', 'hemisphere': 'left', 'skull_reference': 'Bregma' }, skip_duplicates=True) experiment.BrainLocation.insert1( { 'brain_location_name': 'right_medulla', 'brain_area': 'Medulla', 'hemisphere': 'right', 'skull_reference': 'Bregma' }, skip_duplicates=True) experiment.BrainLocation.insert1( { 'brain_location_name': 'both_medulla', 'brain_area': 'Medulla', 'hemisphere': 'both', 'skull_reference': 'Bregma' }, skip_duplicates=True) # Probe (Neuropixel) npx_probe_model = '15131808323' # using Model No. - SN TBD? lab.Probe.insert1( { 'probe': npx_probe_model, 'probe_type': 'neuropixel' }, skip_duplicates=True, ) lab.Probe.Electrode.insert( ({ 'probe': npx_probe_model, 'electrode': x } for x in range(1, 961)), skip_duplicates=True, ) except Exception as e: print("error creating mock data: {e}".format(e=e), file=sys.stderr) raise
def mockdata(): print('populating with mock data') reload(ccf) reload(lab) reload(experiment) reload(ephys) reload(publication) try: # TODO: these should be loaded in a more 'official' way lab.Person().insert1({ 'username': '******', 'fullname': 'Dave Liu' }, skip_duplicates=True) lab.ModifiedGene().insert1( { 'gene_modification': 'VGAT-Chr2-EYFP Jax', 'gene_modification_description': 'VGAT' }, skip_duplicates=True) lab.ModifiedGene().insert1( { 'gene_modification': 'PV-ires-Cre X Ai32', 'gene_modification_description': 'PV' }, skip_duplicates=True) lab.ModifiedGene().insert1( { 'gene_modification': 'Rosa26 Cag lsl reachR-citrine 1A4 X PV-ires-Cre', 'gene_modification_description': 'reachR PV' }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 399752, 'username': '******', 'cage_number': 145375, 'date_of_birth': '2017-08-03', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 399752, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 399752, 'surgery_id': 1, 'username': '******', 'start_time': '2017-11-03', 'end_time': '2017-11-03', 'surgery_description': 'Headbar anterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 399752, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -4, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 399752, 'water_restriction_number': 'dl7', 'cage_number': 148861, 'wr_start_date': '2017-11-07', 'wr_start_weight': 25 }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 397853, 'username': '******', 'cage_number': 144545, 'date_of_birth': '2017-07-15', 'sex': 'M', 'animal_source': 'Allen Institute' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 397853, 'gene_modification': 'PV-ires-Cre X Ai32' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 397853, 'surgery_id': 1, 'username': '******', 'start_time': '2017-11-20', 'end_time': '2017-11-20', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 397853, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 397853, 'water_restriction_number': 'dl14', 'cage_number': 149595, 'wr_start_date': '2017-11-27', 'wr_start_weight': 24.1 }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 400480, 'username': '******', 'cage_number': 145700, 'date_of_birth': '2017-08-09', 'sex': 'M', 'animal_source': 'Allen Institute' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 400480, 'gene_modification': 'PV-ires-Cre X Ai32' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 400480, 'surgery_id': 1, 'username': '******', 'start_time': '2017-11-21', 'end_time': '2017-11-21', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 400480, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 400480, 'water_restriction_number': 'dl15', 'cage_number': 149598, 'wr_start_date': '2017-11-27', 'wr_start_weight': 27.6 }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 406680, 'username': '******', 'cage_number': 148859, 'date_of_birth': '2017-10-06', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 406680, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 406680, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-04', 'end_time': '2018-01-04', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 406680, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 406680, 'water_restriction_number': 'dl20', 'cage_number': 151282, 'wr_start_date': '2018-01-10', 'wr_start_weight': 22.7 }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 408022, 'username': '******', 'cage_number': 148859, 'date_of_birth': '2017-10-19', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 408022, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 408022, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-05', 'end_time': '2018-01-05', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 408022, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 408022, 'water_restriction_number': 'dl21', 'cage_number': 151283, 'wr_start_date': '2018-01-10', 'wr_start_weight': 21.1 }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 408021, 'username': '******', 'cage_number': 148859, 'date_of_birth': '2017-10-19', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 408021, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 408021, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-15', 'end_time': '2018-01-15', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 408021, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 408021, 'water_restriction_number': 'dl22', 'cage_number': 151704, 'wr_start_date': '2018-01-19', 'wr_start_weight': 21 }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 407512, 'username': '******', 'cage_number': 151629, 'date_of_birth': '2017-10-13', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 407512, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 407512, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-16', 'end_time': '2018-01-16', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 407512, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 407512, 'water_restriction_number': 'dl24', 'cage_number': 151793, 'wr_start_date': '2018-01-22', 'wr_start_weight': 26 }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 407513, 'username': '******', 'cage_number': 148636, 'date_of_birth': '2017-10-13', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 407513, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 407513, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-17', 'end_time': '2018-01-17', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 407513, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 407513, 'water_restriction_number': 'dl25', 'cage_number': 151794, 'wr_start_date': '2018-01-22', 'wr_start_weight': 25.5 }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 407986, 'username': '******', 'cage_number': 152268, 'date_of_birth': '2017-10-18', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 407986, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 407986, 'surgery_id': 1, 'username': '******', 'start_time': '2018-02-01', 'end_time': '2018-02-01', 'surgery_description': 'Headbar anterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 407986, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -4, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 407986, 'water_restriction_number': 'dl28', 'cage_number': 152312, 'wr_start_date': '2018-02-05', 'wr_start_weight': 19.8 }, skip_duplicates=True) lab.Subject().insert1( { 'subject_id': 123457, 'username': '******', 'cage_number': 145375, 'date_of_birth': '2017-08-03', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 123457, 'water_restriction_number': 'tw5', 'cage_number': 148861, 'wr_start_date': '2017-11-07', 'wr_start_weight': 20.5 }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'TRig1', 'room': '2w.334', 'rig_description': 'Training rig 1' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'TRig2', 'room': '2w.334', 'rig_description': 'Training rig 2' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'TRig3', 'room': '2w.334', 'rig_description': 'Training rig 3' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'RRig', 'room': '2w.334', 'rig_description': 'Recording rig' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'Ephys1', 'room': '2w.334', 'rig_description': 'Recording computer' }, skip_duplicates=True) except Exception as e: print("error creating mock data: {e}".format(e=e), file=sys.stderr) raise
def mockdata(): print('populating with mock data') reload(lab) reload(ccf) reload(experiment) reload(ephys) reload(histology) reload(tracking) try: lab.Person().insert1({ 'username': '******', 'fullname': 'Unknown' }, skip_duplicates=True) lab.Person().insert1({ 'username': '******', 'fullname': 'Dave Liu' }, skip_duplicates=True) lab.Person().insert1({ 'username': '******', 'fullname': 'Susu Chen' }, skip_duplicates=True) lab.Person().insert1({ 'username': '******', 'fullname': 'Thinh Nguyen' }, skip_duplicates=True) lab.ModifiedGene().insert1( { 'gene_modification': 'VGAT-Chr2-EYFP Jax', 'gene_modification_description': 'VGAT' }, skip_duplicates=True) lab.ModifiedGene().insert1( { 'gene_modification': 'PV-ires-Cre X Ai32', 'gene_modification_description': 'PV' }, skip_duplicates=True) lab.ModifiedGene().insert1( { 'gene_modification': 'Rosa26 Cag lsl reachR-citrine 1A4 X PV-ires-Cre', 'gene_modification_description': 'reachR PV' }, skip_duplicates=True) # Subject 399752 / dl7 lab.Subject().insert1( { 'subject_id': 399752, 'username': '******', 'cage_number': 145375, 'date_of_birth': '2017-08-03', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 399752, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 399752, 'surgery_id': 1, 'username': '******', 'start_time': '2017-11-03', 'end_time': '2017-11-03', 'surgery_description': 'Headbar anterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 399752, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -4, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 399752, 'water_restriction_number': 'dl7', 'cage_number': 148861, 'wr_start_date': '2017-11-07', 'wr_start_weight': 25 }, skip_duplicates=True) # Subject 397853 / dl14 lab.Subject().insert1( { 'subject_id': 397853, 'username': '******', 'cage_number': 144545, 'date_of_birth': '2017-07-15', 'sex': 'M', 'animal_source': 'Allen Institute' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 397853, 'gene_modification': 'PV-ires-Cre X Ai32' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 397853, 'surgery_id': 1, 'username': '******', 'start_time': '2017-11-20', 'end_time': '2017-11-20', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 397853, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 397853, 'water_restriction_number': 'dl14', 'cage_number': 149595, 'wr_start_date': '2017-11-27', 'wr_start_weight': 24.1 }, skip_duplicates=True) # Subject 400480 / dl15 lab.Subject().insert1( { 'subject_id': 400480, 'username': '******', 'cage_number': 145700, 'date_of_birth': '2017-08-09', 'sex': 'M', 'animal_source': 'Allen Institute' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 400480, 'gene_modification': 'PV-ires-Cre X Ai32' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 400480, 'surgery_id': 1, 'username': '******', 'start_time': '2017-11-21', 'end_time': '2017-11-21', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 400480, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 400480, 'water_restriction_number': 'dl15', 'cage_number': 149598, 'wr_start_date': '2017-11-27', 'wr_start_weight': 27.6 }, skip_duplicates=True) # Subject 406680 / dl20 lab.Subject().insert1( { 'subject_id': 406680, 'username': '******', 'cage_number': 148859, 'date_of_birth': '2017-10-06', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 406680, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 406680, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-04', 'end_time': '2018-01-04', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 406680, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 406680, 'water_restriction_number': 'dl20', 'cage_number': 151282, 'wr_start_date': '2018-01-10', 'wr_start_weight': 22.7 }, skip_duplicates=True) # Subject 408022 / dl21 lab.Subject().insert1( { 'subject_id': 408022, 'username': '******', 'cage_number': 148859, 'date_of_birth': '2017-10-19', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 408022, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 408022, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-05', 'end_time': '2018-01-05', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 408022, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 408022, 'water_restriction_number': 'dl21', 'cage_number': 151283, 'wr_start_date': '2018-01-10', 'wr_start_weight': 21.1 }, skip_duplicates=True) # Subject 408021 / dl22 lab.Subject().insert1( { 'subject_id': 408021, 'username': '******', 'cage_number': 148859, 'date_of_birth': '2017-10-19', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 408021, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 408021, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-15', 'end_time': '2018-01-15', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 408021, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 408021, 'water_restriction_number': 'dl22', 'cage_number': 151704, 'wr_start_date': '2018-01-19', 'wr_start_weight': 21 }, skip_duplicates=True) # Subject 407512 / dl24 lab.Subject().insert1( { 'subject_id': 407512, 'username': '******', 'cage_number': 151629, 'date_of_birth': '2017-10-13', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 407512, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 407512, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-16', 'end_time': '2018-01-16', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 407512, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 407512, 'water_restriction_number': 'dl24', 'cage_number': 151793, 'wr_start_date': '2018-01-22', 'wr_start_weight': 26 }, skip_duplicates=True) # 407513 / dl25 lab.Subject().insert1( { 'subject_id': 407513, 'username': '******', 'cage_number': 148636, 'date_of_birth': '2017-10-13', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 407513, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 407513, 'surgery_id': 1, 'username': '******', 'start_time': '2018-01-17', 'end_time': '2018-01-17', 'surgery_description': 'Headbar posterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 407513, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -1.75, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 407513, 'water_restriction_number': 'dl25', 'cage_number': 151794, 'wr_start_date': '2018-01-22', 'wr_start_weight': 25.5 }, skip_duplicates=True) # Subject 407986 / dl28 lab.Subject().insert1( { 'subject_id': 407986, 'username': '******', 'cage_number': 152268, 'date_of_birth': '2017-10-18', 'sex': 'F', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.Subject.GeneModification().insert1( { 'subject_id': 407986, 'gene_modification': 'VGAT-Chr2-EYFP Jax' }, skip_duplicates=True) lab.Surgery().insert1( { 'subject_id': 407986, 'surgery_id': 1, 'username': '******', 'start_time': '2018-02-01', 'end_time': '2018-02-01', 'surgery_description': 'Headbar anterior' }, skip_duplicates=True) lab.Surgery.Procedure().insert1( { 'subject_id': 407986, 'surgery_id': 1, 'procedure_id': 1, 'skull_reference': 'Bregma', 'ml_location': 0, 'ap_location': -4, 'surgery_procedure_description': 'Fiducial marker' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 407986, 'water_restriction_number': 'dl28', 'cage_number': 152312, 'wr_start_date': '2018-02-05', 'wr_start_weight': 19.8 }, skip_duplicates=True) # Subject 123457 / tw5 lab.Subject().insert1( { 'subject_id': 123457, 'username': '******', 'cage_number': 145375, 'date_of_birth': '2017-08-03', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 123457, 'water_restriction_number': 'tw5', 'cage_number': 148861, 'wr_start_date': '2017-11-07', 'wr_start_weight': 20.5 }, skip_duplicates=True) # Subject 412330 / tw34 lab.Subject().insert1( { 'subject_id': 412330, 'username': '******', 'cage_number': 154522, 'date_of_birth': '2017-12-05', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 412330, 'water_restriction_number': 'tw34', 'cage_number': 154522, 'wr_start_date': '2018-03-18', 'wr_start_weight': 21.0 }, skip_duplicates=True) # subject 432998 / dl55 lab.Subject().insert1( { 'subject_id': 432998, 'username': '******', 'cage_number': 160920, 'date_of_birth': '2018-07-02', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 432998, 'water_restriction_number': 'dl55', 'cage_number': 160920, 'wr_start_date': '2018-09-05', 'wr_start_weight': 21.0 }, skip_duplicates=True) # Subject 435884 / dl59 lab.Subject().insert1( { 'subject_id': 435884, 'username': '******', 'cage_number': 161908, 'date_of_birth': '2018-08-06', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 435884, 'water_restriction_number': 'dl59', 'cage_number': 154522, 'wr_start_date': '2018-09-30', 'wr_start_weight': 21.0 }, skip_duplicates=True) # Subject 432572 / dl56 lab.Subject().insert1( { 'subject_id': 432572, 'username': '******', 'cage_number': 161125, 'date_of_birth': '2018-06-28', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 432572, 'water_restriction_number': 'dl56', 'cage_number': 161125, 'wr_start_date': '2018-09-10', 'wr_start_weight': 21.0 }, skip_duplicates=True) # Subject 412753 / dl36 lab.Subject().insert1( { 'subject_id': 412753, 'username': '******', 'cage_number': 154570, 'date_of_birth': '2017-12-07', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 412753, 'water_restriction_number': 'dl36', 'cage_number': 154570, 'wr_start_date': '2017-03-30', 'wr_start_weight': 21.0 }, skip_duplicates=True) # Subject 440010 / dl62 lab.Subject().insert1( { 'subject_id': 440010, 'username': '******', 'cage_number': 163782, 'date_of_birth': '2018-09-24', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 440010, 'water_restriction_number': 'dl62', 'cage_number': 163782, 'wr_start_date': '2018-11-24', 'wr_start_weight': 23.0 }, skip_duplicates=True) # Subject 55004 / DL004 lab.Subject().insert1( { 'subject_id': 550004, 'username': '******', 'cage_number': 163782, 'date_of_birth': '2018-09-24', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 550004, 'water_restriction_number': 'DL004', 'cage_number': 163782, 'wr_start_date': '2018-11-24', 'wr_start_weight': 23.0 }, skip_duplicates=True) # Subject 550009 / DL009 lab.Subject().insert1( { 'subject_id': 550009, 'username': '******', 'cage_number': 163782, 'date_of_birth': '2018-09-24', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 550009, 'water_restriction_number': 'DL009', 'cage_number': 163782, 'wr_start_date': '2018-11-24', 'wr_start_weight': 23.0 }, skip_duplicates=True) # Subject 550010 / DL010 lab.Subject().insert1( { 'subject_id': 550010, 'username': '******', 'cage_number': 163782, 'date_of_birth': '2018-09-24', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 550010, 'water_restriction_number': 'DL010', 'cage_number': 163782, 'wr_start_date': '2018-11-24', 'wr_start_weight': 23.0 }, skip_duplicates=True) # Subject 550022 / DL022 lab.Subject().insert1( { 'subject_id': 550022, 'username': '******', 'cage_number': 163782, 'date_of_birth': '2018-09-24', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 550022, 'water_restriction_number': 'DL022', 'cage_number': 163782, 'wr_start_date': '2018-11-24', 'wr_start_weight': 23.0 }, skip_duplicates=True) # Subject 440959 / SC011 lab.Subject().insert1( { 'subject_id': 440959, 'username': '******', 'cage_number': 440959, 'date_of_birth': '2018-10-09', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 440959, 'water_restriction_number': 'SC011', 'cage_number': 440959, 'wr_start_date': '2018-12-21', 'wr_start_weight': 22.8 }, skip_duplicates=True) # Subject 442571 / SC022 lab.Subject().insert1( { 'subject_id': 442571, 'username': '******', 'cage_number': 442571, 'date_of_birth': '2018-10-29', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 442571, 'water_restriction_number': 'SC022', 'cage_number': 442571, 'wr_start_date': '2019-01-02', 'wr_start_weight': 26.5 }, skip_duplicates=True) # Subject 460432 / SC030 lab.Subject().insert1( { 'subject_id': 456773, 'username': '******', 'cage_number': 171857, 'date_of_birth': '2019-05-29', 'sex': 'M', 'animal_source': 'Jackson Labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 456773, 'water_restriction_number': 'SC030', 'cage_number': 171857, 'wr_start_date': '2019-08-08', 'wr_start_weight': 25.700 }, skip_duplicates=True) # Subject 460432 / SC032 lab.Subject().insert1( { 'subject_id': 460432, 'username': '******', 'cage_number': 173167, 'date_of_birth': '2019-07-15', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 460432, 'water_restriction_number': 'SC032', 'cage_number': 173167, 'wr_start_date': '2019-09-20', 'wr_start_weight': 22.8 }, skip_duplicates=True) for num in range(1, 20): lab.Subject().insert1( { 'subject_id': 777000 + num, 'username': '******', 'cage_number': 173167, 'date_of_birth': '2019-07-15', 'sex': 'M', 'animal_source': 'Jackson labs' }, skip_duplicates=True) lab.WaterRestriction().insert1( { 'subject_id': 777000 + num, 'water_restriction_number': 'FOR' + f'{num:02}', 'cage_number': 173167, 'wr_start_date': '2019-09-20', 'wr_start_weight': 22.8 }, skip_duplicates=True) # Rig lab.Rig().insert1( { 'rig': 'TRig1', 'room': '2w.334', 'rig_description': 'Training rig 1' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'TRig2', 'room': '2w.334', 'rig_description': 'Training rig 2' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'TRig3', 'room': '2w.334', 'rig_description': 'Training rig 3' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'RRig', 'room': '2w.334', 'rig_description': 'Recording rig' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'RRig2', 'room': '2w.334', 'rig_description': 'Recording rig2' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'RRig3', 'room': '2w.334', 'rig_description': 'Recording rig3 for multi-target-licking' }, skip_duplicates=True) lab.Rig().insert1( { 'rig': 'Ephys1', 'room': '2w.334', 'rig_description': 'Recording computer' }, skip_duplicates=True) lab.ProbeType.create_neuropixels_probe() except Exception as e: print("error creating mock data: {e}".format(e=e), file=sys.stderr) raise
'Rin':list(), 'AP_amplitude':list(), 'AP_halfwidth':list(), 'AP_threshold':list(), 'resting':list()} cells = ephys_patch.Cell() APs_needed = 50 AP_max_RS = 40 AP_max_baseline = -40 #mV max_baseline_current = 100*10**-12 #A max_v0 = -.04 #V min_current = -40*10**-12 #A min_pulse_time = 0.3 #s integration_window = .04 #sec for cell in cells: if len((lab.Surgery()&'subject_id = {}'.format(cell['subject_id'])).fetch('start_time'))==1: continue # if there is only one surgery, we don't care expression_time = np.diff((lab.Surgery()&'subject_id = {}'.format(cell['subject_id'])).fetch('start_time'))[0].days virus_id = (lab.Surgery.VirusInjection()&'subject_id = {}'.format(cell['subject_id'])).fetch('virus_id')[0] if virus_id == 238: virus = 'Voltron 1' elif virus_id == 240: virus = 'Voltron 2' else: virus = '??' squarepulses = ephysanal.SquarePulse()&cell&'square_pulse_amplitude < {}'.format(min_current)&'square_pulse_length > {}'.format(min_pulse_time) Rins = list() RSs = list() v0s = list() for squarepulse in squarepulses:
#%% metadata for methods subject_ids = np.unique(imaging.Movie().fetch('subject_id')) movie_num_list = list() sex_list = list() age_first_surgery_list = list() expression_time_list = list() ml_list = list() ap_list=list() depth_list = list() for subject_id in subject_ids: virus_ids = (lab.Surgery.VirusInjection()&'subject_id = {}'.format(subject_id)).fetch('virus_id') virus_id = virus_ids[0] virus_name = (lab.Virus()&'virus_id = {}'.format(virus_id)).fetch1('virus_name') if virus_name != 'syn-FLEX-Voltron-ST': continue if len(lab.Surgery()&'subject_id = {}'.format(subject_id))!=2: print('only {} surgery for {}'.format(len(lab.Surgery()&'subject_id = {}'.format(subject_id)),subject_id)) continue movie_num_list.append(len(imaging.Movie()&'subject_id = {}'.format(subject_id))) date_of_birth,sex = (lab.Subject()&'subject_id = {}'.format(subject_id)).fetch1('date_of_birth','sex') surgery_times = (lab.Surgery()&'subject_id = {}'.format(subject_id)).fetch('start_time') ml,ap = (lab.Surgery.Procedure()&'subject_id = {}'.format(subject_id)).fetch1('ml_location','ap_location') ml_list.append(int(ml)) ap_list.append(int(ap)) age_first_surgery_list.append((np.min(surgery_times).date()-date_of_birth).days) expression_time_list.append(np.diff(surgery_times)[0].days) sex_list.append(sex) depth_list.extend((ephys_patch.Cell()&'subject_id = {}'.format(subject_id)).fetch('depth')) depth_list = np.asarray(depth_list) ap_list = np.asarray(ap_list)
def plot_cell_SN_ratio_APwise(roi_type='VolPy', v0_max=-35, holding_min=-600, frame_rate_min=300, frame_rate_max=1800, F0_min=50, bin_num=10): #%% Show S/N ratios for each AP bin_num = 10 holding_min = -600 #pA v0_max = -35 #mV roi_type = 'VolPy_raw' #'Spikepursuit'#'VolPy_denoised'#'SpikePursuit'#'VolPy_dexpF0'#'VolPy'#'SpikePursuit_dexpF0'#'VolPy_dexpF0'#''Spikepursuit'#'VolPy'# F0_min = 50 frame_rate_min = 200 frame_rate_max = 800 cmap = cm.get_cmap('jet') key = {'roi_type': roi_type} gtdata = pd.DataFrame((imaging_gt.GroundTruthROI() & key)) cells = gtdata.groupby([ 'session', 'subject_id', 'cell_number', 'motion_correction_method', 'roi_type' ]).size().reset_index(name='Freq') snratio = list() v0s = list() holdings = list() rss = list() threshs = list() mintreshs = list() f0s_all = list() snratios_all = list() peakamplitudes_all = list() noise_all = list() for cell in cells.iterrows(): cell = cell[1] key_cell = dict(cell) del key_cell['Freq'] snratios, f0, peakamplitudes, noises = ( imaging.Movie() * imaging_gt.GroundTruthROI() * imaging_gt.ROIAPWave() * ephysanal.ActionPotentialDetails() & key_cell & 'ap_real = 1' & 'movie_frame_rate > {}'.format(frame_rate_min) & 'movie_frame_rate < {}'.format(frame_rate_max) & 'apwave_f0 > {}'.format(F0_min)).fetch('apwave_snratio', 'apwave_f0', 'apwave_peak_amplitude', 'apwave_noise') #f0 = (imaging_gt.GroundTruthROI()*imaging.ROI()&key_cell).fetch('roi_f0') sweep = (imaging_gt.GroundTruthROI() * imaging_gt.ROIAPWave() & key_cell).fetch('sweep_number')[0] thresh = (imaging_gt.GroundTruthROI() * imaging_gt.ROIAPWave() * ephysanal.ActionPotentialDetails() & key_cell & 'ap_real = 1').fetch('ap_threshold') trace = (ephys_patch.SweepResponse() * imaging_gt.GroundTruthROI() & key_cell & 'sweep_number = {}'.format(sweep)).fetch('response_trace') trace = trace[0] stimulus = (ephys_patch.SweepStimulus() * imaging_gt.GroundTruthROI() & key_cell & 'sweep_number = {}'.format(sweep)).fetch('stimulus_trace') stimulus = stimulus[0] RS = (ephysanal.SweepSeriesResistance() * imaging_gt.GroundTruthROI() & key_cell & 'sweep_number = {}'.format(sweep)).fetch('series_resistance') RS = RS[0] medianvoltage = np.median(trace) * 1000 holding = np.median(stimulus) * 10**12 #print(np.mean(snratios[:100])) snratio.append(np.mean(snratios[:50])) v0s.append(medianvoltage) holdings.append(holding) rss.append(RS) threshs.append(thresh) mintreshs.append(np.min(thresh)) f0s_all.append(f0) snratios_all.append(snratios) peakamplitudes_all.append(peakamplitudes) noise_all.append(noises) #plot_AP_waveforms(key_cell,AP_tlimits) #%% # ============================================================================= # virus_list=list() # subject_ids = list() # for cell in cells.iterrows(): # cell = cell[1] # key_cell = dict(cell) # del key_cell['Freq'] # virus_id = (lab.Surgery.VirusInjection()&'subject_id = {}'.format(key_cell['subject_id'])).fetch('virus_id')[0] # if virus_id == 238: # virus = 'Voltron 1' # elif virus_id == 240: # virus = 'Voltron 2' # virus_list.append(virus) # subject_ids.append(key_cell['subject_id']) # # order = np.argsort(virus_list) # order = np.lexsort((virus_list, subject_ids)) # snratio = np.asarray(snratio)[order] # v0s = np.asarray(v0s)[order] # holdings = np.asarray(holdings)[order] # rss = np.asarray(rss)[order] # threshs =np.asarray(threshs)[order] # mintreshs = np.asarray(mintreshs)[order] # f0s_all = np.asarray(f0s_all)[order] # snratios_all = np.asarray(snratios_all)[order] # peakamplitudes_all = np.asarray(peakamplitudes_all)[order] # noise_all = np.asarray(noise_all)[order] # virus_list = np.asarray(virus_list)[order] # cells = cells.set_index(order, append=True).sort_index(level=1).reset_index(1, drop=True) # ============================================================================= #%% apnum = 50 fig = plt.figure(figsize=[10, 10]) ax_exptime_f0 = fig.add_subplot(221) ax_exptime_dff = fig.add_subplot(222) ax_exptime_noise = fig.add_subplot(223) ax_exptime_snration = fig.add_subplot(224) for loopidx, (f0, snratio_now, noise_now, peakampl_now, cell_now) in enumerate( zip(f0s_all, snratios_all, noise_all, peakamplitudes_all, cells.iterrows())): if len( f0 ) > 0: # and cell_now[1]['subject_id']==466774:# and cell_now[1]['cell_number']==1: coloridx = loopidx / len(cells) cell_now = cell_now[1] virus_id = (lab.Surgery.VirusInjection() & 'subject_id = {}'.format( cell_now['subject_id'])).fetch('virus_id')[0] if virus_id == 238: virus = 'Voltron 1' elif virus_id == 240: virus = 'Voltron 2' else: virus = '??' label_now = 'Subject:{}'.format( cell_now['subject_id']) + ' Cell:{} - {}'.format( cell_now['cell_number'], virus) expression_time = np.diff( (lab.Surgery() & 'subject_id = {}'.format( cell_now['subject_id'])).fetch('start_time'))[0].days ax_exptime_f0.plot(expression_time, np.mean(f0[:apnum]), 'o', ms=10, color=cmap(coloridx), label=label_now) ax_exptime_f0.errorbar(expression_time, np.mean(f0[:apnum]), np.std(f0[:apnum]), ecolor=cmap(coloridx)) ax_exptime_f0.set_xlabel('expression time (days)') ax_exptime_f0.set_ylabel('F0 (pixel intensity)') ax_exptime_dff.plot(expression_time, np.mean(peakampl_now[:apnum]), 'o', ms=10, color=cmap(coloridx), label=label_now) ax_exptime_dff.errorbar(expression_time, np.mean(peakampl_now[:apnum]), np.std(peakampl_now[:apnum]), ecolor=cmap(coloridx)) ax_exptime_dff.set_xlabel('expression time (days)') ax_exptime_dff.set_ylabel('AP peak amplitude (dF/F)') ax_exptime_noise.plot(expression_time, np.mean(noise_now[:apnum]), 'o', ms=10, color=cmap(coloridx), label=label_now) ax_exptime_noise.errorbar(expression_time, np.mean(noise_now[:apnum]), np.std(noise_now[:apnum]), ecolor=cmap(coloridx)) ax_exptime_noise.set_xlabel('expression time (days)') ax_exptime_noise.set_ylabel('noise (dF/F)') ax_exptime_snration.plot(expression_time, np.mean(snratio_now[:apnum]), 'o', ms=10, color=cmap(coloridx), label=label_now) ax_exptime_snration.errorbar(expression_time, np.mean(snratio_now[:apnum]), np.std(snratio_now[:apnum]), ecolor=cmap(coloridx)) ax_exptime_snration.set_xlabel('expression time (days)') ax_exptime_snration.set_ylabel('S/N ratio') #%% for each AP fig = plt.figure() ax_sn_f0 = fig.add_axes([0, 0, 1, 1]) ax_sn_f0_binned = fig.add_axes([0, -1.2, 1, 1]) ax_noise_f0 = fig.add_axes([2.6, 0, 1, 1]) ax_noise_f0_binned = fig.add_axes([2.6, -1.2, 1, 1]) ax_peakampl_f0 = fig.add_axes([1.3, 0, 1, 1]) ax_peakampl_f0_binned = fig.add_axes([1.3, -1.2, 1, 1]) for loopidx, (f0, snratio_now, noise_now, peakampl_now, cell_now) in enumerate( zip(f0s_all, snratios_all, noise_all, peakamplitudes_all, cells.iterrows())): if len( f0 ) > 0: # and cell_now[1]['subject_id']==466774:# and cell_now[1]['cell_number']==1: coloridx = loopidx / len(cells) cell_now = cell_now[1] virus_id = (lab.Surgery.VirusInjection() & 'subject_id = {}'.format( cell_now['subject_id'])).fetch('virus_id')[0] if virus_id == 238: virus = 'Voltron 1' elif virus_id == 240: virus = 'Voltron 2' else: virus = '??' label_now = 'Subject:{}'.format( cell_now['subject_id']) + ' Cell:{} - {}'.format( cell_now['cell_number'], virus) ax_sn_f0.plot(f0, snratio_now, 'o', ms=1, color=cmap(coloridx), label=label_now) ax_noise_f0.plot(f0, noise_now, 'o', ms=1, color=cmap(coloridx), label=label_now) ax_peakampl_f0.plot(f0, peakampl_now, 'o', ms=1, color=cmap(coloridx), label=label_now) lows = np.arange(np.min(f0), np.max(f0), (np.max(f0) - np.min(f0)) / (bin_num + 1)) highs = lows + (np.max(f0) - np.min(f0)) / (bin_num + 1) mean_f0 = list() sd_f0 = list() mean_sn = list() sd_sn = list() mean_noise = list() sd_noise = list() mean_ampl = list() sd_ampl = list() for low, high in zip(lows, highs): idx = (f0 >= low) & (f0 < high) if len(idx) > 10: mean_f0.append(np.mean(f0[idx])) sd_f0.append(np.std(f0[idx])) mean_sn.append(np.mean(snratio_now[idx])) sd_sn.append(np.std(snratio_now[idx])) mean_noise.append(np.mean(noise_now[idx])) sd_noise.append(np.std(noise_now[idx])) mean_ampl.append(np.mean(peakampl_now[idx])) sd_ampl.append(np.std(peakampl_now[idx])) ax_sn_f0_binned.errorbar(mean_f0, mean_sn, sd_sn, sd_f0, 'o-', color=cmap(coloridx), label=label_now) ax_noise_f0_binned.errorbar(mean_f0, mean_noise, sd_noise, sd_f0, 'o-', color=cmap(coloridx), label=label_now) ax_peakampl_f0_binned.errorbar(mean_f0, mean_ampl, sd_ampl, sd_f0, 'o-', color=cmap(coloridx), label=label_now) ax_sn_f0.set_xlabel('F0') ax_sn_f0.set_ylabel('S/N ratio') ax_sn_f0_binned.set_xlabel('F0') ax_sn_f0_binned.set_ylabel('S/N ratio') #ax_sn_f0_binned.legend() ax_sn_f0_binned.legend(loc='upper center', bbox_to_anchor=(-.45, 1.5), shadow=True, ncol=1) ax_noise_f0.set_xlabel('F0') ax_noise_f0.set_ylabel('Noise (std(dF/F))') ax_noise_f0_binned.set_xlabel('F0') ax_noise_f0_binned.set_ylabel('Noise (std(dF/F))') ax_peakampl_f0.set_xlabel('F0') ax_peakampl_f0.set_ylabel('Peak amplitude (dF/F)') ax_peakampl_f0_binned.set_xlabel('F0') ax_peakampl_f0_binned.set_ylabel('Peak amplitude (dF/F)') #%% cells['SN'] = snratio cells['V0'] = v0s cells['holding'] = holdings cells['RS'] = np.asarray(rss, float) print(cells) cells = cells[cells['V0'] < v0_max] cells = cells[cells['holding'] > holding_min] print(cells) #% S/N ratio histogram fig = plt.figure() ax_hist = fig.add_axes([0, 0, 1, 1]) ax_hist.hist(cells['SN'].values) ax_hist.set_xlabel('S/N ratio of first 50 spikes') ax_hist.set_ylabel('# of cells') ax_hist.set_title(roi_type.replace('_', ' ')) ax_hist.set_xlim([0, 15])