xradio 0.0.28__tar.gz → 0.0.29__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 (91) hide show
  1. {xradio-0.0.28 → xradio-0.0.29}/LICENSE.txt +6 -1
  2. {xradio-0.0.28/src/xradio.egg-info → xradio-0.0.29}/PKG-INFO +11 -6
  3. {xradio-0.0.28 → xradio-0.0.29}/pyproject.toml +23 -6
  4. xradio-0.0.29/src/xradio/__init__.py +13 -0
  5. xradio-0.0.29/src/xradio/_utils/array.py +90 -0
  6. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/_utils/zarr/common.py +48 -3
  7. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/zarr.py +4 -1
  8. xradio-0.0.29/src/xradio/schema/__init__.py +35 -0
  9. xradio-0.0.29/src/xradio/schema/bases.py +444 -0
  10. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/schema/check.py +96 -55
  11. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/schema/dataclass.py +123 -27
  12. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/schema/metamodel.py +21 -4
  13. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/schema/typing.py +33 -18
  14. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/__init__.py +5 -2
  15. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_processing_set.py +28 -20
  16. xradio-0.0.29/src/xradio/vis/_vis_utils/_ms/_tables/create_field_and_source_xds.py +710 -0
  17. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/_tables/load.py +23 -10
  18. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/_tables/load_main_table.py +145 -64
  19. xradio-0.0.29/src/xradio/vis/_vis_utils/_ms/_tables/read.py +1254 -0
  20. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/_tables/read_main_table.py +173 -44
  21. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/_tables/read_subtables.py +79 -28
  22. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/_tables/write.py +102 -45
  23. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/_tables/write_exp_api.py +127 -65
  24. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/chunks.py +58 -21
  25. xradio-0.0.29/src/xradio/vis/_vis_utils/_ms/conversion.py +912 -0
  26. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/descr.py +52 -20
  27. xradio-0.0.29/src/xradio/vis/_vis_utils/_ms/msv2_to_msv4_meta.py +146 -0
  28. xradio-0.0.29/src/xradio/vis/_vis_utils/_ms/msv4_infos.py +0 -0
  29. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/msv4_sub_xdss.py +76 -9
  30. xradio-0.0.29/src/xradio/vis/_vis_utils/_ms/optimised_functions.py +0 -0
  31. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/partition_queries.py +308 -119
  32. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/partitions.py +82 -25
  33. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/subtables.py +32 -14
  34. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_utils/partition_attrs.py +30 -11
  35. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_utils/xds_helper.py +136 -45
  36. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_zarr/read.py +60 -22
  37. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_zarr/write.py +83 -9
  38. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/ms.py +48 -29
  39. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/zarr.py +44 -20
  40. xradio-0.0.29/src/xradio/vis/convert_msv2_to_processing_set.py +172 -0
  41. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/load_processing_set.py +38 -61
  42. xradio-0.0.29/src/xradio/vis/read_processing_set.py +116 -0
  43. xradio-0.0.29/src/xradio/vis/schema.py +687 -0
  44. xradio-0.0.29/src/xradio/vis/vis_io.py +146 -0
  45. {xradio-0.0.28 → xradio-0.0.29/src/xradio.egg-info}/PKG-INFO +11 -6
  46. {xradio-0.0.28 → xradio-0.0.29}/src/xradio.egg-info/SOURCES.txt +3 -1
  47. {xradio-0.0.28 → xradio-0.0.29}/src/xradio.egg-info/requires.txt +3 -3
  48. xradio-0.0.28/src/xradio/__init__.py +0 -12
  49. xradio-0.0.28/src/xradio/schema/__init__.py +0 -17
  50. xradio-0.0.28/src/xradio/schema/bases.py +0 -6
  51. xradio-0.0.28/src/xradio/vis/_vis_utils/_ms/_tables/read.py +0 -679
  52. xradio-0.0.28/src/xradio/vis/_vis_utils/_ms/conversion.py +0 -443
  53. xradio-0.0.28/src/xradio/vis/_vis_utils/_ms/msv2_to_msv4_meta.py +0 -111
  54. xradio-0.0.28/src/xradio/vis/_vis_utils/_ms/msv4_infos.py +0 -59
  55. xradio-0.0.28/src/xradio/vis/_vis_utils/_ms/optimised_functions.py +0 -46
  56. xradio-0.0.28/src/xradio/vis/convert_msv2_to_processing_set.py +0 -98
  57. xradio-0.0.28/src/xradio/vis/model.py +0 -497
  58. xradio-0.0.28/src/xradio/vis/read_processing_set.py +0 -150
  59. xradio-0.0.28/src/xradio/vis/vis_io.py +0 -114
  60. {xradio-0.0.28 → xradio-0.0.29}/MANIFEST.in +0 -0
  61. {xradio-0.0.28 → xradio-0.0.29}/README.md +0 -0
  62. {xradio-0.0.28 → xradio-0.0.29}/setup.cfg +0 -0
  63. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/_utils/__init__.py +0 -0
  64. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/_utils/_casacore/tables.py +0 -0
  65. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/_utils/common.py +0 -0
  66. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/_utils/zarr/__init__.py +0 -0
  67. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/__init__.py +0 -0
  68. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/__init__.py +0 -0
  69. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/_casacore/__init__.py +0 -0
  70. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/_casacore/common.py +0 -0
  71. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/_casacore/xds_from_casacore.py +0 -0
  72. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/_casacore/xds_to_casacore.py +0 -0
  73. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/_fits/xds_from_fits.py +0 -0
  74. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/_zarr/common.py +0 -0
  75. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/_zarr/xds_from_zarr.py +0 -0
  76. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/_zarr/xds_to_zarr.py +0 -0
  77. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/_zarr/zarr_low_level.py +0 -0
  78. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/casacore.py +0 -0
  79. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/common.py +0 -0
  80. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/fits.py +0 -0
  81. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/_util/image_factory.py +0 -0
  82. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/image/image.py +0 -0
  83. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/__init__.py +0 -0
  84. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/_tables/table_query.py +0 -0
  85. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_ms/msv2_msv3.py +0 -0
  86. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_utils/cds.py +0 -0
  87. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_utils/stokes_types.py +0 -0
  88. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/_zarr/encoding.py +0 -0
  89. {xradio-0.0.28 → xradio-0.0.29}/src/xradio/vis/_vis_utils/ms_column_descriptions_dicts.py +0 -0
  90. {xradio-0.0.28 → xradio-0.0.29}/src/xradio.egg-info/dependency_links.txt +0 -0
  91. {xradio-0.0.28 → xradio-0.0.29}/src/xradio.egg-info/top_level.txt +0 -0
@@ -1,6 +1,11 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2023, Associated Universities, Inc.
3
+ All works in this repository are copyrighted 2024.
4
+ For inquiries contact Associated Universities, Inc., 2650 Park Tower Drive Vienna, VA 22180, USA.
5
+
6
+ Portions of this repository are copyrighted by the following entities:
7
+ 1. AUI/NRAO, ESO, NAOJ, in the framework of the ALMA partnership.
8
+ 2. AUI/NRAO in the framework of the ngVLA project.
4
9
 
5
10
  Redistribution and use in source and binary forms, with or without
6
11
  modification, are permitted provided that the following conditions are met:
@@ -1,11 +1,16 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xradio
3
- Version: 0.0.28
4
- Summary: Xarray Radio Astronomy Data IO
3
+ Version: 0.0.29
4
+ Summary: Xarray Radio Astronomy Data IO
5
5
  Author-email: Jan-Willem Steeb <jsteeb@nrao.edu>
6
6
  License: BSD 3-Clause License
7
7
 
8
- Copyright (c) 2023, Associated Universities, Inc.
8
+ All works in this repository are copyrighted 2024.
9
+ For inquiries contact Associated Universities, Inc., 2650 Park Tower Drive Vienna, VA 22180, USA.
10
+
11
+ Portions of this repository are copyrighted by the following entities:
12
+ 1. AUI/NRAO, ESO, NAOJ, in the framework of the ALMA partnership.
13
+ 2. AUI/NRAO in the framework of the ngVLA project.
9
14
 
10
15
  Redistribution and use in source and binary forms, with or without
11
16
  modification, are permitted provided that the following conditions are met:
@@ -42,7 +47,7 @@ Requires-Dist: distributed
42
47
  Requires-Dist: graphviper
43
48
  Requires-Dist: matplotlib
44
49
  Requires-Dist: numba>=0.57.0
45
- Requires-Dist: numpy
50
+ Requires-Dist: numpy<2.0.0
46
51
  Requires-Dist: prettytable
47
52
  Requires-Dist: pytest
48
53
  Requires-Dist: pytest-cov
@@ -52,12 +57,12 @@ Requires-Dist: scipy
52
57
  Requires-Dist: tqdm
53
58
  Requires-Dist: xarray
54
59
  Requires-Dist: zarr
55
- Requires-Dist: bokeh
56
- Requires-Dist: jupyterlab
57
60
  Requires-Dist: pyarrow
58
61
  Requires-Dist: python_casacore>=3.5.2; sys_platform != "darwin"
59
62
  Requires-Dist: typing_extensions; python_version < "3.10"
63
+ Requires-Dist: typeguard
60
64
  Provides-Extra: docs
65
+ Requires-Dist: jupyterlab; extra == "docs"
61
66
  Requires-Dist: ipykernel; extra == "docs"
62
67
  Requires-Dist: ipympl; extra == "docs"
63
68
  Requires-Dist: ipython; extra == "docs"
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "xradio"
3
- version = "0.0.28"
4
- description = "Xarray Radio Astronomy Data IO"
3
+ version = "0.0.29"
4
+ description = " Xarray Radio Astronomy Data IO"
5
5
  authors = [
6
6
  {name = "Jan-Willem Steeb", email="jsteeb@nrao.edu"},
7
7
  ]
@@ -17,7 +17,7 @@ dependencies = [
17
17
  'graphviper',
18
18
  'matplotlib',
19
19
  'numba>=0.57.0',
20
- 'numpy',
20
+ 'numpy<2.0.0',
21
21
  'prettytable',
22
22
  'pytest',
23
23
  'pytest-cov',
@@ -27,15 +27,15 @@ dependencies = [
27
27
  'tqdm',
28
28
  'xarray',
29
29
  'zarr',
30
- 'bokeh',
31
- 'jupyterlab',
32
30
  'pyarrow',
33
31
  'python_casacore>=3.5.2; sys_platform != "darwin" ',
34
- 'typing_extensions; python_version < "3.10"'
32
+ 'typing_extensions; python_version < "3.10"',
33
+ 'typeguard'
35
34
  ]
36
35
 
37
36
  [project.optional-dependencies]
38
37
  docs = [
38
+ 'jupyterlab',
39
39
  'ipykernel',
40
40
  'ipympl',
41
41
  'ipython',
@@ -49,3 +49,20 @@ docs = [
49
49
  'twine',
50
50
  'pandoc'
51
51
  ]
52
+
53
+ [tool.pytest.ini_options]
54
+ addopts = [
55
+ "--import-mode=importlib",
56
+ "--strict-markers"
57
+ ]
58
+ testpaths = [
59
+ "tests"
60
+ ]
61
+ pythonpath = [
62
+ "."
63
+ ]
64
+
65
+ [tool.black]
66
+ line-length = 88
67
+ target-version = ['py39']
68
+ include = '\.py$'
@@ -0,0 +1,13 @@
1
+ import os
2
+ from graphviper.utils.logger import setup_logger
3
+
4
+ _logger_name = "xradio"
5
+ if os.getenv("VIPER_LOGGER_NAME") != _logger_name:
6
+ os.environ["VIPER_LOGGER_NAME"] = _logger_name
7
+ setup_logger(
8
+ logger_name="xradio",
9
+ log_to_term=True,
10
+ log_to_file=False, # True
11
+ log_file="xradio-logfile",
12
+ log_level="DEBUG",
13
+ )
@@ -0,0 +1,90 @@
1
+ """Contains optimised functions to be used within other modules."""
2
+
3
+ import numpy as np
4
+
5
+
6
+ def check_if_consistent(array: np.ndarray, array_name: str) -> np.ndarray:
7
+ """_summary_
8
+
9
+ Parameters
10
+ ----------
11
+ col : _type_
12
+ _description_
13
+ col_name : _type_
14
+ _description_
15
+
16
+ Returns
17
+ -------
18
+ _type_
19
+ _description_
20
+ """
21
+ if array.ndim == 0:
22
+ return array.item()
23
+
24
+ array_unique = unique_1d(array)
25
+ assert len(array_unique) == 1, array_name + " is not consistent."
26
+ return array_unique[0]
27
+
28
+
29
+ import numpy as np
30
+ import pandas as pd
31
+
32
+
33
+ def unique_1d(array: np.ndarray) -> np.ndarray:
34
+ """
35
+ Optimised version of np.unique for 1D arrays.
36
+
37
+ Parameters
38
+ ----------
39
+ array : np.ndarray
40
+ a 1D array of values.
41
+
42
+ Returns
43
+ -------
44
+ np.ndarray
45
+ a sorted array of unique values.
46
+
47
+ """
48
+ return np.sort(pd.unique(array))
49
+
50
+
51
+ def pairing_function(antenna_pairs: np.ndarray) -> np.ndarray:
52
+ """
53
+ Pairing function to convert each array pair to a single value.
54
+
55
+ This custom pairing function will only work if the maximum value is less
56
+ than 2**20 and less than 2,048 if using signed 32-bit integers.
57
+
58
+ Parameters
59
+ ----------
60
+ antenna_pairs : np.ndarray
61
+ a 2D array containing antenna 1 and antenna
62
+ 2 ids, which forms a baseline.
63
+
64
+ Returns
65
+ -------
66
+ np.ndarray
67
+ a 1D array of the paired values.
68
+
69
+ """
70
+ return antenna_pairs[:, 0] * 2**20 + antenna_pairs[:, 1]
71
+
72
+
73
+ def inverse_pairing_function(paired_array: np.ndarray) -> np.ndarray:
74
+ """
75
+ Inverse pairing function to convert each paired value to an antenna pair.
76
+
77
+ This inverse pairing function is the inverse of the custom pairing function.
78
+
79
+ Parameters
80
+ ----------
81
+ paired_array : np.ndarray
82
+ a 1D array of the paired values.
83
+
84
+ Returns
85
+ -------
86
+ np.ndarray
87
+ a 2D array containing antenna 1 and antenna 2 ids.
88
+
89
+ """
90
+ return np.column_stack(np.divmod(paired_array, 2**20))
@@ -2,9 +2,54 @@ import copy
2
2
  import xarray as xr
3
3
  import zarr
4
4
  import s3fs
5
+ import os
6
+ from botocore.exceptions import NoCredentialsError
7
+
8
+
9
+ def _get_ms_stores_and_file_system(ps_store: str):
10
+
11
+ if os.path.isdir(ps_store):
12
+ # default to assuming the data are accessible on local file system
13
+ items = os.listdir(ps_store)
14
+ file_system = os
15
+
16
+ elif ps_store.startswith("s3"):
17
+ # only if not found locally, check if dealing with an S3 bucket URL
18
+ # if not ps_store.endswith("/"):
19
+ # # just for consistency, as there is no os.path equivalent in s3fs
20
+ # ps_store = ps_store + "/"
21
+
22
+ try:
23
+ # initialize the S3 "file system", first attempting to use pre-configured credentials
24
+ file_system = s3fs.S3FileSystem(anon=False, requester_pays=False)
25
+ items = [
26
+ bd.split(sep="/")[-1]
27
+ for bd in file_system.listdir(ps_store, detail=False)
28
+ ]
29
+
30
+ except (NoCredentialsError, PermissionError) as e:
31
+ # only public, read-only buckets will be accessible
32
+ # we will want to add messaging and error handling here
33
+ file_system = s3fs.S3FileSystem(anon=True)
34
+ items = [
35
+ bd.split(sep="/")[-1]
36
+ for bd in file_system.listdir(ps_store, detail=False)
37
+ ]
38
+ else:
39
+ raise (
40
+ FileNotFoundError,
41
+ f"Could not find {ps_store} either locally or in the cloud.",
42
+ )
43
+
44
+ items = [
45
+ item for item in items if not item.startswith(".")
46
+ ] # Mac OS likes to place hidden files in the directory (.DStore).
47
+ return file_system, items
5
48
 
6
49
 
7
- def _open_dataset(store, xds_isel=None, data_variables=None, load=False, **kwargs):
50
+ def _open_dataset(
51
+ store, file_system=os, xds_isel=None, data_variables=None, load=False
52
+ ):
8
53
  """
9
54
 
10
55
  Parameters
@@ -26,8 +71,8 @@ def _open_dataset(store, xds_isel=None, data_variables=None, load=False, **kwarg
26
71
 
27
72
  import dask
28
73
 
29
- if "s3" in kwargs.keys():
30
- mapping = s3fs.S3Map(root=store, s3=kwargs["s3"], check=False)
74
+ if isinstance(file_system, s3fs.core.S3FileSystem):
75
+ mapping = s3fs.S3Map(root=store, s3=file_system, check=False)
31
76
  xds = xr.open_zarr(store=mapping)
32
77
  else:
33
78
  xds = xr.open_zarr(store)
@@ -25,7 +25,10 @@ def _xds_from_zarr(
25
25
 
26
26
 
27
27
  def _load_image_from_zarr_no_dask(zarr_file: str, selection: dict) -> xr.Dataset:
28
- image_xds = _open_dataset(zarr_file, selection, load=True)
28
+ # At the moment image module does not support S3 file system. file_system=os is hardcoded.
29
+ image_xds = _open_dataset(
30
+ store=zarr_file, file_system=os, xds_isel=selection, load=True
31
+ )
29
32
  for h in ["HISTORY", "_attrs_xds_history"]:
30
33
  history = os.sep.join([zarr_file, h])
31
34
  if os.path.isdir(history):
@@ -0,0 +1,35 @@
1
+ from .dataclass import (
2
+ xarray_dataclass_to_array_schema,
3
+ xarray_dataclass_to_dataset_schema,
4
+ xarray_dataclass_to_dict_schema,
5
+ )
6
+ from .bases import (
7
+ xarray_dataarray_schema,
8
+ xarray_dataset_schema,
9
+ dict_schema,
10
+ )
11
+ from .check import (
12
+ SchemaIssue,
13
+ SchemaIssues,
14
+ check_array,
15
+ check_dataset,
16
+ check_dict,
17
+ schema_checked,
18
+ )
19
+
20
+ __all__ = [
21
+ "xarray_dataclass_to_array_schema",
22
+ "xarray_dataclass_to_dataset_schema",
23
+ "xarray_dataclass_to_dict_schema",
24
+ "AsDataArray",
25
+ "AsDataset",
26
+ "AsDict",
27
+ "xarray_dataarray_schema",
28
+ "xarray_dataset_schema",
29
+ "SchemaIssue",
30
+ "SchemaIssues",
31
+ "check_array",
32
+ "check_dataset",
33
+ "check_dict",
34
+ "schema_checked",
35
+ ]