def test_visdef_object(): vd = Visdef( "msymb", { "symbol_type": "text", "symbol_table_mode": "advanced", "symbol_advanced_table_text_font_colour": "black", }, ) # clone v = vd.clone() assert v.verb == vd.verb assert v.params == vd.params assert id(v) != id(vd) assert id(v.params) != id(vd.params) # change vd.change("msymb", "symbol_advanced_table_text_font_colour", "red") assert vd.params["symbol_advanced_table_text_font_colour"] == "red" vd.change("mcont", "symbol_advanced_table_text_font_colour", "blue") assert vd.params["symbol_advanced_table_text_font_colour"] == "red" # from request r = mv.msymb({ "symbol_type": "text", "symbol_table_mode": "advanced", "symbol_advanced_table_text_font_colour": "black", }) v = Visdef.from_request(r) assert v.verb == vd.verb for k, v in v.params.items(): assert r[k.upper()].lower() == v.lower()
def plot_obs_freq(predictor_matrix, code): coastline = mv.mcoast(map_coastline_thickness=2, map_boundaries="on", map_coastline_colour="chestnut") symbol = mv.msymb( legend="on", symbol_type="marker", symbol_table_mode="on", symbol_outline="on", symbol_min_table=[1, 2, 5, 10, 15, 20, 25, 30], symbol_max_table=[2, 5, 10, 15, 20, 25, 30, 100000], symbol_colour_table=[ "RGB(0.7020,0.7020,0.7020)", "RGB(0.4039,0.4039,0.4039)", "blue", "RGB(0.4980,1.0000,0.0000)", "RGB(1.0000,0.8549,0.0000)", "orange", "red", "magenta", ], symbol_marker_table=15, symbol_height_table=0.3, ) legend = mv.mlegend( legend_text_font="arial", legend_text_font_size=0.35, legend_entry_plot_direction="row", legend_box_blanking="on", legend_entry_text_width=50, ) title = mv.mtext( text_line_count=4, text_line_1= "OBS Frequency", # To sostitute with "FE" values when relevant. text_line_2=f"WT Code = {code}", text_line_4=" ", text_font="arial", text_font_size=0.4, ) df = predictor_matrix[["LonOBS", "LatOBS", "OBS"]] grouped_df = df.groupby(["LatOBS", "LonOBS"], as_index=False).count() geo = mv.create_geo(len(grouped_df), "xyv") geo = mv.set_latitudes(geo, grouped_df["LatOBS"].to_numpy(dtype=np.float)) geo = mv.set_longitudes(geo, grouped_df["LonOBS"].to_numpy(dtype=np.float)) geo = mv.set_values(geo, grouped_df["OBS"].to_numpy(dtype=np.float)) with NamedTemporaryFile(delete=False, suffix=".pdf") as pdf: pdf_obj = mv.pdf_output(output_name=pdf.name.replace(".pdf", "")) mv.setoutput(pdf_obj) mv.plot(coastline, symbol, legend, title, geo) return pdf.name
def plot_std(predictor_matrix, code): coastline = mv.mcoast(map_coastline_thickness=2, map_boundaries="on", map_coastline_colour="chestnut") symbol = mv.msymb( legend="on", symbol_type="marker", symbol_table_mode="on", symbol_outline="on", symbol_min_table=[0, 0.0001, 0.5, 1, 2, 5], symbol_max_table=[0.0001, 0.5, 1, 2, 5, 1000], symbol_colour_table=[ "RGB(0.7020,0.7020,0.7020)", "RGB(0.2973,0.2973,0.9498)", "RGB(0.1521,0.6558,0.5970)", "RGB(1.0000,0.6902,0.0000)", "red", "RGB(1.0000,0.0000,1.0000)", ], symbol_marker_table=15, symbol_height_table=0.3, ) legend = mv.mlegend( legend_text_font="arial", legend_text_font_size=0.35, legend_entry_plot_direction="row", legend_box_blanking="on", legend_entry_text_width=50, ) error = "FER" if "FER" in predictor_matrix.columns else "FE" title = mv.mtext( text_line_count=4, text_line_1=f"{error} Standard Deviation", text_line_2=f"WT Code = {code}", text_line_4=" ", text_font="arial", text_font_size=0.4, ) df = predictor_matrix[["LonOBS", "LatOBS", error]] grouped_df = df.groupby(["LatOBS", "LonOBS"])[error].mean().reset_index() geo = mv.create_geo(len(grouped_df), "xyv") geo = mv.set_latitudes(geo, grouped_df["LatOBS"].to_numpy(dtype=np.float)) geo = mv.set_longitudes(geo, grouped_df["LonOBS"].to_numpy(dtype=np.float)) geo = mv.set_values(geo, grouped_df[error].to_numpy(dtype=np.float)) with NamedTemporaryFile(delete=False, suffix=".pdf") as pdf: pdf_obj = mv.pdf_output(output_name=pdf.name.replace(".pdf", "")) mv.setoutput(pdf_obj) mv.plot(coastline, symbol, legend, title, geo) return pdf.name
def plot_avg(predictor_matrix, code): coastline = mv.mcoast(map_coastline_thickness=2, map_boundaries="on", map_coastline_colour="chestnut") symbol = mv.msymb( legend="on", symbol_type="marker", symbol_table_mode="on", symbol_outline="on", symbol_min_table=[-1, -0.25, 0.25, 2], symbol_max_table=[-0.025, 0.25, 2, 1000], symbol_colour_table=[ "RGB(0.0000,0.5490,0.1882)", "black", "RGB(1.0000,0.6902,0.0000)", "red", ], symbol_marker_table=15, symbol_height_table=0.3, ) legend = mv.mlegend( legend_text_font="arial", legend_text_font_size=0.35, legend_entry_plot_direction="row", legend_box_blanking="on", legend_entry_text_width=50, ) error = "FER" if "FER" in predictor_matrix.columns else "FE" title = mv.mtext( text_line_count=4, text_line_1=f"{error} Mean", text_line_2=f"WT Code = {code}", text_line_4=" ", text_font="arial", text_font_size=0.4, ) df = predictor_matrix[["LonOBS", "LatOBS", error]] grouped_df = df.groupby(["LatOBS", "LonOBS"])[error].mean().reset_index() geo = mv.create_geo(len(grouped_df), "xyv") geo = mv.set_latitudes(geo, grouped_df["LatOBS"].to_numpy(dtype=np.float)) geo = mv.set_longitudes(geo, grouped_df["LonOBS"].to_numpy(dtype=np.float)) geo = mv.set_values(geo, grouped_df[error].to_numpy(dtype=np.float)) return plot_geo(geo, coastline, symbol, legend, title)
def test_definitions(): mcont_def = mv.mcont({'legend': True}) msymb_def = mv.msymb({'symbol_type': 'marker'}) mcoast_def = mv.mcoast({'map_coastline_land_shade': True}) mobs_def = mv.mobs({'obs_temperature': False}) mtext_def = mv.mtext({'text_font_size': '0.80'}) geoview_def = mv.geoview({'map_projection': 'polar_stereographic'}) ps_output_def = mv.ps_output({'output_name': 'test'}) assert mcont_def['LEGEND'] == 'ON' assert msymb_def['SYMBOL_TYPE'] == 'MARKER' assert mcoast_def['MAP_COASTLINE_LAND_SHADE'] == 'ON' assert mobs_def['OBS_TEMPERATURE'] == 'OFF' assert mtext_def['TEXT_FONT_SIZE'] == 0.8 assert geoview_def['MAP_PROJECTION'] == 'POLAR_STEREOGRAPHIC' assert ps_output_def['OUTPUT_NAME'] == 'test'
obs_plotting = mv.mobs( obs_temperature=False, obs_cloud=False, obs_low_cloud=False, obs_dewpoint_colour="purple", ) mv.setoutput(mv.png_output(output_width=1200, output_name="./obsplot2")) mv.plot(area_view, obs, obs_plotting) # ALTERNATIVELY, if we don't want to plot the whole observations, but instead want to # extract a specific parameter from the BUFR messages, then we use the Observation Filter # as shown here: # dewpoint_t is a 'geopoints' variable dewpoint_t = mv.obsfilter(output="geopoints", parameter="012006", data=obs) # add an optional Symbol Plotting definition to get nice coloured circles # at each point symb_visdef = mv.msymb( legend=True, symbol_type="marker", symbol_table_mode="advanced", symbol_advanced_table_max_level_colour="red", symbol_advanced_table_min_level_colour="blue", symbol_advanced_table_colour_direction="clockwise", ) mv.setoutput(mv.png_output(output_width=1200, output_name="./obsplot3")) mv.plot(area_view, dewpoint_t, symb_visdef)
# define a view over the area of interest area_view = mv.geoview(map_area_definition="corners", area=[45.83, -13.87, 62.03, 8.92]) t2m_grib = mv.read("./t2m_grib.grib") obs_3day = mv.read("./obs_3day.bufr") t2m_gpt = mv.obsfilter(parameter="012004", output="geopoints", data=obs_3day) diff = t2m_grib - t2m_gpt diff_symb = mv.msymb( legend=True, symbol_type="marker", symbol_table_mode="advanced", ) mv.setoutput(mv.png_output(output_width=1000, output_name="./obsdiff1")) mv.plot(area_view, diff, diff_symb) # Extract geopoints that are hotter by 1 deg or more # hotter = mv.filter(diff, diff >= 1) hotter = diff.filter(diff >= 1) # Extract geopoints that are colder by 1 deg or more # colder = mv.filter(diff, diff <= -1) colder = diff.filter(diff <= -1) # Get geopoints that are within +/-1
# define a view over the area of interest area_view = mv.geoview(map_area_definition='corners', area=[45.83, -13.87, 62.03, 8.92]) t2m_grib = mv.read('./t2m_grib.grib') obs_3day = mv.read('./obs_3day.bufr') t2m_gpt = mv.obsfilter(parameter='012004', output='geopoints', data=obs_3day) diff = t2m_grib - t2m_gpt diff_symb = mv.msymb( legend=True, symbol_type='marker', symbol_table_mode='advanced', ) mv.setoutput(mv.png_output(output_width=1000, output_name='./obsdiff1')) mv.plot(area_view, diff, diff_symb) # Extract geopoints that are hotter by 1 deg or more #hotter = mv.filter(diff, diff >= 1) hotter = diff.filter(diff >= 1) # Extract geopoints that are colder by 1 deg or more #colder = mv.filter(diff, diff <= -1) colder = diff.filter(diff <= -1) # Get geopoints that are within +/-1
mv.plot(area_view, obs) # ALTERNATIVELY, add an Observations Plotting visual definition obs_plotting = mv.mobs(obs_temperature=False, obs_cloud=False, obs_low_cloud=False, obs_dewpoint_colour='purple') mv.setoutput(mv.png_output(output_width=1200, output_name='./obsplot2')) mv.plot(area_view, obs, obs_plotting) # ALTERNATIVELY, if we don't want to plot the whole observations, but instead want to # extract a specific parameter from the BUFR messages, then we use the Observation Filter # as shown here: # dewpoint_t is a 'geopoints' variable dewpoint_t = mv.obsfilter(output="geopoints", parameter='012006', data=obs) # add an optional Symbol Plotting definition to get nice coloured circles # at each point symb_visdef = mv.msymb(legend=True, symbol_type='marker', symbol_table_mode='advanced', symbol_advanced_table_max_level_colour='red', symbol_advanced_table_min_level_colour='blue', symbol_advanced_table_colour_direction='clockwise') mv.setoutput(mv.png_output(output_width=1200, output_name='./obsplot3')) mv.plot(area_view, dewpoint_t, symb_visdef)