Esempio n. 1
0
    def compute_params(self, region_mapping_volume=None, measure=None, data_slice='', background=None):
        # type: (RegionVolumeMappingIndex, DataTypeMatrix, str, StructuralMRIIndex) -> dict

        region_mapping_volume = self._ensure_region_mapping_index(region_mapping_volume, measure)
        url_voxel_region = URLGenerator.build_url(self.stored_adapter.id, 'get_voxel_region', region_mapping_volume.gid,
                                                  parameter='')

        if measure is None:
            params = self._compute_region_volume_map_params(region_mapping_volume)
        else:
            params = self._compute_measure_params(region_mapping_volume, measure, data_slice)

        volume_gid = region_mapping_volume.fk_volume_gid
        volume_index = self.load_entity_by_gid(volume_gid)
        assert isinstance(volume_index, VolumeIndex)
        volume_shape = region_mapping_volume.parsed_shape
        volume_shape = (1,) + volume_shape

        params.update(volumeShape=json.dumps(volume_shape),
                      volumeOrigin=volume_index.origin,
                      voxelUnit=volume_index.voxel_unit,
                      voxelSize=volume_index.voxel_size,
                      urlVoxelRegion=url_voxel_region)

        if background is None:
            background = dao.try_load_last_entity_of_type(self.current_project_id, StructuralMRIIndex)
        if background is None:  # still
            params.update(self.compute_background_params())
        else:
            url_volume_data = URLGenerator.build_url(self.stored_adapter.id, 'get_volume_view', background.gid, '')
            params.update(self.compute_background_params(background.array_data_min,
                                                         background.array_data_max, url_volume_data))
        return params
Esempio n. 2
0
    def launch(self, view_model):
        # type: (ConnectivityAnnotationsViewModel) -> dict

        annotations_index = self.load_entity_by_gid(view_model.annotations_index)

        if view_model.connectivity_index is None:
            connectivity_index = self.load_entity_by_gid(annotations_index.connectivity_gid)
        else:
            connectivity_index = self.load_entity_by_gid(view_model.connectivity_index)

        if view_model.region_mapping_index is None:
            region_map = dao.get_generic_entity(RegionMappingIndex, connectivity_index.gid,
                                                'connectivity_gid')
            if len(region_map) < 1:
                raise LaunchException(
                    "Can not launch this viewer unless we have at least a RegionMapping for the current Connectivity!")
            region_mapping_index = region_map[0]
        else:
            region_mapping_index = self.load_entity_by_gid(view_model.region_mapping_index)

        boundary_url = SurfaceURLGenerator.get_url_for_region_boundaries(region_mapping_index.surface_gid,
                                                                         region_mapping_index.gid,
                                                                         self.stored_adapter.id)

        surface_index = self.load_entity_by_gid(region_mapping_index.surface_gid)
        surface_h5 = h5.h5_file_for_index(surface_index)
        assert isinstance(surface_h5, SurfaceH5)
        url_vertices_pick, url_normals_pick, url_triangles_pick = SurfaceURLGenerator.get_urls_for_pick_rendering(
            surface_h5)
        url_vertices, url_normals, _, url_triangles, url_region_map = SurfaceURLGenerator.get_urls_for_rendering(
            surface_h5, region_mapping_index.gid)

        params = dict(title="Connectivity Annotations Visualizer",
                      baseUrl=TvbProfile.current.web.BASE_URL,
                      annotationsTreeUrl=URLGenerator.build_url(self.stored_adapter.id, 'tree_json',
                                                                view_model.annotations_index),
                      urlTriangleToRegion=URLGenerator.build_url(self.stored_adapter.id, "get_triangles_mapping",
                                                                 region_mapping_index.gid),
                      urlActivationPatterns=URLGenerator.paths2url(view_model.annotations_index,
                                                                   "get_activation_patterns"),

                      minValue=0,
                      maxValue=connectivity_index.number_of_regions - 1,
                      urlColors=json.dumps(url_region_map),

                      urlVerticesPick=json.dumps(url_vertices_pick),
                      urlTrianglesPick=json.dumps(url_triangles_pick),
                      urlNormalsPick=json.dumps(url_normals_pick),
                      brainCenter=json.dumps(surface_h5.center()),

                      urlVertices=json.dumps(url_vertices),
                      urlTriangles=json.dumps(url_triangles),
                      urlNormals=json.dumps(url_normals),
                      urlRegionBoundaries=boundary_url)

        return self.build_display_result("annotations/annotations_view", params,
                                         pages={"controlPage": "annotations/annotations_controls"})
    def launch(self, view_model):
        # type: (TimeSeriesVolumeVisualiserModel) -> dict

        url_volume_data = URLGenerator.build_url(self.stored_adapter.id, 'get_volume_view', view_model.time_series, '')
        url_timeseries_data = URLGenerator.build_url(self.stored_adapter.id, 'get_voxel_time_series',
                                                     view_model.time_series, '')

        ts_h5_class, ts_h5_path = self._load_h5_of_gid(view_model.time_series.hex)
        ts_h5 = ts_h5_class(ts_h5_path)
        min_value, max_value = ts_h5.get_min_max_values()

        ts_index = self.load_entity_by_gid(view_model.time_series)

        if isinstance(ts_h5, TimeSeriesVolumeH5):
            volume_h5_class, volume_h5_path = self._load_h5_of_gid(ts_h5.volume.load())
            volume_h5 = volume_h5_class(volume_h5_path)
            volume_shape = ts_h5.data.shape
        else:
            rmv_index = self.load_entity_by_gid(ts_h5.region_mapping_volume.load())
            rmv_h5_class, rmv_h5_path = self._load_h5_of_gid(rmv_index.gid)
            rmv_h5 = rmv_h5_class(rmv_h5_path)
            volume_index = self.load_entity_by_gid(rmv_h5.volume.load())
            volume_h5_class, volume_h5_path = self._load_h5_of_gid(volume_index.gid)
            volume_h5 = volume_h5_class(volume_h5_path)
            volume_shape = [ts_h5.data.shape[0]]
            volume_shape.extend(rmv_h5.array_data.shape)
            rmv_h5.close()

        background_index = None
        if view_model.background:
            background_index = self.load_entity_by_gid(view_model.background)

        params = dict(title="Volumetric Time Series",
                      ts_title=ts_h5.title.load(),
                      labelsStateVar=ts_index.get_labels_for_dimension(1),
                      labelsModes=list(range(ts_index.data_length_4d)),
                      minValue=min_value, maxValue=max_value,
                      urlVolumeData=url_volume_data,
                      urlTimeSeriesData=url_timeseries_data,
                      samplePeriod=ts_h5.sample_period.load(),
                      samplePeriodUnit=ts_h5.sample_period_unit.load(),
                      volumeShape=json.dumps(volume_shape),
                      volumeOrigin=json.dumps(volume_h5.origin.load().tolist()),
                      voxelUnit=volume_h5.voxel_unit.load(),
                      voxelSize=json.dumps(volume_h5.voxel_size.load().tolist()))

        params.update(self.ensure_background(background_index))

        volume_h5.close()
        ts_h5.close()
        return self.build_display_result("time_series_volume/view", params,
                                         pages=dict(controlPage="time_series_volume/controls"))
    def launch(self, view_model):
        # type: (BaseVolumeVisualizerModel) -> dict

        structural_mri = self.load_entity_by_gid(view_model.background)
        assert isinstance(structural_mri, StructuralMRIIndex)

        volume_shape = structural_mri.parsed_shape
        volume_shape = (1, ) + volume_shape

        url_volume_data = URLGenerator.build_url(self.stored_adapter.id,
                                                 'get_volume_view',
                                                 view_model.background, '')

        volume_gid = structural_mri.fk_volume_gid
        volume_index = self.load_entity_by_gid(volume_gid)
        assert isinstance(volume_index, VolumeIndex)

        params = dict(title="MRI Volume visualizer",
                      minValue=structural_mri.array_data_min,
                      maxValue=structural_mri.array_data_max,
                      urlVolumeData=url_volume_data,
                      volumeShape=json.dumps(volume_shape),
                      volumeOrigin=volume_index.origin,
                      voxelUnit=volume_index.voxel_unit,
                      voxelSize=volume_index.voxel_size,
                      urlVoxelRegion='',
                      urlBackgroundVolumeData='',
                      minBackgroundValue=structural_mri.array_data_min,
                      maxBackgroundValue=structural_mri.array_data_max)

        return self.build_display_result(
            "time_series_volume/staticView",
            params,
            pages=dict(controlPage="time_series_volume/controls"))
Esempio n. 5
0
 def get_url_for_region_boundaries(surface_gid, region_mapping_gid,
                                   adapter_id):
     return URLGenerator.build_url(adapter_id,
                                   'generate_region_boundaries',
                                   surface_gid,
                                   parameter='region_mapping_gid=' +
                                   region_mapping_gid)
Esempio n. 6
0
def prepare_mapped_sensors_as_measure_points_params(sensors,
                                                    eeg_cap=None,
                                                    adapter_id=None):
    """
    Compute sensors positions by mapping them to the ``eeg_cap`` surface
    If ``eeg_cap`` is not specified the mapping will use a default EEGCal DataType in current project.
    If no default EEGCap is found, return sensors as they are (not projected)

    :returns: dictionary to be used in Viewers for rendering measure_points
    :rtype: dict
    """

    if eeg_cap:
        sensor_locations = URLGenerator.build_url(
            adapter_id,
            'sensors_to_surface',
            sensors.gid,
            parameter='surface_to_map_gid=' + eeg_cap.gid)
        sensor_no = sensors.number_of_sensors
        sensor_labels = URLGenerator.build_h5_url(sensors.gid, 'get_labels')

        return {
            'urlMeasurePoints': sensor_locations,
            'urlMeasurePointsLabels': sensor_labels,
            'noOfMeasurePoints': sensor_no,
            'minMeasure': 0,
            'maxMeasure': sensor_no,
            'urlMeasure': ''
        }

    return prepare_sensors_as_measure_points_params(sensors)
Esempio n. 7
0
    def _compute_measure_params(self, region_mapping_volume, measure,
                                data_slice):
        # prepare the url that will project the measure onto the region volume map
        measure_h5_class, measure_h5_path = self._load_h5_of_gid(measure.gid)
        measure_h5 = measure_h5_class(measure_h5_path)
        min_value, max_value = measure_h5.get_min_max_values()
        measure_shape = measure_h5.array_data.shape
        if not data_slice:
            conn_index = dao.get_datatype_by_gid(
                region_mapping_volume.connectivity.load().hex)
            data_slice = self.get_default_slice(measure_shape,
                                                conn_index.number_of_regions)
            data_slice = slice_str(data_slice)
        url_volume_data = URLGenerator.build_url(
            self.stored_adapter.id,
            'get_mapped_array_volume_view',
            region_mapping_volume.gid.load(),
            parameter='')
        url_volume_data += 'mapped_array_gid=' + measure.gid + ';mapped_array_slice=' + data_slice + ';'

        return dict(minValue=min_value,
                    maxValue=max_value,
                    urlVolumeData=url_volume_data,
                    measureShape=slice_str(measure_shape),
                    measureSlice=data_slice)
Esempio n. 8
0
 def get_url_for_region_boundaries(surface_h5, region_mapping_gid,
                                   adapter_id):
     surface_gid = surface_h5.gid.load().hex
     return URLGenerator.build_url(surface_gid,
                                   'generate_region_boundaries',
                                   adapter_id=adapter_id,
                                   parameter='region_mapping_gid=' +
                                   region_mapping_gid)
Esempio n. 9
0
 def _compute_region_volume_map_params(self, region_mapping_volume):
     # type: (RegionVolumeMappingIndex) -> dict
     # prepare the url that will display the region volume map
     conn_index = dao.get_datatype_by_gid(region_mapping_volume.fk_connectivity_gid)
     min_value, max_value = [0, conn_index.number_of_regions]
     url_volume_data = URLGenerator.build_url(self.stored_adapter.id, 'get_volume_view',
                                              region_mapping_volume.gid, '')
     return dict(minValue=min_value, maxValue=max_value, urlVolumeData=url_volume_data)
Esempio n. 10
0
 def _prepare_data_slices(self, time_series_index):
     """
     Prepare data URL for retrieval with slices of timeSeries activity and Time-Line.
     :returns: [activity_urls], [timeline_urls]
              Currently timeline_urls has just one value, as on client is loaded entirely anyway.
     """
     time_series_gid = time_series_index.gid
     activity_base_url = URLGenerator.build_url(self.stored_adapter.id, 'read_data_page_split', time_series_gid, "")
     time_urls = [SurfaceURLGenerator.build_h5_url(time_series_gid, 'read_time_page',
                                                   parameter="current_page=0;page_size=" +
                                                             str(time_series_index.data_length_1d))]
     return activity_base_url, time_urls
Esempio n. 11
0
    def ensure_background(self, background_index):
        if background_index is None:
            background_index = dao.try_load_last_entity_of_type(self.current_project_id, StructuralMRIIndex)

        if background_index is None:
            return _MappedArrayVolumeBase.compute_background_params()

        with h5.h5_file_for_index(background_index) as background_h5:
            min_value, max_value = background_h5.get_min_max_values()

        url_volume_data = URLGenerator.build_url(self.stored_adapter.id, 'get_volume_view', background_index.gid, '')
        return _MappedArrayVolumeBase.compute_background_params(min_value, max_value, url_volume_data)
Esempio n. 12
0
    def _compute_measure_params(self, rvm_index, measure, data_slice):
        # type: (RegionVolumeMappingIndex, DataTypeMatrix, str) -> dict
        # prepare the url that will project the measure onto the region volume map
        measure_shape = measure.parsed_shape
        if not data_slice:
            conn_index = dao.get_datatype_by_gid(rvm_index.fk_connectivity_gid)
            data_slice = self.get_default_slice(measure_shape, conn_index.number_of_regions)
            data_slice = slice_str(data_slice)
        url_volume_data = URLGenerator.build_url(self.stored_adapter.id, 'get_mapped_array_volume_view',
                                                 rvm_index.gid, parameter='')
        url_volume_data += 'mapped_array_gid=' + measure.gid + ';mapped_array_slice=' + data_slice + ';'

        return dict(minValue=measure.array_data_min, maxValue=measure.array_data_max,
                    urlVolumeData=url_volume_data, measureShape=measure.shape, measureSlice=data_slice)
Esempio n. 13
0
    def _compute_background(self, background):
        if background is None:
            return self.compute_background_params()

        background_class, background_path = self._load_h5_of_gid(
            background.gid)
        background_h5 = background_class(background_path)
        min_value, max_value = background_h5.get_min_max_values()
        background_h5.close()

        url_volume_data = URLGenerator.build_url(self.stored_adapter.id,
                                                 'get_volume_view',
                                                 background.gid, '')
        return self.compute_background_params(min_value, max_value,
                                              url_volume_data)
Esempio n. 14
0
    def launch(self, view_model):
        # type: (VolumeVisualizerModel) -> dict

        background_class, background_path = self._load_h5_of_gid(
            view_model.background.hex)
        background_h5 = background_class(background_path)
        volume_shape = background_h5.array_data.shape
        volume_shape = (1, ) + volume_shape

        min_value, max_value = background_h5.get_min_max_values()
        url_volume_data = URLGenerator.build_url(self.stored_adapter.id,
                                                 'get_volume_view',
                                                 view_model.background, '')

        volume_gid = background_h5.volume.load()
        volume_class, volume_path = self._load_h5_of_gid(volume_gid.hex)
        volume_h5 = volume_class(volume_path)
        params = dict(
            title="MRI Volume visualizer",
            minValue=min_value,
            maxValue=max_value,
            urlVolumeData=url_volume_data,
            volumeShape=json.dumps(volume_shape),
            volumeOrigin=json.dumps(volume_h5.origin.load().tolist()),
            voxelUnit=volume_h5.voxel_unit.load(),
            voxelSize=json.dumps(volume_h5.voxel_size.load().tolist()),
            urlVoxelRegion='',
            minBackgroundValue=min_value,
            maxBackgroundValue=max_value,
            urlBackgroundVolumeData='')

        background_h5.close()
        volume_h5.close()
        return self.build_display_result(
            "time_series_volume/staticView",
            params,
            pages=dict(controlPage="time_series_volume/controls"))