Closed SchabiDesigns closed 2 months ago
Hi,
the unit is encoded in .Unit()
which returns an integer from an enumation which den be converted with
import openmeteo_requests
import openmeteo_sdk
[...]
def unit_to_name(code):
for name, value in openmeteo_sdk.Unit.Unit.__dict__.items():
if value == code:
return name
return None
# Process hourly data. The order of variables needs to be the same as requested.
hourly = response.Hourly()
#hourly_temperature_2m = hourly.Variables(0).ValuesAsNumpy()
hourly_temperature_2m = hourly.Variables(0)
unit = hourly_temperature_2m.Unit()
print(unit)
print(type(unit))
print(unit_to_name(unit))
hourly_temperature_2m_Data = hourly_temperature_2m.ValuesAsNumpy()
Prints
1
<class 'int'>
celsius
Hello guys Is there a way to get the variable units from the response?
_variables and models are just lists of variables I pass to the function... for example: variables = ["temperature_2m", "precipitation"] models = ["bestmatch"]
I would like to do something similar for the units in my variables like that:
hourly_units
= {var: hourly.Units(i).ValuesAsNumpy() for var, i in zip(variables, range(len(variables)))}` If I check the API in the response there is hourly_units which is what I need...Thanks for your help! To the developers: Thanks for that epic possiblity to get forcast and historical data for so many weather-models!!!! I absolutly love it 💕 Regards Schabi