dask: `Data.reconstruct_sectioned_data` by davidhassell · Pull Request #407 · NCAS-CMS/cf-python

Expand Up @@ -5914,73 +5914,6 @@ def concatenate_data(cls, data_list, axis): assert len(data_list) == 1 return data_list[0]
@classmethod def reconstruct_sectioned_data(cls, sections, cyclic=(), hardmask=None): """Expects a dictionary of Data objects with ordering information as keys, as output by the section method when called with a Data object. Returns a reconstructed cf.Data object with the sections in the original order.
:Parameters:
sections: `dict` The dictionary of `Data` objects with ordering information as keys.
:Returns:
`Data` The resulting reconstructed Data object.
**Examples**
>>> d = cf.Data(numpy.arange(120).reshape(2, 3, 4, 5)) >>> x = d.section([1, 3]) >>> len(x) 8 >>> e = cf.Data.reconstruct_sectioned_data(x) >>> e.equals(d) True
""" ndims = len(list(sections.keys())[0])
for i in range(ndims - 1, -1, -1): keys = sorted(sections.keys()) if i == 0: if keys[0][i] is None: assert len(keys) == 1 return tuple(sections.values())[0] else: data_list = [] for k in keys: data_list.append(sections[k])
out = cls.concatenate_data(data_list, i)
out.cyclic(cyclic) if hardmask is not None: out.hardmask = hardmask
return out
if keys[0][i] is not None: new_sections = {} new_key = keys[0][:i] data_list = [] for k in keys: if k[:i] == new_key: data_list.append(sections[k]) else: new_sections[new_key] = cls.concatenate_data( data_list, axis=i ) new_key = k[:i] data_list = [sections[k]]
new_sections[new_key] = cls.concatenate_data(data_list, i) sections = new_sections
def argmax(self, axis=None, unravel=False): """Return the indices of the maximum values along an axis.
Expand Down