Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Image RemovedImage Added

Info
titleDownload source and data

odb_scatterplot_binning.tar.gz

...

Tabs Container
directionhorizontal


Tabs Page
titleMacro


Code Block
languagepy
titleODB scatterplot with binningScatterplot Example

# Metview Macro

# **************************** LICENSE START ***********************************
#
# Copyright 2018 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 ************************************

# ------------------------------------------------------------------
# Tags: ODB,Cartesian
# Title: ODB scatterplot with binning
# Description: Demonstrates how to generate a scatterpot from ODB 
#              using binning.
# ------------------------------------------------------------------


use_mars = 0
if use_mars then
    #  retrieve ODBfrom MARS retrieval - for AMSUA channel 5 (all satellites)
    db = retrieve(
            type     : "mfb",
            repres   : "bu",
            obsgroup : "amsua",
            time     : 00,
            date     : -2,
            filter   : "select an_depar@body,fg_depar@body " &
                       "where vertco_reference_1=5"
        )
else
    db =           read('amsua.odb')
end if


# Define binning - with 100 bins both in the horizontal and vertical axes
bin_100 = binning(
        binning_x_count : 100,
        binning_y_count : 100
        )

# Define visualiser for scatterplot with binning
bin_plot = odb_visualiser(
        odb_plot_type      : "xy_binning",
        odb_x_variable     : "fg_depar@body",
        odb_y_variable     : "an_depar@body",
        odb_value_variable : "",
        #odb_where          : "vertco_reference_1@body =5 ",
        odb_data           : db,
        odb_binning        : bin_100
        )

# Define grid shading - the binned dataset will be defined on a grid
bin_grid_shade = mcont(
        legend                         : "on",
        contour                        : "off",
        contour_min_level              : 1,
        contour_shade_min_level        : 1,
        contour_level_count            : 20,
        contour_shade                  : "on",
        contour_shade_technique        : "grid_shading",
        contour_shade_method           : "area_fill",
        contour_shade_max_level_colour : "red",
        contour_shade_min_level_colour : "blue",
        contour_shade_colour_direction : "clockwise"
        )

# Define title
title = mtext(
        text_line_count : 1,
        text_line_1     : "Sensor: AMSU-A  Channel: 5 Param: Tb"
        )

# Define horizontal axis
hor_axis = maxis(
        axis_position         : "left",
        axis_title_text       : "fg_depar (K)",
        axis_tick_interval    : 0.5,
        axis_minor_tick       : "on",
        axis_minor_tick_count : 4,
        axis_grid             : "on",
        axis_grid_colour      : "black",
        axis_grid_line_style  : "dot"
        )

# Define vertical axis 
ver_axis = maxis(
        axis_orientation      : "vertical",
        axis_title_text       : "an_depar (K)",
        axis_tick_interval    : 0.5,
        axis_minor_tick       : "on",
        axis_minor_tick_count : 4,
        axis_grid             : "on",
        axis_grid_colour      : "black",
        axis_grid_line_style  : "dot"
        )

# Define Catresian view
scatter_view = cartesianview(
        x_min              : -1,
        x_max              : 1,
        y_min              : -1,
        y_max              : 1,
        subpage_y_position : 12.5,
        subpage_y_length   : 75,
        horizontal_axis    : hor_axis,
        vertical_axis      : ver_axis
        )


# define the output plot file
setoutput(pdf_output(output_name : 'odb_scatterplot_binning'))

# Plot
plot(scatter_view,bin_plot,bin_grid_shade,title)


Tabs Page
titlePython


Code Block
languagepy
titleODB Scatterplot Example

...

# Metview Example

# **************************** LICENSE START ***********************************
#
# Copyright 2018 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 ************************************

# ------------------------------------------------------------------
# Tags: ODB,Cartesian
# Title: ODB scatterplot with binning
# Description: Demonstrates how to generate a scatterpot from ODB 
#              using binning.
# ------------------------------------------------------------------

import metview as mv

use_mars = 0
if use_mars:
    #  retrieve from MARS - for AMSUA channel 5 (all satellites)
    db = mv.retrieve(
            type     

...

= "mfb",
            repres   

...

= "bu",
            obsgroup 

...

= "amsua",
            time     

...

= 00,
            date     

...

= -2,
            filter   

...

= "select an_depar@body,fg_depar@body " 

...

+
                       "where vertco_reference_1=5"
            )
else:
   

...

 db = mv.read("amsua.odb")

# Define binning - with 100 bins both in the horizontal and vertical 

...

axes
bin_100 = mv.binning(
        binning_x_count 

...

= 100,
        binning_y_count 

...

= 100
        )

# Define visualiser for scatterplot with binning
bin_plot = mv.odb_visualiser(
        odb_plot_type      

...

= "xy_binning",
        odb_x_variable     

...

= "fg_depar@body",
        odb_y_variable     

...

= "an_depar@body",
        odb_value_variable 

...

= "",
        #odb_where          = "vertco_reference_1@body =5 ",
        odb_data           

...

= db,
        odb_binning        

...

= bin_100
        )

# Define grid shading - the binned dataset will be defined on a 

...

grid

...

bin_grid_shade = mv.mcont(
        legend                         

...

= "on",
        contour                        

...

= "off",
        contour_min_level              

...

= 1,
        contour_shade_min_level        

...

= 1,
        contour_level_count            

...

= 20,
        contour_shade                  

...

= "on",
        contour_shade_technique        

...

= "grid_shading",
        contour_shade_method           

...

= "area_fill",
        contour_shade_max_level_colour 

...

= "red",
        contour_shade_min_level_colour 

...

= "blue",
        contour_shade_colour_direction 

...

= "clockwise"
        )

# Define 

...

title

...

title = mv.mtext(
        text_line_count 

...

= 1,
        text_line_1     

...

= "Sensor: AMSU-A  Channel: 5 Param: Tb"
        )

# Define horizontal axis
hor_axis = mv.maxis(
        axis_position         

...

= "left",
        axis_title_text       

...

= "fg_depar (K)",
        axis_tick_interval    

...

= 0.5,
        axis_minor_tick       

...

= "on",
        axis_minor_tick_count 

...

= 4,
        axis_grid             

...

= "on",
        axis_grid_colour      

...

= "black",
        axis_grid_line_style  

...

= "dot"
        )

# Define vertical axis 
ver_axis = mv.maxis(
        axis_orientation      = 

...

"vertical",
        axis_title_text       

...

= "an_depar (K)",
        axis_tick_interval    

...

= 0.5,
        axis_minor_tick       

...

= "on",
        axis_minor_tick_count 

...

= 4,
        axis_grid             

...

= "on",
        axis_grid_colour      

...

= "black",
        axis_grid_line_style  

...

= "dot"
        )

# Define Catresian view
scatter_view

...

 = mv.cartesianview(
        x_

...

min              

...

= -1,
        

...

x_

...

max              

...

= 

...

1,
        y_

...

min              

...

= -1,
        

...

y_

...

max 

...

 

...

      

...

   

...

 

...

  

...

= 1,
        

...

subpage_y_

...

position = 12.5,
     

...

 

...

  subpage_y_length   = 75,
  

...

 

...

 

...

    

...

horizontal_

...

axis 

...

  

...

 = 

...

hor_axis,
        

...

vertical_axis 

...

 

...

    = 

...

ver_axis
 

...

  

...

 

...

 

...

   )


# define the output plot file
mv.setoutput(

...

mv.pdf_output(output_name = 'odb_scatterplot_binning'))

# Plot
mv.plot(scatter_view,bin_plot,bin_grid_shade,title)