def test_build_and_read_nwb(self): metadata = MetadataManager( str(path) + '/rec_to_nwb/rec_to_nwb/test/processing/res/metadata.yml', [ str(path) + '/rec_to_nwb/rec_to_nwb/test/processing/res/probe1.yml', str(path) + '/rec_to_nwb/rec_to_nwb/test/processing/res/probe2.yml', str(path) + '/rec_to_nwb/rec_to_nwb/test/processing/res/probe3.yml' ]) builder = RawToNWBBuilder( animal_name='beans', data_path=str(path) + '/rec_to_nwb/rec_to_nwb/test/test_data/', dates=['20190718'], nwb_metadata=metadata, output_path='', extract_spikes=False, extract_mda=True, extract_lfps=False, extract_analog=True, extract_dio=True, overwrite=True, trodes_rec_export_args=_DEFAULT_TRODES_REC_EXPORT_ARGS, video_path=str(path) + '/rec_to_nwb/rec_to_nwb/test/test_data') builder.build_nwb() self.assertTrue(os.path.exists('beans20190718.nwb')) with pynwb.NWBHDF5IO('beans20190718.nwb', 'r', load_namespaces=True) as nwb_file_handler: nwb_file = nwb_file_handler.read() print(nwb_file) if os.path.isfile('beans20190718.nwb'): os.remove('beans20190718.nwb')
class TestRawToNWBGeneration(unittest.TestCase): def setUp(self): self.metadata = MetadataManager( 'C:/Users/wmery/PycharmProjects/rec_to_nwb/rec_to_nwb/test/test_data/KF2/raw/20170120/kibbles20170216_metadata.yml', [ 'C:/Users/wmery/PycharmProjects/rec_to_nwb/rec_to_nwb/test/test_data/KF2/raw/20170120/64c-3s6mm6cm-20um-40um-sl.yml', 'C:/Users/wmery/PycharmProjects/rec_to_nwb/rec_to_nwb/test/test_data/KF2/raw/20170120/64c-4s6mm6cm-20um-40um-dl.yml' ]) self.builder = RawToNWBBuilder( animal_name='KF2', data_path=str(path) + '/../test_data/', dates=['20170120'], nwb_metadata=self.metadata, output_path='', video_path=str(path) + '/../test_data', extract_spikes=False, extract_mda=True, extract_lfps=False, extract_analog=True, extract_dio=True, overwrite=True, trodes_rec_export_args=_DEFAULT_TRODES_REC_EXPORT_ARGS) def test_from_raw_to_nwb_generation(self): self.builder.build_nwb(process_mda_valid_time=False, process_mda_invalid_time=False, process_pos_valid_time=False, process_pos_invalid_time=False) self.assertTrue(os.path.exists('beans20190718.nwb'), 'NWBFile did not build') @should_raise(TypeError) def test_raw_to_nwb_builder_failed_due_to_none_parameters(self): RawToNWBBuilder( animal_name='beans', data_path=str(path) + '/../test_data/', dates=['20190718'], nwb_metadata=None, ) @should_raise(TypeError) def test_raw_to_nwb_builder_failed_due_to_incorrect_type_parameters(self): RawToNWBBuilder(animal_name=11111, data_path=str(path) + '/../test_data/', dates=['20190718'], nwb_metadata=self.metadata, output_path='', extract_spikes=False, extract_mda=True, extract_lfps=False, extract_analog=True, extract_dio=True, overwrite=True, trodes_rec_export_args=_DEFAULT_TRODES_REC_EXPORT_ARGS)
def convert_kibbles_single_day(animal_name: str, date: str, yaml_path='../yaml', reconfig_file=None): dates = [date] # single date for now # Specify the paths for the data, the output nwb file, and the video files # data are saved in data_path/animal_name/raw/date/*.* # data_path = '/data2/data1_backup/jason/' data_path = '/stelmo/jhbak/Data/' # temporary copy with renamed files out_path = '/stelmo/jhbak/nwb/conversion/' # both preprocessing and NWB output_path = out_path + animal_name + '/out/' video_path = out_path + animal_name + '/video/' # Specify metadata files animal_metadata_file = '{}_{}_metadata.yml'.format(animal_name, date) probe_metadata_files = [ 'tetrode_12.5.yml', '32c-2s8mm6cm-20um-40um-dl.yml', '64c-3s6mm6cm-20um-40um-sl.yml', # kibbles '64c-4s6mm6cm-20um-40um-dl.yml', # kibbles ] # specify the locations of the metadata files for the animal and the probe(s). # Note that specifying all possible probes is fine animal_metadata = os.path.join(yaml_path, animal_metadata_file) probe_metadata = [ os.path.join(yaml_path, file) for file in probe_metadata_files ] # Specify any optional trodes export flags if reconfig_file is None: trodes_rec_export_args = () else: trodes_rec_export_args = ('-reconfig', reconfig_file) metadata = MetadataManager(animal_metadata, probe_metadata) builder = RawToNWBBuilder( animal_name=animal_name, data_path=data_path, dates=dates, nwb_metadata=metadata, overwrite=OVERWRITE, preprocessing_path=out_path, # new output_path=output_path, video_path=video_path, trodes_rec_export_args=trodes_rec_export_args) _ = builder.build_nwb(run_preprocessing=RUN_PREPROCESSING)
def test_raw_to_nwb_builder_failed_due_to_none_parameters(self): RawToNWBBuilder( animal_name='beans', data_path=str(path) + '/../test_data/', dates=['20190718'], nwb_metadata=None, )
def setUp(self): self.metadata = MetadataManager( 'C:/Users/wmery/PycharmProjects/rec_to_nwb/rec_to_nwb/test/test_data/KF2/raw/20170120/kibbles20170216_metadata.yml', [ 'C:/Users/wmery/PycharmProjects/rec_to_nwb/rec_to_nwb/test/test_data/KF2/raw/20170120/64c-3s6mm6cm-20um-40um-sl.yml', 'C:/Users/wmery/PycharmProjects/rec_to_nwb/rec_to_nwb/test/test_data/KF2/raw/20170120/64c-4s6mm6cm-20um-40um-dl.yml' ]) self.builder = RawToNWBBuilder( animal_name='KF2', data_path=str(path) + '/../test_data/', dates=['20170120'], nwb_metadata=self.metadata, output_path='', video_path=str(path) + '/../test_data', extract_spikes=False, extract_mda=True, extract_lfps=False, extract_analog=True, extract_dio=True, overwrite=True, trodes_rec_export_args=_DEFAULT_TRODES_REC_EXPORT_ARGS)
def test_raw_to_nwb_builder_failed_due_to_incorrect_type_parameters(self): RawToNWBBuilder(animal_name=11111, data_path=str(path) + '/../test_data/', dates=['20190718'], nwb_metadata=self.metadata, output_path='', extract_spikes=False, extract_mda=True, extract_lfps=False, extract_analog=True, extract_dio=True, overwrite=True, trodes_rec_export_args=_DEFAULT_TRODES_REC_EXPORT_ARGS)
def setUp(self): self.metadata = MetadataManager( str(path) + '/../processing/res/metadata.yml', [ str(path) + '/../processing/res/probe1.yml', str(path) + '/../processing/res/probe2.yml', str(path) + '/../processing/res/probe3.yml' ] ) self.builder = RawToNWBBuilder( animal_name='beans', data_path=str(path) + '/../test_data/', dates=['20190718'], nwb_metadata=self.metadata, output_path='', video_path=str(path) + '/../test_data', extract_spikes=False, extract_mda=True, extract_lfps=False, extract_analog=True, extract_dio=True, overwrite=True, trodes_rec_export_args=_DEFAULT_TRODES_REC_EXPORT_ARGS )
def main(): print('Setting variables', flush=True) # set the animal name and the date or list of dates to process # animal_name = 'beans' # date = '20190718' # animal_metadata_file = 'beans20190718_metadata.yml' # reconfig_file = '/stelmo/loren/beans/Probe_128ch_allnT_DIOs_PTP_reconfig_export_shanks.xml' animal_name = 'despereaux' date = '20191125' animal_metadata_file = 'despereaux20191125.yml' reconfig_file = None #reconfig_file = '/stelmo/loren/despereaux/raw/20191125/20191125_despereaux_01_s1.rec_header.xml' # animal_name = 'Jaq' # date = '20190826' # animal_metadata_file = 'jaq20190826.yml' # reconfig_file = None yaml_path = '/home/loren/Src/NWB/franklabnwb/yaml' probe1_metadata_file = '128c-4s8mm6cm-20um-40um-sl.yml' probe2_metadata_file = 'tetrode_12.5.yml' #Specify the paths for the data, the output nwb file, and the video files data_path = '/stelmo/loren/' output_path = '/stelmo/nwb/' video_path = '/stelmo/nwb/video/' # data_path = '/Users/loren/data/nwb_builder_test_data/' # output_path='//Users/loren/data/nwb_builder_test_data/tmp' # video_path='/Users/loren/data/nwb_builder_test_data/tmp' # specify the locations of the metadata files for the animal and the probe(s). # Note that specifying all possible probes is fine animal_metadata = os.path.join(yaml_path, animal_metadata_file) probe_metadata = [ os.path.join(yaml_path, probe1_metadata_file), os.path.join(yaml_path, probe2_metadata_file) ] print(probe_metadata) # Specify whether data should be reextracted. overwrite = False # metadata parameters metadata = MetadataManager(animal_metadata, probe_metadata) print(metadata, flush=True) print('Creating Builder', flush=True) if reconfig_file is not None: # Specify any optional trodes export flags trodes_rec_export_args = ('-reconfig', reconfig_file) builder = RawToNWBBuilder( animal_name=animal_name, data_path=data_path, dates=[date], nwb_metadata=metadata, overwrite=overwrite, output_path=output_path, video_path=video_path, extract_analog=True, trodes_rec_export_args=trodes_rec_export_args) else: builder = RawToNWBBuilder(animal_name=animal_name, data_path=data_path, dates=[date], nwb_metadata=metadata, overwrite=overwrite, output_path=output_path, video_path=video_path, extract_analog=True) print('Building and Writing', flush=True) builder.build_nwb(process_mda_valid_time='False', process_mda_invalid_time='False', process_pos_valid_time='False', process_pos_invalid_time='False') print('Done', flush=True)
class TestRawToNWBGeneration(unittest.TestCase): def setUp(self): self.metadata = MetadataManager( str(path) + '/../processing/res/metadata.yml', [ str(path) + '/../processing/res/probe1.yml', str(path) + '/../processing/res/probe2.yml', str(path) + '/../processing/res/probe3.yml' ] ) self.builder = RawToNWBBuilder( animal_name='beans', data_path=str(path) + '/../test_data/', dates=['20190718'], nwb_metadata=self.metadata, output_path='', video_path=str(path) + '/../test_data', extract_spikes=False, extract_mda=True, extract_lfps=False, extract_analog=True, extract_dio=True, overwrite=True, trodes_rec_export_args=_DEFAULT_TRODES_REC_EXPORT_ARGS ) def test_from_raw_to_nwb_generation(self): self.builder.build_nwb( process_mda_valid_time=True, process_mda_invalid_time=True, process_pos_valid_time=True, process_pos_invalid_time=True ) self.assertTrue(os.path.exists('beans20190718.nwb'), 'NWBFile did not build') @should_raise(TypeError) def test_raw_to_nwb_builder_failed_due_to_none_parameters(self): RawToNWBBuilder( animal_name='beans', data_path=str(path) + '/../test_data/', dates=['20190718'], nwb_metadata=None, ) @should_raise(TypeError) def test_raw_to_nwb_builder_failed_due_to_incorrect_type_parameters(self): RawToNWBBuilder( animal_name=11111, data_path=str(path) + '/../test_data/', dates=['20190718'], nwb_metadata=self.metadata, output_path='', extract_spikes=False, extract_mda=True, extract_lfps=False, extract_analog=True, extract_dio=True, overwrite=True, trodes_rec_export_args=_DEFAULT_TRODES_REC_EXPORT_ARGS ) def tearDown(self): self.builder.cleanup()