pnuu / fmiopendata

Python interface for FMI open data
GNU General Public License v3.0
50 stars 9 forks source link

Forecast data download - ModuleNotFoundError: No module named 'eccodes' " #18

Closed jeppoo1 closed 3 years ago

jeppoo1 commented 3 years ago

Hello, I'm having problems with downloading FMI forecast data with python (3.9).

I'm using your code example from github:

from fmiopendata.wfs import download_stored_query

model_data = download_stored_query("fmi::forecast::harmonie::surface::grid",
                                   args=["starttime=2020-07-06T18:00:00Z",
                                         "endtime=2020-07-06T20:00:00Z",
                                         "bbox=18,55,35,75"])

and getting the following error message:

  File "c:/****/****.py", line 561, in <module>
    model_data = download_stored_query("fmi::forecast::harmonie::surface::grid",
  File "C:\***\****\Python\Python38-32\lib\site-packages\fmiopendata\wfs.py", line 120, in download_stored_query
    from fmiopendata.grid import download_and_parse
  File "C:\***\****\AppData\Local\Programs\Python\Python38-32\lib\site-packages\fmiopendata\grid.py", line 31, in <module>
    import eccodes
ModuleNotFoundError: No module named 'eccodes'

I have eccodes installed, here are the messages for pip install eccodes:

pip install eccodes
Requirement already satisfied: eccodes in c:\python39\lib\site-packages (1.1.0)
Requirement already satisfied: cffi in c:\python39\lib\site-packages (from eccodes) (1.14.4)
Requirement already satisfied: attrs in c:\python39\lib\site-packages (from eccodes) (20.3.0)
Requirement already satisfied: numpy in c:\python39\lib\site-packages (from eccodes) (1.20.1)
Requirement already satisfied: pycparser in c:\python39\lib\site-packages (from cffi->eccodes) (2.20)
jeppoo1 commented 3 years ago

@pnuu For the record, the following Python program seems to be working:

from fmiopendata.wfs import download_stored_query

model_data = download_stored_query("fmi::forecast::hirlam::surface::obsstations::multipointcoverage",
                                   args=["starttime=2020-07-06T18:00:00Z",
                                         "endtime=2020-07-06T20:00:00Z",
                                         "bbox=18,55,35,75"])

but to my knowledge it is only able to download forecast data for the following 48 hours or so. Is this a limitation of the FMI open data servers, or can it be set in the Python program to download more future forecast data (for example, the next two weeks)?

pnuu commented 3 years ago

Sorry for the late reply. The description of the StoredQuery in your second message says that the default query (without start/end times) returns 36 hours, but it doesn't state how long forecasts are available. I'd expect it to be around a week, or probably less than that. In any case, the limitation is at the FMI side.

pnuu commented 3 years ago

I'm having problems with downloading FMI forecast data with python (3.9).

The exception shows that the script is trying to use Python 3.8 (32-bit version?). Are you had the correct Python environment in use for the script?

jeppoo1 commented 3 years ago

@pnuu Thank you, I didn't notice I had Python 3.8 selected! Now that I selected Python 3.9 and ran your ::harmonie:: code example, I got the following error:

... in <module>
    model_data = download_stored_query("fmi::forecast::harmonie::surface::grid",
  File "C:\Python39\lib\site-packages\fmiopendata\wfs.py", line 120, in download_stored_query
    from fmiopendata.grid import download_and_parse
  File "C:\Python39\lib\site-packages\fmiopendata\grid.py", line 31, in <module>
    import eccodes
  File "C:\Python39\lib\site-packages\eccodes\__init__.py", line 15, in <module>
    from .eccodes import *
  File "C:\Python39\lib\site-packages\eccodes\eccodes.py", line 12, in <module>
    from gribapi import __version__
  File "C:\Python39\lib\site-packages\gribapi\__init__.py", line 13, in <module>
    from .gribapi import *  # noqa
  File "C:\Python39\lib\site-packages\gribapi\gribapi.py", line 2228, in <module>
    __version__ = grib_get_api_version()
  File "C:\Python39\lib\site-packages\gribapi\gribapi.py", line 2218, in grib_get_api_version
    raise RuntimeError("Could not load the ecCodes library!")
RuntimeError: Could not load the ecCodes library!

I have confirmed I have both fmiopendata and eccodes installed in Python 3.9 also.

JaniKallankari commented 3 years ago

I get same error with python 3.8. Is there any plans to fix this error?

pnuu commented 3 years ago

Sorry, haven't had time to do anything with fmiopendata for months so haven't checked the issues either.

From the error messages I guess you are either missing eccodes the library, or the Python wrapper for the library. The library can be installed with conda install eccodes or via your operating systems package manager. The latter can be installed with conda install python-eccodes or pip install eccodes. In any case, not related to fmiopendata, so closing this issue.