Section |
---|
Column |
---|
| ![](/download/attachments/24317025/map.png?version=1&modificationDate=1362578004546&api=v2&effects=border-simple,blur-border)
|
Column |
---|
| Panel |
---|
Objectives
- Set-up a cylindrical projection over the United States.
- Apply land-sahding shading on the coastlines.
- Load a grib GRIB file containing Mean-Sea level Presssure and visualise it using black isolines.
- Load a grib 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
- Add a text.
You will need to download
|
|
|
Setting of the geographical area
The Geographical geographical area we want to work with today is defined by its lower-left corner [20oN, 110oEW] and its upper-right corner [70oN, 30oEW].
Have a look at the subpage documentation to learn how to setup a projection .
Section |
---|
Column |
---|
| Info |
---|
|
Useful subpage parameters |
---|
subpage_lower_left_longitude | subpage_lower_left_latitude | subpage_upper_right_longitude | subpage_upper_right_latitude |
|
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Setting a projection |
---|
collapse | true |
---|
| 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()) |
|
Column |
---|
| | Image Modified
|
|
...
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.
Section |
---|
Column |
---|
| Info |
---|
|
Useful Coastlines parameters |
---|
map_coastline_land_shade | map_coastline_land_shade_colour | map_coastline_colour | map_grid_colour | map_grid_line_style |
|
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Coastlines |
---|
collapse | true |
---|
| from Magics.macro import *
#setting the |
|
|
Have a look at the PNG output documentation to see which parameters are available to set-up a PNG output.
To create a PNG output Magics, you have to create an output object and to insert at the first position in the plot command
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Output |
---|
collapse | true |
---|
|
Section |
---|
from Magics.macro import *
#settings of the png
output_formats = ['png'],
|
| magics output_name_first_page_number = "off"
|
| )
#Theplotcommadwillcreateapngoutputcalledmagics.png
plot(output, mcoast()) |
Setting the coastlines
The object mcoast allows the parametrisation of the coastlines.
Have a look at the Coastlines documentation to see which parameters are available.
To configure the look of your coastlines you have to create a mcoast object with the parameters you want.
The mcoast object has to be inserted in the plot command.
Column |
---|
| Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Coastlines |
---|
collapse | true |
---|
| from Magics.macro import *
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 png output
outputcaostlines
coast = output(
output_formats = ['png'],
output_name = "coast",
output_name_first_page_number = "off"
)
##settings of the coastlines attributes
coast = mcoast(
map_coastline_land_shade = "on",
map_coastline_land_shademcoast(map_coastline_land_shade = "on",
map_coastline_land_shade_colour = "cream",
map_grid_line_style = "dash",
map_grid_colour = "creamgrey",
map_grid_line_style = "dash",
map_grid_colourlabel = "brownon",
map_label_colour = "brown",
map_coastline_colour = "browngrey"
)
#The plot command will now use the coast object
plot(output, area, coast) |
|
Column |
---|
| Image Removed Image Added |
|
Adding a text
Magics allows the user to add of or several lines of text. The position of the text is by default above the plot, but some parameters aloow it to be moved around.
A basic html formatting can be used for colour, style, and font size.
The mtext object has to be inserted in the plot command to see the text on the result.
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 mcont, using black for the lines. We want an interval of 5 hPa between isolines. We also want to add an automatic legend, with our own text "Mean Sea Level Pressure". Follow the link to access the Contouring Documentation.
Section |
---|
Column |
---|
| Info |
---|
|
mgrib action to load the data |
---|
grib_input_file_name |
mcont action to define a contouring |
---|
contour_line_colour | contour_line_thickness | contour_highlight_colour | contour_highlight_thickness | contour_hilo | contour_level_selection_type | contour_interval | legend | contour_legend_text |
|
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Msl Visualisation |
---|
collapse | true |
---|
| 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) |
|
Column |
---|
| Image Added |
|
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 a 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"]
Section |
---|
Column |
---|
| Info |
---|
|
mgrib action to load the data |
---|
grib_input_file_name | grib_automatic_scaling | grib_scaling_factor |
mcont action to define a contouring |
---|
contour_level_selection_type | contour_level_list | contour_shade | contour_shade_method | contour_shade_colour_method | contour_level_selection_type | contour_shade_colour_list | legend |
|
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Use of Shading |
---|
collapse | true |
---|
| #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) |
|
Column |
---|
| Image Added |
|
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.
Section |
---|
Column |
---|
| Info |
---|
|
Useful legend parameters |
---|
legend | legend_display_type | legend_text_colour | legend_text_font_size |
|
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Overlay |
---|
collapse | true |
---|
| 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) |
|
Column |
---|
| Image Added |
|
Adding the position of New York City
To demonstrate the use of symbols plotting, we are going to add a big red dot where New York City is.We will the add the text NYC in black on top of the dot.
The position of New York is [41oN, 74oW], we can give this position to Magics using the minput object, documented in Input Data Page.
The symbol is performed using the msymb object. You can find the full options in the Symbol Documentation.
Section |
---|
Column |
---|
| Info |
---|
|
Useful input parameters |
---|
input_x_values | input_y_values |
Useful Symbol parameters |
---|
symbol_colour | symbol_marker_index | symbol_height | symbol_type | symbol_text_list | symbol_text_font_size | symbol_text_font_colour | symbol_text_font_style | symbol_text_position |
|
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Adding New-York City |
---|
collapse | true |
---|
| from Magics.macro import *
#setting the output
output = output(
output_formats = ['png'],
output_name = "map_step6",
output_name_first_page_number = "off"
)
#---------------------------------------
# definition of the previsous layers
# ...
# ...
#---------------------------------------
#definition of New-York city
new_york = minput(
input_x_values = [-74.],
input_y_values = [41.]
)
#definition of the symbol
point = msymb(
symbol_type = "both",
symbol_text_list = ["NYC"],
symbol_marker_index = 28,
symbol_colour = "red",
symbol_height = 0.5,
symbol_text_font_size = 0.40,
symbol_text_font_colour = "black",
symbol_text_position = "top",
symbol_text_font_style = "bold ",
)
plot(output, area, coast, precip, shading, msl, contour, new_york, point, legend) |
|
Column |
---|
| Image Added |
|
Adding a line to show our next Cross-section
In the next exercise, we will display a Cross-section of the Vorticity across the Storm.
We want to show this line of our plot as a black thick line.
The stating point is [50oN, 90oW], the end point is [30oN, 60oW] : it can be passed to Magics using the minput object, documented in Input Data Page.
To draw the line we will use the mgraph object. All the parameters are available in the Graph Plotting Documentation.
Section |
---|
Column |
---|
| Info |
---|
|
Useful input parameters |
---|
input_x_values | input_y_values |
Useful Graph parameters |
---|
graph_line | graph_line_colour |
|
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Adding a line |
---|
collapse | true |
---|
| from Magics.macro import *
#setting the output
output = output(
output_formats = ['png'],
output_name = "map_step7",
output_name_first_page_number = "off"
)
#---------------------------------------
# definition of the previous layers
# ...
# ...
#---------------------------------------
#definition of the Xsection Line
xsection = minput(
input_x_values = [-90., -60.],
input_y_values = [50., 30.]
)
#definition of the graph
line = mgraph(
graph_line_colour = "black",
graph_line_thickness = 4
)
plot(output, area, coast, precip, shading, msl, contour, new_york, point, xsection, line, legend) |
|
Column |
---|
| Image Added |
|
Adding a title
We have now a very nice plot... let's add a title at the top.
Text box can be embedded everywhere on a plot, but the default position will be a title at the top of the plot, above an potential legend.
The text facility is documented in the Text Plotting Page.
Section |
---|
Column |
---|
| Info |
---|
|
Useful Text parameters |
---|
text_lines | text_font_size | text_colour | text_font_style |
|
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Adding a text |
---|
collapse | true |
---|
| from Magics.macro import *
#setting the output
output = output(
output_formats = ['png'],
output_name = "map_step8",
output_name_first_page_number = "off"
)
#---------------------------------------
# definition of the previous layers
# ...
# ...
#---------------------------------------
#definition of the text
title = mtext(text_lines=['Sandy', '30th of October 2012'],
text_font_size = 0.8,
text_colour= "charcoal",
text_font_style='bold',
)
plot(output, area, coast, precip, shading, msl, contour, new_york, point, xsection, line, legend |
|
|
Column |
---|
|
Code Block |
---|
theme | Confluence |
---|
language | python |
---|
title | Python - Title |
---|
collapse | true |
---|
| from Magics.macro import *
#settings of the png output
output = output(
output_formats = ['png'],
output_name = "coast",
output_name_first_page_number = "off"
)
##settings of the coastlines attributes
coast = mcoast(
map_coastline_land_shade = "on",
map_coastline_land_shade_colour = "cream",
map_grid_line_style = "dash",
map_grid_colour = "brown",
map_label_colour = "brown",
map_coastline_colour = "brown"
)
##settings of the text (notice the Html formatting)
title = mtext(
text_lines = ["Hello World!", " <b>This is my first plot</b> !"],
text_font_size = "0.7",
text_colour = "charcoal"
)
#The plot command will now use the coast and title objects
plot(output, coast |
Column |
---|
| Image Added |
Image Removed |
Go to the next step...
Go back to the main page ...