예제 #1
0
    def plot(self, measurement, *args, **kwargs):
        """
        Plot heat-map for the  measurement.
        The code will plot any measurement that satisfies its requirements.

        Arguments
        -------------
        measurement :: pandas.DataFrame with a MultiIndex
        with index labels ('pre_mtype', 'post_mtype')
        """
        def __get_value(pre_mtype, post_mtype):
            """
            Get the value for pre-mtype to post-mtype.
            """
            return measurement.loc(pre_mtype, post_mtype)["mean"]\
                if (pre_mtype, post_mtype) in measurement.index\
                   else np.nan

        index_mtypes =\
            sorted(list({
                mtype for tup in measurement.index.values
                for mtype in tup}))
        matrix = np.array([[
            __get_value(pre_mtype, post_mtype) for pre_mtype in index_mtypes
        ] for post_mtype in index_mtypes])

        xticks_rotation = 90

        xvar = "post_mtype"
        yvar = "pre_mtype"

        figure =\
            golden_figure(
                height=self._height,
                width=self._width)
        axes =\
            figure.add_axes(
                [0.075, 0.125, 0.9, 0.8])
        image =\
            axes.imshow(
                matrix_data,
                interpolation="nearest")

        n_data_points =\
            len(index_mtypes)

        axes.set_xlabel(xvar)
        axes.set_xticklabels(index_mtypes,
                             rotation="vertical",
                             size="xx-small")
        axes.set_ylabel(yvar)
        axes.set_yticklabels(index_mtypes, size="xx-small")
        color_limits = (np.nanmin(matrix), np.nanmax(matrix))
        image.set_clim(color_limits)
        colorbar=\
            plt.colorbar(image)
        return figure
예제 #2
0
    def _section(label, subsections=NA):
        """
        Each section will generate it's own 'CircuitAnalysisReport` instance,
        just as we will implement `Report.sections` as a list of independent
        reports.
        """
        figure, axes =\
            golden_figure(14, 12)
        xs = np.linspace(0., 1., 100)
        ys = np.cumsum(np.random.uniform(size=100))
        measurement =\
            pd.DataFrame({"x": xs, "y": ys}).set_index(["x"])
        plt.plot(xs, ys)

        return\
            CircuitAnalysisReport(
                author=Author.anonymous,
                phenomenon="{}".format(label),
                abstract="""
                Abstract {}
                """.format(label),
                introduction="""
                Introduce {}
                """.format(label),
                methods="""
                Methods {}
                """.format(label),
                measurement=measurement,
                figures={
                    "random_walk_{}".format(label): Figure(
                        figure,
                        caption="""
                        Each random walk step size is uniformly drawn from [0, 1).
                        The individual steps are added up cummulatively to obtain
                        the location of the walk at a given time.
                        """.format(label))},
                results="""
                Results {}
                """.format(label),
                discussion="""
                Discussion {}
                """.format(label),
                references={"{}".format(label): "https://www.example.org/{}".format(label)},
                sections=subsections,
                provenance_model=provenance)
예제 #3
0
파일: circle.py 프로젝트: BlueBrain/DMT
    def plot(self, df, values=None):
        groups, group_labels, group_patchdata, conn_angles\
            = self.__plot_components__(df, values=values)
        group_angles, group_colors = group_patchdata
        source_angles, dest_angles = conn_angles
        sz = 60  # len(pivot_table.index)*4
        fig, ax = golden_figure(width=sz, height=sz)
        # TODO: adapt limits to text
        ax.set_xlim(left=-1.3, right=+1.3)
        ax.set_ylim(bottom=-1.3, top=+1.3)
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)
        ax.set_xticklabels([])
        ax.set_yticklabels([])
        ax.add_collection(
            matplotlib.collections.PatchCollection([
                self._conn_patch(s_angles, dest_angles[from_][to],
                                 group_colors[from_])
                for from_, conn in source_angles.items()
                for to, s_angles in conn.items()
            ],
                                                   match_original=True))
        ax.add_collection(
            matplotlib.collections.PatchCollection([
                self._group_patch(angles, **group_colors[group])
                for group, angles in group_angles.items()
            ],
                                                   match_original=True))

        oldfont = plt.rcParams.get('font.size')
        plt.rcParams.update({'font.size': sz})
        textcirc = CircleTool(self.circle.radius * 1.2)
        for t, a in group_labels.items():
            plt.text(*textcirc.angles_to_points(a),
                     t,
                     rotation=90 - a * (180 / np.pi),
                     rotation_mode="anchor")
        plt.rcParams.update({"font.size": oldfont})
        return fig
예제 #4
0
def test_post():
    """
    Reporter should be able to post the report to a location.
    """
    figure, axes =\
        golden_figure(14, 12)
    xs = np.linspace(0., 1., 100)
    ys = np.cumsum(np.random.uniform(size=100))
    measurement =\
        pd.DataFrame({"x": xs, "y": ys}).set_index(["x"])
    plt.plot(xs, ys)

    provenance =\
        CircuitProvenance(
            label="Test",
            authors=3*[Author.anonymous],
            date_release="XXXXXXXX",
            uri="UnknownLocation",
            animal="UnkownAnimal",
            age="UnknownAge",
            brain_region="UnknownBrainArea")
    report =\
        CircuitAnalysisReport(
            author=Author.anonymous,
            phenomenon="unknown",
            abstract="""
            This is an abstract.
            """,
            introduction="""
            This is an introduction.
            A single paragraph can have lines ending in at most a single endline
            marker. If you insert two line breaks, such as follows

            a new paragraph should start...
            """,
            measurement=measurement,
            figures={
                "random_walk_1": Figure(
                    figure,
                    caption="""
                    Random Walk
                    ================
                    Each random walk step size is uniformly drawn from [0, 1).
                    The individual steps are added up cummulatively to obtain
                    the location of the walk at a given time.
                    """)},
            methods="""
            Describe how.
            """,
            results="""
            Test results are good.
            """,
            discussion="""
            No need to discuss.
            """,
            references={"xyz": "https://www.xxx.yyy.zzz/qqq"},
            provenance_model=provenance)
    reporter =\
        CheetahReporter(
            path_output_folder=os.path.join(
                os.getcwd(), "random_walks"))
    path_report =\
        reporter.post(report)
    return\
        Record(
            provenance=provenance,
            report=report,
            reporter=reporter,
            path_report=path_report)