emf-creaf / meteospain

Access to Spanish Meteorological Stations Services
https://emf-creaf.github.io/meteospain
Other
8 stars 4 forks source link

Allow fetching all vars exposed through Meteocat API (with new param?) #27

Closed xavidp closed 1 month ago

xavidp commented 1 month ago

I was reviewing some extreme temperature values from this last July through meteocat api (using meteospain) and I was surprised to notice that the extreme temperature value in daily values was not detected in the hourly values of that day.

And that seem to be due to fetching through meteospain hourly values in meteocat only average temperatures (variable 32) every half an hour, but not the max temperature (variable 40) and min temperature (variable 42): https://github.com/emf-creaf/meteospain/blob/63972c1c22a4ef59ecb1f64a60e48dad59e0b855/R/meteocat_helpers.R#L202

Codes obtained from https://analisi.transparenciacatalunya.cat/Medi-Ambient/Metadades-variables-meteorol-giques/4fb2-n3yi/explore/query/SELECT%0A%20%20%60codi_variable%60%2C%0A%20%20%60nom_variable%60%2C%0A%20%20%60unitat%60%2C%0A%20%20%60acronim%60%2C%0A%20%20%60codi_tipus_var%60%2C%0A%20%20%60decimals%60%0AORDER%20BY%20%60nom_variable%60%20ASC%20NULL%20LAST/page/filter

And I reckon that other people might also want some other values that are available in the hourly values. Example: https://www.meteo.cat/observacions/xema/dades?codi=D5&dia=2024-07-30T00:00Z

Therefore, could it be possible to expose all variables that come through the API from meteocat to the user? And eventually, allow limiting the number of variables to fetch through some new param. Or the other way around, expose some new param in the meteospain package for meteocat, to allow the user to fetch all variables offered by the API?

There are some protocols that read like: "when min temperature at the time range from 00 am to 6:00am is above certain threshold, some phase of extreme heat is activated in some public administrations, etc. Right now, if we want to monitor the temperature data through the awesome "meteospain" package you developed, we can't, and we need to explore other ways aside of meteospain (RSocrata, etc) for such use case. which is a pity, and more tedious to work with.

I could just hack the functions in that R file (once forked) and try to add the missing Tmax and Tmin variables here and there, but maybe there is some more generic approach.

What do you think?

MalditoBarbudo commented 1 month ago

Sounds reasonable. I can look into it to add the missing vars.
On the other hand, I don't like the idea of adding more parameters to select / filter variables. One can always ignore the variables not interested in or drop them with dplyr::select and the API will always return all variables, so any filtering step is just overload in meteospain. I would rather keep it simple and return as much as we can from the API response, leaving the selecting / filtering to the user.

MalditoBarbudo commented 1 month ago
xavidp commented 1 month ago

Awesome! The simpler the better (I'd rather prefer this solution, fetch everything, let the user select what is needed).

MalditoBarbudo commented 1 month ago

Seem like instant and hourly radiation data were in wrong units until now. Fixed also here.

MalditoBarbudo commented 1 month ago

Fixed in devel

@xavidp If you install the devel version with devtools or remotes now the hourly scale should return all the data (except for wind directions at 6 and 10m)

xavidp commented 1 month ago

Fix confirmed! (the variables I reported that were missing are nowadays included). Congrats and thanks heaps!

xavidp commented 1 month ago

Sorry, forgot to close as fixed. Doing it right now.