Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

 

 

Section
Column
width250px

Column
width60%
Panel

Objectives


  • Set-Up a cartesian projection
  • Learn how to pass  arrays as input of curves
  • Learn how to use CSV files as input of curves
  • Add a text.
  • Create a layout

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 .

 

 

Profile: create the Cartesian Projection

For our vertical profile, we will need :

  • a horizontal regular axis for a temperature range going from -60oC to 20oC.
  • a vertical logarithmic axis going from 1020 hPa to 10 hPa

Have a look at the Subpage Documentation and at the Axis Plotting Documentation, and try to get the 0oC grid line highlighted.

Section
Column
width50%
Info
titleParameters to check

...

 

 

Useful

...

projection parameters

subpage_

...

map_

...

projection

subpage_

...

x_

...

axis_

...

type
subpage_

...

y_

...

axis_

...

type
subpage_

...

 

 

 

 

x_min
subpage_y_min
subpage_x_max
subpage_y_max
Useful axis parameters
axis_orientation
axis_type
axis_grid

axis_grid_reference

axis_title
Code Block
themeConfluence
languagepython
titlePython - set-up of cartesian projection
collapsetrue
# importing Magics module
from Magics.macro import *
# define the output
output = 

...

output(output_formats=['png'],
        output_name

...

_

...

first_page_number=

...

'off',
        output_name="profile_step1")
projection = mmap(
    subpage_map_projection=

...

'cartesian',
    subpage_

...

x_

...

axis_

...

type='regular',
    subpage_y_axis_type='logarithmic',   
    subpage_x_min=-70.,
    subpage_x_max=20.,
    subpage_

...

y_

...

min=1020.,
    subpage_

...

y_

...

max=

...

10.,)

...

 

 

 

 

 

Image Removed

 

 

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.

 

 

 

 

Useful Coastlines parameters

map_coastline_land_shade

map_coastline_land_shade_colour

map_coastline_colour

map_grid_colour

map_grid_line_style

 

 

 

 

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)

 

 

 

 

 

Image Removed

 

 

 

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.

 

 

 

 

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

 

 

 

 

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)

 

 

 

 

 

Image Removed

 

 

 

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"]

 

 

 

 

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

 

 

 

 

#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)

 

 

 

 

 

Image Removed

 

 

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.

 

 

 

 

Useful legend parameters

legend

legend_display_type

legend_text_colour

legend_text_font_size

 

 

 

 

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)

 

 

 

 

 

Image Removed

 

 

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, 74oE], 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.

 

 

 

 

 

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

 

 

 

 

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)

 

 

 

 

 

Image Removed

 

 

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, 90oE], the end point is  [30oN, 60oE] : 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.

 

 

 

 

 

Useful input parameters

input_x_values

input_y_values

 

Useful Graph parameters

graph_line

graph_line_colour

 

 

 

 

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 = [-74.], input_y_values = [41.] ) #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)

 

 

 

 

 

Image Removed

 

 

 

 

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.

 

 

 

 

Useful Text parameters

text_lines

text_font_size

text_colour

text_font_style

 

 

 

 

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, title)

 

 

 

 

 

Image Removed

 


#define the vertical axis
vertical = maxis(
    axis_orientation='vertical',
    axis_grid='on',
    axis_type='logarithmic',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid_colour='charcoal',
    axis_grid_line_style='dash',
    axis_title='on',
    axis_title_text='Pressure',
    axis_title_font='arial',
    axis_title_font_style='bold',
    axis_title_height=1.,
    )
# define the horizontal axis
horizontal = maxis(
    axis_orientation='horizontal',
    axis_type='regular',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid='on',
    axis_grid_colour='charcoal',
    axis_grid_thickness=1,
    axis_grid_reference_level=0.,
    axis_grid_reference_line_style='solid',
    axis_grid_reference_thickness=1,
    axis_grid_line_style='dash',)
    
plot(output, projection, vertical, horizontal)
Column
width200px

 Image Added

 

Profile: Using Arrays as Input of a Graph

Here is the list of levels, and the list of Temperature in Kelvin at each levels.

levels = [1.,2.,3,5,7,10,20,30,50,70,100,150,200,250,300,400,500,600,700,800,850,900,925,950,1000]
kelvin = ([263.118652344,254.822738647,242.517868042,223.301025391,219.254943848,216.710174561,216.507095337, 215.398986816,211.643295288,207.18812561,207.172134399,217.097396851,223.809326172,235.13168335,243.377059937,260.635147095,272.02935791,272.145584106,273.448501587,279.562927246,281.745040894,285.503082275,287.543685913,289.284072876,292.170974731]

We can pass these arrays to Magics using the minput object . Check the Input Data Documentation for more information about the parameters. Note that we want to use Celsius in our graph...

The mgraph object can then be used to  preform the visualisation. All the parameters can be found in the Graph Plotting Page.

Section
Column
width50%
Info
titleParameters to check

 


 

Useful input parameters

input_x_values

input_y_values
Useful graph parameters
graph_line_colour
graph_line_thickness
Code Block
themeConfluence
languagepython
titlePython - Input data for graph
collapsetrue
# importing Magics module
from Magics.macro import *
# define the output
output = output(output_formats=['png'],
        output_name_first_page_number='off',
        output_name="profile_step2")
projection = mmap(
    subpage_map_projection='cartesian',
    subpage_x_axis_type='regular',
    subpage_y_axis_type='logarithmic',   
    subpage_x_min=-70.,
    subpage_x_max=20.,
    subpage_y_min=1020.,
    subpage_y_max=10.,)
#define the vertical axis
vertical = maxis(
    axis_orientation='vertical',
    axis_grid='on',
    axis_type='logarithmic',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid_colour='charcoal',
    axis_grid_line_style='dash',
    axis_title='on',
    axis_title_text='Pressure',
    axis_title_font='arial',
    axis_title_font_style='bold',
    axis_title_height=1.,
    )
# define the horizontal axis
horizontal = maxis(
    axis_orientation='horizontal',
    axis_type='regular',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid='on',
    axis_grid_colour='charcoal',
    axis_grid_thickness=1,
    axis_grid_reference_level=0.,
    axis_grid_reference_line_style='solid',
    axis_grid_reference_thickness=1,
    axis_grid_line_style='dash',)
levels = [1.,2.,3,5,7,10,20,30,50,70,100,150,200,250,300,400,500,600,700,800,850,900,925,950,1000]
kelvin = numpy.array([263.118652344,254.822738647,242.517868042,223.301025391,219.254943848,216.710174561,216.507095337,
    215.398986816,211.643295288,207.18812561,207.172134399,217.097396851,
    223.809326172,235.13168335,243.377059937,260.635147095,272.02935791,
    272.145584106,273.448501587,279.562927246,281.745040894,285.503082275,287.543685913,289.284072876,292.170974731]) 
celsius = kelvin -273.16
# Define the input of the graph
data = minput(input_x_values = celsius,
        input_y_values = levels, )
#define the graph action.
graph = mgraph( legend='on' ,
            legend_user_text= 'Tempe', 
            graph_line_colour="navy", 
            graph_line_thickness= 3, )
    
plot(output, projection, vertical, horizontal, data, graph)
Column
width200px

 Image Added

 

Profile: Using Arrays as Input for wind Plotting

Here is the list of pressure levels, and the list of u and v components for each pressure level.

levels = [1.,2.,3,5,7,10,20,30,50,70,100,150,200,250,300,400,500,600,700,800,850,900,925,950,1000]
u_component = [77.815612793,63.232711792,44.9090881348,28.2789916992,17.401763916,
    11.8307037354,-0.725036621094,-4.75889587402,-7.83796691895,-3.76489257812,
    -6.18388366699,-13.1139526367,-13.05027771,-15.1851959229,-23.5844726562,
    -27.866394043,-33.0458984375,-45.8946380615,-41.540222168,-39.6210327148,
    -37.6231689453,-32.947265625,-29.4743499756,-22.0828552246,-10.0008392334]
v_component = [7.38911437988,5.23355102539,0.636322021484,-3.75567626953,
    0.167388916016,-3.12893676758,-3.60003662109,0.0688171386719,
    0.305236816406,7.06889343262,8.10516357422,11.1141815186,
    -2.29931640625,3.08065795898,7.5965423584,11.0112915039,
    13.6437530518,11.2753143311,11.1552124023,13.1494903564,
    6.01538085938,1.37588500977,-0.0724334716797,-0.953598022461,-0.508377075195]

We can pass these arrays to Magics using the minput object . Check the Input Data Documentation for more information about the parameters.

We want to plot these winds as red flags on the vertical of -20.

The mgraph object can then be used to preform the visualisation. All the parameters can be found in the Graph Plotting Page.

Do not forget to add a legend with some meaningful text!

Section
Column
width50%
Info
titleParameters to check

 


 

Useful input parameters

input_x_values

input_y_values
input_x_component_values
input_y_component_values
Useful graph parameters
graph_type
graph_flag_colour
graph_flag_length
legend
legend_user_text
Code Block
themeConfluence
languagepython
titlePython - Input data and Flags plotting
collapsetrue
# importing Magics module
from Magics.macro import *
# define the output
output = output(output_formats=['png'],
        output_name_first_page_number='off',
        output_name="profile_step2")
projection = mmap(
    subpage_map_projection='cartesian',
    subpage_x_axis_type='regular',
    subpage_y_axis_type='logarithmic',   
    subpage_x_min=-70.,
    subpage_x_max=20.,
    subpage_y_min=1020.,
    subpage_y_max=10.,)
#define the vertical axis
vertical = maxis(
    axis_orientation='vertical',
    axis_grid='on',
    axis_type='logarithmic',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid_colour='charcoal',
    axis_grid_line_style='dash',
    axis_title='on',
    axis_title_text='Pressure',
    axis_title_font='arial',
    axis_title_font_style='bold',
    axis_title_height=1.,
    )
# define the horizontal axis
horizontal = maxis(
    axis_orientation='horizontal',
    axis_type='regular',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid='on',
    axis_grid_colour='charcoal',
    axis_grid_thickness=1,
    axis_grid_reference_level=0.,
    axis_grid_reference_line_style='solid',
    axis_grid_reference_thickness=1,
    axis_grid_line_style='dash',)
levels = [1.,2.,3,5,7,10,20,30,50,70,100,150,200,250,300,400,500,600,700,800,850,900,925,950,1000]
kelvin = numpy.array([263.118652344,254.822738647,242.517868042,223.301025391,219.254943848,216.710174561,216.507095337,
    215.398986816,211.643295288,207.18812561,207.172134399,217.097396851,
    223.809326172,235.13168335,243.377059937,260.635147095,272.02935791,
    272.145584106,273.448501587,279.562927246,281.745040894,285.503082275,287.543685913,289.284072876,292.170974731]) 
celsius = kelvin -273.16
# Define the input of the graph
data = minput(input_x_values = celsius,
        input_y_values = levels, )
#define the graph action.
graph = mgraph( legend='on' ,
            legend_user_text= 'Tempe', 
            graph_line_colour="navy", 
            graph_line_thickness= 3, )
#define the input for the wind plotting
wind_position = [-20.] * len(levels)
u_component = [77.815612793,63.232711792,44.9090881348,28.2789916992,17.401763916,
    11.8307037354,-0.725036621094,-4.75889587402,-7.83796691895,-3.76489257812,
    -6.18388366699,-13.1139526367,-13.05027771,-15.1851959229,-23.5844726562,
    -27.866394043,-33.0458984375,-45.8946380615,-41.540222168,-39.6210327148,
    -37.6231689453,-32.947265625,-29.4743499756,-22.0828552246,-10.0008392334]
v_component = [7.38911437988,5.23355102539,0.636322021484,-3.75567626953,
    0.167388916016,-3.12893676758,-3.60003662109,0.0688171386719,
    0.305236816406,7.06889343262,8.10516357422,11.1141815186,
    -2.29931640625,3.08065795898,7.5965423584,11.0112915039,
    13.6437530518,11.2753143311,11.1552124023,13.1494903564,
    6.01538085938,1.37588500977,-0.0724334716797,-0.953598022461,-0.508377075195]
wind = minput(
        input_y_component_values = v_component,
        input_x_values = wind_position,
        input_x_component_values = u_component,
        input_y_values = levels)
#define wind plotting
flags = mgraph(graph_type = "flag",
        graph_flag_colour = "red",
        legend = "on",
        graph_flag_length = 1.00,
        legend_user_text = " Wind ")

 plot(output, projection, vertical, horizontal, data, graph, wind, flags)
Column
width200px

 Image Added

 

Time Series: Setting the Cartesian Projection for the Mean Sea Level Pressure time series

In this exercise, we will learn how to setup a date Coordinate, and browse the parameters available to style the style a date axis.

We want

  • a horizontal date axis going from the 2012-10-27at  00:00:00 to 2012-11-02 12:00:00
  • a vertical regular axis  going from 950 hPa to 1050 hPa

Have a look at the Subpage Documentation and at the Axis Plotting Documentation,

Section
Column
width50%
Info
titleParameters to check

 


 

Useful projection parameters

subpage_map_projection

subpage_x_axis_type
subpage_y_axis_type
subpage_x_date_min
subpage_y_min
subpage_x_date_max
subpage_y_max
Useful axis parameters
axis_orientation
axis_type
Code Block
themeConfluence
languagepython
titlePython - Date Coordinates system
collapsetrue
 # importing Magics module
from Magics.macro import *
# define the output
output = output(output_formats=['png'],
        output_name_first_page_number='off',
        output_name="time_serie_step1")
projection = mmap(
    subpage_map_projection='cartesian',
    subpage_x_axis_type='date',
    subpage_y_axis_type='regular',   
    subpage_x_date_min='2012-10-27 00:00:00',
    subpage_x_date_max='2012-11-02 12:00:00',
    subpage_y_max=1050.,
    subpage_y_min=950.,
    )
# Vertical axis
vertical = maxis(
    axis_orientation='vertical',
    axis_grid='on',
    axis_type='regular',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid_colour='charcoal',
    axis_grid_thickness=1,
    axis_grid_reference_level=0.,
    axis_grid_reference_line_style='solid',
    axis_grid_reference_thickness=1,
    axis_grid_line_style='dash',
    axis_title='on',
    axis_title_text='Pressure',
    axis_title_font='arial',
    axis_title_height=0.5,
    )
# Horizontal axis
horizontal = maxis(
    axis_orientation='horizontal',
    axis_type='date',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid='on',
    axis_grid_colour='charcoal',
    axis_grid_thickness=1,
    axis_grid_line_style='dash',
    )
    
plot(output, projection, horizontal, vertical)
Column
width200px

 Image Added

 

 

Time Series: Using a CSV file as input of a curve

The values for our time series are in CSV (Comma-Separeted-Value) ascii file called msl.csv.

Code Block
titlefirst few lines of msl.csv
1,2012-10-27 00:00:00,1020.64125,0
2,2012-10-27 12:00:00,1017.261875,0.1220703125
3,2012-10-28 00:00:00,1014.27125,-9.58071727163e-21
4,2012-10-28 12:00:00,1011.97375,-2.80979885101e-20

The valid date is defined in the second column, the value of msl in the third.

This information need to be given to Magics . This can be done with the mtable data action,. See the full documentation.

The mgraph action will then be used to define the curve attributes. All the parameters can be found in the Graph Plotting Page.

You can always add a title using the mtext object.

Section
Column
width50%
Info
titleParameters to check

 


 

Useful table parameters

table_filename

table_variable_identifier_type
table_x_type
table_x_variable
table_y_variable
table_header_row
Useful graph parameters
graph_line_colour
legend
legend_user_text
Code Block
themeConfluence
languagepython
titlePython - CSV file
collapsetrue
# importing Magics module
from Magics.macro import *
# define the output
output = output(output_formats=['png'],
        output_name_first_page_number='off',
        output_name="time_serie_step2")
projection = mmap(
    subpage_map_projection='cartesian',
    subpage_x_axis_type='date',
    subpage_y_axis_type='regular',   
    subpage_x_date_min='2012-10-27 00:00:00',
    subpage_x_date_max='2012-11-02 12:00:00',
    subpage_y_max=1050.,
    subpage_y_min=950.,
    )
# Vertical axis
vertical = maxis(
    axis_orientation='vertical',
    axis_grid='on',
    axis_type='regular',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid_colour='charcoal',
    axis_grid_thickness=1,
    axis_grid_reference_level=0.,
    axis_grid_reference_line_style='solid',
    axis_grid_reference_thickness=1,
    axis_grid_line_style='dash',
    axis_title='on',
    axis_title_text='Pressure',
    axis_title_font='arial',
    axis_title_height=0.5,
    )
# Horizontal axis
horizontal = maxis(
    axis_orientation='horizontal',
    axis_type='date',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid='on',
    axis_grid_colour='charcoal',
    axis_grid_thickness=1,
    axis_grid_line_style='dash',)
#load the csv file, and define how to interpret it
data = mtable(table_filename = "msl.csv",
    table_x_type='date',
    table_variable_identifier_type='index',
    table_x_variable = "2",
    table_y_variable = "3",
    table_header_row = 0
 )
#define the visualisation
graph = mgraph( legend='on' ,
    legend_user_text= '<font colour="navy" size="0.3"> Mean Sea Level</font>', 
    graph_line_colour="navy", 
    graph_line_thickness= 3, )
#add a title
title = mtext(
            text_lines= ['Mean Sea Level plotted as curve...', ],
            text_html= 'true',
            text_justification= 'left',
            text_font_size= 0.8,
            text_colour= 'charcoal',
        )
plot(output, projection, horizontal, vertical, data, graph, title)
Column
width200px

 

 Image Added

Time Series : Using Automatic Axis and bar plotting

Magics can automatically set-up the coordinates system according to the plotted data.

In this exercise, we will use this functionality to draw the time series of the precipitation.

  • The horizontal date coordinate system is set automatically.
  • The vertical coordinate system is regular going from 0 to 5

The data will be pass to Magics using arrays:

dates = ["2012-10-27 00:00:00","2012-10-27 12:00:00","2012-10-28 00:00:00",
        "2012-10-28 12:00:00","2012-10-29 00:00:00","2012-10-29 12:00:00",
        "2012-10-30 00:00:00","2012-10-30 12:00:00",
        "2012-10-31 00:00:00","2012-10-31 12:00:00",
        "2012-11-01 00:00:00","2012-11-01 12:00:00",
        "2012-11-02 00:00:00","2012-11-02 12:00:00"]
precip = [0.,0.1220703125,0.,0., 0., 3.16429138184,
            2.18200683594,1.75476074219,0,0,0,0,0,0.]

We want to display the information using bar plotting. 

We will perhaps need to check quickly

Section
Column
width50%
Info
titleParameters to check

 


 

Useful projection parameters

subpage_x_automatic

Useful input parameters

input_x_type

input_date_x_values
input_y_values
input_y2_values
Useful graph parameters
graph_type
graph_bar_line_colour
graph_shade_colour
legend
legend_user_text
Code Block
themeConfluence
languagepython
titlePython - Automatic projection and bar plotting
collapsetrue
# importing Magics module
from Magics.macro import *
# define the output
output = output(output_formats=['png'],
        output_name_first_page_number='off',
        output_name="time_serie_step3")
# Setting the cartesian view
projection = mmap(
    subpage_map_projection='cartesian',
    subpage_x_axis_type='date',
    subpage_y_axis_type='regular',   
    subpage_x_automatic='on',
    subpage_y_max=5.,
    subpage_y_min=0.,
    )
    
# Vertical axis
vertical = maxis(
    axis_orientation='vertical',
    axis_grid='on',
    axis_type='regular',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid_colour='charcoal',
    axis_grid_thickness=1,
    axis_grid_reference_level=0.,
    axis_grid_reference_line_style='solid',
    axis_grid_reference_thickness=1,
    axis_grid_line_style='dash',
    axis_title='on',
    axis_title_text='Amount of rain',
    axis_title_font='arial',
    axis_title_height=0.5,
    )
# Horizontal axis
horizontal = maxis(
    axis_orientation='horizontal',
    axis_type='date',
    axis_tick_label_height=0.4,
    axis_tick_label_colour='charcoal',
    axis_grid='on',
    axis_grid_colour='charcoal',
    axis_grid_thickness=1,
    axis_grid_line_style='dash',
    )
dates = ["2012-10-27 00:00:00","2012-10-27 12:00:00","2012-10-28 00:00:00",
    "2012-10-28 12:00:00","2012-10-29 00:00:00","2012-10-29 12:00:00",
    "2012-10-30 00:00:00","2012-10-30 12:00:00",
    "2012-10-31 00:00:00","2012-10-31 12:00:00",
    "2012-11-01 00:00:00","2012-11-01 12:00:00",
    "2012-11-02 00:00:00","2012-11-02 12:00:00"]
    
precip = [0.,0.1220703125,0.,0., 0., 3.16429138184,
        2.18200683594,1.75476074219,0,0,0,0,0,0.]
#defining the data 
data = minput(
    input_x_type='date',
    input_date_x_values= dates,
    input_y2_values= precip,
    input_y_values= [0.] * len(precip),
     )
#defining the visualisation
bar = mgraph( legend='on' ,
        graph_type ='bar',
        graph_bar_line_colour = "navy",
        graph_shade_colour = "evergreen",
        legend_user_text= '<font colour ="evergreen" size="0.4"> Precipitation </font>', 
        graph_line_colour="navy", 
        graph_bar_width = 3600.00 *6,
        graph_line_thickness= 3, )
#adding a title  
title = mtext(
        text_lines=  ['Precipitation as Bar Plotting..', ],
        text_html= 'true',
        text_justification= 'left',
        text_font_size= 0.8,
        text_colour= 'charcoal',
    )
plot(output, projection, vertical, horizontal, data, bar, title)
Column
width200px

 

 Image Added

Finally, A bit of layout ...

On our image, we want to create 3 pages.. We will use the pseudo action page to do that..

Gliffy Diagram
namelayout

The position of the page is set with the 4 following parameters

  • page_x_position / page_y_position : to position in cm the bottom left corner of the page in its parent
  • page_x_length / page_y_length : the dimension in cm.

The drawing area ( where the plotting is rendered) is called subpage and can position into the page using the 4 following parameters

  • subpage_x_position / subpage_y_position : to position in cm the bottom left corner of the drawing area (subpage)  in its parent page.
  • subpage_x_length / subpage_y_length : the dimension in cm.

 

Section
Column
width50%
Info
titleParameters to check

 


 

Useful page parameters

layout

page_x_position
page_y_position
page_x_length
page_y_length
subpage_x_position
subpage_y_position
subpage_x_length
subpage_y_length
page_id_line
page_frame
Code Block
themeConfluence
languagepython
titlePython - complex layout
collapsetrue
# importing Magics module
from Magics.macro import *
from profile import profile
from timeserie import msl_timeserie
from timeserie import precip_timeserie
#Setting the output
output = output(output_name = 'layout', 
                output_formats = ["png"],
                output_name_first_page_number = "off")
profile_left = page(
        layout='positional',
        page_frame='off', 
        page_x_length=15., 
        page_id_line='off',
        subpage_y_length=17.,
        )
        
graph_bottom = page(
        layout='positional',
        page_frame='off', 
        page_x_length=15., 
        page_y_length= 10., 
        page_id_line='off',
        page_x_position=15., 
        page_y_position=0.5,
        subpage_x_position=1.5,
        subpage_y_position=0.5,
        subpage_y_length=7.,
        )
        
graph_top = page(
        layout='positional',
        page_frame='off', 
        page_x_length=15., 
        page_y_length=10., 
        page_id_line='off',
        page_x_position=15.,
        page_y_position=10.5, 
        subpage_x_position=1.5,
        subpage_y_position=0.5,    
        subpage_y_length=7.,
        )
plot(output, 
    profile_left, profile(title_size=0.6),
    graph_bottom, msl_timeserie(title_size=0.6),
    graph_top, precip_timeserie(title_size=0.6),
    )
Column
width200px

Image Added

Go to the next step...

Go to to the Main Magics Tutorial

 

Go to the next step...

Go back to the main page...