1919from . import metadata
2020from .header import LabViewHeader , LabViewVersions
2121from .imaging import Modes
22+ from .rois import RoiReader
2223from .timings import LabViewTimings231 , LabViewTimingsPre2018
2324
2425try :
@@ -969,28 +970,11 @@ def add_rois(self, roi_path):
969970 organised by ROI number and channel name, so we can iterate there. Issue #16.
970971 """
971972 self .log ('Loading ROI locations from {}' , roi_path )
972- assert os .path .isfile (roi_path )
973- roi_data = pd .read_csv (
974- roi_path , sep = '\t ' , header = 0 , index_col = False , dtype = np .float16 ,
975- converters = {'Z start' : np .float64 , 'Z stop' : np .float64 }, memory_map = True )
976- # Rename the columns so that we can use them as identifiers later on
977- column_mapping = {
978- 'ROI index' : 'roi_index' , 'Pixels in ROI' : 'num_pixels' ,
979- 'X start' : 'x_start' , 'Y start' : 'y_start' , 'Z start' : 'z_start' ,
980- 'X stop' : 'x_stop' , 'Y stop' : 'y_stop' , 'Z stop' : 'z_stop' ,
981- 'Laser Power (%)' : 'laser_power' , 'ROI Time (ns)' : 'roi_time_ns' ,
982- 'Angle (deg)' : 'angle_deg' , 'Composite ID' : 'composite_id' ,
983- 'Number of lines' : 'num_lines' , 'Frame Size' : 'frame_size' ,
984- 'Zoom' : 'zoom' , 'ROI group ID' : 'roi_group_id'
985- }
986- roi_data .rename (columns = column_mapping , inplace = True )
973+ reader = RoiReader ()
974+ roi_data = reader .read_roi_table (roi_path )
987975 module = self .nwb_file .create_processing_module (
988976 'Acquired_ROIs' ,
989977 'ROI locations and acquired fluorescence readings made directly by the AOL microscope.' )
990- # Convert some columns to int
991- roi_data = roi_data .astype (
992- {'x_start' : np .uint16 , 'x_stop' : np .uint16 , 'y_start' : np .uint16 , 'y_stop' : np .uint16 ,
993- 'num_pixels' : int })
994978 seg_iface = ImageSegmentation ()
995979 module .add (seg_iface )
996980 self ._write ()
@@ -1015,9 +999,8 @@ def add_rois(self, roi_path):
1015999 )
10161000 # Specify the non-standard data we will be storing for each ROI,
10171001 # which includes all the raw data fields from the original file
1018- plane .add_column ('dimensions' , 'Dimensions of the ROI' )
1019- for old_name , new_name in column_mapping .items ():
1020- plane .add_column (new_name , old_name )
1002+ for column_name , column_description in reader .columns .items ():
1003+ plane .add_column (column_name , column_description )
10211004 index = 0 # index of the row as it will be stored in the ROI table
10221005 self .roi_mapping [plane_name ] = {}
10231006 for row in roi_group .itertuples ():
@@ -1044,7 +1027,7 @@ def add_rois(self, roi_path):
10441027 pixels [i , 2 ] = 1 # weight for this pixel
10451028 plane .add_roi (id = roi_id , pixel_mask = [tuple (r ) for r in pixels .tolist ()],
10461029 dimensions = dimensions ,
1047- ** { field : getattr (row , field ) for field in column_mapping . values ()} )
1030+ ** reader . get_row_attributes (row ) )
10481031 self .roi_mapping [plane_name ][roi_id ] = index
10491032 index += 1
10501033 self ._write ()
0 commit comments