Page 1 of 1

Reader for KNMI data from DeveloperPortal

Posted: Thursday 13 July 2023 10:20
by Toulon7559
At their DeveloperPortal KNMI provides (among a bounty of other information) actual weather data for all their networked stations.
Interesting to pick data for a station in your vicinity or near you holiday address.
Unfortunately the output format is not something like JSON-file or XML-file, but nc-type files:
;) very professional, but less used by 'amateurs'.

Tried to make a Python-reader extracting station data from the nc-files, but struggle with application of Python-module netCDF4.
Running on a Raspberry with Raspian_Buster, in combination with venv, have tried installation of the required modules both for Python2.7 and for Python3.x.
Same for running the application-script.
The simple, basic installation-line does not result in subsequent, easy import of the module in the application-script.

Code: Select all

pip install netCDF4
Therefore separately installed all required submodules, using it's tar-file for netCDF462.
Installation of that module netCDF4 and related modules for hdf5, pandas and numpy now seems OK, as shown by Putty CLI

Code: Select all

nc-config --all

but running the application-script still reports that import of the module netCDF4 fails.

Somebody with experience for a simple, yet reliable procdure to get import of netCDF4, preferably for application-script in Python3.x?
Nagging feeling that location of modules has effects, but unsure howto check & remedy.

Re: Reader for KNMI data from DeveloperPortal

Posted: Thursday 13 July 2023 10:50
by FireWizard
Hello @Toulon7559,

I think this might be interesting as well: https://github.com/parro-it/netcdf4.

You can implement this in Node Red.

Regards

Re: Reader for KNMI data from DeveloperPortal

Posted: Thursday 13 July 2023 13:59
by Toulon7559
Using the hinted Github, checking with the installation CLI

Code: Select all

sudo apt-get install libnetcdf-dev
The response tells that latest version of netCDF4 already present (which seems OK).

The original script-setup uses an import-line as required for the 'read'-instruction later in the script to get the nc-file from folder data

Code: Select all

from netCDF4 import Dataset
=> error report telling that netCDF4 not found

Code: Select all

dataset = Dataset('data/'+filename, 'r', format='NETCDF4')
Using the hinted github-solution for Usage, IMHO that translates into the alternative scriptlines for nc-reading

Code: Select all

    var netcdf4 = require("netCDF4");

    var dataset = new netcdf4.File('data/'+filename, 'r');
Tried with setups for CLI and script both for Python2.7 and Python3.x,
but unfortunately in both cases the result is same

Code: Select all

  File "knmi-synop.py", line 181
    var netcdf4 = require("netCDF4");
              ^
SyntaxError: invalid syntax
Puzzled, because the CLIs and scriptlines look OK

Must be some 'linking'-error, because nc-config reports netCDF4 as present, but both the 'import' and the 'require' fail to find.

Re: Reader for KNMI data from DeveloperPortal

Posted: Friday 14 July 2023 22:57
by Toulon7559
From developer of the Python-script the info that he applies Debian11.
On my testing Raspberry still Raspian_Buster ~ Debian10, including Domoticz.
When developer tests on machine with Debian10, also gets all kind of odd errors:
conclusion that such 'environment' not suitable for the script.

Obvious next move is testing of script+environment on a Raspberry with 'newer' OS-release = Bullseye ~ Debian11.
Without Domoticz, to avoid any discussion which instance of Python is applied.
Installation without trouble, but the script still does not find module netCDF4.
For prudent approach simplifying the script by insertion of an extra line

Code: Select all

import netCDF4
However result is an error

Code: Select all

  File "/home/pi/Python_scripts/knmi-synop-stations/knmi-synop.py", line 12, in <module>
    import netCDF4
ModuleNotFoundError: No module named 'netCDF4'
After such report one takes less conventional approach:
with WinSCP searched the subject Raspberry for text 'netCDF4' starting in the root-directory => nothing found!
Searchscan for 'netcdf' has same (negative) result.

Question mark remains: how resolution for 'missing module' .........