Examples¶
This page follows through a worked example:
Example data file
Creating a new mapping file
Editing the mapping file
Running the transformation
All the example files used are downloadable at the end of this page.
Data file (example-data.csv)¶
wsi |
year |
month |
day |
hour |
minute |
latitude |
longitude |
slp |
mslp |
ppp |
a |
brmh |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0-20000-0-06700 |
2022 |
02 |
10 |
6 |
0 |
46.2475 |
6.12774 |
978.3 |
1029.90 |
-0.4 |
8 |
412.3 |
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 --output bufr-mappings.json
generates the following file:
{
"inputDelayedDescriptorReplicationFactor": [],
"inputShortDelayedDescriptorReplicationFactor": [],
"inputExtendedDelayedDescriptorReplicationFactor": [],
"wigos_station_identifier": "data:wsi",
"number_header_rows": 1,
"column_names_row": 1,
"header": [
{
"eccodes_key": "edition",
"value": ""
},
{
"eccodes_key": "masterTableNumber",
"value": ""
},
{
"eccodes_key": "bufrHeaderCentre",
"value": ""
},
{
"eccodes_key": "bufrHeaderSubCentre",
"value": ""
},
{
"eccodes_key": "updateSequenceNumber",
"value": ""
},
{
"eccodes_key": "dataCategory",
"value": ""
},
{
"eccodes_key": "internationalDataSubCategory",
"value": ""
},
{
"eccodes_key": "dataSubCategory",
"value": ""
},
{
"eccodes_key": "masterTablesVersionNumber",
"value": ""
},
{
"eccodes_key": "localTablesVersionNumber",
"value": ""
},
{
"eccodes_key": "typicalYear",
"value": ""
},
{
"eccodes_key": "typicalMonth",
"value": ""
},
{
"eccodes_key": "typicalDay",
"value": ""
},
{
"eccodes_key": "typicalHour",
"value": ""
},
{
"eccodes_key": "typicalMinute",
"value": ""
},
{
"eccodes_key": "typicalSecond",
"value": ""
},
{
"eccodes_key": "typicalDate",
"value": ""
},
{
"eccodes_key": "typicalTime",
"value": ""
},
{
"eccodes_key": "numberOfSubsets",
"value": ""
},
{
"eccodes_key": "observedData",
"value": ""
},
{
"eccodes_key": "compressedData",
"value": ""
},
{
"eccodes_key": "unexpandedDescriptors",
"value": "array:301150,301011,301012,301021,7031,302001"
},
{
"eccodes_key": "subsetNumber",
"value": ""
}
],
"data": [
{
"eccodes_key": "#1#wigosIdentifierSeries",
"value": "",
"valid_min": "const:0",
"valid_max": "const:14",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#wigosIssuerOfIdentifier",
"value": "",
"valid_min": "const:0",
"valid_max": "const:65534",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#wigosIssueNumber",
"value": "",
"valid_min": "const:0",
"valid_max": "const:65534",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#wigosLocalIdentifierCharacter",
"value": ""
},
{
"eccodes_key": "#1#year",
"value": "",
"valid_min": "const:0",
"valid_max": "const:4094",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#month",
"value": "",
"valid_min": "const:0",
"valid_max": "const:14",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#day",
"value": "",
"valid_min": "const:0",
"valid_max": "const:62",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#hour",
"value": "",
"valid_min": "const:0",
"valid_max": "const:30",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#minute",
"value": "",
"valid_min": "const:0",
"valid_max": "const:62",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#latitude",
"value": "",
"valid_min": "const:-90.0",
"valid_max": "const:245.5443",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#longitude",
"value": "",
"valid_min": "const:-180.0",
"valid_max": "const:491.08862",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#heightOfBarometerAboveMeanSeaLevel",
"value": "",
"valid_min": "const:-400.0",
"valid_max": "const:12707.0",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#nonCoordinatePressure",
"value": "",
"valid_min": "const:0",
"valid_max": "const:163820",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#pressureReducedToMeanSeaLevel",
"value": "",
"valid_min": "const:0",
"valid_max": "const:163820",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#3HourPressureChange",
"value": "",
"valid_min": "const:-5000",
"valid_max": "const:5220",
"scale": "const:0",
"offset": "const:0"
},
{
"eccodes_key": "#1#characteristicOfPressureTendency",
"value": "",
"valid_min": "const:0",
"valid_max": "const:14",
"scale": "const:0",
"offset": "const:0"
}
]
}
This file includes the representable range (valid_min
and valid_max
) for the different BUFR elements.
These should be set to the physical range where applicable.
Customising the mapping file (bufr-mappings-edited.json)¶
Editing the bufr mappings file to map to the above example CSV data we have:
{
"inputDelayedDescriptorReplicationFactor": [],
"inputShortDelayedDescriptorReplicationFactor": [],
"inputExtendedDelayedDescriptorReplicationFactor": [],
"wigos_station_identifier": "data:wsi",
"number_header_rows": 1,
"column_names_row": 1,
"header": [
{
"eccodes_key": "edition",
"value": "const:4"
},
{
"eccodes_key": "masterTableNumber",
"value": "const:0"
},
{
"eccodes_key": "updateSequenceNumber",
"value": "const:0"
},
{
"eccodes_key": "dataCategory",
"value": "const:0"
},
{
"eccodes_key": "internationalDataSubCategory",
"value": "const:6"
},
{
"eccodes_key": "masterTablesVersionNumber",
"value": "const:36"
},
{
"eccodes_key": "typicalYear",
"value": "data:year"
},
{
"eccodes_key": "typicalMonth",
"value": "data:month"
},
{
"eccodes_key": "typicalDay",
"value": "data:day"
},
{
"eccodes_key": "typicalHour",
"value": "data:hour"
},
{
"eccodes_key": "typicalMinute",
"value": "data:minute"
},
{
"eccodes_key": "numberOfSubsets",
"value": "const:1"
},
{
"eccodes_key": "observedData",
"value": "const:1"
},
{
"eccodes_key": "compressedData",
"value": "const:0"
},
{
"eccodes_key": "unexpandedDescriptors",
"value": "array: 301150, 301011, 301012, 301021, 7031, 302001"
}
],
"data": [
{
"eccodes_key": "#1#wigosIdentifierSeries",
"value": "metadata:wsi_series",
"valid_min": "const:0",
"valid_max": "const:0"
},
{
"eccodes_key": "#1#wigosIssuerOfIdentifier",
"value": "metadata:wsi_issuer",
"valid_min": "const:0",
"valid_max": "const:65534"
},
{
"eccodes_key": "#1#wigosIssueNumber",
"value": "metadata:wsi_issue_number",
"valid_min": "const:0",
"valid_max": "const:65534"
},
{
"eccodes_key": "#1#wigosLocalIdentifierCharacter",
"value": "metadata:wsi_local"
},
{
"eccodes_key": "#1#year",
"value": "data:year",
"valid_min": "const:2022",
"valid_max": "const:2025"
},
{
"eccodes_key": "#1#month",
"value": "data:month",
"valid_min": "const:1",
"valid_max": "const:12"
},
{
"eccodes_key": "#1#day",
"value": "data:day",
"valid_min": "const:1",
"valid_max": "const:31"
},
{
"eccodes_key": "#1#hour",
"value": "data:hour",
"valid_min": "const:0",
"valid_max": "const:23"
},
{
"eccodes_key": "#1#minute",
"value": "data:minute",
"valid_min": "const:0",
"valid_max": "const:59"
},
{
"eccodes_key": "#1#latitude",
"value": "data:latitude",
"valid_min": "const:-90.0",
"valid_max": "const:90.0"
},
{
"eccodes_key": "#1#longitude",
"value": "data:longitude",
"valid_min": "const:-180.0",
"valid_max": "const:180.0"
},
{
"eccodes_key": "#1#heightOfBarometerAboveMeanSeaLevel",
"value": "data:brmh",
"valid_min": "const:-400.0",
"valid_max": "const:12707.0"
},
{
"eccodes_key": "#1#nonCoordinatePressure",
"value": "data:slp",
"valid_min": "const:0",
"valid_max": "const:163820",
"scale": "const:2",
"offset": "const:0"
},
{
"eccodes_key": "#1#pressureReducedToMeanSeaLevel",
"value": "data:mslp",
"valid_min": "const:0",
"valid_max": "const:163820",
"scale": "const:2",
"offset": "const:0"
},
{
"eccodes_key": "#1#3HourPressureChange",
"value": "data:ppp",
"valid_min": "const:-5000",
"valid_max": "const:5220",
"scale": "const:2",
"offset": "const:0"
},
{
"eccodes_key": "#1#characteristicOfPressureTendency",
"value": "data:a",
"valid_min": "const:0",
"valid_max": "const:14"
}
]
}
Note that the sequence includes no delayed replications and so the inputDelayedDescriptorReplicationFactor
etc can be left as empty arrays.
Elements that would be set to null have been removed.
Transformation¶
csv2bufr data transform \
./example-data.csv \
--bufr-template ./bufr-mappings-edited.json \
--output-dir ./
The links below can be used to download the example files: