Skip to content

Use xr.DataTree #213

@brendan-m-murphy

Description

@brendan-m-murphy

Replacing a dictionary of Datasets by a DataTree means you can simplify some code:

ds_all_mf = read_model_output(
    data_dir,
    file_type="concentration",
    species=species,
    models=models,
    config_data=config_data,
    period=period,
)
mf_dt = xr.DataTree.from_dict(ds_all_mf)
mf_dt.sel(platform="MHD")  # select from all Datasets at once

To convert back to the dictionary of datasets:

{m: v.to_dataset() for m, v in mf_dt.items()}

I think if you don't do reset_index("index") in edit_vars_and_attributes, you could probably also do

mf_dt.sel(time=slice(start_date, end_date))

but resetting index also removes the time dimension it seems. (Also resetting index means you can't unstack it... leaving index as a coordinate would probably simplify other code.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions