Skip to content

Commit

Permalink
Experiment with accessors and links in attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
sjperkins committed Oct 15, 2024
1 parent f151e81 commit 25f132b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions xarray_ms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import xarray_ms.accessors # noqa: F401
21 changes: 21 additions & 0 deletions xarray_ms/accessors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from xarray.core.datatree import DataTree
from xarray.core.extensions import (
register_datatree_accessor,
)


@register_datatree_accessor("subtable")
class SubTableAccessor:
def __init__(self, node: DataTree):
self.node = node

@property
def antenna(self) -> DataTree:
"""Returns the antenna dataset"""

try:
link = self.node.attrs["antenna_xds_link"]
except KeyError:
raise ValueError("antenna_xds_link not found")
else:
return self.node.root[link]
1 change: 1 addition & 0 deletions xarray_ms/backend/msv2/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ def open_datatree(
antenna_factory = AntennaDatasetFactory(structure_factory)

key = ",".join(f"{k}={v}" for k, v in sorted(partition_key))
ds.attrs["antenna_xds_link"] = f"{key}/ANTENNA"
datasets[key] = ds
datasets[f"{key}/ANTENNA"] = antenna_factory.get_dataset()

Expand Down

0 comments on commit 25f132b

Please sign in to comment.