def _create_time_series(self, volume, title): # Now create TimeSeries and fill it with data from NIFTI image time_series = TimeSeriesVolume() time_series.title = title time_series.labels_ordering = ["Time", "X", "Y", "Z"] time_series.start_time = 0.0 time_series.volume = volume if len(self.parser.zooms) > 3: time_series.sample_period = float(self.parser.zooms[3]) else: # If no time dim, set sampling to 1 sec time_series.sample_period = 1 if self.parser.units is not None and len(self.parser.units) > 1: time_series.sample_period_unit = self.parser.units[1] ts_h5_path = h5.path_for(self.storage_path, TimeSeriesVolumeH5, time_series.gid) nifti_data = self.parser.parse() with TimeSeriesVolumeH5(ts_h5_path) as ts_h5: ts_h5.store(time_series, scalars_only=True, store_references=True) for i in range(self.parser.time_dim_size): ts_h5.write_data_slice([nifti_data[:, :, :, i, ...]]) data_shape = ts_h5.read_data_shape() ts_idx = TimeSeriesVolumeIndex() ts_idx.fill_from_has_traits(time_series) ts_idx.data_ndim = len(data_shape) ts_idx.data_length_1d, ts_idx.data_length_2d, ts_idx.data_length_3d, ts_idx.data_length_4d = prepare_array_shape_meta( data_shape) return ts_idx
def launch(self, data_file, apply_corrections=False, connectivity=None): """ Execute import operations: """ try: parser = NIFTIParser(data_file) # Create volume DT volume = Volume(storage_path=self.storage_path) volume.set_operation_id(self.operation_id) volume.origin = [[0.0, 0.0, 0.0]] volume.voxel_size = [ parser.zooms[0], parser.zooms[1], parser.zooms[2] ] if parser.units is not None and len(parser.units) > 0: volume.voxel_unit = parser.units[0] if parser.has_time_dimension or not connectivity: # Now create TimeSeries and fill it with data from NIFTI image time_series = TimeSeriesVolume(storage_path=self.storage_path) time_series.set_operation_id(self.operation_id) time_series.volume = volume time_series.title = "NIFTI Import - " + os.path.split( data_file)[1] time_series.labels_ordering = ["Time", "X", "Y", "Z"] time_series.start_time = 0.0 if len(parser.zooms) > 3: time_series.sample_period = float(parser.zooms[3]) else: # If no time dim, set sampling to 1 sec time_series.sample_period = 1 if parser.units is not None and len(parser.units) > 1: time_series.sample_period_unit = parser.units[1] parser.parse(time_series, True) return [volume, time_series] else: region2volume_mapping = RegionVolumeMapping( storage_path=self.storage_path) region2volume_mapping.set_operation_id(self.operation_id) region2volume_mapping.volume = volume region2volume_mapping.connectivity = connectivity region2volume_mapping.title = "NIFTI Import - " + os.path.split( data_file)[1] region2volume_mapping.dimensions_labels = ["X", "Y", "Z"] region2volume_mapping.apply_corrections = apply_corrections parser.parse(region2volume_mapping, False) return [volume, region2volume_mapping] except ParseException, excep: logger = get_logger(__name__) logger.exception(excep) raise LaunchException(excep)
def launch(self, data_file, apply_corrections=False, connectivity=None): """ Execute import operations: """ try: parser = NIFTIParser(data_file) # Create volume DT volume = Volume(storage_path=self.storage_path) volume.set_operation_id(self.operation_id) volume.origin = [[0.0, 0.0, 0.0]] volume.voxel_size = [parser.zooms[0], parser.zooms[1], parser.zooms[2]] if parser.units is not None and len(parser.units) > 0: volume.voxel_unit = parser.units[0] if parser.has_time_dimension or not connectivity: # Now create TimeSeries and fill it with data from NIFTI image time_series = TimeSeriesVolume(storage_path=self.storage_path) time_series.set_operation_id(self.operation_id) time_series.volume = volume time_series.title = "NIFTI Import - " + os.path.split(data_file)[1] time_series.labels_ordering = ["Time", "X", "Y", "Z"] time_series.start_time = 0.0 if len(parser.zooms) > 3: time_series.sample_period = float(parser.zooms[3]) else: # If no time dim, set sampling to 1 sec time_series.sample_period = 1 if parser.units is not None and len(parser.units) > 1: time_series.sample_period_unit = parser.units[1] parser.parse(time_series, True) return [volume, time_series] else: region2volume_mapping = RegionVolumeMapping(storage_path=self.storage_path) region2volume_mapping.set_operation_id(self.operation_id) region2volume_mapping.volume = volume region2volume_mapping.connectivity = connectivity region2volume_mapping.title = "NIFTI Import - " + os.path.split(data_file)[1] region2volume_mapping.dimensions_labels = ["X", "Y", "Z"] region2volume_mapping.apply_corrections = apply_corrections parser.parse(region2volume_mapping, False) return [volume, region2volume_mapping] except ParseException, excep: logger = get_logger(__name__) logger.exception(excep) raise LaunchException(excep)
def _create_time_series(self, volume): # Now create TimeSeries and fill it with data from NIFTI image time_series = TimeSeriesVolume(storage_path=self.storage_path) time_series.volume = volume time_series.title = "NIFTI Import - " + os.path.split(self.data_file)[1] time_series.labels_ordering = ["Time", "X", "Y", "Z"] time_series.start_time = 0.0 if len(self.parser.zooms) > 3: time_series.sample_period = float(self.parser.zooms[3]) else: # If no time dim, set sampling to 1 sec time_series.sample_period = 1 if self.parser.units is not None and len(self.parser.units) > 1: time_series.sample_period_unit = self.parser.units[1] self.parser.parse(time_series, True) return time_series