xbudget.presets.save_yaml¶
- xbudget.presets.save_yaml(recipe, filepath)[source]¶
Write a recipe to a yaml file, after checking that it is valid.
Validating here means a malformed recipe cannot reach disk: you get a
xbudget.BudgetParseErrornaming the offending path while you are authoring it, rather than a confusing failure the next time it is loaded.Key order is preserved rather than sorted, because it is meaningful: the operands of a
sum/productare reported in recipe order byxbudget.BudgetQuery.get_vars().- Parameters:
- Raises:
xbudget.BudgetParseError – If the recipe does not match the schema. Nothing is written.
Examples
>>> recipe = {"heat": {"rhs": {"sum": {"forcing": {"var": "surface_heat_flux"}}}}} >>> xbudget.save_yaml(recipe, "my_model.yaml") >>> xbudget.load_yaml("my_model.yaml") == recipe True
See also
load_yaml,xbudget.parse_budgets