def plot_one_storm_cell_to_winds(
        storm_to_winds_table, storm_id, basemap_object=None, axes_object=None,
        storm_colour=storm_plotting.DEFAULT_TRACK_COLOUR,
        storm_line_width=storm_plotting.DEFAULT_TRACK_WIDTH,
        wind_barb_length=wind_plotting.DEFAULT_BARB_LENGTH,
        empty_wind_barb_radius=wind_plotting.DEFAULT_EMPTY_BARB_RADIUS,
        fill_empty_wind_barb=wind_plotting.FILL_EMPTY_BARB_DEFAULT,
        wind_colour_map=wind_plotting.DEFAULT_COLOUR_MAP,
        colour_minimum_kt=wind_plotting.DEFAULT_COLOUR_MINIMUM_KT,
        colour_maximum_kt=wind_plotting.DEFAULT_COLOUR_MAXIMUM_KT):
    """Plots wind observations linked to one storm cell.

    :param storm_to_winds_table: pandas DataFrame with columns documented in
        `link_storms_to_winds.write_storm_to_winds_table`.
    :param storm_id: String ID for storm cell.  Only this storm cell and wind
        observations linked thereto will be plotted.
    :param basemap_object: Instance of `mpl_toolkits.basemap.Basemap`.
    :param axes_object: Instance of `matplotlib.axes._subplots.AxesSubplot`.
    :param storm_colour: Colour for storm track, first storm object, and last
        storm object (in any format accepted by `matplotlib.colors`).
    :param storm_line_width: Line width for storm track, first storm object, and
        last storm object (real positive number).
    :param wind_barb_length: Length of each wind barb.
    :param empty_wind_barb_radius: Radius of circle for 0-metre-per-second wind
        barb.
    :param fill_empty_wind_barb: Boolean flag.  If fill_empty_barb = True,
        0-metre-per-second wind barb will be a filled circle.  Otherwise, it
        will be an empty circle.
    :param wind_colour_map: Instance of `matplotlib.pyplot.cm`.
    :param colour_minimum_kt: Minimum speed for colour map (kt or nautical miles
        per hour).
    :param colour_maximum_kt: Maximum speed for colour map (kt or nautical miles
        per hour).
    """

    error_checking.assert_is_string(storm_id)
    error_checking.assert_is_geq(colour_minimum_kt, 0.)
    error_checking.assert_is_greater(colour_maximum_kt, colour_minimum_kt)

    storm_cell_flags = [this_id == storm_id for this_id in storm_to_winds_table[
        tracking_io.STORM_ID_COLUMN].values]
    storm_cell_rows = numpy.where(numpy.array(storm_cell_flags))[0]

    centroid_latitudes_deg = storm_to_winds_table[
        tracking_io.CENTROID_LAT_COLUMN].values[storm_cell_rows]
    centroid_longitudes_deg = storm_to_winds_table[
        tracking_io.CENTROID_LNG_COLUMN].values[storm_cell_rows]

    storm_plotting.plot_storm_track(
        basemap_object=basemap_object, axes_object=axes_object,
        latitudes_deg=centroid_latitudes_deg,
        longitudes_deg=centroid_longitudes_deg, line_colour=storm_colour,
        line_width=storm_line_width)

    storm_times_unix_sec = storm_to_winds_table[tracking_io.TIME_COLUMN].values[
        storm_cell_rows]
    first_storm_object_row = storm_cell_rows[numpy.argmin(storm_times_unix_sec)]
    last_storm_object_row = storm_cell_rows[numpy.argmax(storm_times_unix_sec)]

    first_vertex_dict = polygons.polygon_object_to_vertex_arrays(
        storm_to_winds_table[tracking_io.POLYGON_OBJECT_LATLNG_COLUMN].values[
            first_storm_object_row])
    first_vertex_latitudes_deg = first_vertex_dict[polygons.EXTERIOR_Y_COLUMN]
    first_vertex_longitudes_deg = first_vertex_dict[polygons.EXTERIOR_X_COLUMN]

    storm_plotting.plot_unfilled_polygon(
        basemap_object=basemap_object, axes_object=axes_object,
        vertex_latitudes_deg=first_vertex_latitudes_deg,
        vertex_longitudes_deg=first_vertex_longitudes_deg,
        exterior_colour=storm_colour, exterior_line_width=storm_line_width)

    last_vertex_dict = polygons.polygon_object_to_vertex_arrays(
        storm_to_winds_table[tracking_io.POLYGON_OBJECT_LATLNG_COLUMN].values[
            last_storm_object_row])
    last_vertex_latitudes_deg = last_vertex_dict[polygons.EXTERIOR_Y_COLUMN]
    last_vertex_longitudes_deg = last_vertex_dict[polygons.EXTERIOR_X_COLUMN]

    storm_plotting.plot_unfilled_polygon(
        basemap_object=basemap_object, axes_object=axes_object,
        vertex_latitudes_deg=last_vertex_latitudes_deg,
        vertex_longitudes_deg=last_vertex_longitudes_deg,
        exterior_colour=storm_colour, exterior_line_width=storm_line_width)

    wind_latitudes_deg = numpy.array([])
    wind_longitudes_deg = numpy.array([])
    u_winds_m_s01 = numpy.array([])
    v_winds_m_s01 = numpy.array([])

    for this_row in storm_cell_rows:
        wind_latitudes_deg = numpy.concatenate((
            wind_latitudes_deg, storm_to_winds_table[
                storms_to_winds.WIND_LATITUDES_COLUMN].values[this_row]))
        wind_longitudes_deg = numpy.concatenate((
            wind_longitudes_deg, storm_to_winds_table[
                storms_to_winds.WIND_LONGITUDES_COLUMN].values[this_row]))
        u_winds_m_s01 = numpy.concatenate((
            u_winds_m_s01, storm_to_winds_table[
                storms_to_winds.U_WINDS_COLUMN].values[this_row]))
        v_winds_m_s01 = numpy.concatenate((
            v_winds_m_s01, storm_to_winds_table[
                storms_to_winds.V_WINDS_COLUMN].values[this_row]))

    wind_plotting.plot_wind_barbs(
        basemap_object=basemap_object, axes_object=axes_object,
        latitudes_deg=wind_latitudes_deg, longitudes_deg=wind_longitudes_deg,
        u_winds_m_s01=u_winds_m_s01, v_winds_m_s01=v_winds_m_s01,
        barb_length=wind_barb_length, empty_barb_radius=empty_wind_barb_radius,
        fill_empty_barb=fill_empty_wind_barb, colour_map=wind_colour_map,
        colour_minimum_kt=colour_minimum_kt,
        colour_maximum_kt=colour_maximum_kt)
Esempio n. 2
0
def plot_wind_barbs_on_subgrid(
        u_wind_matrix_m_s01,
        v_wind_matrix_m_s01,
        model_name,
        axes_object,
        basemap_object,
        grid_id=None,
        first_row_in_full_grid=0,
        first_column_in_full_grid=0,
        plot_every_k_rows=1,
        plot_every_k_columns=1,
        barb_length=wind_plotting.DEFAULT_BARB_LENGTH,
        empty_barb_radius=wind_plotting.DEFAULT_EMPTY_BARB_RADIUS,
        fill_empty_barb=wind_plotting.FILL_EMPTY_BARB_DEFAULT,
        colour_map=wind_plotting.DEFAULT_COLOUR_MAP,
        colour_minimum_kt=wind_plotting.DEFAULT_COLOUR_MINIMUM_KT,
        colour_maximum_kt=wind_plotting.DEFAULT_COLOUR_MAXIMUM_KT):
    """Plots wind barbs over subgrid.

    :param u_wind_matrix_m_s01: M-by-N numpy array of zonal wind speeds (metres
        per second).
    :param v_wind_matrix_m_s01: M-by-N numpy array of meridional wind speeds
        (metres per second).
    :param model_name: See doc for `plot_subgrid`.
    :param axes_object: Same.
    :param basemap_object: Same.
    :param grid_id: Same.
    :param first_row_in_full_grid: Row 0 in the subgrid (i.e., row 0 in
        `u_wind_matrix_m_s01` and `v_wind_matrix_m_s01` is row
        `first_row_in_full_grid` in the full grid).
    :param first_column_in_full_grid: Column 0 in the subgrid (i.e., column 0 in
        `u_wind_matrix_m_s01` and `v_wind_matrix_m_s01` is column
        `first_column_in_full_grid` in the full grid).
    :param plot_every_k_rows: Wind barbs will be plotted for every [k]th row in
        the subgrid, where k = `plot_every_k_rows`.  For example, if
        `plot_every_k_rows = 2`, wind barbs will be plotted for rows 0, 2, 4,
        etc.
    :param plot_every_k_columns: Same as above, but for columns.
    :param barb_length: See doc for `wind_plotting.plot_wind_barbs`.
    :param empty_barb_radius: Same.
    :param fill_empty_barb: Same.
    :param colour_map: Same.
    :param colour_minimum_kt: Same.
    :param colour_maximum_kt: Same.
    """

    error_checking.assert_is_real_numpy_array(u_wind_matrix_m_s01)
    error_checking.assert_is_numpy_array(u_wind_matrix_m_s01, num_dimensions=2)
    error_checking.assert_is_real_numpy_array(v_wind_matrix_m_s01)

    these_expected_dim = numpy.array(u_wind_matrix_m_s01.shape, dtype=int)
    error_checking.assert_is_numpy_array(v_wind_matrix_m_s01,
                                         exact_dimensions=these_expected_dim)

    error_checking.assert_is_integer(plot_every_k_rows)
    error_checking.assert_is_geq(plot_every_k_rows, 1)
    error_checking.assert_is_integer(plot_every_k_columns)
    error_checking.assert_is_geq(plot_every_k_columns, 1)

    num_rows_in_subgrid = u_wind_matrix_m_s01.shape[0]
    num_columns_in_subgrid = u_wind_matrix_m_s01.shape[1]

    coordinate_dict = _get_grid_point_coords(
        model_name=model_name,
        grid_id=grid_id,
        first_row_in_full_grid=first_row_in_full_grid,
        last_row_in_full_grid=first_row_in_full_grid + num_rows_in_subgrid - 1,
        first_column_in_full_grid=first_column_in_full_grid,
        last_column_in_full_grid=first_column_in_full_grid +
        num_columns_in_subgrid - 1,
        basemap_object=basemap_object)

    grid_point_lat_matrix_deg = coordinate_dict[LATITUDE_MATRIX_KEY]
    grid_point_lng_matrix_deg = coordinate_dict[LONGITUDE_MATRIX_KEY]

    u_wind_matrix_m_s01 = u_wind_matrix_m_s01[::plot_every_k_rows, ::
                                              plot_every_k_columns]
    v_wind_matrix_m_s01 = v_wind_matrix_m_s01[::plot_every_k_rows, ::
                                              plot_every_k_columns]
    grid_point_lat_matrix_deg = grid_point_lat_matrix_deg[::
                                                          plot_every_k_rows, ::
                                                          plot_every_k_columns]
    grid_point_lng_matrix_deg = grid_point_lng_matrix_deg[::
                                                          plot_every_k_rows, ::
                                                          plot_every_k_columns]

    num_wind_barbs = u_wind_matrix_m_s01.size
    u_winds_m_s01 = numpy.reshape(u_wind_matrix_m_s01, num_wind_barbs)
    v_winds_m_s01 = numpy.reshape(v_wind_matrix_m_s01, num_wind_barbs)
    latitudes_deg = numpy.reshape(grid_point_lat_matrix_deg, num_wind_barbs)
    longitudes_deg = numpy.reshape(grid_point_lng_matrix_deg, num_wind_barbs)

    nan_flags = numpy.logical_or(numpy.isnan(u_winds_m_s01),
                                 numpy.isnan(v_winds_m_s01))
    real_indices = numpy.where(numpy.invert(nan_flags))[0]

    wind_plotting.plot_wind_barbs(basemap_object=basemap_object,
                                  axes_object=axes_object,
                                  latitudes_deg=latitudes_deg[real_indices],
                                  longitudes_deg=longitudes_deg[real_indices],
                                  u_winds_m_s01=u_winds_m_s01[real_indices],
                                  v_winds_m_s01=v_winds_m_s01[real_indices],
                                  barb_length=barb_length,
                                  empty_barb_radius=empty_barb_radius,
                                  fill_empty_barb=fill_empty_barb,
                                  colour_map=colour_map,
                                  colour_minimum_kt=colour_minimum_kt,
                                  colour_maximum_kt=colour_maximum_kt)
Esempio n. 3
0
def plot_wind_linkages(
        storm_to_winds_table, basemap_object, axes_object,
        storm_colour=storm_plotting.DEFAULT_TRACK_COLOUR,
        storm_line_width=storm_plotting.DEFAULT_TRACK_WIDTH,
        wind_barb_length=wind_plotting.DEFAULT_BARB_LENGTH,
        empty_wind_barb_radius=wind_plotting.DEFAULT_EMPTY_BARB_RADIUS,
        fill_empty_wind_barb=wind_plotting.FILL_EMPTY_BARB_DEFAULT,
        wind_colour_map=wind_plotting.DEFAULT_COLOUR_MAP,
        colour_minimum_kt=wind_plotting.DEFAULT_COLOUR_MINIMUM_KT,
        colour_maximum_kt=wind_plotting.DEFAULT_COLOUR_MAXIMUM_KT):
    """Plots wind linkages.

    :param storm_to_winds_table: pandas DataFrame with columns listed in
        `link_events_to_storms.write_storm_to_winds_table`.  This method will
        plot linkages for all storm cells in the table.
    :param basemap_object: Instance of `mpl_toolkits.basemap.Basemap`.
    :param axes_object: Instance of `matplotlib.axes._subplots.AxesSubplot`.
    :param storm_colour: Colour for storm tracks and outlines (in any format
        accepted by `matplotlib.colors`).
    :param storm_line_width: Line width for storm tracks and outlines.
    :param wind_barb_length: See doc for `wind_plotting.plot_wind_barbs`.
    :param empty_wind_barb_radius: Same.
    :param fill_empty_wind_barb: Same.
    :param wind_colour_map: Same.
    :param colour_minimum_kt: Same.
    :param colour_maximum_kt: Same.
    """

    storm_object_ids = numpy.array(
        storm_to_winds_table[tracking_utils.STORM_ID_COLUMN].values)
    storm_cell_ids, object_to_cell_indices = numpy.unique(
        storm_object_ids, return_inverse=True)
    num_storm_cells = len(storm_cell_ids)

    for i in range(num_storm_cells):
        these_object_indices = numpy.where(object_to_cell_indices == i)[0]
        storm_plotting.plot_storm_track(
            basemap_object=basemap_object, axes_object=axes_object,
            centroid_latitudes_deg=storm_to_winds_table[
                tracking_utils.CENTROID_LAT_COLUMN
            ].values[these_object_indices],
            centroid_longitudes_deg=storm_to_winds_table[
                tracking_utils.CENTROID_LNG_COLUMN
            ].values[these_object_indices],
            line_colour=storm_colour, line_width=storm_line_width)

        these_wind_latitudes_deg = numpy.concatenate(tuple(
            [storm_to_winds_table[
                linkage.EVENT_LATITUDES_COLUMN
            ].values[j] for j in these_object_indices]))
        these_wind_longitudes_deg = numpy.concatenate(tuple(
            [storm_to_winds_table[
                linkage.EVENT_LONGITUDES_COLUMN
            ].values[j] for j in these_object_indices]))
        these_u_winds_m_s01 = numpy.concatenate(tuple(
            [storm_to_winds_table[
                linkage.U_WINDS_COLUMN
            ].values[j] for j in these_object_indices]))
        these_v_winds_m_s01 = numpy.concatenate(tuple(
            [storm_to_winds_table[
                linkage.V_WINDS_COLUMN
            ].values[j] for j in these_object_indices]))

        wind_plotting.plot_wind_barbs(
            basemap_object=basemap_object, axes_object=axes_object,
            latitudes_deg=these_wind_latitudes_deg,
            longitudes_deg=these_wind_longitudes_deg,
            u_winds_m_s01=these_u_winds_m_s01,
            v_winds_m_s01=these_v_winds_m_s01, barb_length=wind_barb_length,
            empty_barb_radius=empty_wind_barb_radius,
            fill_empty_barb=fill_empty_wind_barb, colour_map=wind_colour_map,
            colour_minimum_kt=colour_minimum_kt,
            colour_maximum_kt=colour_maximum_kt)