Selecting groups in a hollow datatree using a string
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What is your issue?
I'm using datatree to read in CORDEX formatted directories of climate data. As a small example I have a hollow datatree with the following groups:
dt2.groups
('/',
'/BOM',
'/BOM/ACCESS-CM2',
'/BOM/ACCESS-CM2/ssp370',
'/BOM/ACCESS-CM2/ssp126',
'/BOM/ACCESS-CM2/historical',
'/BOM/ACCESS-CM2/ssp370/r4i1p1f1',
'/BOM/ACCESS-CM2/ssp126/r4i1p1f1',
'/BOM/ACCESS-CM2/historical/r4i1p1f1',
'/BOM/ACCESS-CM2/ssp370/r4i1p1f1/BARPA-R',
'/BOM/ACCESS-CM2/ssp126/r4i1p1f1/BARPA-R',
'/BOM/ACCESS-CM2/historical/r4i1p1f1/BARPA-R',
'/BOM/ACCESS-CM2/ssp370/r4i1p1f1/BARPA-R/v1-r1-ACS-QME-AGCDv1-1960-2022',
'/BOM/ACCESS-CM2/ssp126/r4i1p1f1/BARPA-R/v1-r1-ACS-QME-AGCDv1-1960-2022',
'/BOM/ACCESS-CM2/historical/r4i1p1f1/BARPA-R/v1-r1-ACS-QME-AGCDv1-1960-2022',
'/BOM/ACCESS-CM2/ssp370/r4i1p1f1/BARPA-R/v1-r1-ACS-QME-AGCDv1-1960-2022/day',
'/BOM/ACCESS-CM2/ssp126/r4i1p1f1/BARPA-R/v1-r1-ACS-QME-AGCDv1-1960-2022/day',
'/BOM/ACCESS-CM2/historical/r4i1p1f1/BARPA-R/v1-r1-ACS-QME-AGCDv1-1960-2022/day')
If I want to access only the leaves of the datatree that have historical in the group, is there a simple built in way to do it? I haven't been able to find anything in the documentation so far, and have come up with something rather clunky to do it myself:
def node_selector(dt_in,string_in):
def node_selector_worker(self):
if (string_in in str(self.groups)):
return True
return False
return dt_in.filter(node_selector_worker)
This gives me a datatree that I can call leaves on:
node_selector(dt2,'historical').leaves
Cheers
Ben
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the DataTree.filter behavior and the groups and leaves accessors used in the example. Check how a node predicate is applied to hollow trees, then define the expected result as a tree whose leaves are limited to groups containing "historical" and verify that the built-in approach matches the shown custom selector.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100