Add function to retrieve requested variables from data request API#228
Add function to retrieve requested variables from data request API#228
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #228 +/- ##
==========================================
+ Coverage 47.47% 47.58% +0.10%
==========================================
Files 22 22
Lines 4183 4195 +12
==========================================
+ Hits 1986 1996 +10
- Misses 2197 2199 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| from data_request_api.query import dreq_query as dq | ||
| from data_request_api.utilities.config import update_config | ||
|
|
||
| update_config("variable_name", f"{variable_name} Compound Name") |
There was a problem hiding this comment.
Not sure what will happen on this line if variable_name is invalid.
There was a problem hiding this comment.
Actually, during test, if I define CMIP3 as variable_name, there will be no issue raise here, but in the following process dq.get_requested_variables , following issue will occured:
ValueError: Unrecognized unique variable identifier: cmip3_compound_name
Set "variable_name" in API configuration
So it's better if we add a process here to explicitly defined which variable_name is valid.
| priority_cutoff=priority.lower(), | ||
| ) | ||
|
|
||
| return list(requested["experiment"][experiment][priority.capitalize()]) |
There was a problem hiding this comment.
If experiment or priority is not present in the returned dictionary, a KeyError will be raised directly, and the error message is not very user-friendly. It is recommended to add explicit checks and raise a more meaningful exception. For example:
if experiment not in requested.get("experiment", {}):
raise KeyError(f"Experiment '{experiment}' not found in data request.")
|
Overall, there are no major logical issues with this function. Based on testing, all parameters work as expected, although a few minor details may need some adjustments. |
Add utility function to get the list of required variable for a CMIP7 experiment, based on priority level.
Utility for #227