Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mosmix_forecasts.py doesn't work #289

Closed
JohannaSte opened this issue Dec 15, 2020 · 3 comments
Closed

mosmix_forecasts.py doesn't work #289

JohannaSte opened this issue Dec 15, 2020 · 3 comments

Comments

@JohannaSte
Copy link

JohannaSte commented Dec 15, 2020

Hey everyone,

I was trying to get the mosmix data in Python using your example. It states the following:

Traceback (most recent call last):
  File "xxx/main.py", line 56, in <module>
    print(response.metadata)
AttributeError: 'generator' object has no attribute 'metadata'
<generator object DWDMosmixData.collect_data at 0x7fbd7ac5a0a0>

I was running the code of the mosmix_forecasts.py in the example folder.

Desktop:

  • OS: Ubuntu 18.04
  • Python-Version 3.6
  • Using the package "wetterdienst" Version 0.11.1

Any ideas what goes wrong or how I could fix it?

Best regards

@amotl
Copy link
Member

amotl commented Dec 15, 2020

Dear Johanna,

thanks for reporting this and for using Wetterdienst.

While we tried hard to reproduce your observations, we are not able to see any problems on our end. As we are still regularly refining our API, the most likely cause that something croaks on your end is that you might be using an outdated example program.

So, I want to humbly ask you to verify MOSMIX data acquisition with Wetterdienst 0.11.1 using the example program matching the respective version [1].

In order to make sure the example programs are always valid, we recently started to include them into the test harness which is checking the whole code base in order to be confident that we don't put out releases with wrong code examples - it happened before and we are always aiming to get better.

Please let us know if this will already resolve the issue for you. While we are sorry that things might regularly break while we are still on 0.xx versions, we are still committed to make our users happy and listen to them.

With kind regards,
Andreas.

[1] https://github.com/earthobservations/wetterdienst/blob/v0.11.1/example/mosmix_forecasts.py

@amotl
Copy link
Member

amotl commented Dec 15, 2020

Hi again,

if my suggestion to use the respective example program won't help, please try to purge the local cache folder of Wetterdienst. You can find its location by invoking

python -c 'import appdirs; print(appdirs.user_cache_dir(appname="wetterdienst"))'

We are seeing different problems with the current cache implementation and will replace it by a better alternative within one of the next iterations, see also #243.

With kind regards,
Andreas.

@gutzbenj
Copy link
Member

gutzbenj commented Dec 15, 2020

Dear Johanna, it seems you were running roughly such kind of code sample

from wetterdienst.dwd.forecasts.metadata.dates import DWDForecastDate
from wetterdienst.dwd.forecasts import DWDMosmixData, DWDMosmixType
from wetterdienst.util.cli import setup_logging

mosmix = DWDMosmixData(
        station_ids=["01001", "01008"],
        parameters=["DD", "ww"],
        start_date=DWDForecastDate.LATEST,  # automatically set if left empty
        mosmix_type=DWDMosmixType.LARGE,
        tidy_data=True,
        humanize_column_names=True,
    )

response = mosmix.collect_data()

print(response.metadata)

The collect_data method is written as a generator, which means it returns chunk by chunk of whatever was requested. This behavior is mainly to reduce occupied RAM which may by full at some point. To use the generator there are two main options which are

respose = next(mosmix.collect_data())

which would return only one next chunk. To draft all data coming from the generator you may instead use the iterator in
to go through the whole generator and return whatever is found e.g.

for response in mosmix.collect_data():
    print(response.metadata)

I hope that those two code samples will fix your problem and if not please come back to us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants