intake-esm
intake-esm copied to clipboard
Drop non-requested variables from datasets
Is your feature request related to a problem? Please describe.
When using the catalog with a derived variable registry and calling to_dataset_dict, all variables that were needed for the derived variable computation are in the final datasets, even if they were not requested directly.
Describe the solution you'd like
In the following imaginary example, say we have datasets for tasmin, tasmax and pr and a function for tas = func(tasmin, tasmax) in the DVR.
subcat = cat.search(variable=['tas', 'pr'])
subcat.to_dataset_dict()
I would expect the ouput dataset to only include tas and pr, but with the current intake-esm tasmin and tasmax are also returned.
Describe alternatives you've considered
- Wrapping it myself. Remembering what I wanted in a list and dropping the rest.
- Instead of passing
_requested_variablesto theESMDataSourceobjects, perform that subset into_dataset_dictdirectly, after the derived variables have been created. - Add an aditionnal
_needed_variablesthat would store a list of variables including dependencies, while_requested_variableswould not list dependencies. And a subset would be performed byto_dataset_dictafter the derived variable creation.
There is already a dependents variable created during the search() function, but it gets merged into _requested_variables and the information is lost afterwards.
Would it be a realistic solution to decouple _dependent_variables and _requested_variables, using both when necessary to open the datasets and extract data, and then only keep the _requested_variables for the final output?