-
Notifications
You must be signed in to change notification settings - Fork 41
Ignore missing dims when mapping over tree #67
Comments
Continuing from related discussion in https://discourse.pangeo.io/t/xarray-and-collections-of-forecasts/3054/6 It would also be helpful to have it on I haven't dug around in the guts of datatree enough to understand how it's mapping functions to each group, but would it be possible to add a If I'm understanding things right, |
Hi @abkfenris !
def map_over_subtree(func, dt, *args, **kwargs):
new_tree = ...
for node in dt.subtree
result_ds = func(node.ds, *args, **kwargs)
new_tree[node.path] = result_ds but generalised to potentially map over multiple trees simultaneously (e.g. for binary operations like
We could, but |
I wonder if ignoring |
Yes that's a good point. I am not sure what the best solution is here.
…On Mon, Jan 9, 2023, 2:16 PM Alex Kerney ***@***.***> wrote:
I wonder if ignoring KeyError might be too broad and could catch more
than intended (I'm thinking Dask or fsspec KeyErrors bubbling up). Might
be worth exploring getting more tightly defined errors upstream.
—
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AISNPIZJLLCJRG375IC4CSLWRR52BANCNFSM5P3S737Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
See pydata/xarray#8949 for a much more thought-out solution to this problem |
Closing this in favour of pydata/xarray#8949 upstream. |
This tree has a dimension present in some nodes and not others (the "people" dimension).
If a user calls
dt.mean(dim='people')
, then at the moment this will raise an error. That's because it maps the.mean
call over each group, and when it gets to either the'coarse'
group or the'fine'
group it will not find a dimension called'people'
.However the user might want to take the mean of groups only where this makes sense, and ignore the rest.
I think the best solution is to have a
missing_dims
argument, like xarray's.isel
already has. Then the user can dodt.mean(dim='people', missing_dims='ignore')
.To actually implement this I think only requires changes in xarray, not here, because those changes should propagate down to datatree. pydata/xarray#5030
The text was updated successfully, but these errors were encountered: