def make_contour(contour, legend): if isinstance(contour, list): return [make_contour(c, legend) for c in contour] if contour is not None: if isinstance(contour, str): return macro.mcont( contour_automatic_setting='ecmwf', legend=legend, contour_style_name=contour, ) else: d = dict(**contour) d['legend'] = legend return macro.mcont(**d) else: return macro.mcont( contour_automatic_setting='ecmwf', legend=legend, )
def _get_gh_contour(interval=20, reference=5880, color='black'): """ geopotential height contours. """ return magics.mcont(legend='off', contour_level_selection_type='interval', contour_interval=interval, contour_reference_level=reference, contour_line_colour=color, contour_line_thickness=2, contour_label='on', contour_label_height=0.5, contour_highlight_colour='black', contour_highlight_thickness=4)
def _get_mslp_contour(interval=4, color='#399c9c'): """ mean sea level contour plot. """ return magics.mcont(legend='off', contour_level_selection_type='interval', contour_interval=interval, contour_reference_level=1000., contour_line_colour=color, contour_line_thickness=3, contour_label='on', contour_label_height=0.5, contour_highlight_colour=color, contour_highlight_thickness=4, contour_hilo="on", contour_hilo_height=0.6, contour_hi_colour='blue', contour_lo_colour='red', contour_hilo_window_size=5)
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)
def plot_to_file(field, file, size=10., projection=None, contour=None, grid=True, title=True, title_text='Title', width=400, ratio=1.0, area=None, metadata=None, text_format='(automatic)', position=0, format=None, preproc=None, legend=False, boxes=[]): plottable = as_plottable(field, position, metadata, preproc) if isinstance(plottable, list): _, in_file_area, metadata, what = plottable[0] grib = [g[0] for g in plottable] else: grib, in_file_area, metadata, what = plottable # print("XXXX PLOT", what, "metadata =>", metadata, # "contour => ", contour, # "area =>", area) if projection is None: if area is None: area = in_file_area if area: n, w, s, e = area projection = macro.mmap(subpage_upper_right_longitude=float(e), subpage_upper_right_latitude=float(n), subpage_lower_left_latitude=float(s), subpage_lower_left_longitude=float(w), subpage_map_projection='cylindrical') else: projection = macro.mmap(subpage_map_projection='cylindrical') if isinstance(projection, str): projection = PROJECTIONS[projection] contour = make_contour(contour, legend) if isinstance(grib, list) and not isinstance(contour, list): contour = [contour] * len(grib) base, ext = os.path.splitext(file) if format is None: format = ext[1:] output = macro.output(output_formats=[format], output_name_first_page_number='off', page_x_length=float(size), page_y_length=float(size) * ratio, super_page_x_length=float(size), super_page_y_length=float(size) * ratio, subpage_x_length=float(size), subpage_y_length=float(size) * ratio, subpage_x_position=0., subpage_y_position=0., output_width=width, page_frame='on', page_id_line='off', output_name=base) foreground = macro.mcoast(map_grid=ONOFF[grid], map_label='off') background = macro.mcoast(map_grid=ONOFF[grid], map_grid_colour='tan', map_label='off', map_coastline_land_shade='on', map_coastline_land_shade_colour='cream', map_coastline_colour='tan') data = [] data.append(background) if isinstance(grib, list): for g, c in zip(grib, contour): data.append(g) data.append(c) else: data.append(grib) data.append(contour) data.append(foreground) bb = float(len(boxes) + 1) for i, b in enumerate(boxes): inc = 0.1 n, w, s, e = b a = np.ones(((e - w + inc) / inc - 2, ((n - s + inc) / inc) - 2)) a = np.pad(a, 1, 'constant', constant_values=0) b = macro.minput(input_field=a, input_field_initial_latitude=float(n), input_field_latitude_step=-float(inc), input_field_initial_longitude=float(w), input_field_longitude_step=float(inc), input_metadata={}) data.append(b) # print a.shape d = "rgba(1,0,0,%g)" % (i / bb) c = macro.mcont( contour="off", contour_shade="on", contour_shade_method="area_fill", contour_shade_max_level_colour=d, contour_shade_min_level_colour=d, ) data.append(c) if title: data.append(macro.mtext()) if legend: width = 1000 height = 200 width_cm = float(width) / 40. height_cm = float(height) / 40. output = macro.output( output_formats=[format], output_name_first_page_number='off', # output_cairo_transparent_background='on', output_width=width, super_page_x_length=width_cm, super_page_y_length=height_cm, output_name=base, subpage_frame=False, page_frame=False, page_id_line=False) leg = macro.mlegend(legend_title="on", legend_title_font_size=1.1, legend_display_type="continuous", legend_title_text=title_text, legend_text_colour="charcoal", legend_box_mode="positional", legend_text_format=text_format, legend_box_x_position=0.00, legend_box_y_position=0.00, legend_box_x_length=width_cm, legend_box_y_length=height_cm, legend_box_blanking="on", legend_text_font_size="15%", legend_border=False, legend_border_colour="rgb(0.18,0.18,0.62)") with LOCK: # print(output, data[1], data[2], leg) macro.plot(output, data[1], data[2], leg) return data.append(macro.page()) # print(output, projection, data) with LOCK: macro.plot(output, projection, data)
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)
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)
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)
def geoplot(data): contour = macro.mcont(contour_automatic_setting="ecmwf", legend=True) legend = macro.mlegend(legend_display_type="continuous") return macro.plot(data, contour, macro.mcoast(), macro.mtext(), legend)
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)
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)
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)
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)
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)
data = magics.minput( input_field=values, input_field_initial_latitude=firstlat, input_field_latitude_step=steplat, input_field_initial_longitude=firstlon, input_field_longitude_step=steplon, input_mars_metadata=json.dumps(metadata), ) #Setting the field contour contour = magics.mcont(contour_shade="on", legend="on", legend_display_type="continuous", contour_highlight="off", contour_shade_method="area_fill", contour_shade_colour_direction="clockwise", contour_shade_colour_method="calculate", contour_shade_max_level_colour="red", contour_shade_min_level_colour=" blue") eccharts = magics.mcont(contour_automatic_setting="ecchart") #Setting the title title = magics.mtext(text_lines=["Using Grib API and arrays..."], text_colour="charcoal", text_font_size='0.8', text_justification='left') #Plot the map magics.plot(output, europe, data, eccharts, magics.mcoast(), title)
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)
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)
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)
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)
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)
# (C) Copyright 1996-2019 ECMWF. # # This software is licensed under the terms of the Apache Licence Version 2.0 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. # In applying this licence, ECMWF does not waive the privileges and immunities # granted to it by virtue of its status as an intergovernmental organisation nor # does it submit to any jurisdiction. import xarray as xr import numpy as np from Magics import macro as magics ref = "xarray2" ds = xr.open_dataset('netcdf3_t_z.nc') png = magics.output(output_name_first_page_number = "off", output_name = ref) data = magics.mxarray( xarray_dataset = ds, xarray_variable_name = "z", xarray_dimension_settings = { "time": np.datetime64('2017-10-13T00:00:00.000000000'), "level": 925}), contour = magics.mcont(contour_automatic_setting = "ecmwf") magics.plot(png, data, contour, magics.mcoast())
from Magics import macro as magics #name = 'magics' #Setting of the output file name output = magics.output(output_formats=['png'], output_name_first_page_number="off", output_name="mymagicsplot") #Import the data data = magics.mnetcdf(netcdf_filename="test.nc", netcdf_value_variable="aps") #Apply styling legend = magics.mlegend() contour = magics.mcont(contour_shade="on", contour_shade_method="area_fill", legend='on') coast = magics.mcoast() # Make the plot magics.plot(output, data, contour, coast, legend)