Ejemplo n.º 1
0
def _get_wind_flags(thick=1, min_speed=0.0, color='charcoal'):
    """
    wind flags.
    """
    return magics.mwind(legend='off',
                        wind_field_type='flags',
                        wind_flag_length=0.6,
                        wind_flag_style='solid',
                        wind_flag_thickness=1,
                        wind_flag_origin_marker='dot',
                        wind_flag_min_speed=0.0,
                        wind_flag_colour='charcoal')
Ejemplo n.º 2
0
def draw_wind_upper(uwind,
                    vwind,
                    lon,
                    lat,
                    gh=None,
                    skip_vector=None,
                    map_region=None,
                    title_kwargs={},
                    outfile=None):
    """
    Draw 200hPa wind speed and vector field.

    Args:
        uwind (np.array): u wind component, 2D array, [nlat, nlon]
        vwind (np.array): v wind component, 2D array, [nlat, nlon]
        lon (np.array): longitude, 1D array, [nlon]
        lat (np.array): latitude, 1D array, [nlat]
        gh (np.array): geopotential height, 2D array, [nlat, nlon]
        skip_vector (integer): skip grid number for vector plot
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # check default parameters
    if skip_vector is None:
        skip_vector = util.get_skip_vector(lon, lat, map_region)

    # put data into fields
    wind_field = util.minput_2d_vector(uwind,
                                       vwind,
                                       lon,
                                       lat,
                                       skip=skip_vector)
    wspeed = np.sqrt(uwind * uwind + vwind * vwind)
    wspeed_field = util.minput_2d(wspeed, lon, lat, {
        'long_name': 'Wind Speed',
        'units': 'm/s'
    })
    if gh is not None:
        gh_field = util.minput_2d(gh, lon, lat, {
            'long_name': 'height',
            'units': 'gpm'
        })

    #
    # set up visual parameters
    #

    plots = []

    # Setting the coordinates of the geographical area
    if map_region is None:
        china_map = map_set.get_mmap(name='CHINA_CYLINDRICAL',
                                     subpage_frame_thickness=5)
    else:
        china_map = map_set.get_mmap(name='CHINA_REGION_CYLINDRICAL',
                                     map_region=map_region,
                                     subpage_frame_thickness=5)
    plots.append(china_map)

    # Background Coaslines
    coastlines = map_set.get_mcoast(name='COAST_FILL')
    plots.append(coastlines)

    # Define the shading for the wind speed
    if wspeed.max() > 30.:
        wspeed_contour = magics.mcont(
            legend='on',
            contour_level_selection_type='level_list',
            contour_level_list=[30., 40., 50., 60., 70., 80., 90., 100.],
            contour_shade='on',
            contour_shade_max_level_colour='evergreen',
            contour_shade_min_level_colour='yellow',
            contour_shade_method='area_fill',
            contour_reference_level=0.,
            contour_highlight='off',
            contour_hilo='hi',
            contour_hilo_format='(F3.0)',
            contour_hilo_height=0.6,
            contour_hilo_type='number',
            contour_hilo_window_size=10,
            contour_label='off')
        plots.extend([wspeed_field, wspeed_contour])

    # Define the wind vector
    wind_vector = magics.mwind(legend='on',
                               wind_field_type='arrows',
                               wind_arrow_head_shape=1,
                               wind_arrow_thickness=0.5,
                               wind_arrow_unit_velocity=50,
                               wind_arrow_colour='evergreen')
    plots.extend([wind_field, wind_vector])

    # Define the simple contouring for gh
    if gh is not None:
        gh_contour = common._get_gh_contour(interval=50,
                                            reference=12520,
                                            color='black')
        plots.extend([gh_field, gh_contour])

    # Add a legend
    legend = common._get_legend(china_map, title="Wind Speed [m/s]")
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head', "200hPa Wind | GH")
    title = common._get_title(**title_kwargs)
    plots.append(title)

    # Add china province
    china_coastlines = map_set.get_mcoast(name='PROVINCE')
    plots.append(china_coastlines)

    # final plot
    return util.magics_plot(plots, outfile)
Ejemplo n.º 3
0
def draw_ivt(iqu,
             iqv,
             lon,
             lat,
             mslp=None,
             skip_vector=None,
             map_region=None,
             title_kwargs={},
             outfile=None):
    """
    Draw integrated Water Vapor Transport (IVT) .

    Args:
        iqu (np.array): u * q transport, 2D array, [nlat, nlon]
        iqv (np.array): v * q transport, 2D array, [nlat, nlon]
        lon (np.array): longitude, 1D array, [nlon]
        lat (np.array): latitude, 1D array, [nlat]
        mslp (np.array): mean sea level pressure, 2D array, [nlat, nlon]
        skip_vector (integer): skip grid number for vector plot
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # check default parameters
    if skip_vector is None:
        skip_vector = util.get_skip_vector(lon, lat, map_region)

    # put data into fields
    ivt_field = util.minput_2d_vector(iqu, iqv, lon, lat, skip=skip_vector)
    ivt_mag_field = util.minput_2d(np.sqrt(iqu * iqu + iqv * iqv), lon, lat, {
        'long_name': 'Integrated Water Vapor Transport',
        'units': 'kg/m/s'
    })
    mslp_field = util.minput_2d(mslp, lon, lat, {
        'long_name': 'mean sea level pressure',
        'units': 'mb'
    })

    #
    # set up visual parameters
    #

    plots = []

    # Setting the coordinates of the geographical area
    if map_region is None:
        china_map = map_set.get_mmap(name='CHINA_CYLINDRICAL',
                                     subpage_frame_thickness=5)
    else:
        china_map = map_set.get_mmap(name='CHINA_REGION_CYLINDRICAL',
                                     map_region=map_region,
                                     subpage_frame_thickness=5)
    plots.append(china_map)

    # Background Coaslines
    coastlines = map_set.get_mcoast(name='COAST_FILL')
    plots.append(coastlines)

    # Define the shading for the wind speed
    ivt_mag_contour = magics.mcont(
        legend='on',
        contour="off",
        contour_level_selection_type="level_list",
        contour_level_list=[i * 50.0 + 150 for i in range(3)] +
        [i * 100.0 + 300 for i in range(17)],
        contour_shade='on',
        contour_shade_method='area_fill',
        contour_shade_colour_method="list",
        contour_shade_colour_list=[
            '#fdd6c4', '#fcae92', '#fc8363', '#f6573e', '#de2b25', '#b81419',
            '#840711', '#fbb1ba', '#f98cae', '#f25e9f', '#dc3296', '#b40781',
            '#890179', '#600070', '#787878', '#8c8c8c', '#a0a0a0', '#b4b4b4',
            '#c8c8c8', '#dcdcdc'
        ],
        contour_highlight='off',
        contour_hilo='off',
        contour_label='off')
    plots.extend([ivt_mag_field, ivt_mag_contour])

    # Define the wind vector
    if ivt_field is not None:
        ivt_vector = magics.mwind(legend='off',
                                  wind_field_type='arrows',
                                  wind_arrow_head_shape=1,
                                  wind_arrow_head_ratio=0.5,
                                  wind_arrow_thickness=2,
                                  wind_arrow_unit_velocity=1000.0,
                                  wind_arrow_min_speed=150.0,
                                  wind_arrow_calm_below=150,
                                  wind_arrow_colour='#31043a')
        plots.extend([ivt_field, ivt_vector])

    # Define the simple contouring for gh
    if mslp_field is not None:
        interval = check_region_to_contour(map_region, 4, 2, thred=600)
        mslp_contour = common._get_mslp_contour(interval=interval)
        plots.extend([mslp_field, mslp_contour])

    # Add a legend
    legend = common._get_legend(
        china_map, title="Integrated Water Vapor Transport [kg/m/s]")
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head',
                                "Integrated Water Vapor Transport | MSLP")
    title = common._get_title(**title_kwargs)
    plots.append(title)

    # Add china province
    china_province_coastlines = map_set.get_mcoast(
        name='PROVINCE',
        map_user_layer_thickness=2,
        map_user_layer_colour='black')
    plots.append(china_province_coastlines)
    china_river_coastlines = map_set.get_mcoast(
        name='RIVER',
        map_user_layer_thickness=2,
        map_user_layer_colour='#71b2fd')
    plots.append(china_river_coastlines)

    # final plot
    return util.magics_plot(plots, outfile)