ecmwf / magics-python

Python interface to Magics meteorological plotting package
Apache License 2.0
49 stars 12 forks source link

Generating a wind flags plot using ERA5 GRIBS data #24

Closed winash12 closed 4 years ago

winash12 commented 4 years ago

I am trying to generate a wind flags plot from ERA5 GRIBS data using the code shown here in this link

https://confluence.ecmwf.int/display/MAGP/Wind+6+-+Temperature+and+wind+flags

`#importing Magics module from Magics.macro import *

Example reference

ref = 'wind2'

Setting of the output file name

output = output(output_formats= ['png'], output_name_first_page_number= 'off', output_name= ref)

Setting the coordinates of the geographical area

world = mmap(subpage_upper_right_longitude= 180., subpage_upper_right_latitude= 90., subpage_lower_left_longitude= -180., subpage_map_projection= 'cylindrical', subpage_lower_left_latitude= -90.)

Background Coastlines

background = mcoast( map_coastline_sea_shade_colour= 'white', map_coastline_land_shade_colour= 'cream', map_grid= 'off', map_coastline_land_shade= 'on', map_coastline_sea_shade= 'on', map_label= 'off', map_coastline_colour= 'tan')

Define the shading for the wind speed

speed200_contour = mcont( legend= 'on', contour_level_selection_type= 'level_list', contour_level_list= [30., 40., 50., 60., 70., 80., 90., 100.], contour_shade= 'on', contour_shade_min_level_colour= 'blue_green', contour_shade_max_level_colour= 'blue_purple', contour_shade_method= 'area_fill', contour_reference_level= 0., contour_highlight= 'off', contour_hilo= 'off', contour_hilo_format= '(F3.0)', contour_hilo_height= 0.2, contour_hilo_type= 'number', contour_hilo_suppress_radius= 30., contour_hi_min_value= 15., contour_label= 'off')

Import the wind at 200hPa uv200

uv200 = mgrib( grib_input_file_name = './download.grib',grib_wind_position_1=1,grib_wind_position_2=2)

uv200_wind = mwind( legend= 'on', wind_field_type = 'flags', wind_flag_length = 0.8, wind_thinning_factor= 6., wind_flag_calm_below = 15, wind_flag_origin_marker = 'circle', wind_flag_min_speed = 10.0, wind_flag_colour = 'chestnut')

title = mtext( text_lines = ["Wind flags where speed is over 10 m/s"], text_justification = 'left', text_font_size = 0.5, text_colour = 'charcoal')

add a legend

legend = mlegend(legend= 'on', legend_text_colour= 'charcoal', legend_box_mode= 'positional', legend_box_x_position= 27.5, legend_box_y_position= 4., legend_box_x_length= 2., legend_box_y_length= 12., legend_border= 'off', legend_border_colour= 'charcoal', legend_box_blanking= 'on', legend_display_type= 'continuous', legend_title = 'on', legend_title_text= 'Wind speed at 200 hPa', legend_text_font_size = '0.5')

To the plot

plot(output, world, background,uv200, uv200_wind, title, legend) `

But in the image I get the wind flags outside the world map and they are all clustered together and not visible.

I would like my output to be either like this https://confluence.ecmwf.int/display/MAGP/Wind+3+-+Wind+flags or having them colored like this - https://confluence.ecmwf.int/display/MAGP/Wind+4+-+Coloured+wind+flags https://imgur.com/a/JJWFFpw

sylvielamythepaut commented 4 years ago

Hi, Magics comes with a full list of parameters that should allow you to achieve the plot you want. In particular you can thin the wind then the plot will be more readable, you can also clip the arrows then they do not go outside the plotting area . Finally I think the clustered effect is coming from the fact that in this example, we only display the arrows if the wind speed is greater that a certain value. If you tell me how to access you data, I can quickly create an example,

Thanks

Sylvie

winash12 commented 4 years ago

@sylvielamythepaut Thanks for your prompt response.I have put my file here - https://xfl.jp/B8iFZu

Please let me know if you have any problems.

sylvielamythepaut commented 4 years ago

I have created a small example that could help you to start .. Hope this helps,

wind

importing Magics module

from Magics.macro import *

Example reference

ref = 'wind'

Setting of the output file name

output = output(output_formats= ['png'], output_name_first_page_number= 'off', output_name= ref)

Setting the coordinates of the geographical area

world = mmap(subpage_upper_right_longitude= 180., subpage_upper_right_latitude= 90., subpage_lower_left_longitude= -180., subpage_map_projection= 'cylindrical', subpage_lower_left_latitude= -90., subpage_clipping = True)

Background Coastlines

background = mcoast( map_coastline_sea_shade_colour= 'white', map_coastline_land_shade_colour= 'cream', map_grid= 'off', map_coastline_land_shade= 'on', map_coastline_sea_shade= 'on', map_label= 'off', map_coastline_colour="tan")

Define the shading for the wind speed

Import the wind at 200hPa uv200

uv = mgrib( grib_input_file_name = './wind.grib', grib_wind_position_1=1,grib_wind_position_2=2)

uv_flags = mwind( wind_field_type = "flags", wind_thinning_factor = 20, wind_flag_colour = "evergreen", wind_flag_length = 0.25, wind_flag_origin_marker = "dot" )

title = mtext( text_lines = ["Wind flags"], text_justification = 'left', text_font_size = 0.5, text_colour = 'charcoal')

To the plot

plot(output, world, background, uv, uv_flags, title)

winash12 commented 4 years ago

@sylvielamythepaut Thanks a lot for your help. I can run this successfully on my machine. I went over to this link https://confluence.ecmwf.int/display/MAGP/Wind+4+-+Coloured+wind+flags and added this code to the file you sent me above

` uv_flags = mwind(

wind_field_type = "flags",

wind_thinning_factor = 20,

wind_flag_colour = "evergreen",

wind_flag_length = 0.25,

wind_flag_min_speed = 2.0,

wind_flag_origin_marker = "dot",

wind_advanced_method = "on",

wind_advanced_colour_selection_type = 'interval',

wind_advanced_colour_level_interval = 10.0,

wind_advanced_colour_reference_level = 20.0,

wind_advanced_colour_max_value = 100.0,

wind_advanced_colour_min_value = 20.0,

wind_advanced_colour_table_colour_method = 'calculate',

wind_advanced_colour_direction = 'clockwise',

wind_advanced_colour_min_level_colour = 'turquoise',

wind_advanced_colour_max_level_colour = 'purple_red' ) `

but I get a world map with blank projection. Where am I going wrong ?

sylvielamythepaut commented 4 years ago

Hi,

When using the wind_advanced_method, you choose the colours of the flags according to the wind speed . I think that the values you have chosen for wind_advanced_colour_min_value and wind_advanced_colour_level_interval are too large .. I have tried wind_advanced_colour_level_interval = 0.5 ( range everything 0.5m/s) and to comment out wind_advanced_colour_max_value and wind_advanced_colour_min_value and it works fine . I hope this helps, Sylvie

winash12 commented 4 years ago

@sylvielamythepaut Indeed it does. Thank you very much for your help. I should be able to handle it from here. I am closing this case. If a new problem arises I will open a new issue.