xarray-ms 0.1.9__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. xarray_ms-0.2.1/LICENSE +28 -0
  2. xarray_ms-0.2.1/PKG-INFO +166 -0
  3. xarray_ms-0.2.1/README.rst +143 -0
  4. xarray_ms-0.2.1/pyproject.toml +99 -0
  5. xarray_ms-0.2.1/xarray_ms/backend/msv2/antenna_dataset_factory.py +38 -0
  6. xarray_ms-0.2.1/xarray_ms/backend/msv2/array.py +80 -0
  7. xarray_ms-0.2.1/xarray_ms/backend/msv2/encoders.py +199 -0
  8. xarray_ms-0.2.1/xarray_ms/backend/msv2/entrypoint.py +381 -0
  9. xarray_ms-0.2.1/xarray_ms/backend/msv2/main_dataset_factory.py +225 -0
  10. xarray_ms-0.2.1/xarray_ms/backend/msv2/structure.py +536 -0
  11. xarray_ms-0.2.1/xarray_ms/backend/msv2/table_factory.py +75 -0
  12. xarray_ms-0.2.1/xarray_ms/casa_types.py +492 -0
  13. xarray_ms-0.2.1/xarray_ms/errors.py +19 -0
  14. xarray_ms-0.2.1/xarray_ms/query.py +31 -0
  15. xarray_ms-0.2.1/xarray_ms/testing/__init__.py +0 -0
  16. xarray_ms-0.2.1/xarray_ms/testing/simulator.py +402 -0
  17. xarray_ms-0.2.1/xarray_ms/testing/utils.py +15 -0
  18. xarray_ms-0.2.1/xarray_ms/utils.py +86 -0
  19. xarray-ms-0.1.9/AUTHORS.rst +0 -13
  20. xarray-ms-0.1.9/CONTRIBUTING.rst +0 -136
  21. xarray-ms-0.1.9/HISTORY.rst +0 -58
  22. xarray-ms-0.1.9/LICENSE +0 -339
  23. xarray-ms-0.1.9/MANIFEST.in +0 -11
  24. xarray-ms-0.1.9/PKG-INFO +0 -119
  25. xarray-ms-0.1.9/README.rst +0 -101
  26. xarray-ms-0.1.9/docs/Makefile +0 -20
  27. xarray-ms-0.1.9/docs/api.rst +0 -11
  28. xarray-ms-0.1.9/docs/authors.rst +0 -1
  29. xarray-ms-0.1.9/docs/conf.py +0 -213
  30. xarray-ms-0.1.9/docs/contributing.rst +0 -1
  31. xarray-ms-0.1.9/docs/history.rst +0 -1
  32. xarray-ms-0.1.9/docs/index.rst +0 -20
  33. xarray-ms-0.1.9/docs/installation.rst +0 -51
  34. xarray-ms-0.1.9/docs/make.bat +0 -36
  35. xarray-ms-0.1.9/docs/readme.rst +0 -1
  36. xarray-ms-0.1.9/docs/usage.rst +0 -7
  37. xarray-ms-0.1.9/setup.cfg +0 -30
  38. xarray-ms-0.1.9/setup.py +0 -57
  39. xarray-ms-0.1.9/xarray_ms.egg-info/PKG-INFO +0 -119
  40. xarray-ms-0.1.9/xarray_ms.egg-info/SOURCES.txt +0 -33
  41. xarray-ms-0.1.9/xarray_ms.egg-info/dependency_links.txt +0 -1
  42. xarray-ms-0.1.9/xarray_ms.egg-info/requires.txt +0 -12
  43. xarray-ms-0.1.9/xarray_ms.egg-info/top_level.txt +0 -1
  44. xarray-ms-0.1.9/xarray_ms.egg-info/zip-safe +0 -1
  45. xarray-ms-0.1.9/xarrayms/__init__.py +0 -12
  46. xarray-ms-0.1.9/xarrayms/known_table_schemas.py +0 -94
  47. xarray-ms-0.1.9/xarrayms/table_executor.py +0 -324
  48. xarray-ms-0.1.9/xarrayms/tests/conftest.py +0 -64
  49. xarray-ms-0.1.9/xarrayms/tests/test_ms.py +0 -403
  50. xarray-ms-0.1.9/xarrayms/tests/test_table_executor.py +0 -177
  51. xarray-ms-0.1.9/xarrayms/xarray_ms.py +0 -953
  52. {xarray-ms-0.1.9/xarrayms/tests → xarray_ms-0.2.1/xarray_ms}/__init__.py +0 -0
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, Rhodes University Centre for Radio Astronomy Techniques & Technologies (RATT)
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.1
2
+ Name: xarray-ms
3
+ Version: 0.2.1
4
+ Summary: xarray MSv4 views over MSv2 Measurement Sets
5
+ Author: Simon Perkins
6
+ Author-email: simon.perkins@gmail.com
7
+ Requires-Python: >=3.10,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Provides-Extra: testing
13
+ Requires-Dist: arcae (>=0.2.5,<0.3.0)
14
+ Requires-Dist: cacheout (>=0.16.0,<0.17.0)
15
+ Requires-Dist: dask[testing] (>=2024.5.0,<2025.0.0) ; extra == "testing"
16
+ Requires-Dist: distributed[testing] (>=2024.5.0,<2025.0.0) ; extra == "testing"
17
+ Requires-Dist: pytest[testing] (>=8.0.0,<9.0.0) ; extra == "testing"
18
+ Requires-Dist: typing-extensions (>=4.12.2,<5.0.0) ; python_version < "3.11"
19
+ Requires-Dist: xarray (>=2024.3.0,<2025.0.0)
20
+ Requires-Dist: zarr[testing] (>=2.18.3,<3.0.0) ; extra == "testing"
21
+ Description-Content-Type: text/x-rst
22
+
23
+ =========
24
+ xarray-ms
25
+ =========
26
+
27
+ .. image:: https://img.shields.io/pypi/v/xarray-ms.svg
28
+ :target: https://pypi.python.org/pypi/xarray-ms
29
+
30
+ .. image:: https://github.com/ratt-ru/xarray-ms/actions/workflows/ci.yml/badge.svg
31
+ :target: https://github.com/ratt-ru/xarray-ms/actions/workflows/ci.yml
32
+
33
+ .. image:: https://readthedocs.org/projects/xarray-ms/badge/?version=latest
34
+ :target: https://xarray-ms.readthedocs.io/en/latest/?badge=latest
35
+ :alt: Documentation Status
36
+
37
+ ====
38
+
39
+ xarray-ms presents a Measurement Set v4 view (MSv4) over
40
+ `CASA Measurement Sets <https://casa.nrao.edu/Memos/229.html>`_ (MSv2).
41
+ It provides access to MSv2 data via the xarray API, allowing MSv4 compliant applications
42
+ to be developed on well-understood MSv2 data.
43
+
44
+ .. code-block:: python
45
+
46
+ >>> import xarray_ms
47
+ >>> from xarray.backends.api import datatree
48
+ >>> dt = open_datatree("/data/L795830_SB001_uv.MS/",
49
+ chunks={"time": 2000, "baseline": 1000})
50
+ >>> dt
51
+ <xarray.DataTree>
52
+ Group: /
53
+ └── Group: /DATA_DESC_ID=0,FIELD_ID=0,OBSERVATION_ID=0
54
+ │ Dimensions: (time: 28760, baseline: 2775, frequency: 16,
55
+ │ polarization: 4, uvw_label: 3)
56
+ │ Coordinates:
57
+ │ antenna1_name (baseline) object 22kB ...
58
+ │ antenna2_name (baseline) object 22kB ...
59
+ │ baseline_id (baseline) int64 22kB ...
60
+ │ * frequency (frequency) float64 128B 1.202e+08 ... 1.204e+08
61
+ │ * polarization (polarization) <U2 32B 'XX' 'XY' 'YX' 'YY'
62
+ │ * time (time) float64 230kB 1.601e+09 ... 1.601e+09
63
+ │ Dimensions without coordinates: baseline, uvw_label
64
+ │ Data variables:
65
+ │ EFFECTIVE_INTEGRATION_TIME (time, baseline) float64 638MB ...
66
+ │ FLAG (time, baseline, frequency, polarization) uint8 5GB ...
67
+ │ TIME_CENTROID (time, baseline) float64 638MB ...
68
+ │ UVW (time, baseline, uvw_label) float64 2GB ...
69
+ │ VISIBILITY (time, baseline, frequency, polarization) complex64 41GB ...
70
+ │ WEIGHT (time, baseline, frequency, polarization) float32 20GB ...
71
+ │ Attributes:
72
+ │ version: 0.0.1
73
+ │ creation_date: 2024-09-18T10:49:55.133908+00:00
74
+ │ data_description_id: 0
75
+ └── Group: /DATA_DESC_ID=0,FIELD_ID=0,OBSERVATION_ID=0/ANTENNA
76
+ Dimensions: (antenna_name: 74,
77
+ cartesian_pos_label/ellipsoid_pos_label: 3)
78
+ Coordinates:
79
+ baseline_antenna1_name (baseline) object 22kB ...
80
+ baseline_antenna2_name (baseline) object 22kB ...
81
+ baseline_id (baseline) int64 22kB ...
82
+ * frequency (frequency) float64 128B 1.202e+08 1.202e+08 ... 1.204e+08
83
+ * polarization (polarization) <U2 32B 'XX' 'XY' 'YX' 'YY'
84
+ * time (time) float64 230kB 1.601e+09 1.601e+09 ... 1.601e+09
85
+ * antenna_name (antenna_name) object 592B 'CS001HBA0' ... 'IE613HBA'
86
+ mount (antenna_name) object 592B 'X-Y' 'X-Y' ... 'X-Y' 'X-Y'
87
+ station (antenna_name) object 592B 'LOFAR' 'LOFAR' ... 'LOFAR'
88
+ Dimensions without coordinates: cartesian_pos_label/ellipsoid_pos_label
89
+ Data variables:
90
+ ANTENNA_POSITION (antenna_name, cartesian_pos_label/ellipsoid_pos_label) float64 2kB ...
91
+
92
+ Measurement Set v4
93
+ ------------------
94
+
95
+ NRAO_/SKAO_ are developing a new xarray-based `Measurement Set v4 specification <msv4-spec_>`_.
96
+ While there are many changes some of the major highlights are:
97
+
98
+ * xarray_ is used to define the specification.
99
+ * MSv4 data consists of Datasets of ndarrays on a regular time-channel grid.
100
+ MSv2 data is tabular and, while in many instances the time-channel grid is regular,
101
+ this is not guaranteed, especially after MSv2 datasets have been transformed by various tasks.
102
+
103
+
104
+ xarray_ Datasets are self-describing and they are therefore easier to reason about and work with.
105
+ Additionally, the regularity of data will make writing MSv4-based software less complex.
106
+
107
+ xradio
108
+ ------
109
+
110
+ `casangi/xradio <xradio_>`_ provides a reference implementation that converts
111
+ CASA v2 Measurement Sets to Zarr v4 Measurement Sets using the python-casacore_
112
+ package.
113
+
114
+ Why xarray-ms?
115
+ --------------
116
+
117
+ * By developing against an MSv4 xarray view over MSv2 data,
118
+ developers can develop applications on well-understood data,
119
+ and then seamlessly transition to newer formats.
120
+ Data can also be exported to newer formats (principally zarr_) via xarray's
121
+ native I/O routines.
122
+ However, the xarray view of either format looks the same to the software developer.
123
+
124
+ * xarray-ms builds on xarray's
125
+ `backend API <https://docs.xarray.dev/en/stable/internals/how-to-add-new-backend.html>`_:
126
+ Implementing a formal CASA MSv2 backend has a number of benefits:
127
+
128
+ * xarray's internal I/O routines such as ``open_dataset`` and ``open_datatree``
129
+ can dispatch to the backend to load data.
130
+ * Similarly xarray's `lazy loading mechanism <xarray_lazy_>`_ dispatches
131
+ through the backend.
132
+ * Automatic access to any `chunked array types <xarray_chunked_arrays_>`_
133
+ supported by xarray including, but not limited to dask_.
134
+ * Arbitrary chunking along any xarray dimension.
135
+
136
+ * xarray-ms uses arcae_, a high-performance backend to CASA Tables implementing
137
+ a subset of python-casacore_'s interface.
138
+ * Some limited support for irregular MSv2 data via padding.
139
+
140
+ Work in Progress
141
+ ----------------
142
+
143
+ The Measurement Set v4 specification is currently under active development.
144
+ xarray-ms is also currently under active development and does not yet
145
+ have feature parity with MSv4 or xradio_.
146
+ Most measures information and many secondary sub-tables are currently missing.
147
+
148
+ However, the most important parts of the MSv2 ``MAIN`` tables,
149
+ as well as the ``ANTENNA``, ``POLARIZATON`` and ``SPECTRAL_WINDOW``
150
+ sub-tables are implemented and should be sufficient
151
+ for basic algorithm development.
152
+
153
+ .. _SKAO: https://www.skao.int/
154
+ .. _NRAO: https://public.nrao.edu/
155
+ .. _msv4-spec: https://docs.google.com/spreadsheets/d/14a6qMap9M5r_vjpLnaBKxsR9TF4azN5LVdOxLacOX-s/
156
+ .. _xradio: https://github.com/casangi/xradio
157
+ .. _dask-ms: https://github.com/ratt-ru/dask-ms
158
+ .. _arcae: https://github.com/ratt-ru/arcae
159
+ .. _dask: https://www.dask.org/
160
+ .. _python-casacore: https://github.com/casacore/python-casacore/
161
+ .. _xarray: https://xarray.dev/
162
+ .. _xarray_backend: https://docs.xarray.dev/en/stable/internals/how-to-add-new-backend.html
163
+ .. _xarray_lazy: https://docs.xarray.dev/en/latest/internals/internal-design.html#lazy-indexing-classes
164
+ .. _xarray_chunked_arrays: https://docs.xarray.dev/en/latest/internals/chunked-arrays.html
165
+ .. _zarr: https://zarr.dev/
166
+
@@ -0,0 +1,143 @@
1
+ =========
2
+ xarray-ms
3
+ =========
4
+
5
+ .. image:: https://img.shields.io/pypi/v/xarray-ms.svg
6
+ :target: https://pypi.python.org/pypi/xarray-ms
7
+
8
+ .. image:: https://github.com/ratt-ru/xarray-ms/actions/workflows/ci.yml/badge.svg
9
+ :target: https://github.com/ratt-ru/xarray-ms/actions/workflows/ci.yml
10
+
11
+ .. image:: https://readthedocs.org/projects/xarray-ms/badge/?version=latest
12
+ :target: https://xarray-ms.readthedocs.io/en/latest/?badge=latest
13
+ :alt: Documentation Status
14
+
15
+ ====
16
+
17
+ xarray-ms presents a Measurement Set v4 view (MSv4) over
18
+ `CASA Measurement Sets <https://casa.nrao.edu/Memos/229.html>`_ (MSv2).
19
+ It provides access to MSv2 data via the xarray API, allowing MSv4 compliant applications
20
+ to be developed on well-understood MSv2 data.
21
+
22
+ .. code-block:: python
23
+
24
+ >>> import xarray_ms
25
+ >>> from xarray.backends.api import datatree
26
+ >>> dt = open_datatree("/data/L795830_SB001_uv.MS/",
27
+ chunks={"time": 2000, "baseline": 1000})
28
+ >>> dt
29
+ <xarray.DataTree>
30
+ Group: /
31
+ └── Group: /DATA_DESC_ID=0,FIELD_ID=0,OBSERVATION_ID=0
32
+ │ Dimensions: (time: 28760, baseline: 2775, frequency: 16,
33
+ │ polarization: 4, uvw_label: 3)
34
+ │ Coordinates:
35
+ │ antenna1_name (baseline) object 22kB ...
36
+ │ antenna2_name (baseline) object 22kB ...
37
+ │ baseline_id (baseline) int64 22kB ...
38
+ │ * frequency (frequency) float64 128B 1.202e+08 ... 1.204e+08
39
+ │ * polarization (polarization) <U2 32B 'XX' 'XY' 'YX' 'YY'
40
+ │ * time (time) float64 230kB 1.601e+09 ... 1.601e+09
41
+ │ Dimensions without coordinates: baseline, uvw_label
42
+ │ Data variables:
43
+ │ EFFECTIVE_INTEGRATION_TIME (time, baseline) float64 638MB ...
44
+ │ FLAG (time, baseline, frequency, polarization) uint8 5GB ...
45
+ │ TIME_CENTROID (time, baseline) float64 638MB ...
46
+ │ UVW (time, baseline, uvw_label) float64 2GB ...
47
+ │ VISIBILITY (time, baseline, frequency, polarization) complex64 41GB ...
48
+ │ WEIGHT (time, baseline, frequency, polarization) float32 20GB ...
49
+ │ Attributes:
50
+ │ version: 0.0.1
51
+ │ creation_date: 2024-09-18T10:49:55.133908+00:00
52
+ │ data_description_id: 0
53
+ └── Group: /DATA_DESC_ID=0,FIELD_ID=0,OBSERVATION_ID=0/ANTENNA
54
+ Dimensions: (antenna_name: 74,
55
+ cartesian_pos_label/ellipsoid_pos_label: 3)
56
+ Coordinates:
57
+ baseline_antenna1_name (baseline) object 22kB ...
58
+ baseline_antenna2_name (baseline) object 22kB ...
59
+ baseline_id (baseline) int64 22kB ...
60
+ * frequency (frequency) float64 128B 1.202e+08 1.202e+08 ... 1.204e+08
61
+ * polarization (polarization) <U2 32B 'XX' 'XY' 'YX' 'YY'
62
+ * time (time) float64 230kB 1.601e+09 1.601e+09 ... 1.601e+09
63
+ * antenna_name (antenna_name) object 592B 'CS001HBA0' ... 'IE613HBA'
64
+ mount (antenna_name) object 592B 'X-Y' 'X-Y' ... 'X-Y' 'X-Y'
65
+ station (antenna_name) object 592B 'LOFAR' 'LOFAR' ... 'LOFAR'
66
+ Dimensions without coordinates: cartesian_pos_label/ellipsoid_pos_label
67
+ Data variables:
68
+ ANTENNA_POSITION (antenna_name, cartesian_pos_label/ellipsoid_pos_label) float64 2kB ...
69
+
70
+ Measurement Set v4
71
+ ------------------
72
+
73
+ NRAO_/SKAO_ are developing a new xarray-based `Measurement Set v4 specification <msv4-spec_>`_.
74
+ While there are many changes some of the major highlights are:
75
+
76
+ * xarray_ is used to define the specification.
77
+ * MSv4 data consists of Datasets of ndarrays on a regular time-channel grid.
78
+ MSv2 data is tabular and, while in many instances the time-channel grid is regular,
79
+ this is not guaranteed, especially after MSv2 datasets have been transformed by various tasks.
80
+
81
+
82
+ xarray_ Datasets are self-describing and they are therefore easier to reason about and work with.
83
+ Additionally, the regularity of data will make writing MSv4-based software less complex.
84
+
85
+ xradio
86
+ ------
87
+
88
+ `casangi/xradio <xradio_>`_ provides a reference implementation that converts
89
+ CASA v2 Measurement Sets to Zarr v4 Measurement Sets using the python-casacore_
90
+ package.
91
+
92
+ Why xarray-ms?
93
+ --------------
94
+
95
+ * By developing against an MSv4 xarray view over MSv2 data,
96
+ developers can develop applications on well-understood data,
97
+ and then seamlessly transition to newer formats.
98
+ Data can also be exported to newer formats (principally zarr_) via xarray's
99
+ native I/O routines.
100
+ However, the xarray view of either format looks the same to the software developer.
101
+
102
+ * xarray-ms builds on xarray's
103
+ `backend API <https://docs.xarray.dev/en/stable/internals/how-to-add-new-backend.html>`_:
104
+ Implementing a formal CASA MSv2 backend has a number of benefits:
105
+
106
+ * xarray's internal I/O routines such as ``open_dataset`` and ``open_datatree``
107
+ can dispatch to the backend to load data.
108
+ * Similarly xarray's `lazy loading mechanism <xarray_lazy_>`_ dispatches
109
+ through the backend.
110
+ * Automatic access to any `chunked array types <xarray_chunked_arrays_>`_
111
+ supported by xarray including, but not limited to dask_.
112
+ * Arbitrary chunking along any xarray dimension.
113
+
114
+ * xarray-ms uses arcae_, a high-performance backend to CASA Tables implementing
115
+ a subset of python-casacore_'s interface.
116
+ * Some limited support for irregular MSv2 data via padding.
117
+
118
+ Work in Progress
119
+ ----------------
120
+
121
+ The Measurement Set v4 specification is currently under active development.
122
+ xarray-ms is also currently under active development and does not yet
123
+ have feature parity with MSv4 or xradio_.
124
+ Most measures information and many secondary sub-tables are currently missing.
125
+
126
+ However, the most important parts of the MSv2 ``MAIN`` tables,
127
+ as well as the ``ANTENNA``, ``POLARIZATON`` and ``SPECTRAL_WINDOW``
128
+ sub-tables are implemented and should be sufficient
129
+ for basic algorithm development.
130
+
131
+ .. _SKAO: https://www.skao.int/
132
+ .. _NRAO: https://public.nrao.edu/
133
+ .. _msv4-spec: https://docs.google.com/spreadsheets/d/14a6qMap9M5r_vjpLnaBKxsR9TF4azN5LVdOxLacOX-s/
134
+ .. _xradio: https://github.com/casangi/xradio
135
+ .. _dask-ms: https://github.com/ratt-ru/dask-ms
136
+ .. _arcae: https://github.com/ratt-ru/arcae
137
+ .. _dask: https://www.dask.org/
138
+ .. _python-casacore: https://github.com/casacore/python-casacore/
139
+ .. _xarray: https://xarray.dev/
140
+ .. _xarray_backend: https://docs.xarray.dev/en/stable/internals/how-to-add-new-backend.html
141
+ .. _xarray_lazy: https://docs.xarray.dev/en/latest/internals/internal-design.html#lazy-indexing-classes
142
+ .. _xarray_chunked_arrays: https://docs.xarray.dev/en/latest/internals/chunked-arrays.html
143
+ .. _zarr: https://zarr.dev/
@@ -0,0 +1,99 @@
1
+ [tool.poetry]
2
+ name = "xarray-ms"
3
+ version = "0.2.1"
4
+ description = "xarray MSv4 views over MSv2 Measurement Sets"
5
+ authors = ["Simon Perkins <simon.perkins@gmail.com>"]
6
+ readme = "README.rst"
7
+
8
+ [tool.poetry.dependencies]
9
+ python = "^3.10"
10
+ pytest = {version = "^8.0.0", optional = true, extras = ["testing"]}
11
+ xarray = "^2024.3.0"
12
+ dask = {version = "^2024.5.0", optional = true, extras = ["testing"]}
13
+ distributed = {version = "^2024.5.0", optional = true, extras = ["testing"]}
14
+ cacheout = "^0.16.0"
15
+ arcae = "^0.2.5"
16
+ typing-extensions = { version = "^4.12.2", python = "<3.11" }
17
+ zarr = {version = "^2.18.3", optional = true, extras = ["testing"]}
18
+
19
+ [tool.poetry.extras]
20
+ testing = ["dask", "distributed", "pytest", "zarr"]
21
+
22
+ [tool.poetry.plugins."xarray.backends"]
23
+ "xarray-ms:msv2" = "xarray_ms.backend.msv2.entrypoint:MSv2PartitionEntryPoint"
24
+
25
+ [tool.poetry.group.dev]
26
+ optional = true
27
+
28
+ [tool.poetry.group.dev.dependencies]
29
+ pre-commit = "^3.8.0"
30
+ tbump = "^6.11.0"
31
+
32
+ [tool.poetry.group.doc]
33
+ optional = true
34
+
35
+ [tool.poetry.group.doc.dependencies]
36
+ sphinx = "^8.0.2"
37
+ pygments = "^2.18.0"
38
+ sphinx-copybutton = "^0.5.2"
39
+ pydata-sphinx-theme = "^0.15.4"
40
+ ipython = "^8.27.0"
41
+ dask = "^2024.9.0"
42
+ zarr = "^2.18.3"
43
+
44
+ [tool.ruff]
45
+ line-length = 88
46
+ indent-width = 2
47
+ target-version = "py311"
48
+
49
+ [tool.ruff.lint]
50
+ select = ["F", "E", "W", "I001"]
51
+ extend-select = ["I"]
52
+
53
+ [build-system]
54
+ requires = ["poetry-core"]
55
+ build-backend = "poetry.core.masonry.api"
56
+ [tool.tbump]
57
+ # Uncomment this if your project is hosted on GitHub:
58
+ # github_url = "https://github.com/<user or organization>/<project>/"
59
+
60
+ [tool.tbump.version]
61
+ current = "0.2.1"
62
+
63
+ # Example of a semver regexp.
64
+ # Make sure this matches current_version before
65
+ # using tbump
66
+ regex = '''
67
+ (?P<major>\d+)
68
+ \.
69
+ (?P<minor>\d+)
70
+ \.
71
+ (?P<patch>\d+)
72
+ '''
73
+
74
+ [tool.tbump.git]
75
+ message_template = "Bump to {new_version}"
76
+ tag_template = "{new_version}"
77
+
78
+ # For each file to patch, add a [[tool.tbump.file]] config
79
+ # section containing the path of the file, relative to the
80
+ # tbump.toml location.
81
+ [[tool.tbump.file]]
82
+ src = "pyproject.toml"
83
+
84
+ [[tool.tbump.file]]
85
+ src = "doc/source/conf.py"
86
+
87
+ # You can specify a list of commands to
88
+ # run after the files have been patched
89
+ # and before the git commit is made
90
+
91
+ # [[tool.tbump.before_commit]]
92
+ # name = "check changelog"
93
+ # cmd = "grep -q {new_version} Changelog.rst"
94
+
95
+ # Or run some commands after the git tag and the branch
96
+ # have been pushed:
97
+ # [[tool.tbump.after_push]]
98
+ # name = "publish"
99
+ # cmd = "./publish.sh"
@@ -0,0 +1,38 @@
1
+ from typing import Mapping
2
+
3
+ from xarray import Dataset, Variable
4
+
5
+ from xarray_ms.backend.msv2.structure import MSv2StructureFactory
6
+
7
+
8
+ class AntennaDatasetFactory:
9
+ _structure_factory: MSv2StructureFactory
10
+
11
+ def __init__(self, structure_factory: MSv2StructureFactory):
12
+ self._structure_factory = structure_factory
13
+
14
+ def get_dataset(self) -> Mapping[str, Variable]:
15
+ ants = self._structure_factory()._ant
16
+
17
+ import pyarrow.compute as pac
18
+
19
+ ant_pos = pac.list_flatten(ants["POSITION"]).to_numpy().reshape(-1, 3)
20
+
21
+ return Dataset(
22
+ data_vars={
23
+ "ANTENNA_POSITION": Variable(
24
+ ("antenna_name", "cartesian_pos_label/ellipsoid_pos_label"), ant_pos
25
+ )
26
+ },
27
+ coords={
28
+ "antenna_name": Variable("antenna_name", ants["NAME"].to_numpy()),
29
+ "mount": Variable(
30
+ "antenna_name",
31
+ ants["MOUNT"].to_numpy(),
32
+ ),
33
+ "station": Variable(
34
+ "antenna_name",
35
+ ants["STATION"].to_numpy(),
36
+ ),
37
+ },
38
+ )
@@ -0,0 +1,80 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING, Any, Callable, Tuple
4
+
5
+ import numpy as np
6
+ from xarray.backends import BackendArray
7
+ from xarray.core.indexing import IndexingSupport, explicit_indexing_adapter
8
+
9
+ if TYPE_CHECKING:
10
+ import numpy.typing as npt
11
+
12
+ from xarray_ms.backend.msv2.structure import MSv2StructureFactory, PartitionKeyT
13
+ from xarray_ms.backend.msv2.table_factory import TableFactory
14
+
15
+
16
+ def slice_length(s, max_len):
17
+ if isinstance(s, np.ndarray):
18
+ if s.ndim != 1:
19
+ raise NotImplementedError("Slicing with non-1D numpy arrays")
20
+ return len(s)
21
+
22
+ start, stop, step = s.indices(max_len)
23
+ if step != 1:
24
+ raise NotImplementedError(f"Slicing with steps {s} other than 1 not supported")
25
+ return stop - start
26
+
27
+
28
+ class MSv2Array(BackendArray):
29
+ """Backend array containing functionality for reading an MSv2 column"""
30
+
31
+ _table_factory: TableFactory
32
+ _structure_factory: MSv2StructureFactory
33
+ _partition: PartitionKeyT
34
+ _column: str
35
+ _shape: Tuple[int, ...]
36
+ _dtype: npt.DTypeLike
37
+ _default: Any | None
38
+ _transform: Callable[[npt.NDArray], npt.NDArray] | None
39
+
40
+ def __init__(
41
+ self,
42
+ table_factory: TableFactory,
43
+ structure_factory: MSv2StructureFactory,
44
+ partition: PartitionKeyT,
45
+ column: str,
46
+ shape: Tuple[int, ...],
47
+ dtype: npt.DTypeLike,
48
+ default: Any | None = None,
49
+ transform: Callable[[npt.NDArray], npt.NDArray] | None = None,
50
+ ):
51
+ self._table_factory = table_factory
52
+ self._structure_factory = structure_factory
53
+ self._partition = partition
54
+ self._column = column
55
+ self._default = default
56
+ self._transform = transform
57
+ self.shape = shape
58
+ self.dtype = np.dtype(dtype)
59
+
60
+ assert len(shape) >= 2, "(time, baseline) required"
61
+
62
+ def __getitem__(self, key) -> npt.NDArray:
63
+ return explicit_indexing_adapter(
64
+ key, self.shape, IndexingSupport.OUTER, self._getitem
65
+ )
66
+
67
+ def _getitem(self, key) -> npt.NDArray:
68
+ assert len(key) == len(self.shape)
69
+ expected_shape = tuple(slice_length(k, s) for k, s in zip(key, self.shape))
70
+ # Map the (time, baseline) coordinates onto row indices
71
+ rows = self._structure_factory()[self._partition].row_map[key[:2]]
72
+ xkey = (rows.ravel(),) + key[2:]
73
+ row_shape = (rows.size,) + expected_shape[2:]
74
+ result = np.full(row_shape, self._default, dtype=self.dtype)
75
+ self._table_factory().getcol(self._column, xkey, result)
76
+ result = result.reshape(rows.shape + expected_shape[2:])
77
+ return self._transform(result) if self._transform else result
78
+
79
+ def set_transform(self, transform: Callable[[npt.NDArray], npt.NDArray]):
80
+ self._transform = transform