Examples

This page follows through a worked example:

  1. Example data file

  2. Example metadata file

  3. Creating a new mapping file

  4. Editing the mapping file

  5. Running the transformation

All the example files used are downloadable at the end of this page.

Data file (example-data.csv)

example-data.csv

year

month

day

hour

minute

latitude

longitude

slp

mslp

ppp

a

brmh

2022

02

10

6

0

46.2475

6.12774

978.3

1029.90

-0.4

8

412.3

Metadata file (example-metadata.json)

{
  "wigosIds": [
    {
      "wid": "0-20000-0-06700"
    }
  ]
}

Creating a new mapping file

A command line tool to create an empty BUFR mapping template has been included as part of the csv2bufr module. This can be invoked using the csv2bufr mappings create <BUFR descriptors> command. E.g.:

csv2bufr mappings create 301150 301011 301012 301021 007031 302001 > bufr-mappings.json

generates the following file:

{
    "inputDelayedDescriptorReplicationFactor": [],
    "number_header_rows": 1,
    "names_on_row": 1,
    "header": [
        {
            "eccodes_key": "edition",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "masterTableNumber",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "bufrHeaderCentre",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "bufrHeaderSubCentre",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "updateSequenceNumber",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "dataCategory",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "internationalDataSubCategory",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "dataSubCategory",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "masterTablesVersionNumber",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "localTablesVersionNumber",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "typicalYear",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "typicalMonth",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "typicalDay",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "typicalHour",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "typicalMinute",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "typicalSecond",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "typicalDate",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "typicalTime",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "numberOfSubsets",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "observedData",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "compressedData",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "unexpandedDescriptors",
            "value": [
                301150,
                301011,
                301012,
                301021,
                  7031,
                302001
            ],
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "subsetNumber",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        }
    ],
    "data": [
        {
            "eccodes_key": "#1#wigosIdentifierSeries",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#wigosIssuerOfIdentifier",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#wigosIssueNumber",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#wigosLocalIdentifierCharacter",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#year",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#month",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#day",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#hour",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#minute",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#latitude",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#longitude",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#heightOfBarometerAboveMeanSeaLevel",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#nonCoordinatePressure",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#pressureReducedToMeanSeaLevel",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#3HourPressureChange",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        },
        {
            "eccodes_key": "#1#characteristicOfPressureTendency",
            "value": null,
            "csv_column": null,
            "jsonpath": null,
            "valid_min": null,
            "valid_max": null,
            "scale": null,
            "offset": null
        }
    ],
    "wigos_identifier": {
        "value": null,
        "jsonpath": null,
        "csv_column": null
    }
}

Customising the mapping file (bufr-mappings-edited.json)

Editing the bufr mappings file to map to the above example CSV data we have:

{
    "inputDelayedDescriptorReplicationFactor": [],
    "number_header_rows": 1,
    "names_on_row": 1,
    "header": [
        {
            "eccodes_key": "edition",
            "value": 4
        },
        {
            "eccodes_key": "masterTableNumber",
            "value": 0
        },
        {
            "eccodes_key": "updateSequenceNumber",
            "value": 0
        },
        {
            "eccodes_key": "dataCategory",
            "value": 0
        },
        {
            "eccodes_key": "internationalDataSubCategory",
            "value": 6
        },
        {
            "eccodes_key": "masterTablesVersionNumber",
            "value": 36
        },
        {
            "eccodes_key": "typicalYear",
            "csv_column": "year"
        },
        {
            "eccodes_key": "typicalMonth",
            "csv_column": "month"
        },
        {
            "eccodes_key": "typicalDay",
            "csv_column": "day"
        },
        {
            "eccodes_key": "typicalHour",
            "csv_column": "hour"
        },
        {
            "eccodes_key": "typicalMinute",
            "csv_column": "minute"
        },
        {
            "eccodes_key": "numberOfSubsets",
            "value": 1
        },
        {
            "eccodes_key": "observedData",
            "value": 1
        },
        {
            "eccodes_key": "compressedData",
            "value": 0
        },
        {
            "eccodes_key": "unexpandedDescriptors",
            "value": [
                301150,
                301011,
                301012,
                301021,
                  7031,
                302001
            ]
        }
    ],
    "data": [
        {
            "eccodes_key": "#1#wigosIdentifierSeries",
            "jsonpath": "$.wigosIds[0].wid_series"
        },
        {
            "eccodes_key": "#1#wigosIssuerOfIdentifier",
            "jsonpath": "$.wigosIds[0].wid_issuer"
        },
        {
            "eccodes_key": "#1#wigosIssueNumber",
            "jsonpath": "$.wigosIds[0].wid_issue_number"
        },
        {
            "eccodes_key": "#1#wigosLocalIdentifierCharacter",
            "jsonpath": "$.wigosIds[0].wid_local"
        },
        {
            "eccodes_key": "#1#year",
            "csv_column": "year"
        },
        {
            "eccodes_key": "#1#month",
            "csv_column": "month"
        },
        {
            "eccodes_key": "#1#day",
            "csv_column": "day"
        },
        {
            "eccodes_key": "#1#hour",
            "csv_column": "hour"
        },
        {
            "eccodes_key": "#1#minute",
            "csv_column": "minute"
        },
        {
            "eccodes_key": "#1#latitude",
            "csv_column": "latitude"
        },
        {
            "eccodes_key": "#1#longitude",
            "csv_column": "longitude"
        },
        {
            "eccodes_key": "#1#heightOfBarometerAboveMeanSeaLevel",
            "csv_column": "brmh"
        },
        {
            "eccodes_key": "#1#nonCoordinatePressure",
            "csv_column": "slp",
            "scale": 2,
            "offset": 0
        },
        {
            "eccodes_key": "#1#pressureReducedToMeanSeaLevel",
            "csv_column": "mslp",
            "scale": 2,
            "offset": 0
        },
        {
            "eccodes_key": "#1#3HourPressureChange",
            "csv_column": "ppp",
            "scale": 2,
            "offset": 0
        },
        {
            "eccodes_key": "#1#characteristicOfPressureTendency",
            "csv_column": "a"
        }
    ]
}

Note that the sequence includes no delayed replications and so the inputDelayedDescriptorReplicationFactor can be left as an empty array. Elements that would be set to null have been removed.

Transformation

csv2bufr data transform ./example-data.csv --bufr-template ./bufr-mappings-edited.json \
    --station-metadata ./example-metadata.json --output-dir ./

The links below can be used to download the example files: