From 6533c7f49d8d9455a2fce6a50abad9e7ac5ca72b Mon Sep 17 00:00:00 2001 From: Fabian Wachsmann <k204210@cmip-transfer2.dkrz.de> Date: Mon, 20 Sep 2021 12:24:52 +0200 Subject: [PATCH] Collect tracking ids and add them to mf_dset --- tzis/tzis.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tzis/tzis.py b/tzis/tzis.py index 0edb0d2..f1d5bef 100644 --- a/tzis/tzis.py +++ b/tzis/tzis.py @@ -34,6 +34,16 @@ class Tzis(): #if type(mf) != list and type(mf) != str : # raise ValueError("Dataset '{0}' must either be a string or a list of strings") if mf: + tracking_ids=[] + if type(mf) == str : + mf = [mf] + try : + for dset in mf : + dset = xarray.open_dataset(dset) + tracking_ids.append(dset.attrs["tracking_id"]) + except : + if self.verbose : + print("Could not collect 'tracking_ids'.") if xarray_kwargs: mf_dset = xarray.open_mfdataset(mf, decode_cf=True, @@ -51,6 +61,8 @@ class Tzis(): data_vars='minimal', coords='minimal', compat='override') + if tracking_ids : + mf_dset.attrs["tracking_id"]=tracking_ids if not self.varname : self.varname = mf_dset.variables[0] -- GitLab