Versions Compared

Key

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

...

Metview incorporates functionality to read, process and visualise data stored in ASCII table files, including the commonly-used CSV (comma-separated value) format.

Visualising ASCII table data

Look at the supplied file t2_20120304_1400_1200.csv. This is a standard CSV file, with a header row at the top, followed by one row per observation, one column per field.

 

Panel
Station,Lat,Lon,T2m
1,71.1,28.23,271.3
2,70.93,-8.67,274.7
. . .

A CSV file can have any number of columns, but this is a simple example.

To plot the data, we need to tell Metview which columns contain the coordinates and which contain the values. Create a new Table Visualiser icon and edit it. Drop the CSV icon into the Table Data field and set the following parameters:

Table Plot TypeGeo Points
Table Longitude VariableLon
Table Latitude VariableLat
Table Value VariableT2m

Notice that this icon contains several parameters at the bottom which allow you to read differently-formatted ASCII table files. The question-mark buttons beside the parameter names give brief information on what they mean. The defaults are set up to read a standard CSV file, so we don't need to touch these parameters in this example.

Visualise this icon to plot the data, and apply the supplied symb_colours icon to get a nicer plot.

Converting ASCII Table data to geopoints format

Although Metview has some functionality for handling this type of data in Macro, it can do much more with the geopoints format. Therefore, if the data points are in geographic coordinates, one useful exercise is to read one of these files and convert it to geopoints.

Create a new Table Reader icon - this is purely a helper icon which exists only to aid the generation of Macro code. Drop the CSV file into the Data field. We do not need to touch the other parameters since this is a standard CSV file.

Drop the icon into a new Macro to generate the code to read the file. Rename the resulting variable to data. The following lines of code will print some information about the data:

Code Block
languagepy
print('Num cols: ', count(data))
print('Col 4: ', name(data, 4))

 

Now we will create a new geopoints variable, and set its lats, lons and values to those from the CSV data.

First, use the values() function to extract arrays of lats, lons and T2m from the CSV data. These will be returned in variables of type vector - this is an in-memory array of double-precision numbers.

Panel

vector or list values( table, number )
vector or list values( table, string )

Returns the given column specified either by an index (starting at 1) or a name (only valid if the table has a header row). If the column type is number, a vector is returned; if it is string, then a list of strings is returned. If the column cannot be found, an error message is generated.

Next, find out how many values there are, using the count() function on one of the returned vectors.

Finally, the following code shows how to construct a simple geopoints variable using only these columns (i.e. it will be in XYV format):

Code Block
languagepy
geo = create_geo(num_vals, 'xyv')
geo = set_latitudes (geo, lats)
geo = set_longitudes(geo, lons)
geo = set_values    (geo, vals)

The macro can now write this to disk, return it to the user interface or process it further using all the available geopoints functions.