Download source and data
De-accumulate Precipitation Forecast Example
#Metview Macro # **************************** LICENSE START *********************************** # # Copyright 2020 ECMWF. This software is distributed under the terms # of the Apache License version 2.0. In applying this license, ECMWF does not # waive the privileges and immunities granted to it by virtue of its status as # an Intergovernmental Organization or submit itself to any jurisdiction. # # ***************************** LICENSE END ************************************ # # getting data use_mars = 0 # 0 or 1 # getting forecast data from MARS if use_mars = 1 then prec = retrieve( type : "fc", levtype : "sfc", param : "tp", date : 20190809, time : 0, step : [0,12,24,36,48], area : [12,110,40,148], grid : [0.1,0.1] ) # read data from file else prec =read("lekima_prec.grib") end if # de-accumulate precipitation by subtracting consecutive steps. # The result is accumulated precipitation for 12 h intervals num = count(prec) prec = prec[2,num] - prec[1,num-1] # define contour_shading. To enable the m->mm units conversion # for contouring we need to enable "grib_scaling_of_derived_fields" # since prec is now regarded as derived (we performed a grid operation # on it) by Metview prec_shade = mcont( contour_automatic_setting : "style_name", contour_style_name : "sh_blured_f1t100lst", legend : "on", grib_scaling_of_derived_fields : "on" ) # define coastlines coastlines = mcoast( map_coastline_colour : "charcoal", map_coastline_thickness : 2, map_coastline_land_shade : "on", map_coastline_land_shade_colour : "RGB(0.5569,0.5569,0.5569)", map_coastline_sea_shade : "on", map_coastline_sea_shade_colour : "RGB(0.8941,0.8941,0.8941)" ) # define geographical view view = geoview( map_area_definition : "corners", area : [12,110,40,148], coastlines : coastlines ) # create a 2x2 plot layout with the defined geoview dw = plot_superpage(pages: mvl_regular_layout(view,2,2,1,1,[5,100,15,100])) # define title title = mtext(text_line_1: "Param: <grib_info key='shortName'/> [12h] Run: <grib_info key='base-date' format='%Y%m%d %HUTC'/> Step: <grib_info key='step'/>h", text_font_size: 0.4) # define legend legend = mlegend(legend_text_font_size: 0.3) # define output setoutput(pdf_output(output_name : 'deaccumulate_precip_fc')) # generate plot for i=1 to 4 do plot(dw[i], prec[i], prec_shade, legend, title) end for
De-accumulate Precipitation Forecast Example
""" De-accumulate Precipitation Forecast ====================================== """ # **************************** LICENSE START *********************************** # # Copyright 2020 ECMWF. This software is distributed under the terms # of the Apache License version 2.0. In applying this license, ECMWF does not # waive the privileges and immunities granted to it by virtue of its status as # an Intergovernmental Organization or submit itself to any jurisdiction. # # ***************************** LICENSE END ************************************ # import metview as mv # getting data use_mars = False # getting forecast data from MARS if use_mars: prec = mv.retrieve( type="fc", levtype="sfc", param="tp", date=20190809, time=0, step=[0, 12, 24, 36, 48], area=[12, 110, 40, 148], grid=[0.1, 0.1], ) # read data from file else: prec = mv.read("lekima_prec.grib") # de-accumulate precipitation by subtracting consecutive steps. # The result is accumulated precipitation for 12 h intervals num = len(prec) prec = prec[1:num] - prec[0 : num - 1] # define contour_shading. To enable the m->mm units conversion # for contouring we need to enable "grib_scaling_of_derived_fields" # since prec is now regarded as derived (we performed a grid operation # on it) by Metview prec_shade = mv.mcont( contour_automatic_setting="style_name", contour_style_name="sh_blured_f1t100lst", legend="on", grib_scaling_of_derived_fields="on", ) # define coastlines coastlines = mv.mcoast( map_coastline_colour="charcoal", map_coastline_thickness=2, map_coastline_land_shade="on", map_coastline_land_shade_colour="RGB(0.5569,0.5569,0.5569)", map_coastline_sea_shade="on", map_coastline_sea_shade_colour="RGB(0.8941,0.8941,0.8941)", ) # define geographical view view = mv.geoview( map_area_definition="corners", area=[12, 110, 40, 148], coastlines=coastlines ) # create a 2x2 plot layout with the defined geoview dw = mv.plot_superpage(pages=mv.mvl_regular_layout(view, 2, 2, 1, 1, [5, 100, 15, 100])) # define title title = mv.mtext( text_line_1="Param: <grib_info key='shortName'/> [12h] Run: <grib_info key='base-date' format='%Y%m%d %HUTC'/> Step: +<grib_info key='step'/>h", text_font_size=0.4, ) # define legend legend = mv.mlegend(legend_text_font_size=0.3) # define output mv.setoutput(mv.pdf_output(output_name="deaccumulate_precip_fc")) # generate plot mv.plot( dw[0], prec[0], prec_shade, legend, title, dw[1], prec[1], prec_shade, legend, title, dw[2], prec[2], prec_shade, legend, title, dw[3], prec[3], prec_shade, legend, title, )