Skip to content

Add function to retrieve requested variables from data request API#228

Open
rbeucher wants to merge 1 commit intomainfrom
add_utility
Open

Add function to retrieve requested variables from data request API#228
rbeucher wants to merge 1 commit intomainfrom
add_utility

Conversation

@rbeucher
Copy link
Member

@rbeucher rbeucher commented Mar 18, 2026

Add utility function to get the list of required variable for a CMIP7 experiment, based on priority level.

Utility for #227

@rbeucher rbeucher requested a review from rhaegar325 March 18, 2026 07:37
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 8.33333% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.58%. Comparing base (7549b46) to head (110c936).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/access_moppy/utilities.py 8.33% 11 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what will happen on this line if variable_name is invalid.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.")

@rhaegar325
Copy link
Collaborator

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.

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

Successfully merging this pull request may close these issues.

2 participants