Exemple #1
0
def draw_wind_high(uwind,
                   vwind,
                   lon,
                   lat,
                   gh=None,
                   skip_vector=None,
                   map_region=None,
                   title_kwargs={},
                   outfile=None):
    """
    Draw high wind speed and flags.

    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_field = util.minput_2d(np.sqrt(uwind * uwind + vwind * vwind), 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
    wspeed_contour = magics.mcont(
        legend='on',
        contour_level_selection_type='interval',
        contour_shade_max_level=44.,
        contour_shade_min_level=8.,
        contour_interval=4.,
        contour_shade='on',
        contour="off",
        contour_shade_method='area_fill',
        contour_shade_colour_method='palette',
        contour_shade_palette_name='eccharts_rainbow_blue_purple_9',
        contour_reference_level=8.,
        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 = common._get_wind_flags()
    plots.extend([wind_field, wind_vector])

    # Define the simple contouring for gh
    if gh is not None:
        gh_contour = common._get_gh_contour()
        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',
                                "850hPa Wind | 500hPa 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)
Exemple #2
0
def draw_vort_high(uwind,
                   vwind,
                   lon,
                   lat,
                   vort=None,
                   gh=None,
                   skip_vector=None,
                   smooth_factor=1.0,
                   map_region=None,
                   title_kwargs={},
                   outfile=None):
    """
    Draw high vorticity.

    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]
        vort (np.array, optional): vorticity component, 2D array, [nlat, nlon]
        gh (np.array): geopotential height, 2D array, [nlat, nlon]
        skip_vector (integer): skip grid number for vector plot
        smooth_factor (float): smooth factor for vorticity, larger for smoother.
        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)
    if vort is None:
        dx, dy = calc.lat_lon_grid_deltas(lon, lat)
        vort = calc.vorticity(uwind * units.meter / units.second,
                              vwind * units.meter / units.second, dx, dy)
        vort = ndimage.gaussian_filter(vort, sigma=smooth_factor,
                                       order=0) * 10**5
    vort_field = util.minput_2d(vort, lon, lat, {
        'long_name': 'vorticity',
        'units': 's-1'
    })
    if gh is not None:
        gh_feild = 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 contour
    vort_contour = magics.mcont(
        legend='on',
        contour_level_selection_type='level_list',
        contour_level_list=[
            -200.0, -100.0, -75.0, -50.0, -30.0, -20.0, -15.0, -13.0, -11.0,
            -9.0, -7.0, -5.0, -3.0, -1.0, 1.0, 3.0, 5.0, 7.0, 9.0, 11.0, 13.0,
            15.0, 20.0, 30.0, 50.0, 75.0, 100.0, 200.0
        ],
        contour_shade='on',
        contour="off",
        contour_shade_method='area_fill',
        contour_shade_colour_method='list',
        contour_shade_colour_list=[
            "rgb(0,0,0.3)", "rgb(0,0,0.5)", "rgb(0,0,0.7)", "rgb(0,0,0.9)",
            "rgb(0,0.15,1)", "rgb(0,0.3,1)", "rgb(0,0.45,1)", "rgb(0,0.6,1)",
            "rgb(0,0.75,1)", "rgb(0,0.85,1)", "rgb(0.2,0.95,1)",
            "rgb(0.45,1,1)", "rgb(0.75,1,1)", "none", "rgb(1,1,0)",
            "rgb(1,0.9,0)", "rgb(1,0.8,0)", "rgb(1,0.7,0)", "rgb(1,0.6,0)",
            "rgb(1,0.5,0)", "rgb(1,0.4,0)", "rgb(1,0.3,0)", "rgb(1,0.15,0)",
            "rgb(0.9,0,0)", "rgb(0.7,0,0)", "rgb(0.5,0,0)", "rgb(0.3,0,0)"
        ],
        contour_reference_level=8.,
        contour_highlight='off',
        contour_hilo='off',
        contour_label='off')
    plots.extend([vort_field, vort_contour])

    # Define the wind vector
    wind_vector = common._get_wind_flags()
    plots.extend([wind_field, wind_vector])

    # Define the simple contouring for gh
    if gh is not None:
        gh_contour = common._get_gh_contour()
        plots.extend([gh_feild, gh_contour])

    # Add a legend
    legend = common._get_legend(china_map, title="Vorticity [s^-1]")
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head',
                                "500hPa Relative vorticity | 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)
Exemple #3
0
def draw_efi(efi,
             lon,
             lat,
             sot90=None,
             sot10=None,
             gh=None,
             map_region=None,
             title_kwargs={},
             outfile=None):
    """
    Draw extreme forecast index maps.

    Args:
        efi (np.array): extreme forecast index data, 2D array, [nlat, nlon]
        lon (np.array): longitude, 1D array, [nlon]
        lat (np.array): latitude, 1D array, [nlat]
        gh (np.array, optional), geopotential height, 2D array, [nlat, nlon]
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # put data into fields
    efi_field = util.minput_2d(efi, lon, lat, {
        'long_name': 'extreme forecast index',
        'units': ''
    })
    sot90_field = util.minput_2d(sot90, lon, lat, {
        'long_name': 'shift of tails',
        'units': ''
    })
    sot10_field = util.minput_2d(sot10, lon, lat, {
        'long_name': 'shift of tails',
        'units': ''
    })
    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',
                                    map_grid_latitude_increment=15,
                                    map_grid_longitude_increment=20)
    plots.append(coastlines)

    # Draw shaded contour
    efi_contour1 = magics.mcont(
        legend='on',
        contour_shade="on",
        contour_hilo="off",
        contour="off",
        contour_label="off",
        contour_shade_method="area_fill",
        contour_level_selection_type="level_list",
        contour_level_list=[-1, -0.95, -0.9, -0.8, -0.7, -0.6, -0.5],
        contour_shade_colour_method="list",
        contour_shade_colour_list=[
            '#ff32dd', '#1058b0', '#0066ff', '#00ccff', '#05fcaa', '#aafb02'
        ])
    plots.extend([efi_field, efi_contour1])
    efi_contour2 = magics.mcont(
        legend='on',
        contour_shade="on",
        contour_hilo="off",
        contour="off",
        contour_label="off",
        contour_shade_method="area_fill",
        contour_level_selection_type="level_list",
        contour_level_list=[0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 1.0],
        contour_shade_colour_method="list",
        contour_shade_colour_list=[
            '#fffc01', '#f8b420', '#f86c00', '#f82c00', '#c80800', '#a00000'
        ])
    plots.extend([efi_field, efi_contour2])

    # Draw contour lines
    efi_contour3 = magics.mcont(contour_level_selection_type="level_list",
                                contour_level_list=[0.3],
                                contour_line_colour="red",
                                contour_line_thickness=1,
                                contour_line_style="dash",
                                contour_highlight="off",
                                contour_label="on",
                                contour_label_colour="red",
                                contour_label_height=0.50)
    plots.extend([efi_field, efi_contour3])
    efi_contour4 = magics.mcont(contour_level_selection_type="level_list",
                                contour_level_list=[-0.3],
                                contour_line_colour="blue",
                                contour_line_thickness=1,
                                contour_line_style="dash",
                                contour_highlight="off",
                                contour_label="on",
                                contour_label_colour="blue",
                                contour_label_height=0.50)
    plots.extend([efi_field, efi_contour4])

    # draw SOT (shift of tails) contours
    sot_contour = magics.mcont(contour_level_selection_type="level_list",
                               contour_level_list=[0, 1.0, 2.0, 5.0, 8.0],
                               contour_line_colour="black",
                               contour_line_thickness=2,
                               contour_line_style="solid",
                               contour_highlight="off",
                               contour_label="on",
                               contour_label_colour="red",
                               contour_label_height=0.50)
    if sot90_field is not None:
        plots.extend([sot90_field, sot_contour])
    if sot10_field is not None:
        plots.extend([sot10_field, sot_contour])

    # Define the simple contouring for gh
    if gh_field is not None:
        gh_contour = common._get_gh_contour()
        plots.extend([gh_field, gh_contour])

    # Add a legend
    legend = common._get_legend(china_map,
                                title="Extreme Forecast Index",
                                frequency=1)
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head',
                                "Extreme Forecast Index | 500hPa GH")
    title = common._get_title(**title_kwargs)
    plots.append(title)

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

    # final plot
    return util.magics_plot(plots, outfile)
Exemple #4
0
def draw_height_temp(gh,
                     temp,
                     lon,
                     lat,
                     map_region=None,
                     head_info=None,
                     title_kwargs={},
                     outfile=None):
    """
    Draw geopotential height and temperature.

    Args:
        gh (np.array): geopotential height, 2D array, [nlat, nlon]
        temp (np.array): temperature, 2D array, [nlat, nlon]
        lon (np.array): longitude, 1D array, [nlon]
        lat (np.array): latitude, 1D array, [nlat]
        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.
    """

    # put data into fields
    gh_field = util.minput_2d(gh, lon, lat, {
        'long_name': 'Geopotential Height',
        'units': 'gpm'
    })
    temp_field = util.minput_2d(temp, lon, lat, {
        'long_name': 'Temperature',
        'units': 'm/s'
    })

    #
    # 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 simple contouring for temperature
    if temp.min() < -2.0:
        temp_contour1 = magics.mcont(legend='off',
                                     contour_level_selection_type='interval',
                                     contour_interval=2.0,
                                     contour_reference_level=0.,
                                     contour_line_colour='red',
                                     contour_line_thickness=2,
                                     contour_line_style="dash",
                                     contour_label='on',
                                     contour_label_height=0.5,
                                     contour_max_level=-2.0,
                                     contour_highlight='off')
        plots.extend([temp_field, temp_contour1])

    if temp.min() < 0.0 and temp.max() > 0.0:
        temp_contour2 = magics.mcont(legend='off',
                                     contour_level_selection_type='level_list',
                                     contour_level_list=[0.00],
                                     contour_line_colour='red',
                                     contour_line_thickness=4,
                                     contour_label='on',
                                     contour_label_height=0.5,
                                     contour_highlight='off')
        plots.extend([temp_field, temp_contour2])

    if temp.max() > 2.0:
        temp_contour3 = magics.mcont(legend='off',
                                     contour_level_selection_type='interval',
                                     contour_interval=2.0,
                                     contour_reference_level=0.,
                                     contour_line_colour='red',
                                     contour_line_thickness=2,
                                     contour_label='on',
                                     contour_label_height=0.5,
                                     contour_min_level=2.0,
                                     contour_highlight='off')
        plots.extend([temp_field, temp_contour3])

    # Define the simple contouring for gh
    gh_contour = common._get_gh_contour()
    plots.extend([gh_field, gh_contour])

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head', "500hPa GH | T")
    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)
Exemple #5
0
def draw_rain1h(rain,
                lon,
                lat,
                mslp=None,
                map_region=None,
                title_kwargs={},
                outfile=None):
    """
    Draw 1-hour accumulation rainfall.

    Args:
        rain (np.array): rainfall data, 2D array, [nlat, nlon]
        lon (np.array): longitude, 1D array, [nlon]
        lat (np.array): latitude, 1D array, [nlat]
        mslp (np.array, optional), mean sea level data, 2D array, [nlat, nlon]
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # put data into fields
    rain_field = util.minput_2d(rain,
                                lon,
                                lat, {
                                    'long_name': 'rainfall',
                                    'units': 'mm'
                                },
                                map_region=map_region)
    mslp_field = util.minput_2d(mslp,
                                lon,
                                lat, {
                                    'long_name': 'height',
                                    'units': 'hPa'
                                },
                                map_region=map_region)

    #
    # 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 precipitation water.
    level_list = [0.1, 2, 5, 10, 20, 40, 60, 100, 250]
    rain_contour = magics.mcont(
        legend='on',
        contour_shade="on",
        contour_hilo="off",
        contour="off",
        contour_label="off",
        #contour_shade_method= "area_fill",
        contour_shade_technique="grid_shading",
        contour_level_selection_type="level_list",
        contour_level_list=level_list,
        contour_shade_colour_method="list",
        contour_shade_colour_list=[
            '#a6f28e', '#39a803', '#5db8ff', '#0400f9', '#f804fc', '#ff0000',
            '#ca2f00', '#6f0200'
        ])
    plots.extend([rain_field, rain_contour])

    # Define the simple contouring for gh
    if mslp_field is not None:
        mslp_contour = common._get_mslp_contour()
        plots.extend([mslp_field, mslp_contour])

    # Add a legend
    legend = common._get_legend(china_map, title="Rainfall [mm]", frequency=1)
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head', "Precipitation | MSLP")
    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)
Exemple #6
0
def draw_qpf(prep,
             lon,
             lat,
             mslp=None,
             map_region=None,
             atime=24,
             title_kwargs={},
             outfile=None):
    """
    Draw precipitable water.

    Args:
        prep (np.array): precipitation, 2D array, [nlat, nlon]
        lon (np.array): longitude, 1D array, [nlon]
        lat (np.array): latitude, 1D array, [nlat]
        mslp (np.array, optional), mean sea level data, 2D array, [nlat, nlon]
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # put data into fields
    prep_field = util.minput_2d(prep,
                                lon,
                                lat, {
                                    'long_name': 'precipitation',
                                    'units': 'mm'
                                },
                                map_region=map_region)
    mslp_field = util.minput_2d(mslp,
                                lon,
                                lat, {
                                    'long_name': 'height',
                                    'units': 'hPa'
                                },
                                map_region=map_region)

    #
    # 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 precipitation water.
    if atime == 24:
        level_list = [0.1, 2.5, 5, 7.5] + [3*i+10 for i in range(5)] + [5*i+25 for i in range(5)] + \
                     [5*i+50 for i in range(10)] + [30*i+100 for i in range(5)] + [50*i+250 for i in range(5)] + \
                     [100*i+500 for i in range(6)]
    elif (atime == 12) or (atime == 6):
        level_list = [0.1, 0.5] + [i+1 for i in range(3)] + [1.5*i + 4 for i in range(6)] + \
                     [2*i+13 for i in range(6)] + [5*i+25 for i in range(14)] + [10*i+100 for i in range(9)]
    else:
        level_list = [0.01, 0.1] + [0.5*i+0.5 for i in range(3)] + [i + 2 for i in range(6)] + \
                     [2*i+8 for i in range(8)] + [4*i+24 for i in range(12)] + [8*i+76 for i in range(9)]
    prep_contour = magics.mcont(
        legend='on',
        contour_shade="on",
        contour_hilo="off",
        contour="off",
        contour_label="off",
        #contour_shade_method= "area_fill",
        contour_shade_technique="grid_shading",
        contour_level_selection_type="level_list",
        contour_level_list=level_list,
        contour_shade_colour_method="list",
        contour_shade_colour_list=[
            '#BABABA', '#A6A1A1', '#7E7E7E', '#6C6C6C', '#B2F8B0', '#94F397',
            '#56EE6C', '#2EB045', '#249C3B', '#2562C6', '#347EE4', '#54A1EB',
            '#94CEF4', '#B2EEF6', '#FDF8B2', '#FDE688', '#FDBC5C', '#FD9E42',
            '#FB6234', '#FB3D2D', '#DD2826', '#BA1B21', '#9F1A1D', '#821519',
            '#624038', '#88645C', '#B08880', '#C49C94', '#F0DAD1', '#CBC4D9',
            '#A99CC1', '#9687B6', '#715C99', '#65538B', '#73146F', '#881682',
            '#AA19A4', '#BB1BB5', '#C61CC0', '#D71ECF'
        ])
    plots.extend([prep_field, prep_contour])

    # Define the simple contouring for gh
    if mslp_field is not None:
        mslp_contour = common._get_mslp_contour()
        plots.extend([mslp_field, mslp_contour])

    # Add a legend
    legend = common._get_legend(china_map,
                                title="Precipitation [mm]",
                                frequency=1)
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head', "Precipitation | MSLP")
    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)
Exemple #7
0
def draw_pqpf(pqpf,
              lon,
              lat,
              mslp=None,
              map_region=None,
              title_kwargs={},
              outfile=None):
    """
    Draw precipitation probability .

    Args:
        pqpf (np.array): precipitation probability forecasts, 2D array, [nlat, nlon]
        lon (np.array): longitude, 1D array, [nlon]
        lat (np.array): latitude, 1D array, [nlat]
        mslp (np.array, optional), mean sea level data, 2D array, [nlat, nlon]
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # put data into fields
    pqpf_field = util.minput_2d(
        pqpf,
        lon,
        lat, {
            'long_name': 'Probability quantitative precipitation forecast',
            'units': '%'
        },
        map_region=map_region)
    mslp_field = util.minput_2d(mslp,
                                lon,
                                lat, {
                                    'long_name': 'height',
                                    'units': 'hPa'
                                },
                                map_region=map_region)

    #
    # 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 precipitation water.
    level_list = [0, 1.0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 99, 100.0]
    pqpf_contour = magics.mcont(
        legend='on',
        contour_shade="on",
        contour_hilo="off",
        contour="off",
        contour_label="off",
        #contour_shade_method= "area_fill",
        contour_shade_technique="grid_shading",
        contour_level_selection_type="level_list",
        contour_level_list=level_list,
        contour_shade_colour_method="list",
        contour_shade_colour_list=[
            '#ffffff', '#ff9226', '#ffc02c', '#ffc02c', '#fae931', '#c6fd74',
            '#74ff48', '#79bc21', '#36a318', '#32bbff', '#83b9ff', '#a996ff',
            '#7957f4', '#f192c2'
        ])
    plots.extend([pqpf_field, pqpf_contour])

    # Define the simple contouring for gh
    if mslp_field is not None:
        mslp_contour = common._get_mslp_contour()
        plots.extend([mslp_field, mslp_contour])

    # Add a legend
    legend = common._get_legend(china_map,
                                title="Probability [%]",
                                frequency=1)
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head', "Precipitation | MSLP")
    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)
Exemple #8
0
def get_mcoast(name='PROVINCE', **kwargs):
    """
    Project coastlines and latitude/longitude grid lines onto

    Args:
        name (str, optional): [description]. Defaults to 'PROVINCE'.

    Return:
        map coastlines object.
    """

    if name.upper() == 'COAST':
        kwargs = check_kwargs(kwargs, 'map_coastline_colour', "grey")
        kwargs = check_kwargs(kwargs, 'map_label', "on")
        kwargs = check_kwargs(kwargs, 'map_label_height', 0.6)
        kwargs = check_kwargs(kwargs, 'map_label_right', 'off')
        kwargs = check_kwargs(kwargs, 'map_label_top', 'off')
        kwargs = check_kwargs(kwargs, 'map_grid', "on")
        kwargs = check_kwargs(kwargs, 'map_grid_thickness', 0.2)
        kwargs = check_kwargs(kwargs, 'map_grid_line_style', "dot")
        kwargs = check_kwargs(kwargs, 'map_grid_latitude_increment', 10)
        kwargs = check_kwargs(kwargs, 'map_grid_longitude_increment', 10)
        coast = magics.mcoast(**kwargs)
    elif name.upper() == 'COAST_FILL':
        kwargs = check_kwargs(kwargs, 'map_coastline_colour', "grey")
        kwargs = check_kwargs(kwargs, 'map_coastline_land_shade', "on")
        kwargs = check_kwargs(kwargs, 'map_coastline_sea_shade', "on")
        kwargs = check_kwargs(kwargs, 'map_coastline_land_shade_colour', "cream")
        kwargs = check_kwargs(kwargs, 'map_coastline_sea_shade_colour', "white")
        kwargs = check_kwargs(kwargs, 'map_label', "on")
        kwargs = check_kwargs(kwargs, 'map_label_height', 0.6)
        kwargs = check_kwargs(kwargs, 'map_label_right', 'off')
        kwargs = check_kwargs(kwargs, 'map_label_top', 'off')
        kwargs = check_kwargs(kwargs, 'map_grid', "on")
        kwargs = check_kwargs(kwargs, 'map_grid_thickness', 0.2)
        kwargs = check_kwargs(kwargs, 'map_grid_line_style', "dot")
        kwargs = check_kwargs(kwargs, 'map_grid_latitude_increment', 10)
        kwargs = check_kwargs(kwargs, 'map_grid_longitude_increment', 10)
        coast = magics.mcoast(**kwargs)
    elif name.upper() == 'PROVINCE':
        shpfile = pkg_resources.resource_filename('nmc_met_graphics', 'resources/maps/bou2_4l')
        kwargs = check_kwargs(kwargs, 'map_user_layer_colour', "navy")
        kwargs = check_kwargs(kwargs, 'map_user_layer_thickness', 1)
        kwargs = check_kwargs(kwargs, 'map_label', "off")
        kwargs = check_kwargs(kwargs, 'map_grid', "off")
        coast = magics.mcoast(
            map_user_layer="on",
            map_user_layer_name = shpfile,
            **kwargs)
    elif name.upper() == 'RIVER':
        shpfile = pkg_resources.resource_filename('nmc_met_graphics', 'resources/maps/hyd1_4l')
        kwargs = check_kwargs(kwargs, 'map_user_layer_colour', "blue")
        kwargs = check_kwargs(kwargs, 'map_user_layer_thickness', 1)
        kwargs = check_kwargs(kwargs, 'map_label', "off")
        kwargs = check_kwargs(kwargs, 'map_grid', "off")
        coast = magics.mcoast(
            map_user_layer="on",
            map_user_layer_name = shpfile,
            **kwargs)
    else:
        coast = None

    return coast
Exemple #9
0
def draw_pwat(pwat,
              lon,
              lat,
              gh=None,
              map_region=None,
              title_kwargs={},
              outfile=None):
    """
    Draw precipitable water.

    Args:
        pwat (np.array): pressure, 2D array, [nlat, nlon]
        lon (np.array): longitude, 1D array, [nlon]
        lat (np.array): latitude, 1D array, [nlat]
        gh (np.array, optional), geopotential height, 2D array, [nlat, nlon]
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # put data into fields
    pwat_field = util.minput_2d(pwat, lon, lat, {
        'long_name': 'precipitable water',
        'units': 'mm'
    })
    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 precipitation water.
    pwat_contour = magics.mcont(
        legend='on',
        contour_shade="on",
        contour_hilo="off",
        contour="off",
        contour_label="off",
        contour_shade_method="area_fill",
        contour_level_selection_type="level_list",
        contour_level_list=[i * 1.0 for i in range(25)] +
        [i * 2.0 + 26 for i in range(30)],
        contour_shade_colour_method="list",
        contour_shade_colour_list=[
            '#C5C5C5', '#B5B5B5', '#A1A1A1', '#8B8B8B', '#787878', '#636363',
            '#505050', '#3B3B3B', '#5B431F', '#6D583B', '#866441', '#9C7B46',
            '#B28C5D', '#CA9D64', '#D8AC7D', '#B9B5FF', '#A7A8E1', '#989ACD',
            '#8686C6', '#6B6CA4', '#5A5B91', '#474880', '#016362', '#1D6C59',
            '#2C774E', '#398545', '#589A39', '#6FA720', '#8BB41A', '#A29E54',
            '#AEAD43', '#C4C732', '#D9DB18', '#F0EC11', '#E96F57', '#C55645',
            '#B04035', '#9D2527', '#8A121C', '#7B0007', '#7A0076', '#8E0096',
            '#AE00B8', '#C300C0', '#E200E1', '#A002DB', '#7901DD', '#6201DE',
            '#3C00DC', '#2500D9', '#0028DD', '#004ED6', '#0571E0', '#0C98E7',
            '#02B8DD'
        ])
    plots.extend([pwat_field, pwat_contour])

    # Define the simple contouring for gh
    if gh_field is not None:
        gh_contour = common._get_gh_contour()
        plots.extend([gh_field, gh_contour])

    # Add a legend
    legend = common._get_legend(china_map,
                                title="Precipitable water [mm]",
                                frequency=2)
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head',
                                "Precipitable water | 500hPa 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)
Exemple #10
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)
Exemple #11
0
def draw_rh_high(uwind,
                 vwind,
                 rh,
                 lon,
                 lat,
                 gh=None,
                 skip_vector=None,
                 map_region=None,
                 title_kwargs={},
                 outfile=None):
    """
    Draw high relative humidity.

    Args:
        uwind (np.array): u wind component, 2D array, [nlat, nlon]
        vwind (np.array): v wind component, 2D array, [nlat, nlon]
        rh (np.array): relative humidity 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)
    rh_field = util.minput_2d(rh, lon, lat, {
        'long_name': 'Relative Humidity',
        'units': '%'
    })
    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 specific humidity
    rh_contour = magics.mcont(legend='on',
                              contour_level_selection_type='level_list',
                              contour_level_list=[
                                  0, 1., 5., 10, 20, 30, 40, 50, 60, 65, 70,
                                  75, 80, 85, 90, 99, 100.
                              ],
                              contour_shade='on',
                              contour="off",
                              contour_shade_method='area_fill',
                              contour_shade_colour_method='list',
                              contour_shade_colour_list=[
                                  '#644228', '#7f5330', '#9b6238', '#ab754b',
                                  '#b78a60', '#d0b494', '#decab2', '#e0dac8',
                                  '#bdcbab', '#adc59c', '#88bd89', '#6ba48d',
                                  '#506c93', '#4d6393', '#5c5692', '#6b4b92',
                                  '#7a3e94'
                              ],
                              contour_reference_level=60.,
                              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([rh_field, rh_contour])

    # Define the wind vector
    wind_vector = common._get_wind_flags()
    plots.extend([wind_field, wind_vector])

    # Define the simple contouring for gh
    if gh is not None:
        gh_contour = common._get_gh_contour()
        plots.extend([gh_field, gh_contour])

    # Add a legend
    legend = common._get_legend(china_map, title="Relative Humidity[%]")
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head',
                                "Relative Humidity | Wind | 500hPa 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)
Exemple #12
0
def get_mmap(name='CHINA_LAND_CYLINDRICAL', **kwargs):
    """Get magics map background.

    refer to https://confluence.ecmwf.int/display/MAGP/Subpage+-+Projection
             https://confluence.ecmwf.int/display/MAGP/Subpage+examples
    
    Args:
        name (str, optional): map region name. Defaults to 'CHINA_LAND_CYLINDRICAL'.
            if 'CHINA_REGION_CYLINDRICAL', set map_region=[lonmin, lonmax, latmin, latmax]

    Return:
        map background project object.
    """

    # genderal kwargs
    kwargs = check_kwargs(kwargs, 'subpage_clipping', 'on')
    kwargs = check_kwargs(kwargs, 'page_id_line', 'off')

    if name.upper() == 'CHINA_CYLINDRICAL':                                                  # 中国陆地和海洋范围
        map_region = [70.0, 140.0, 8.0, 60.0]
        kwargs = get_page_setup(kwargs, map_region=map_region)
        kwargs['subpage_lower_left_longitude'] = map_region[0]
        kwargs['subpage_upper_right_longitude'] = map_region[1]
        kwargs['subpage_lower_left_latitude'] = map_region[2]
        kwargs['subpage_upper_right_latitude'] = map_region[3]
        project = magics.mmap(
            subpage_map_projection="cylindrical",
            **kwargs)
    elif name.upper() == 'CHINA_LAND_CYLINDRICAL':
        map_region = [73.0, 136.0, 16.0, 55.0]
        kwargs = get_page_setup(kwargs, map_region=map_region)
        kwargs['subpage_lower_left_longitude'] = map_region[0]
        kwargs['subpage_upper_right_longitude'] = map_region[1]
        kwargs['subpage_lower_left_latitude'] = map_region[2]
        kwargs['subpage_upper_right_latitude'] = map_region[3]
        project = magics.mmap(
            subpage_map_projection="cylindrical",
            **kwargs)
    elif name.upper() == 'CHINA_REGION_CYLINDRICAL':
        if 'map_region' in kwargs.keys():
            map_region = kwargs['map_region']
            del kwargs['map_region']
        else:
            map_region = [70, 140, 8, 60]
        kwargs = get_page_setup(kwargs, map_region=map_region)
        kwargs['subpage_lower_left_longitude'] = map_region[0]
        kwargs['subpage_upper_right_longitude'] = map_region[1]
        kwargs['subpage_lower_left_latitude'] = map_region[2]
        kwargs['subpage_upper_right_latitude'] = map_region[3]
        project = magics.mmap(
            subpage_map_projection="cylindrical",
            **kwargs)
    elif name.upper() == "CHINA_POLAR_STEREOGRAPHIC":
        kwargs = get_page_setup(kwargs)
        kwargs = check_kwargs(kwargs, 'subpage_map_area_definition_polar', 'center')
        kwargs = check_kwargs(kwargs, 'subpage_map_vertical_longitude', 105)
        kwargs = check_kwargs(kwargs, 'subpage_map_centre_latitude', 35)
        kwargs = check_kwargs(kwargs, 'subpage_map_centre_longitude', 105)
        kwargs = check_kwargs(kwargs, 'subpage_map_scale', 32.e6)
        project = magics.mmap(
            subpage_map_projection = "polar_stereographic",
            **kwargs)
    elif name.upper() == "WORLD_mollweide":
        project = magics.mmap(
            subpage_map_projection = "mollweide",
            subpage_map_area_definition = "full",
            subpage_frame = "off",
            page_frame = "off",
            **kwargs)
    else:
        project = None

    return project
Exemple #13
0
def get_page_setup(kwargs, map_region=None):
    """
    设置Magics的默认页面大小和绘图范围大小.
    """

    if map_region is not None:
        super_page_x_length = 29.7
        page_ratio = (map_region[3]-map_region[2])*1.0/(map_region[1]-map_region[0])
        # make sure the page will show all figure contents
        kwargs = check_kwargs(kwargs, 'super_page_x_length', super_page_x_length)
        kwargs = check_kwargs(kwargs, 'super_page_y_length', super_page_x_length * page_ratio)
        # Set subpage_x_length and subpage_y_length, the small one is working
        subpage_x_length = 25.0
        kwargs = check_kwargs(kwargs, 'subpage_x_length', subpage_x_length)
        kwargs = check_kwargs(kwargs, 'subpage_y_length', subpage_x_length * page_ratio)
        # make sure the axis lable will show
        kwargs = check_kwargs(kwargs, 'subpage_x_position', 1.2)
        kwargs = check_kwargs(kwargs, 'subpage_y_position', 1)
    else:
        kwargs = check_kwargs(kwargs, 'super_page_x_length', 29.7)
        kwargs = check_kwargs(kwargs, 'subpage_x_length', 25.0)
        kwargs = check_kwargs(kwargs, 'subpage_y_length', 25.0)
        kwargs = check_kwargs(kwargs, 'subpage_x_position', 1)
        kwargs = check_kwargs(kwargs, 'subpage_y_position', 1)

    return kwargs
Exemple #14
0
def draw_vvel_high(uwind,
                   vwind,
                   wwind,
                   lon,
                   lat,
                   gh=None,
                   skip_vector=None,
                   map_region=None,
                   title_kwargs={},
                   outfile=None):
    """
    Draw high vertical velocity.

    Args:
        uwind (np.array): u wind component, 2D array, [nlat, nlon]
        vwind (np.array): v wind component, 2D array, [nlat, nlon]
        wwind (np.array): w 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)
    vvel_field = util.minput_2d(wwind, lon, lat, {
        'long_name': 'vertical velocity',
        'units': 'Pa/s'
    })
    if gh is not None:
        gh_feild = 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 contour
    vvel_contour = magics.mcont(legend='on',
                                contour_level_selection_type='level_list',
                                contour_level_list=[
                                    -60, -30, -10, -5, -2.5, -1, -0.5, -0.2,
                                    0.2, 0.5, 1, 2.5, 5, 10, 30
                                ],
                                contour_shade='on',
                                contour="off",
                                contour_shade_method='area_fill',
                                contour_shade_colour_method='list',
                                contour_shade_colour_list=[
                                    '#9D0001', '#C90101', '#F10202', '#FF3333',
                                    '#FF8585', '#FFBABA', '#FEDDDD', '#FFFFFF',
                                    '#E1E1FF', '#BABAFF', '#8484FF', '#2C2CF7',
                                    '#0404F1', '#0101C8', '#020299'
                                ],
                                contour_reference_level=0,
                                contour_highlight='off',
                                contour_hilo='off',
                                contour_label='off')
    plots.extend([vvel_field, vvel_contour])

    # Define the wind vector
    wind_vector = common._get_wind_flags()
    plots.extend([wind_field, wind_vector])

    # Define the simple contouring for gh
    if gh is not None:
        gh_contour = common._get_gh_contour()
        plots.extend([gh_feild, gh_contour])

    # Add a legend
    legend = common._get_legend(china_map, title="Vertical Velocity [Pa/s]")
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head',
                                "700hPa Vertical Velocity | 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)
Exemple #15
0
def draw_temp_high(temp,
                   lon,
                   lat,
                   gh=None,
                   map_region=None,
                   title_kwargs={},
                   outfile=None):
    """
    Draw high temperature field.

    Args:
        temperature (np.array): temperature, 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]
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # put data into fields
    temp_field = util.minput_2d(temp, lon, lat, {
        'long_name': 'Temperature',
        'units': 'degree'
    })
    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 teperature
    temp_contour = magics.mcont(
        legend='on',
        contour_shade="on",
        contour_hilo="off",
        contour="off",
        contour_label="off",
        contour_shade_method="area_fill",
        contour_shade_max_level=42.,
        contour_shade_min_level=-42.,
        contour_level_selection_type="interval",
        contour_interval=3.,
        contour_shade_colour_method="palette",
        contour_shade_palette_name="eccharts_rainbow_purple_magenta_31")
    plots.extend([temp_field, temp_contour])

    temp_contour_zero = magics.mcont(contour_level_selection_type="level_list",
                                     contour_level_list=[0.00],
                                     contour_line_colour="red",
                                     contour_line_thickness=4,
                                     contour_highlight="off",
                                     contour_label="off",
                                     contour_min_level=-1.00,
                                     contour_max_level=1.00,
                                     legend="off")
    plots.extend([temp_field, temp_contour_zero])

    # Define the simple contouring for gh
    if gh_field is not None:
        gh_contour = common._get_gh_contour()
        plots.extend([gh_field, gh_contour])

    # Add a legend
    legend = common._get_legend(china_map, title="Temperature [Degree]")
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head', "850hPa T | 500hPa 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)
Exemple #16
0
def draw_mslp(mslp,
              lon,
              lat,
              gh=None,
              map_region=None,
              title_kwargs={},
              outfile=None):
    """
    Draw mean sea level pressure field.

    Args:
        mslp (np.array): sea level pressure field (mb), 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]
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # put data into fields
    mslp_field = util.minput_2d(mslp, lon, lat, {
        'long_name': 'Sea level pressure',
        'units': 'mb'
    })
    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 teperature
    mslp_contour = magics.mcont(
        legend='on',
        contour_shade="on",
        contour_hilo="on",
        contour_hilo_height=0.6,
        contour_hi_colour='blue',
        contour_lo_colour='red',
        contour_hilo_window_size=5,
        contour="off",
        contour_label="off",
        contour_shade_method="area_fill",
        contour_level_selection_type="level_list",
        contour_level_list=[940. + i * 2.5 for i in range(51)],
        contour_shade_colour_method="list",
        contour_shade_colour_list=[
            '#FD90EB', '#EB78E5', '#EF53E0', '#F11FD3', '#F11FD3', '#A20E9B',
            '#880576', '#6D0258', '#5F0853', '#2A0DA8', '#2F1AA7', '#3D27B4',
            '#3F3CB6', '#6D5CDE', '#A28CF9', '#C1B3FF', '#DDDCFE', '#1861DB',
            '#206CE5', '#2484F4', '#52A5EE', '#91D4FF', '#B2EFF8', '#DEFEFF',
            '#C9FDBD', '#91F78B', '#53ED54', '#1DB31E', '#0CA104', '#FFF9A4',
            '#FFE27F', '#FAC235', '#FF9D04', '#FF5E00', '#F83302', '#E01304',
            '#A20200', '#603329', '#8C6653', '#B18981', '#DDC0B3', '#F8A3A2',
            '#DD6663', '#CA3C3B', '#A1241D', '#6C6F6D', '#8A8A8A', '#AAAAAA',
            '#C5C5C5', '#D5D5D5', '#E7E3E4'
        ])
    plots.extend([mslp_field, mslp_contour])

    # Define the simple contouring for gh
    if gh is not None:
        gh_contour = common._get_gh_contour()
        plots.extend([gh_field, gh_contour])

    # Add a legend
    legend = common._get_legend(china_map, title="Pressure [mb]", frequency=2)
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head', "MSLP | 500hPa 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)
Exemple #17
0
def draw_pres_pv2(pres,
                  lon,
                  lat,
                  map_region=None,
                  title_kwargs={},
                  outfile=None):
    """
    Draw pressure field on 2.0PVU surface.

    Args:
        pres (np.array): pressure, 2D array, [nlat, nlon]
        lon (np.array): longitude, 1D array, [nlon]
        lat (np.array): latitude, 1D array, [nlat]
        map_region (list or tuple): the map region limit, [lonmin, lonmax, latmin, latmax]
        title_kwargs (dictionaly, optional): keyword arguments for _get_title function.
    """

    # put data into fields
    pres_field = util.minput_2d(pres, lon, lat, {
        'long_name': 'pressure',
        'units': 'hPa'
    })

    #
    # 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 pressure
    pres_contour = magics.mcont(
        legend='on',
        contour_shade="on",
        contour_hilo="off",
        contour="off",
        contour_label="off",
        contour_shade_method="area_fill",
        contour_level_selection_type="level_list",
        contour_level_list=[80., 190., 200., 310., 320., 430., 440., 550.],
        contour_shade_colour_method="gradients",
        contour_gradients_colour_list=[
            '#440300', '#e7d799', '#dde2a4', '#145360', '#1450b2', '#ddecf3',
            '#d2e2e9', '#a33ab2'
        ],
        contour_gradients_step_list=[11, 1, 11, 1, 11, 1, 11])
    plots.extend([pres_field, pres_contour])

    # Add a legend
    legend = common._get_legend(china_map, title="Pressure [mb]", frequency=2)
    plots.append(legend)

    # Add the title
    title_kwargs = check_kwargs(title_kwargs, 'head', "PVU Surface Pressure")
    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)