Esempio n. 1
0
    def display_surface(surface_gid, region_mapping_gid=None):
        """
        Generates the HTML for displaying the surface with the given ID.
        """
        surface_h5 = h5.h5_file_for_gid(surface_gid)
        if surface_h5 is None:
            raise MissingDataException(
                SpatioTemporalController.MSG_MISSING_SURFACE + "!!")
        common.add2session(PARAM_SURFACE, surface_gid)

        url_vertices_pick, url_normals_pick, url_triangles_pick = SurfaceURLGenerator.get_urls_for_pick_rendering(
            surface_h5)
        url_vertices, url_normals, _, url_triangles, _ = SurfaceURLGenerator.get_urls_for_rendering(
            surface_h5, region_mapping_gid)
        surface_h5.close()

        return {
            'urlVerticesPick': json.dumps(url_vertices_pick),
            'urlTrianglesPick': json.dumps(url_triangles_pick),
            'urlNormalsPick': json.dumps(url_normals_pick),
            'urlVertices': json.dumps(url_vertices),
            'urlTriangles': json.dumps(url_triangles),
            'urlNormals': json.dumps(url_normals),
            'brainCenter': json.dumps(surface_h5.center())
        }
Esempio n. 2
0
    def display_connectivity(connectivity_gid):
        """
        Generates the html for displaying the connectivity matrix.
        """
        connectivity = ABCAdapter.load_entity_by_gid(connectivity_gid)
        if connectivity is None:
            raise MissingDataException(RegionStimulusController.MSG_MISSING_CONNECTIVITY + "!!")
        current_project = common.get_current_project()
        conn_path = FilesHelper().get_project_folder(current_project, str(connectivity.fk_from_operation))
        connectivity_viewer_params = ConnectivityViewer.get_connectivity_parameters(connectivity, conn_path)

        template_specification = dict()
        template_specification['isSingleMode'] = True
        template_specification.update(connectivity_viewer_params)
        return template_specification
Esempio n. 3
0
    def get_equation_chart(self):
        """
        Returns the html which contains the plot with the equations
        specified into 'plotted_equations_prefixes' field.
        """
        try:
            # This should be called once at first rendering and once for any change event on form fields used
            # in computation: equation, equation params, surface, cutoff
            current_lconn = common.get_from_session(KEY_LCONN)
            surface_gid = current_lconn.surface.hex
            surface = load_entity_by_gid(surface_gid)
            if surface is None:
                raise MissingDataException(self.MSG_MISSING_SURFACE + "!!!")
            max_x = current_lconn.cutoff
            if max_x <= 0:
                max_x = 50
            equation = current_lconn.equation
            # What we want
            ideal_case_series, _ = equation.get_series_data(0, 2 * max_x)

            # What we'll mostly get
            avg_res = 2 * int(max_x / surface.edge_mean_length)
            step = max_x * 2 / (avg_res - 1)
            average_case_series, _ = equation.get_series_data(
                0, 2 * max_x, step)

            # It can be this bad
            worst_res = 2 * int(max_x / surface.edge_max_length)
            step = 2 * max_x / (worst_res - 1)
            worst_case_series, _ = equation.get_series_data(0, 2 * max_x, step)

            # This is as good as it gets...
            best_res = 2 * int(max_x / surface.edge_min_length)
            step = 2 * max_x / (best_res - 1)
            best_case_series, _ = equation.get_series_data(0, 2 * max_x, step)

            max_y = -1000000000
            min_y = 10000000000
            for case in ideal_case_series:
                if min_y > case[1]:
                    min_y = case[1]
                if min_y > case[1]:
                    min_y = case[1]
                if max_y < case[1]:
                    max_y = case[1]
                if max_y < case[1]:
                    max_y = case[1]
            vertical_line = []
            vertical_step = (max_y - min_y) / NO_OF_CUTOFF_POINTS
            for i in range(NO_OF_CUTOFF_POINTS):
                vertical_line.append([max_x, min_y + i * vertical_step])
            all_series = self.get_series_json(ideal_case_series,
                                              average_case_series,
                                              worst_case_series,
                                              best_case_series, vertical_line)

            return {
                'allSeries': all_series,
                'prefix': 'spatial',
                "message": None
            }
        except NameError as ex:
            self.logger.exception(ex)
            return {
                'allSeries': None,
                'errorMsg': "Incorrect parameters for equation passed."
            }
        except SyntaxError as ex:
            self.logger.exception(ex)
            return {
                'allSeries': None,
                'errorMsg': "Some of the parameters hold invalid characters."
            }
        except Exception as ex:
            self.logger.exception(ex)
            return {'allSeries': None, 'errorMsg': ex}