Пример #1
0
    def test_get_climatology_line_for_reliability_curve(self):
        """Ensures correctness of get_climatology_line_for_reliability_curve."""

        these_x_values, these_y_values = (
            model_eval.get_climatology_line_for_reliability_curve(
                MEAN_OBSERVED_LABEL))
        self.assertTrue(
            numpy.allclose(these_x_values,
                           X_VALUES_FOR_CLIMATOLOGY_LINE,
                           atol=TOLERANCE))
        self.assertTrue(
            numpy.allclose(these_y_values,
                           Y_VALUES_FOR_CLIMATOLOGY_LINE,
                           atol=TOLERANCE))
Пример #2
0
def _plot_background_of_attributes_diagram(
        axes_object,
        climatology,
        no_skill_line_colour=DEFAULT_ZERO_BSS_COLOUR,
        no_skill_line_width=DEFAULT_ZERO_BSS_WIDTH,
        other_line_colour=DEFAULT_CLIMATOLOGY_COLOUR,
        other_line_width=DEFAULT_CLIMATOLOGY_WIDTH):
    """Plots background (references lines and polygons) of attributes diagram.

    For more on the attributes diagram, see Hsu and Murphy (1986).

    BSS = Brier skill score.  For more on the BSS, see
    `model_evaluation.get_brier_skill_score`.

    :param axes_object: Instance of `matplotlib.axes._subplots.AxesSubplot`.
    :param climatology: Event frequency for the entire dataset.
    :param no_skill_line_colour: Colour (in any format accepted by
        `matplotlib.colors`) of no-skill line, where BSS = 0.
    :param no_skill_line_width: Width (real positive number) of no-skill line.
    :param other_line_colour: Colour of climatology and no-resolution lines.
    :param other_line_width: Width of climatology and no-resolution lines.
    """

    error_checking.assert_is_geq(climatology, 0.)
    error_checking.assert_is_leq(climatology, 1.)

    (x_vertices_for_left_skill_area, y_vertices_for_left_skill_area,
     x_vertices_for_right_skill_area, y_vertices_for_right_skill_area
     ) = model_eval.get_skill_areas_in_reliability_curve(climatology)

    skill_area_colour = matplotlib.colors.to_rgba(
        plotting_utils.colour_from_numpy_to_tuple(no_skill_line_colour),
        TRANSPARENCY_FOR_POSITIVE_BSS_AREA)

    left_polygon_object = polygons.vertex_arrays_to_polygon_object(
        x_vertices_for_left_skill_area, y_vertices_for_left_skill_area)
    left_polygon_patch = PolygonPatch(left_polygon_object,
                                      lw=0,
                                      ec=skill_area_colour,
                                      fc=skill_area_colour)

    axes_object.add_patch(left_polygon_patch)

    right_polygon_object = polygons.vertex_arrays_to_polygon_object(
        x_vertices_for_right_skill_area, y_vertices_for_right_skill_area)
    right_polygon_patch = PolygonPatch(right_polygon_object,
                                       lw=0,
                                       ec=skill_area_colour,
                                       fc=skill_area_colour)

    axes_object.add_patch(right_polygon_patch)

    no_skill_x_coords, no_skill_y_coords = (
        model_eval.get_no_skill_reliability_curve(climatology))

    axes_object.plot(
        no_skill_x_coords,
        no_skill_y_coords,
        color=plotting_utils.colour_from_numpy_to_tuple(no_skill_line_colour),
        linestyle='solid',
        linewidth=no_skill_line_width)

    climo_x_coords, climo_y_coords = (
        model_eval.get_climatology_line_for_reliability_curve(climatology))

    axes_object.plot(
        climo_x_coords,
        climo_y_coords,
        color=plotting_utils.colour_from_numpy_to_tuple(other_line_colour),
        linestyle='dashed',
        linewidth=other_line_width)

    no_resolution_x_coords, no_resolution_y_coords = (
        model_eval.get_no_resolution_line_for_reliability_curve(climatology))

    axes_object.plot(
        no_resolution_x_coords,
        no_resolution_y_coords,
        color=plotting_utils.colour_from_numpy_to_tuple(other_line_colour),
        linestyle='dashed',
        linewidth=other_line_width)
Пример #3
0
def _plot_background_of_attributes_diagram(axes_object, climatology):
    """Plots background (references lines and polygons) of attributes diagram.

    For more on the attributes diagram, see Hsu and Murphy (1986).

    BSS = Brier skill score.  For more on the BSS, see
    `model_evaluation.get_brier_skill_score`.

    :param axes_object: Instance of `matplotlib.axes._subplots.AxesSubplot`.
    :param climatology: Event frequency for the entire dataset.
    """

    error_checking.assert_is_geq(climatology, 0.)
    error_checking.assert_is_leq(climatology, 1.)

    (x_coords_left_skill_area, y_coords_left_skill_area,
     x_coords_right_skill_area, y_coords_right_skill_area
     ) = model_eval.get_skill_areas_in_reliability_curve(climatology)

    skill_area_colour = matplotlib.colors.to_rgba(
        plotting_utils.colour_from_numpy_to_tuple(ZERO_BSS_COLOUR),
        POSITIVE_BSS_OPACITY)

    left_polygon_object = polygons.vertex_arrays_to_polygon_object(
        x_coords_left_skill_area, y_coords_left_skill_area)
    left_polygon_patch = PolygonPatch(left_polygon_object,
                                      lw=0,
                                      ec=skill_area_colour,
                                      fc=skill_area_colour)

    axes_object.add_patch(left_polygon_patch)

    right_polygon_object = polygons.vertex_arrays_to_polygon_object(
        x_coords_right_skill_area, y_coords_right_skill_area)
    right_polygon_patch = PolygonPatch(right_polygon_object,
                                       lw=0,
                                       ec=skill_area_colour,
                                       fc=skill_area_colour)

    axes_object.add_patch(right_polygon_patch)

    no_skill_x_coords, no_skill_y_coords = (
        model_eval.get_no_skill_reliability_curve(climatology))

    axes_object.plot(
        no_skill_x_coords,
        no_skill_y_coords,
        color=plotting_utils.colour_from_numpy_to_tuple(ZERO_BSS_COLOUR),
        linestyle='solid',
        linewidth=ZERO_BSS_LINE_WIDTH)

    climo_x_coords, climo_y_coords = (
        model_eval.get_climatology_line_for_reliability_curve(climatology))

    axes_object.plot(
        climo_x_coords,
        climo_y_coords,
        color=plotting_utils.colour_from_numpy_to_tuple(CLIMO_COLOUR),
        linestyle='dashed',
        linewidth=CLIMO_LINE_WIDTH)

    no_resolution_x_coords, no_resolution_y_coords = (
        model_eval.get_no_resolution_line_for_reliability_curve(climatology))

    axes_object.plot(
        no_resolution_x_coords,
        no_resolution_y_coords,
        color=plotting_utils.colour_from_numpy_to_tuple(CLIMO_COLOUR),
        linestyle='dashed',
        linewidth=CLIMO_LINE_WIDTH)