This document aims to show how to use Diana to create plots of satellite images from Python scripts and from within the ipython notebook.
To get access to the Python modules that expose Diana's plotting features, you need to install the python-diana
package from the local package repository. Either use the package manager to do this, or enter the following in a
terminal:
apt-get install python-diana
Some examples can also be found in the python-diana-examples
package.
You can use Diana's functionality from Python by importing the bdiana
and plotcommands
modules from the metno
package. If you are using
an old version of ipython (earlier than version 1.0) then it is also useful to import the embed
function from the
metno.ipython_extensions
module.
In [1]:
# Import the modules needed to use Diana.
from metno import bdiana, plotcommands
# Import an extension that lets us embed an image into a worksheet.
from metno.ipython_extensions import embed
In [2]:
b = bdiana.BDiana()
By default, Diana doesn't know anything about data files or other resources. The locations of data files,
definitions of plot types, palettes, and other pieces of information are stored in one or more setup files.
We choose one of these and use the setup
method to let Diana know where to get data from.
In [3]:
b.setup("/etc/diana/setup/diana.setup-COMMON")
In [4]:
products = b.getSatProducts()
The dictionary obtained contains information about the satellite products available. The dictionary keys contain the product names. The values are also dictionaries.
In [5]:
keys = products.keys()
keys.sort()
keys
Choosing one of these, we obtain a dictionary containing information about the subproducts.
In [6]:
products["NOAA"]
We obtain the dictionary value that corresponds to the subproduct we are interested in and
read its channel
attribute to get the list of available channels.
In [7]:
channels = products["NOAA"]["N-Europa"].channel
channels
The times for which there are images can be found by querying the BDiana
object with the
product and subproduct names.
In [8]:
times = b.getSatTimes("NOAA", "N-Europa")
times[-5:]
In [9]:
s = plotcommands.Satellite()
s.setOption("product", "NOAA")
s.setOption("subproduct", "N-Europa")
s.setOption("channel", "day_night")
s.setOption("alpha", 64) # 0-255
We create a plot as usual by creating plot commands for the area and map, as well as for the satellite data.
In [10]:
a = plotcommands.Area(name="Atlant")
m = plotcommands.Map(map="Gshhs-Auto", backcolour="white", land="on")
m.setOption("land.colour", "flesh")
l = plotcommands.Label(data="")
b.setPlotCommands([a.text(), m.text(), s.text(), l.text()])
b.setPlotTime(times[-1])
embed(b.plotImage(500, 500))
We can obtain a mosaic of images by setting the mosaic
plot option.
In [11]:
s.setOption("mosaic", 1)
b.setPlotCommands([a.text(), m.text(), s.text(), l.text()])
b.setPlotTime(times[-1])
embed(b.plotImage(500, 500))
In [12]:
products["YR-RADAR"]["WR_NORDICLCC"].channel
We use the Radar
plot command, but this is effectively the same as the Satellite
plot
command. The string passed to Diana contains a command to display a satellite image.
In [13]:
r = plotcommands.Radar()
r.setOption("product", "YR-RADAR")
r.setOption("subproduct", "WR_NORDICLCC")
r.setOption("channel", "PSC_Z")
r.setOption("alpha", 64) # 0-255
a = plotcommands.Area(name="Norge")
b.setPlotCommands([a.text(), m.text(), r.text(), l.text()])
b.setPlotTime(times[-1])
embed(b.plotImage(500, 500))