Simple PHP package to parse SwissMetNet Open Data strings.
Disclaimer: This library is not official and not affiliated with MeteoSwiss.
Created for usage on api.existenz.ch and indirectly on Aare.guru. As of 2023 in productive use.
MeteoSwiss (Bundesamt für Meteorologie und Klimatologie/Federal Office of Meteorology and Climatology) offers a selection of their SwissMetNet measurement data on the opendata.swiss portal.
Measures air temperatures, rain rate, winds, pressure, geopotentials and sunshine duration. Not every station measures every parameter.
Note that most stations measure this 2 meters above ground, but some tower stations locate their sensors higher in the air. The parameters with suffix _tow
are measured on tower stations.
Periodicity: 10 minutes.
Licencing restrictions apply by MeteoSwiss. See the Open Data download for detailed informations. You will have to credit any usage of the data with the string "Source: MeteoSwiss".
- Download the ZIP archive from the Open Data portal.
- Read the legal and licencing information.
- Open
1_download_URL.txt
. - Find the links to the data CSVs (I.e.
VQHA80.csv
orVQHA98.csv
) and metadata TXTs.
Starting from 2020-10-19 the data format of VQHA80
changed slighty from the original format: They are now valid CSV files, semicolon separated, with a new header line:
Station/Location;Date;tre200s0;rre150z0;sre000z0;gre000z0;ure200s0;tde200s0;dkl010z0;fu3010z0;fu3010z1;prestas0;pp0qffs0;pp0qnhs0;ppz850s0;ppz700s0;dv1towz0;fu3towz0;fu3towz1;ta1tows0;uretows0;tdetows0
TAE;202010191400;11.90;0.00;10.00;326.00;67.50;6.10;26.00;4.30;7.20;957.70;1021.00;1021.20;-;-;-;-;-;-;-;-
COM;202010191400;11.70;0.00;0.00;100.00;68.30;6.10;114.00;1.80;4.30;955.90;1023.60;1023.80;-;-;-;-;-;-;-;-
...
MeteoSwiss data files VQHA80
are semicolon separated CSVs with a custom header:
MeteoSchweiz / MeteoSuisse / MeteoSvizzera / MeteoSwiss
stn;time;tre200s0;rre150z0;sre000z0;gre000z0;ure200s0;tde200s0;dkl010z0;fu3010z0;fu3010z1;prestas0;pp0qffs0;pp0qnhs0;ppz850s0;ppz700s0;dv1towz0;fu3towz0;fu3towz1;ta1tows0;uretows0;tdetows0
TAE;201911222230;2.4;0.0;0;1;97;1.9;93;5.0;10.8;939.0;1003.3;1001.5;-;-;-;-;-;-;-;-
COM;201911222230;4.1;0.1;0;1;99;4.0;343;3.6;5.0;944.1;1012.9;1011.4;-;-;-;-;-;-;-;-
...
Older data files like VQHA69.csv
used the pipe symbol as separators:
MeteoSchweiz / MeteoSuisse / MeteoSvizzera / MeteoSwiss
stn|time|tre200s0|sre000z0|rre150z0|dkl010z0|fu3010z0|pp0qnhs0|fu3010z1|ure200s0|prestas0|pp0qffs0
TAE|201803301120|9.1|1|0.0|87|4.7|1000.1|10.4|73|937.6|1000.2
COM|201803301120|7.3|0|0.2|185|16.9|1005.2|26.6|94|938.3|1005.8
...
The metadata files are free form textual files with space separated tables. Good luck parsing those.
Encoding is ISO-8859-1. This library outputs UTF-8.
Starting from 2021, the metadata is split up into two files: A text file (I.e. VQHA80_en.txt
) containing the parameter metadata and a link to a CSV (I.e. ch.meteoschweiz.messnetz-automatisch_en.csv
) containing the location metadata.
composer require cstuder/parse-swissmetnet
<?php
require('vendor/autoload.php');
$raw = file_get_contents('https://data.geo.admin.ch/ch.meteoschweiz.messwerte-aktuell/VQHA80.csv');
$data = \cstuder\ParseSwissMetNet\SuperParser::parse($raw);
var_dump($data);
See the bin
directory for more working code.
The parser is intentionally limited: It parses the given string and returns all data which looks valid. It silently skips over any line it doesn't understand.
Values are converted to float
. Missing data values are not returned, the values will never be null
.
Parses a SwissMetNet data string, tries out all available parsers one after another. If any of them finds anything, returns that data.
Returns an empty row if no parsers find anything. Use at your own risk.
Returns a row of value objects with the keys timestamp
, loc
, par
, val
.
Parses a SwissMetNet data string containing semicolon separated measurements in the 2020 version.
Returns a row of value objects with the keys timestamp
, loc
, par
, val
.
Parses a SwissMetNet data string containing semicolon separated measurements.
Returns a row of value objects with the keys timestamp
, loc
, par
, val
.
Parses an older SwissMetNet data string containing pipe separated measurements.
Returns a row of value objects with the keys timestamp
, loc
, par
, val
.
Parses a SwissMetNet description string containing location and parameter definitions.
Returns two fields: locations
and parameters
, both containing arrays of StdClass objects with fields such as location coordinates or parameter units.
This parse method behaves like the SuperParser
: It tries parsing text files à la VQHA80_en.txt
and CSV files à la ch.meteoschweiz.messnetz-automatisch_en.txt
. It combines the found metadata into one list.
Parses a SwissMetNet description string from a file like VQHA80_en.txt
containing location and parameter definitions.
Returns two fields: locations
and parameters
, both containing arrays of StdClass objects with fields such as location coordinates or parameter units.
Parses a SwissMetNet description string from a file like ch.meteoschweiz.messnetz-automatisch_en.txt
containing location and parameter definitions.
Returns two fields: locations
and parameters
, both containing arrays of StdClass objects with fields such as location coordinates or parameter units.
Run composer test
to execute the PHPUnit test suite.
- Add changes to the changelog.
- Add new parsers to the
SuperParser
. - Create a new tag
vX.X.X
. - Push.
MIT.
Christian Studer [email protected], Bureau für digitale Existenz.