def get_mmap(name='CHINA', **kwargs): """Get magics map background. Args: name (str, optional): map region name. Defaults to 'China'. """ if name.upper == 'CHINA': area = magics.mmap( subpage_map_projection="cylindrical", subpage_lower_left_longitude=73.6667, subpage_lower_left_latitude=3.86667, subpage_upper_right_longitude=135.042, subpage_upper_right_latitude=53.5500, **kwargs) elif name.upper == 'CHINA_LAND': area = magics.mmap( subpage_map_projection="cylindrical", subpage_lower_left_longitude=73., subpage_lower_left_latitude=18., subpage_upper_right_longitude=136., subpage_upper_right_latitude=54., **kwargs) else: area = None return area
def xyplot(x, y, title="", where=None): #Setting the cartesian view projection = macro.mmap( subpage_map_projection='cartesian', subpage_x_automatic='on', subpage_y_automatic='on', ) #Vertical axis vertical = macro.maxis(axis_orientation="vertical", axis_grid="on", axis_grid_colour="grey", axis_grid_thickness=1, axis_grid_line_style="dot") #Horizontal axis horizontal = macro.maxis(axis_orientation="horizontal", axis_grid="on", axis_grid_colour="grey", axis_grid_thickness=1, axis_grid_line_style="dot") x[0] = x[0] * 1. input = macro.minput(input_x_values=x, input_y_values=y) graph = macro.mgraph(graph_line_colour="navy", graph_line_thickness=2) input = macro.minput(input_x_values=x, input_y_values=y) text = macro.mtext(text_lines=[title]) if where: where.clear_output() with where: display( macro.plot(projection, vertical, horizontal, input, graph, text)) else: return macro.plot(projection, vertical, horizontal, input, graph, text)
def test_issue83(self): with tempfile.TemporaryDirectory() as workdir: renderer = Renderer(workdir) with renderer.override_env(): from Magics import macro import Magics output = macro.output(output_formats=['png'], output_name=os.path.join( workdir, "issue83")) parts = [] parts.append( macro.mmap( **{ 'subpage_map_projection': 'mercator', 'subpage_lower_left_longitude': 5.1, 'subpage_lower_left_latitude': 43.0, 'subpage_upper_right_longitude': 15.0, 'subpage_upper_right_latitude': 47.5, 'subpage_map_vertical_longitude': 10.3, })) parts.append( macro.msymb( **{ 'symbol_type': 'marker', 'symbol_marker_index': 15, 'legend': 'off', 'symbol_colour': 'black', 'symbol_height': 0.28 })) has_issue83 = False try: macro.plot(output, *parts) except Magics.Magics.MagicsError as e: if "ProjP: cannot create crs to crs" in str(e): has_issue83 = True else: raise if has_issue83: self.fail( "this system seems to have trouble locating proj.db. See" " https://github.com/ARPA-SIMC/arkimaps/issues/83 or" " https://www.enricozini.org/blog/2021/debian/an-educational-debugging-session/" " for details, and set PROJ_LIB=/usr/share/proj (or the" " equivalent path in your system) as a workaround")
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)
for n in ('LD_LIBRARY_PATH', 'DYLD_LIBRARY_PATH'): os.environ[n] = '/opt/ecmwf/magics/lib:/Users/baudouin/build/magics/lib' # os.environ['MAGPLUS_HOME'] = '/Users/baudouin/build/magics' sys.path.append('/opt/ecmwf/magics/lib/python2.7/site-packages') from Magics import macro LOCK = threading.Lock() PROJECTIONS = { "global": macro.mmap(subpage_upper_right_longitude=180.00, subpage_upper_right_latitude=90.00, subpage_lower_left_latitude=-90.00, subpage_lower_left_longitude=-180.0, subpage_map_projection='cylindrical'), "uk": macro.mmap(subpage_upper_right_longitude=1.5, subpage_upper_right_latitude=60.00, subpage_lower_left_latitude=44.5, subpage_lower_left_longitude=-14.0, subpage_map_projection='cylindrical'), "france": macro.mmap(subpage_upper_right_longitude=10.5, subpage_upper_right_latitude=52.5, subpage_lower_left_latitude=37.0, subpage_lower_left_longitude=-5.0, subpage_map_projection='cylindrical'), }
def legend(self, context, output, format, height, layer, style, version, width, transparent): try: magics_format = MAGICS_OUTPUT_TYPES[format] except KeyError: raise errors.InvalidFormat(format) output_fname = output.target(magics_format) path, _ = os.path.splitext(output_fname) with LOCK: # Magics is talking in cm. width_cm = float(width) / 40.0 height_cm = float(height) / 40.0 args = [ macro.output( output_formats=[magics_format], output_name_first_page_number="off", output_cairo_transparent_background=transparent, output_width=width, output_name=path, ), macro.mmap( subpage_frame="off", page_x_length=width_cm, page_y_length=height_cm, super_page_x_length=width_cm, super_page_y_length=height_cm, subpage_x_length=width_cm, subpage_y_length=height_cm, subpage_x_position=0.0, subpage_y_position=0.0, output_width=width, page_frame="off", page_id_line="off", ), ] contour = layer.style(style, ) args += layer.render(context, macro, contour, { "legend": "on", "contour_legend_only": True }) legend_font_size = "25%" if width_cm < height_cm: legend_font_size = "5%" legend_title = layer.title if hasattr(layer, legend_title): legend_title = layer.legend_title legend = macro.mlegend( legend_title="on", legend_title_text=legend_title, legend_display_type="continuous", legend_box_mode="positional", legend_only=True, 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=not transparent, legend_text_font_size=legend_font_size, legend_text_colour="white", ) # self.log.debug('plot(): Calling macro.plot(%s)', args) try: macro.plot(*args, legend) except Exception as e: self.log.exception("Magics error: %s", e) raise self.log.debug("plot(): Size of %s: %s", output_fname, os.stat(output_fname).st_size) return output_fname
def plot( self, context, output, bbox, crs, format, height, layers, styles, version, width, transparent, _macro=False, bgcolor=None, elevation=None, exceptions=None, time=None, ): lon_vertical = 0.0 if crs.startswith("EPSG:32661:"): crs_name = "polar_north" lon_vertical = float(crs.split(":")[2]) elif crs.startswith("EPSG:32761:"): crs_name = "polar_south" lon_vertical = float(crs.split(":")[2]) elif crs == "EPSG:32761": crs_name = "EPSG:32761" else: try: crs = _CRSS[crs] crs_name = crs.name except KeyError: raise ValueError("Unsupported CRS '{}'".format(crs)) try: magics_format = MAGICS_OUTPUT_TYPES[format] except KeyError: raise errors.InvalidFormat(format) output_fname = output.target(magics_format) path, _ = os.path.splitext(output_fname) with LOCK: min_x, min_y, max_x, max_y = bbox # Magics is talking in cm. width_cm = width / 40.0 height_cm = height / 40.0 macro.silent() coordinates_system = {"EPSG:4326": "latlon"} map_params = { "subpage_map_projection": crs_name, "subpage_lower_left_latitude": min_y, "subpage_lower_left_longitude": min_x, "subpage_upper_right_latitude": max_y, "subpage_upper_right_longitude": max_x, "subpage_coordinates_system": coordinates_system.get(crs_name, "projection"), "subpage_frame": "off", "page_x_length": width_cm, "page_y_length": height_cm, "super_page_x_length": width_cm, "super_page_y_length": height_cm, "subpage_x_length": width_cm, "subpage_y_length": height_cm, "subpage_x_position": 0.0, "subpage_y_position": 0.0, "output_width": width, "page_frame": "off", "skinny_mode": "on", "page_id_line": "off", } # add extra settings for polar stereographic projection when # vertical longitude is not 0 if crs_name in ["polar_north", "polar_south"]: map_params["subpage_map_vertical_longitude"] = lon_vertical if crs_name in ["polar_north"]: map_params["subpage_map_true_scale_north"] = 90 if crs_name in ["polar_south"]: map_params["subpage_map_true_scale_south"] = -90 args = [ macro.output( output_formats=[magics_format], output_name_first_page_number="off", output_cairo_transparent_background=transparent, output_width=width, output_name=path, ), macro.mmap(**map_params), ] for layer, style in zip(layers, styles): style = layer.style(style) args += layer.render(context, macro, style) if _macro: return ( "text/x-python", self.macro_text( args, output.target(".py"), getattr(context, "data_url", None), layers, styles, ), ) # self.log.debug('plot(): Calling macro.plot(%s)', args) try: macro.plot(*args) except Exception as e: self.log.exception("Magics error: %s", e) raise self.log.debug("plot(): Size of %s: %s", output_fname, os.stat(output_fname).st_size) return format, output_fname
#!/usr/local/bin/python import Magics.macro as magics import gribapi as grib import numpy as numpy import json #Setting of the output file name output = magics.output(output_formats=['png'], output_name='mars-array') #Setting the projection attributes europe = magics.mmap(subpage_lower_left_longitude=-20., subpage_upper_right_longitude=20.00, subpage_upper_right_latitude=30., subpage_map_projection="cylindrical", subpage_lower_left_latitude=70.) file = open('z500.grb') #Getting the first message from the file field = grib.grib_new_from_file(file) nj = grib.grib_get(field, "Nj") ni = grib.grib_get(field, "Ni") metadata = { "paramId": grib.grib_get(field, "paramId"), "units": grib.grib_get(field, "units"), "typeOfLevel": grib.grib_get(field, "typeOfLevel"), "marsType": grib.grib_get(field, "marsType"), "marsClass": grib.grib_get(field, "marsClass"),
def plot(self, context, output, bbox, crs, format, height, layers, styles, version, width, transparent, _macro=False, bgcolor=None, elevation=None, exceptions=None, time=None, ): try: crs = _CRSS[crs] except KeyError: raise ValueError("Unsupported CRS '{}'".format(crs)) try: magics_format = MAGICS_OUTPUT_TYPES[format] except KeyError: raise errors.InvalidFormat(format) output_fname = output.target(magics_format) print("OUTPUT", output_fname) path, _ = os.path.splitext(output_fname) with LOCK: min_x, min_y, max_x, max_y = bbox # Magics is talking in cm. width_cm = width / 40. height_cm = height / 40. macro.silent() args = [ macro.output(output_formats=[magics_format], output_name_first_page_number='off', output_cairo_transparent_background=transparent, output_width=width, output_name=path), macro.mmap(subpage_map_projection=crs.name, subpage_lower_left_latitude=min_x, subpage_lower_left_longitude=min_y, subpage_upper_right_latitude=max_x, subpage_upper_right_longitude=max_y, subpage_frame='off', page_x_length=width_cm, page_y_length=height_cm, super_page_x_length=width_cm, super_page_y_length=height_cm, subpage_x_length=width_cm, subpage_y_length=height_cm, subpage_x_position=0., subpage_y_position=0., output_width=width, page_frame='off', page_id_line='off',), ] for layer, style in zip(layers, styles): style = layer.style(style) args += layer.render(context, macro, style) if _macro: return self.macro_text(args, output.target('.py'), getattr(context, 'data_url', None), layers, styles) # self.log.debug('plot(): Calling macro.plot(%s)', args) try: macro.plot(*args) except Exception as e: self.log.exception('Magics error: %s', e) raise self.log.debug('plot(): Size of %s: %s', output_fname, os.stat(output_fname).st_size) return output_fname
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
with open(args.json_fields) as json_data: # this should/could be set as "json.load" for pyhton3 mm_fields = json_load_byteified(json_data) with open(args.json_coasts) as json_data: # this should/could be set as "json.load" for pyhton3 mm_coasts = json_load_byteified(json_data) print("filtering grib: " + args.grib) gb_met = group_grib_metadata_by_fstep(args.grib, args.product, args.level) os.environ["MAGPLUS_QUIET"] = "true" area = mm.mmap(**mm_coasts["mmap"]) bg = mm.mcoast(**mm_coasts["background"]) fg = mm.mcoast(**mm_coasts["foreground"]) mm_coasts["mlegend"]["legend_title_text"] = units legend = mm.mlegend(**mm_coasts["mlegend"]) for k, v in gb_met.iteritems(): print("processing: " + args.product + " +" + str(k).zfill(2)) input_data = mm.mgrib( grib_input_file_name = args.grib, grib_field_position = v, grib_automatic_scaling = 'off', grib_scaling_factor = scaling_factor, grib_scaling_offset = scaling_offset,
input_y_values=highs, input_y2_values=extremes) extreme_input = mag.minput(input_x_type='date', input_date_x_values=min_max_dates, input_date_x2_values=min_max_dates, input_y_values=extremes, input_y2_values=[max_y, max_y]) projection = mag.mmap(super_page_x_length=width + 3, super_page_y_length=height + 4, subpage_x_position=2.2, subpage_y_position=2.8, subpage_x_length=width, subpage_y_length=height, subpage_map_projection='cartesian', subpage_x_axis_type='date', subpage_y_axis_type='regular', subpage_x_date_min=min_date, subpage_x_date_max=max_date, subpage_y_min=min_y, subpage_y_max=max_y, page_id_line="off") mag.plot( myoutput, projection, vertical, horizontal, low_input, low_graph, medium_input,
def plot_in_magics_boxplot(path, date, pointname, var, meta, y_axis_range, filename, lead_times,\ data_percentiles_eu_eps, point_values_eu_det): run_time = datetime.datetime(date['year'], date['month'], date['day'], date['hour']) if var == 't_2m' or var == 'wind_10m' or var == 'mslp' or var == 'clct': lead_times = [-1.0 * x for x in lead_times] elif var == 'prec_rate' or var == 'direct_rad' or var == 'diffuse_rad': lead_times = [-1.0 * x for x in lead_times] time_start = -123. time_end = 3. output_layout = magics.output( output_formats=['png'], output_name=path['base'] + path['plots'] + filename, output_name_first_page_number='off', output_width=1500, super_page_x_length=15.0, super_page_y_length=6.0, ) page_layout = magics.page( layout='positional', page_x_position=0.0, page_y_position=0.0, page_x_length=15.0, page_y_length=6.0, page_id_line='off', ) coord_system = magics.mmap( subpage_map_projection='cartesian', subpage_x_min=time_start, subpage_x_max=time_end, subpage_y_min=y_axis_range['min'], subpage_y_max=y_axis_range['max'], subpage_x_position=1.0, subpage_y_position=0.48, subpage_x_length=13.7, subpage_y_length=5.0, ) vertical_axis = magics.maxis( axis_orientation='vertical', axis_grid='on', axis_tick_label_height=0.7, axis_grid_thickness=1, axis_grid_line_style='dash', axis_tick_interval=y_axis_range['interval'], ) horizontal_axis = magics.maxis( axis_tick_interval=24, axis_tick_label='off', axis_title='off', ) ######################################################################## ##### icon-eu-eps ##### bar_minmax_eu = magics.mgraph( graph_type='bar', graph_bar_colour='black', graph_bar_width=0.05, ) data_minmax_eu = magics.minput( input_x_values=lead_times, input_y_values=data_percentiles_eu_eps[:, 0], input_y2_values=data_percentiles_eu_eps[:, 6], ) bar1090_eu = magics.mgraph( graph_type='bar', graph_bar_colour='rgb(0, 150, 130)', # KIT turquoise graph_bar_width=0.5, ) data1090_eu = magics.minput( input_x_values=lead_times, input_y_values=data_percentiles_eu_eps[:, 1], input_y2_values=data_percentiles_eu_eps[:, 5], ) bar2575_eu = magics.mgraph( graph_type='bar', graph_bar_colour='rgb(0, 150, 130)', # KIT turquoise graph_bar_width=1.0, legend='on', legend_user_text='<font colour="black"> ICON-EU-EPS (20km)</font>') data2575_eu = magics.minput( input_x_values=lead_times, input_y_values=data_percentiles_eu_eps[:, 2], input_y2_values=data_percentiles_eu_eps[:, 4], ) bar_median_eu = magics.mgraph( graph_type='bar', graph_bar_colour='black', graph_bar_width=1.0, ) data_median_eu = magics.minput( input_x_values=lead_times, input_y_values=data_percentiles_eu_eps[:, 3] - (y_axis_range['max'] - y_axis_range['min']) / 400., input_y2_values=data_percentiles_eu_eps[:, 3] + (y_axis_range['max'] - y_axis_range['min']) / 400., ) ##### icon-eu ##### bar_eu_det = magics.mgraph( graph_line='off', graph_symbol='on', graph_symbol_marker_index=15, graph_symbol_height=0.2, graph_symbol_colour='white', graph_symbol_outline='on', graph_symbol_outline_colour='black', graph_symbol_outline_thickness=3, legend='on', legend_user_text='<font colour="black"> ICON-EU-DET (6.5km)</font>') data_eu_det = magics.minput( input_x_values=lead_times, input_y_values=point_values_eu_det[:], ) ######################################################################## analysis_line = magics.mgraph( graph_line_colour='rgb(0, 242, 209)', # bright turquoise graph_line_thickness=3, legend='on', legend_user_text= '<font colour="black"> ICON-EU-DET (6.5km), 0h-Forecast</font>') analysis_value = magics.minput( input_x_values=[time_start, time_end], input_y_values=[y_axis_range['analysis'], y_axis_range['analysis']]) if var == 't_2m' or var == 'mslp': ref_th = 5 else: ref_th = 0 ref_level_line = magics.mgraph( graph_line_colour='black', graph_line_thickness=ref_th, ) ref_level_value = magics.minput( input_x_values=[time_start, time_end], input_y_values=[y_axis_range['ref'], y_axis_range['ref']]) ######################################################################## if var == 'direct_rad' or var == 'diffuse_rad': long_title_adjustment = 0.7 else: long_title_adjustment = 0.0 title_str = '{} in {}'.format(meta['var'], pointname) title = magics.mtext( text_line_1=title_str, text_font_size=1.0, text_colour='black', text_justification='centre', text_mode='positional', text_box_x_position=5.3 + long_title_adjustment, text_box_y_position=5.45, text_box_x_length=5.0, text_box_y_length=0.7, ) ######################################################################## timeshift = get_timeshift() initial_time = run_time.hour + timeshift if timeshift == 1: time_code = 'CET' # UTC+1 elif timeshift == 2: time_code = 'CEST' # UTC+2 if var == 'prec_rate' or var == 'direct_rad' or var == 'diffuse_rad': initial_time2 = initial_time + 6 if initial_time2 == 26: initial_time2 = 2 init_time_str = 'Forecast time: {}, {:02}-{:02}{}'.format(\ run_time.strftime('%a., %d %b. %Y'), initial_time, initial_time2, time_code) else: init_time_str = 'Forecast time: {}, {:02}{}'.format(\ run_time.strftime('%a., %d %b. %Y'), initial_time, time_code) init_time = magics.mtext( text_line_1=init_time_str, text_font_size=0.8, text_colour='black', text_justification='left', text_mode='positional', text_box_x_position=1.0, text_box_y_position=5.45, text_box_x_length=1.5, text_box_y_length=0.5, ) unit_str = meta['units'] unit = magics.mtext( text_line_1=unit_str, text_font_size=0.8, text_colour='black', text_justification='right', text_mode='positional', text_box_x_position=0.31, text_box_y_position=5.55, text_box_x_length=0.5, text_box_y_length=0.5, ) if var == 't_2m': unit_special_str = 'o' correction = -0.12 elif var == 'direct_rad' or var == 'diffuse_rad': unit_special_str = '2' correction = 0.06 else: unit_special_str = '' correction = 0 unit_special = magics.mtext( text_line_1=unit_special_str, text_font_size=0.4, text_colour='black', text_justification='right', text_mode='positional', text_box_x_position=0.31 + correction, text_box_y_position=5.55 + 0.14, text_box_x_length=0.5, text_box_y_length=0.5, ) logo = magics.mimport( import_file_name=path['base'] + 'plots/logo/' + 'w2w_icon.png', import_x_position=13.74, import_y_position=5.52, import_height=0.474, import_width=1.000, ) legend = magics.mlegend( legend_text_font_size=0.8, legend_box_mode='positional', legend_box_x_position=5.0, legend_box_y_position=5.03, legend_box_x_length=9.0, legend_box_y_length=0.5, legend_entry_text_width=90, ) time_labels = ['-120h', '-96h', '-72h', '-48h', '-24h', '0h'] spacing = 2.61 left_pos = 0.58 date1_label = magics.mtext( text_line_1=time_labels[0], text_font_size=0.8, text_colour='black', text_justification='centre', text_mode='positional', text_box_x_position=left_pos + 0 * spacing, text_box_y_position=0.0, text_box_x_length=1.5, text_box_y_length=0.3, text_border='off', ) date2_label = magics.mtext( text_line_1=time_labels[1], text_font_size=0.8, text_colour='black', text_justification='centre', text_mode='positional', text_box_x_position=left_pos + 1 * spacing, text_box_y_position=0.0, text_box_x_length=1.5, text_box_y_length=0.3, text_border='off', ) date3_label = magics.mtext( text_line_1=time_labels[2], text_font_size=0.8, text_colour='black', text_justification='centre', text_mode='positional', text_box_x_position=left_pos + 2 * spacing, text_box_y_position=0.0, text_box_x_length=1.5, text_box_y_length=0.3, text_border='off', ) date4_label = magics.mtext( text_line_1=time_labels[3], text_font_size=0.8, text_colour='black', text_justification='centre', text_mode='positional', text_box_x_position=left_pos + 3 * spacing, text_box_y_position=0.0, text_box_x_length=1.5, text_box_y_length=0.3, text_border='off', ) date5_label = magics.mtext( text_line_1=time_labels[4], text_font_size=0.8, text_colour='black', text_justification='centre', text_mode='positional', text_box_x_position=left_pos + 4 * spacing, text_box_y_position=0.0, text_box_x_length=1.5, text_box_y_length=0.3, text_border='off', ) date6_label = magics.mtext( text_line_1=time_labels[5], text_font_size=0.8, text_colour='black', text_justification='centre', text_mode='positional', text_box_x_position=left_pos + 5 * spacing, text_box_y_position=0.0, text_box_x_length=1.5, text_box_y_length=0.3, text_border='off', ) magics.context.silent = True magics.plot( output_layout, page_layout, coord_system, vertical_axis, horizontal_axis, ref_level_value, ref_level_line, data_minmax_eu, bar_minmax_eu, data1090_eu, bar1090_eu, data2575_eu, bar2575_eu, data_median_eu, bar_median_eu, data_eu_det, bar_eu_det, analysis_value, analysis_line, title, init_time, unit, unit_special, logo, legend, date1_label, date2_label, date3_label, date4_label, date5_label, date6_label, ) return
import Magics.macro as magics # Setting the projection projection = magics.mmap(subpage_map_projection="lambert", subpage_lower_left_latitude=-0.00, subpage_lower_left_longitude=-80.00, subpage_upper_right_latitude=70.00, subpage_upper_right_longitude=160.00, subpage_map_area_definition="corners", page_id_line="off") # Defining the coastlines coast = magics.mcoast(map_coastline_resolution="automatic", map_coastline_colour="tan", map_coastline_land_shade="on", map_coastline_land_shade_colour="cream", map_grid="on", map_grid_line_style="dot", map_grid_colour="tan") png = magics.output(output_formats=['png'], output_name_first_page_number="off", output_name="my_png") magics.plot(png, projection, coast)