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

Unable to retrieve values for the daily variables 'sunrise' and 'sunset' #44

Open
alexiosgkikas opened this issue Feb 22, 2024 · 3 comments

Comments

@alexiosgkikas
Copy link

alexiosgkikas commented Feb 22, 2024

import openmeteo_requests

url = "https://api.open-meteo.com/v1/forecast"
params = {
    "latitude": 52.52,
    "longitude": 13.41,
    "daily": [
        "sunrise",
        "sunset",
    ],
}
openmeteo = openmeteo_requests.Client()
responses = openmeteo.weather_api(url, params=params)

response = responses[0]
daily = response.Daily()
daily_sunrise = daily.Variables(0).ValuesAsNumpy()
daily_sunset = daily.Variables(1).ValuesAsNumpy()

print("Sunrise type:", type(daily_sunrise))
print("Sunrise values:", daily_sunrise)
print("Sunset type:", type(daily_sunset))
print("Sunset values:", daily_sunset)

By running the previous snippet of code it prints the below results.

Sunrise type: <class 'int'>
Sunrise values: 0
Sunset type: <class 'int'>
Sunset values: 0

Question:
Is this the expected behavior or should it return a list of values for each variable(i.e ["2024-02-22T16:30", ...])?

It was tested in Python version 3.11.7, with the below libraries:
openmeteo_requests==1.2.0
openmeteo_sdk==1.10.0

@patrick-zippenfenig
Copy link
Member

Hi,
this is a shortcoming of the automatic code generator. Sunrise and set values are stored as 64-bit integers. Below the corrected code to get the correct values.
Support for automatic code generation will follow at some point

daily_sunrise = daily.Variables(0).ValuesInt64AsNumpy()
daily_sunset = daily.Variables(1).ValuesInt64AsNumpy()

@Sunwx123
Copy link

Sunwx123 commented Aug 20, 2024

Hi,
i use the code that you provided.

The results of data about sunrise and sunset are as follow: [1724126298 1724212798 1724299297 1724385797 1724472297 1724558798, 1724645298].

How do I get a normal sunrise time like ["2024-02-22T16:30", ...]?

@patrick-zippenfenig
Copy link
Member

Those are unix timestamps which you can convert using datetime functions

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