This repository was archived by the owner on Oct 24, 2024. It is now read-only.
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
Make DatasetView in map_over_subtree aware of its path? #266
Closed
Description
Raised by @observingClouds in #254 (comment)
Currently, I use the @map_over_subtree decorator, which also has some limitations as the function does not know its tree origin (as noted in the code) and it needs to be inferred from the dataset itself, which is sometimes possible (here the length of the dataset) but does not need to be always the case.
@map_over_subtree
def resolution_specific_func(ds):
if len(ds.x) == 3:
ds = ds.z*2
elif len(ds.x) == 6:
ds = ds.z*4
return ds
z= resolution_specific_func(dt)
I do not know how the tree information could be passed through the decorator, but maybe it is okay if the DatasetView
class has an additional property (e.g. _path
) that could be filled with dt.path
during the call of DatasetView._from_node()?. This would lead to
@map_over_subtree
def resolution_specific_func(ds):
if 'lowRes' in ds._path:
ds = ds.z*2
if 'highRes' in ds._path:
ds = ds.z*4
return ds
and would allow for tree-aware manipulation of the datasets.