xradio 0.0.48__py3-none-any.whl → 0.0.49__py3-none-any.whl

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 (32) hide show
  1. xradio/__init__.py +1 -0
  2. xradio/_utils/dict_helpers.py +69 -2
  3. xradio/image/_util/__init__.py +0 -3
  4. xradio/image/_util/_casacore/common.py +0 -13
  5. xradio/image/_util/_casacore/xds_from_casacore.py +102 -97
  6. xradio/image/_util/_casacore/xds_to_casacore.py +36 -24
  7. xradio/image/_util/_fits/xds_from_fits.py +81 -36
  8. xradio/image/_util/_zarr/zarr_low_level.py +3 -3
  9. xradio/image/_util/casacore.py +7 -5
  10. xradio/image/_util/common.py +13 -26
  11. xradio/image/_util/image_factory.py +143 -191
  12. xradio/image/image.py +10 -59
  13. xradio/measurement_set/__init__.py +11 -6
  14. xradio/measurement_set/_utils/_msv2/_tables/read.py +187 -46
  15. xradio/measurement_set/_utils/_msv2/_tables/table_query.py +22 -0
  16. xradio/measurement_set/_utils/_msv2/conversion.py +351 -318
  17. xradio/measurement_set/_utils/_msv2/msv4_info_dicts.py +20 -17
  18. xradio/measurement_set/convert_msv2_to_processing_set.py +46 -6
  19. xradio/measurement_set/load_processing_set.py +100 -53
  20. xradio/measurement_set/measurement_set_xdt.py +197 -0
  21. xradio/measurement_set/open_processing_set.py +122 -86
  22. xradio/measurement_set/processing_set_xdt.py +1552 -0
  23. xradio/measurement_set/schema.py +199 -94
  24. xradio/schema/bases.py +5 -1
  25. xradio/schema/check.py +97 -5
  26. {xradio-0.0.48.dist-info → xradio-0.0.49.dist-info}/METADATA +4 -4
  27. {xradio-0.0.48.dist-info → xradio-0.0.49.dist-info}/RECORD +30 -30
  28. {xradio-0.0.48.dist-info → xradio-0.0.49.dist-info}/WHEEL +1 -1
  29. xradio/measurement_set/measurement_set_xds.py +0 -117
  30. xradio/measurement_set/processing_set.py +0 -803
  31. {xradio-0.0.48.dist-info → xradio-0.0.49.dist-info/licenses}/LICENSE.txt +0 -0
  32. {xradio-0.0.48.dist-info → xradio-0.0.49.dist-info}/top_level.txt +0 -0
@@ -1,15 +1,14 @@
1
1
  import os
2
-
3
- from xradio.measurement_set import ProcessingSet
4
2
  import toolviper.utils.logger as logger
5
3
  from xradio._utils.zarr.common import _open_dataset, _get_file_system_and_items
6
4
  import s3fs
5
+ import xarray as xr
7
6
 
8
7
 
9
8
  def open_processing_set(
10
9
  ps_store: str,
11
10
  intents: list = None,
12
- ) -> ProcessingSet:
11
+ ) -> xr.DataTree:
13
12
  """Creates a lazy representation of a Processing Set (only meta-data is loaded into memory).
14
13
 
15
14
  Parameters
@@ -17,96 +16,133 @@ def open_processing_set(
17
16
  ps_store : str
18
17
  String of the path and name of the processing set. For example '/users/user_1/uid___A002_Xf07bba_Xbe5c_target.lsrk.vis.zarr'.
19
18
  intents : list, optional
20
- A list of intents to be open for example ['OBSERVE_TARGET#ON_SOURCE']. The intents in a processing set can be seen by calling processing_set.summary().
21
- By default None, which will open all intents.
19
+ A list of intents to be opened for example ['OBSERVE_TARGET#ON_SOURCE']. The intents in a processing_set_xdt can be seen by calling processing_set_xdt.ps.summary().
20
+ By default None, which will include all intents.
22
21
 
23
22
  Returns
24
23
  -------
25
- processing_set
26
- Lazy representation of processing set (data is represented by Dask.arrays).
24
+ xarray.DataTree
25
+ Lazy representation of processing set (the data arrays of the datasets are
26
+ represented by Dask.arrays).
27
27
  """
28
- from xradio.measurement_set import MeasurementSetXds
29
28
 
30
29
  file_system, ms_store_list = _get_file_system_and_items(ps_store)
31
30
 
32
- ps = ProcessingSet()
33
- data_group = "base"
34
- for ms_name in ms_store_list:
35
- # try:
36
- ms_store = os.path.join(ps_store, ms_name)
37
- correlated_store = os.path.join(ms_store, "correlated_xds")
38
-
39
- xds = _open_dataset(correlated_store, file_system)
40
- data_groups = xds.attrs["data_groups"]
41
-
42
- if (intents is None) or (
43
- bool(set(xds.attrs["partition_info"]["intents"]).intersection(intents))
44
- ):
45
- sub_xds_dict, field_and_source_xds_dict = _open_sub_xds(
46
- ms_store, file_system=file_system, data_groups=data_groups
47
- )
48
-
49
- xds.attrs = {
50
- **xds.attrs,
51
- **sub_xds_dict,
52
- }
53
-
54
- for data_group_name, data_group_vals in data_groups.items():
55
- xds[data_group_vals["correlated_data"]].attrs[
56
- "field_and_source_xds"
57
- ] = field_and_source_xds_dict[data_group_name]
58
-
59
- ps[ms_name] = MeasurementSetXds(xds)
60
- # except Exception as e:
61
- # logger.warning(f"Could not open {ms_name} due to {e}")
62
- # continue
63
-
64
- return ps
65
-
66
-
67
- def _open_sub_xds(ms_store, file_system, data_groups, load=False):
68
- sub_xds_dict = {}
69
- field_and_source_xds_dict = {}
70
-
71
31
  if isinstance(file_system, s3fs.core.S3FileSystem):
72
- file_names = [
73
- bd.split(sep="/")[-1] for bd in file_system.listdir(ms_store, detail=False)
74
- ]
32
+ mapping = s3fs.S3Map(root=ps_store, s3=file_system, check=False)
33
+ ps_xdt = xr.open_datatree(mapping, engine="zarr")
75
34
  else:
76
- file_names = file_system.listdir(ms_store)
77
- file_names = [item for item in file_names if not item.startswith(".")]
78
-
79
- file_names.remove("correlated_xds")
80
-
81
- field_dict = {"field_and_source_xds_" + key: key for key in data_groups.keys()}
82
-
83
- # field_and_source_xds_name_start = "FIELD"
84
- for n in file_names:
85
- xds = _open_dataset(
86
- os.path.join(ms_store, n), load=load, file_system=file_system
87
- )
88
- # Skip empty tables
89
- if not xds.coords and not xds.data_vars:
90
- continue
91
- if n in field_dict.keys():
92
- field_and_source_xds_dict[field_dict[n]] = xds
93
- else:
94
- sub_xds_dict[n] = xds
95
-
96
- return sub_xds_dict, field_and_source_xds_dict
97
-
98
-
99
- def _get_data_name(xds, data_group):
100
- if "visibility" in xds.attrs["data_groups"][data_group]:
101
- data_name = xds.attrs["data_groups"][data_group]["visibility"]
102
- elif "spectrum" in xds.attrs["data_groups"][data_group]:
103
- data_name = xds.attrs["data_groups"][data_group]["spectrum"]
35
+ ps_xdt = xr.open_datatree(ps_store, engine="zarr")
36
+
37
+ # Future work is to add ASDM backend
38
+
39
+ if intents is None:
40
+ return ps_xdt
104
41
  else:
105
- error_message = (
106
- "No Visibility or Spectrum data variable found in data_group "
107
- + data_group
108
- + "."
109
- )
110
- logger.exception(error_message)
111
- raise ValueError(error_message)
112
- return data_name
42
+ return ps_xdt.xr_ps.query(intents=intents)
43
+
44
+
45
+ # def open_processing_set(
46
+ # ps_store: str,
47
+ # intents: list = None,
48
+ # ): #-> ProcessingSet:
49
+ # """Creates a lazy representation of a Processing Set (only meta-data is loaded into memory).
50
+
51
+ # Parameters
52
+ # ----------
53
+ # ps_store : str
54
+ # String of the path and name of the processing set. For example '/users/user_1/uid___A002_Xf07bba_Xbe5c_target.lsrk.vis.zarr'.
55
+ # intents : list, optional
56
+ # A list of intents to be open for example ['OBSERVE_TARGET#ON_SOURCE']. The intents in a processing set can be seen by calling processing_set.summary().
57
+ # By default None, which will open all intents.
58
+
59
+ # Returns
60
+ # -------
61
+ # processing_set
62
+ # Lazy representation of processing set (data is represented by Dask.arrays).
63
+ # """
64
+ # from xradio.measurement_set import MeasurementSetXds
65
+
66
+ # file_system, ms_store_list = _get_file_system_and_items(ps_store)
67
+ # from xradio.measurement_set import ProcessingSet
68
+ # ps = ProcessingSet()
69
+ # data_group = "base"
70
+ # for ms_name in ms_store_list:
71
+ # # try:
72
+ # ms_store = os.path.join(ps_store, ms_name)
73
+ # correlated_store = os.path.join(ms_store, "correlated_xds")
74
+
75
+ # xds = _open_dataset(correlated_store, file_system)
76
+ # data_groups = xds.attrs["data_groups"]
77
+
78
+ # if (intents is None) or (
79
+ # bool(set(xds.attrs["partition_info"]["intents"]).intersection(intents))
80
+ # ):
81
+ # sub_xds_dict, field_and_source_xds_dict = _open_sub_xds(
82
+ # ms_store, file_system=file_system, data_groups=data_groups
83
+ # )
84
+
85
+ # xds.attrs = {
86
+ # **xds.attrs,
87
+ # **sub_xds_dict,
88
+ # }
89
+
90
+ # for data_group_name, data_group_vals in data_groups.items():
91
+ # xds[data_group_vals["correlated_data"]].attrs[
92
+ # "field_and_source_xds"
93
+ # ] = field_and_source_xds_dict[data_group_name]
94
+
95
+ # ps[ms_name] = MeasurementSetXds(xds)
96
+ # # except Exception as e:
97
+ # # logger.warning(f"Could not open {ms_name} due to {e}")
98
+ # # continue
99
+
100
+ # return ps
101
+
102
+
103
+ # def _open_sub_xds(ms_store, file_system, data_groups, load=False):
104
+ # sub_xds_dict = {}
105
+ # field_and_source_xds_dict = {}
106
+
107
+ # if isinstance(file_system, s3fs.core.S3FileSystem):
108
+ # file_names = [
109
+ # bd.split(sep="/")[-1] for bd in file_system.listdir(ms_store, detail=False)
110
+ # ]
111
+ # else:
112
+ # file_names = file_system.listdir(ms_store)
113
+ # file_names = [item for item in file_names if not item.startswith(".")]
114
+
115
+ # file_names.remove("correlated_xds")
116
+
117
+ # field_dict = {"field_and_source_xds_" + key: key for key in data_groups.keys()}
118
+
119
+ # # field_and_source_xds_name_start = "FIELD"
120
+ # for n in file_names:
121
+ # xds = _open_dataset(
122
+ # os.path.join(ms_store, n), load=load, file_system=file_system
123
+ # )
124
+ # # Skip empty tables
125
+ # if not xds.coords and not xds.data_vars:
126
+ # continue
127
+ # if n in field_dict.keys():
128
+ # field_and_source_xds_dict[field_dict[n]] = xds
129
+ # else:
130
+ # sub_xds_dict[n] = xds
131
+
132
+ # return sub_xds_dict, field_and_source_xds_dict
133
+
134
+
135
+ # def _get_data_name(xds, data_group):
136
+ # if "visibility" in xds.attrs["data_groups"][data_group]:
137
+ # data_name = xds.attrs["data_groups"][data_group]["visibility"]
138
+ # elif "spectrum" in xds.attrs["data_groups"][data_group]:
139
+ # data_name = xds.attrs["data_groups"][data_group]["spectrum"]
140
+ # else:
141
+ # error_message = (
142
+ # "No Visibility or Spectrum data variable found in data_group "
143
+ # + data_group
144
+ # + "."
145
+ # )
146
+ # logger.exception(error_message)
147
+ # raise ValueError(error_message)
148
+ # return data_name