@@ -333,37 +333,48 @@ def add_running_speed_to_nwbfile(nwbfile, running_speed, name='speed', unit='cm/
333333        unit = unit 
334334    )
335335
336-     running_mod  =  ProcessingModule ('running' , 'Running speed processing module' )
337-     nwbfile .add_processing_module (running_mod )
336+     if  'running'  in  nwbfile .processing :
337+         running_mod  =  nwbfile .processing ['running' ]
338+     else :
339+         running_mod  =  ProcessingModule ('running' , 'Running speed processing module' )
340+         nwbfile .add_processing_module (running_mod )
338341
339342    running_mod .add_data_interface (running_speed_series )
340343
341344    return  nwbfile 
342345
343346
344- def  add_running_data_df_to_nwbfile (nwbfile , running_data_df , unit_dict ,  index_key = 'timestamps' ):
345-     '''  Adds running speed data to an NWBFile as timeseries in acquisition and processing
347+ def  add_running_data_dfs_to_nwbfile (nwbfile , running_data_df , running_data_df_unfiltered ,  unit_dict ):
348+     """ Adds both unfiltered (raw) and filtered  running speed data to an NWBFile as timeseries in acquisition and processing
346349
347350    Parameters 
348351    ---------- 
349352    nwbfile : pynwb.NWBFile 
350-         File to which runnign speeds will be written 
351-     running_speed : pandas.DataFrame 
352-         Contains 'speed' and 'times', 'v_in', 'vsig', 'dx' 
353-     unit : str, optional 
353+         File to which running speeds will be written 
354+     running_data_df : pandas.DataFrame 
355+         Filtered running data 
356+         Contains 'speed', 'v_in', 'vsig', 'dx' 
357+         Note that 'v_in', 'vsig', 'dx' are expected to be the same as in running_data_df_unfiltered 
358+     running_data_df_unfiltered : pandas.DataFrame 
359+         Unfiltered (raw) Running data 
360+         Contains 'speed', 'v_in', 'vsig', 'dx' 
361+         Note that 'v_in', 'vsig', 'dx' are expected to be the same as in running_data_df 
362+     unit_dict : dict, optional 
354363        SI units of running speed values 
355364
356365    Returns 
357366    ------- 
358367    nwbfile : pynwb.NWBFile 
359368
360-     ''' 
361-     assert  running_data_df .index .name  ==  index_key 
362- 
369+     """ 
363370    running_speed  =  RunningSpeed (timestamps = running_data_df .index .values ,
364371                                 values = running_data_df ['speed' ].values )
365372
373+     running_speed_unfiltered  =  RunningSpeed (timestamps = running_data_df_unfiltered .index .values ,
374+                                             values = running_data_df_unfiltered ['speed' ].values )
375+ 
366376    add_running_speed_to_nwbfile (nwbfile , running_speed , name = 'speed' , unit = unit_dict ['speed' ])
377+     add_running_speed_to_nwbfile (nwbfile , running_speed_unfiltered , name = 'speed_unfiltered' , unit = unit_dict ['speed' ])
367378
368379    running_mod  =  nwbfile .processing ['running' ]
369380    timestamps_ts  =  running_mod .get_data_interface ('speed' ).timestamps 
@@ -883,9 +894,9 @@ def add_cell_specimen_table(nwbfile: NWBFile,
883894        imaging_plane = imaging_plane )
884895
885896    for  col_name  in  cell_roi_table .columns :
886-         # the columns 'image_mask ', 'pixel_mask', and 'voxel_mask' are already defined 
897+         # the columns 'roi_mask ', 'pixel_mask', and 'voxel_mask' are already defined 
887898        # in the nwb.ophys::PlaneSegmentation Object 
888-         if  col_name  not  in 'id' , 'mask_matrix' , 'image_mask ' , 'pixel_mask' , 'voxel_mask' ]:
899+         if  col_name  not  in 'id' , 'mask_matrix' , 'roi_mask ' , 'pixel_mask' , 'voxel_mask' ]:
889900            # This builds the columns with name of column and description of column 
890901            # both equal to the column name in the cell_roi_table 
891902            plane_segmentation .add_column (col_name ,
@@ -895,13 +906,13 @@ def add_cell_specimen_table(nwbfile: NWBFile,
895906    # go through each roi and add it to the plan segmentation object 
896907    for  cell_roi_id , table_row  in  cell_roi_table .iterrows ():
897908
898-         # NOTE: The 'image_mask ' in this cell_roi_table has already been 
909+         # NOTE: The 'roi_mask ' in this cell_roi_table has already been 
899910        # processing by the function from  
900911        # allensdk.brain_observatory.behavior.session_apis.data_io.ophys_lims_api 
901912        # get_cell_specimen_table() method. As a result, the ROI is stored in 
902913        # an array that is the same shape as the FULL field of view of the 
903914        # experiment (e.g. 512 x 512). 
904-         mask  =  table_row .pop ('image_mask ' )
915+         mask  =  table_row .pop ('roi_mask ' )
905916
906917        csid  =  table_row .pop ('cell_specimen_id' )
907918        table_row ['cell_specimen_id' ] =  - 1  if  csid  is  None  else  csid 
0 commit comments