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 compute_parameters(self, time_series, shell_surface=None): """ Create the required parameter dictionary for the HTML/JS viewer. :rtype: `dict` :raises Exception: when * number of measure points exceeds the maximum allowed * a Face object cannot be found in database """ self.populate_surface_fields(time_series) url_vertices, url_normals, url_lines, url_triangles, url_region_map = SurfaceURLGenerator.get_urls_for_rendering( self.surface_h5, self.region_map_gid) hemisphere_chunk_mask = self.surface_h5.get_slices_to_hemisphere_mask() params = self.retrieve_measure_points_params(time_series) if not self.one_to_one_map and self.measure_points_no > MAX_MEASURE_POINTS_LENGTH: raise Exception("Max number of measure points " + str(MAX_MEASURE_POINTS_LENGTH) + " exceeded.") time_series_h5 = h5.h5_file_for_index(time_series) assert isinstance(time_series_h5, TimeSeriesH5) base_adapter_url, time_urls = self._prepare_data_slices(time_series) min_val, max_val = time_series_h5.get_min_max_values() legend_labels = self._compute_legend_labels(min_val, max_val) state_variables = time_series.get_labels_for_dimension(1) if self.surface_gid and self.region_map_gid: boundary_url = SurfaceURLGenerator.get_url_for_region_boundaries(self.surface_gid, self.region_map_gid, self.stored_adapter.id) else: boundary_url = '' shell_surface = ensure_shell_surface(self.current_project_id, shell_surface) params.update(dict(title="Cerebral Activity: " + time_series.title, isOneToOneMapping=self.one_to_one_map, urlVertices=json.dumps(url_vertices), urlTriangles=json.dumps(url_triangles), urlLines=json.dumps(url_lines), urlNormals=json.dumps(url_normals), urlRegionMap=json.dumps(url_region_map), base_adapter_url=base_adapter_url, time=json.dumps(time_urls), minActivity=min_val, maxActivity=max_val, legendLabels=legend_labels, labelsStateVar=state_variables, labelsModes=list(range(time_series.data_length_4d)), extended_view=False, shellObject=self.prepare_shell_surface_params(shell_surface, SurfaceURLGenerator), biHemispheric=self.surface_h5.bi_hemispheric.load(), hemisphereChunkMask=json.dumps(hemisphere_chunk_mask), pageSize=self.PAGE_SIZE, urlRegionBoundaries=boundary_url, measurePointsLabels=self.get_space_labels(time_series_h5), measurePointsTitle=time_series.title)) params.update(self.build_params_for_subselectable_ts(time_series_h5)) time_series_h5.close() if self.surface_h5: self.surface_h5.close() return params
def generate_preview(self, time_series, shell_surface=None, figure_size=None): """ Generate the preview for the burst page """ self.populate_surface_fields(time_series) url_vertices, url_normals, url_lines, url_triangles, url_region_map = \ SurfaceURLGenerator.get_urls_for_rendering(self.surface_h5, self.region_map_gid) params = self.retrieve_measure_points_prams(time_series) time_series_h5 = h5.h5_file_for_index(time_series) assert isinstance(time_series_h5, TimeSeriesH5) base_activity_url, time_urls = self._prepare_data_slices( time_series_h5) min_val, max_val = time_series_h5.get_min_max_values() time_series_h5.close() if self.surface_h5 and self.region_map_gid: boundary_url = SurfaceURLGenerator.get_url_for_region_boundaries( self.surface_h5, self.region_map_gid, self.stored_adapter.id) else: boundary_url = '' params.update(urlVertices=json.dumps(url_vertices), urlTriangles=json.dumps(url_triangles), urlLines=json.dumps(url_lines), urlNormals=json.dumps(url_normals), urlRegionMap=json.dumps(url_region_map), urlRegionBoundaries=boundary_url, base_activity_url=base_activity_url, isOneToOneMapping=self.one_to_one_map, minActivity=min_val, maxActivity=max_val) normalization_factor = figure_size[0] / 800 if figure_size[1] / 600 < normalization_factor: normalization_factor = figure_size[1] / 600 params['width'] = figure_size[0] * normalization_factor params['height'] = figure_size[1] * normalization_factor if self.surface_h5: self.surface_h5.close() return self.build_display_result("brain/portlet_preview", params)