Objectives
- Set-up a cylindrical projection over the United States.
- Apply land-shading on the coastlines.
- Load a grib file containing Mean-Sea level Presssure and visualise it using black isolines.
- Load a grib file containing Precipitation and visualise it using shading technique.
- Add a legend.
- Add a text.
- Draw the position of New-York City
- Draw a line to materialise the Xsection we are going to visualise in a next tutorial
You will need to download
Setting of the geographical area
The Geographical area we want to work with today is defined by its lower-left corner [20oN, 110oE] and its upper-right corner [70oN, 30oE].
Have a look at the subpage documentation to learn how to setup a projection .
from Magics.macro import *
#setting the output
output = output(
output_formats = ['png'],
output_name = "map_step1",
output_name_first_page_number = "off"
)
#settings of the geographical area
area = mmap(subpage_map_projection="cylindrical",
subpage_lower_left_longitude=-110.,
subpage_lower_left_latitude=20.,
subpage_upper_right_longitude=-30.,
subpage_upper_right_latitude=70.,
)
#Using a default coastlines to see the result
plot(output, area, mcoast())
Setting the coastlines
Until now you have used the mcoast to add coastlines to your plot. The mcoast object comes with a lot of parameters to allow you to style your coastlines layer.
The full list of parameters can be found in the Coastlines documentation.
In this first exercise, we will like to see:
- The land coloured in cream.
- The coastlines in grey.
- The grid as a grey dash line.
from Magics.macro import *
#setting the output
output = output(
output_formats = ['png'],
output_name = "map_step2",
output_name_first_page_number = "off"
)
#settings of the geographical area
area = mmap(subpage_map_projection="cylindrical",
subpage_lower_left_longitude=-110.,
subpage_lower_left_latitude=20.,
subpage_upper_right_longitude=-30.,
subpage_upper_right_latitude=70.,
)
#settings of the caostlines
coast = mcoast(map_coastline_land_shade = "on",
map_coastline_land_shade_colour = "cream",
map_grid_line_style = "dash",
map_grid_colour = "grey",
map_label = "on",
map_coastline_colour = "grey")
plot(output, area, coast)
Visualising the Mean Sea Level Pressure field
The visualisation of any data in Magics is done by combining 2 kind of objects. One, the Data Action, is used to define the data and explain to Magics how to interpret it, the other one is called Visual Action and will define the type of visualisation and its attributes.
In this example our data are in a grib file msl.grib. The Data Action to be used is mgrib in is documented in Grib Input Documentation.
The Visualisation we want to apply is a basic contouring, using black for the lines and an interval of 5 hPa, between isolines. We also want to add a automatic legend, with our own text "Mean Sea Level Pressure". Follow the link to access the Contouring Documentation.
from Magics.macro import *
#setting the output
output = output(
output_formats = ['png'],
output_name = "map_step3",
output_name_first_page_number = "off"
)
#settings of the geographical area
area = mmap(subpage_map_projection="cylindrical",
subpage_lower_left_longitude=-110.,
subpage_lower_left_latitude=20.,
subpage_upper_right_longitude=-30.,
subpage_upper_right_latitude=70.,
)
#settings of the caostlines
coast = mcoast(map_coastline_land_shade = "on",
map_coastline_land_shade_colour = "cream",
map_grid_line_style = "dash",
map_grid_colour = "grey",
map_label = "on",
map_coastline_colour = "grey")
#Loading the msl Grib data
msl = mgrib(grib_input_file_name="msl.grib")
#Defining the controur
contour = mcont(contour_highlight_colour= "black",
contour_highlight_thickness= 4,
contour_hilo= "off",
contour_interval= 5.,
contour_label= "on",
contour_label_frequency= 2,
contour_label_height= 0.4,
contour_level_selection_type= "interval",
contour_line_colour= "black",
contour_line_thickness= 2,
legend='on',
contour_legend_text= "Mean Sea Level Pressure",
)
plot(output, area, coast, msl, contour)
Visualising the precipitation field
The goal of this exercise is to discover a bit more the diverse styles of visualisation offered by the mcont object.
We are pre-processed grib field containing the precipitation accumulated in the last 6 hours of the valid time. We want to disable the automatic scaling appled by Magics and use our own scaling factor, in this case 1000.
Here we will work with shading, and we will use a different technique to setup the levels we want to contour.
We want to use the following list of levels for contouring [0.5, 2., 4., 10., 25., 50., 100., 250.]
and the following list of colours ["cyan", "greenish_blue", "blue", "bluish_purple", "magenta", "orange", "red", "charcoal"]
#setting the output
output = output(
output_formats = ['png'],
output_name = "map_step4",
output_name_first_page_number = "off"
)
#settings of the geographical area
area = mmap(subpage_map_projection="cylindrical",
subpage_lower_left_longitude=-110.,
subpage_lower_left_latitude=20.,
subpage_upper_right_longitude=-30.,
subpage_upper_right_latitude=70.,
)
#settings of the caostlines
coast = mcoast(map_coastline_land_shade = "on",
map_coastline_land_shade_colour = "cream",
map_grid_line_style = "dash",
map_grid_colour = "grey",
map_label = "on",
map_coastline_colour = "grey")
#definition of the input data
precip = mgrib(grib_input_file_name="precip.grib",
grib_automatic_scaling='off',
grib_scaling_factor=1000.)
shading = mcont( contour_highlight= "off",
contour_hilo= "off",
contour_label="off",
contour_level_list=[0.5, 2., 4., 10., 25., 50., 100., 250.],
contour_level_selection_type= "level_list",
contour_shade= "on",
contour_shade_method= "area_fill",
contour_shade_colour_method= "list",
contour_shade_colour_list= ["cyan", "greenish_blue", "blue", "bluish_purple", "magenta", "orange", "red", "charcoal"],
legend="on")
plot(output, area, coast, precip, shading)
Overlaying the 2 layers and playing with legend
Here, we want to demonstrate the plot command.
The actions added to the plot command will be executed sequentially, and their result will be displayed from the background to the foreground .
Then, try to put the shaded layer (precipitation) behind the contoured layer (msl)
and try to improve the legend to make it look continuous, by checking the Legend Documentation.
from Magics.macro import *
#setting the output
output = output(
output_formats = ['png'],
output_name = "map_step5",
output_name_first_page_number = "off"
)
#settings of the geographical area
area = mmap(subpage_map_projection="cylindrical",
subpage_lower_left_longitude=-110.,
subpage_lower_left_latitude=20.,
subpage_upper_right_longitude=-30.,
subpage_upper_right_latitude=70.,
)
#settings of the caostlines
coast = mcoast(map_coastline_land_shade = "on",
map_coastline_land_shade_colour = "cream",
map_grid_line_style = "dash",
map_grid_colour = "grey",
map_label = "on",
map_coastline_colour = "grey")
#definition of the input data
precip = mgrib(grib_input_file_name="precip.grib",
grib_automatic_scaling='off',
grib_scaling_factor=1000.)
#definition of shading
shading = mcont( contour_highlight= "off",
contour_hilo= "off",
contour_label="off",
contour_level_list=[0.5, 2., 4., 10., 25., 50., 100., 250.],
contour_level_selection_type= "level_list",
contour_shade= "on",
contour_shade_method= "area_fill",
contour_shade_colour_method= "list",
contour_shade_colour_list= ["cyan", "greenish_blue", "blue", "bluish_purple", "magenta", "orange", "red", "charcoal"],
legend="on")
#definition of msl
msl = mgrib(grib_input_file_name="msl.grib")
#Definition of the black contouring
contour = mcont( contour_highlight_colour= "black",
contour_highlight_thickness= 4,
contour_hilo= "off",
contour_interval= 5.,
contour_label= "on",
contour_label_frequency= 2,
contour_label_height= 0.4,
contour_legend_text= "Mean Sea Level Pressure",
contour_level_selection_type= "interval",
contour_line_colour= "black",
contour_line_thickness= 2,
legend='on'
)
#Definition of the legend
legend = mlegend(legend='on',
legend_display_type='continuous',
legend_text_colour='charcoal',
legend_text_font_size=0.4,
)
plot(output, area, coast, precip, shading, msl, contour, legend)