sd-dougu 0.0.1__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.
dougu/graph/graph.py ADDED
@@ -0,0 +1,175 @@
1
+ import dataclasses
2
+
3
+ import dask
4
+ import operator
5
+
6
+ import toolviper
7
+
8
+ import xarray as xr
9
+ import graphviper.graph_tools as graph_tools
10
+ import toolviper.utils.logger as logger
11
+
12
+ from graphviper.graph_tools.generate_dask_workflow import generate_dask_workflow
13
+
14
+
15
+ class Graph:
16
+ def __init__(self):
17
+ self._nodes = {}
18
+
19
+ self._node_mapping = None
20
+ self._coordinates = None
21
+ self._graph = None
22
+ self._dataset = None
23
+
24
+ def __getitem__(self, item):
25
+
26
+ # convert to a list so we can parse the input
27
+ item = list(item)
28
+ trees = {
29
+ key: value
30
+ for key, value in zip(item, list(operator.itemgetter(*item)(self._dataset)))
31
+ }
32
+
33
+ return xr.DataTree.from_dict(data=trees)
34
+
35
+ def filter(self, leaves=None):
36
+ drop = set(self._dataset.keys()) ^ set(leaves)
37
+
38
+ logger.info(f"Dropping nodes: {drop}")
39
+ self._dataset = self._dataset.drop_nodes(names=drop)
40
+
41
+ @classmethod
42
+ def from_dataset(cls, dataset):
43
+ logger.info("Creating graph from dataset ...")
44
+ graph = cls()
45
+ graph._dataset = dataset
46
+ return graph
47
+
48
+ def build_node(self, ps_partition=None):
49
+ """Builds a node from the dataset and coordinates"""
50
+ if self._coordinates is None:
51
+ raise ValueError("Coordinates must be set before building node")
52
+
53
+ if self._dataset is None:
54
+ raise ValueError("Dataset must be set before building node")
55
+
56
+ self._node_mapping = (
57
+ graph_tools.coordinate_utils.interpolate_data_coords_onto_parallel_coords(
58
+ self._coordinates, self._dataset, ps_partition=ps_partition
59
+ )
60
+ )
61
+
62
+ def make_coordinates(self, coords):
63
+ self._coordinates = dict.fromkeys(coords)
64
+
65
+ for coord in coords:
66
+ if coord == "antenna_name":
67
+ logger.info("Making antenna coordinate ...")
68
+ xds = self._dataset.xr_ps.get_combined_antenna_xds()
69
+ self._coordinates[coord] = (
70
+ graph_tools.coordinate_utils.make_parallel_coord(
71
+ coord=xds.antenna_name, n_chunks=xds.antenna_name.shape[0]
72
+ )
73
+ )
74
+
75
+ elif coord == "field_name":
76
+ logger.info("Making field coordinate ...")
77
+ xds = self._dataset.xr_ps.get_combined_field_and_source_xds()
78
+ self._coordinates[coord] = (
79
+ graph_tools.coordinate_utils.make_parallel_coord(
80
+ coord=xds.field_name, n_chunks=xds.field_name.shape[0]
81
+ )
82
+ )
83
+
84
+ elif coord == "polarization":
85
+ logger.info("Making polarization coordinate ...")
86
+ xds = self._dataset.xr_ps.get_combined_field_and_source_xds()
87
+ self._coordinates[coord] = (
88
+ graph_tools.coordinate_utils.make_parallel_coord(
89
+ coord=xds.polarization,
90
+ n_chunks=xds.polarization.values.shape[0],
91
+ )
92
+ )
93
+
94
+ else:
95
+ logger.error(f"Coordinate {coord} not found in dataset.")
96
+
97
+ def map(self, function, parameters=None, connect=None, make_workflow=False):
98
+
99
+ name = function.__name__
100
+
101
+ self._graph = graph_tools.map(
102
+ input_data=self._dataset,
103
+ node_task_data_mapping=self._node_mapping,
104
+ node_task=function,
105
+ input_params=parameters,
106
+ previous=self._nodes[connect].result if connect is not None else None,
107
+ )
108
+
109
+ if parameters is None:
110
+ parameters = {}
111
+
112
+ if make_workflow:
113
+ self._graph = generate_dask_workflow(self._graph)
114
+
115
+ self._nodes[name] = GraphNode(
116
+ parameters=parameters,
117
+ function=function,
118
+ previous=None if connect is None else self._nodes[connect].result,
119
+ result=self._graph,
120
+ )
121
+
122
+ def reduce(self, function, parameters=None, connect=None, mode="tree"):
123
+ name = function.__name__
124
+
125
+ graph_tools.reduce(
126
+ graph=self._graph,
127
+ reduce_node_task=function,
128
+ input_params=parameters,
129
+ mode=mode,
130
+ )
131
+
132
+ self._graph = generate_dask_workflow(self._graph)
133
+
134
+ self._nodes[name] = GraphNode(
135
+ parameters=parameters,
136
+ function=function,
137
+ previous=None if connect is None else self._nodes[connect].result,
138
+ result=self._graph,
139
+ )
140
+
141
+ def reset(self):
142
+ self._nodes = {}
143
+ self._graph = None
144
+ # self._dataset = None
145
+ self._coordinates = None
146
+ self._node_mapping = None
147
+
148
+ def compute(self):
149
+ return dask.compute(self._graph)
150
+
151
+ @property
152
+ def datatree(self):
153
+ return self._dataset
154
+
155
+ @property
156
+ def coordinates(self):
157
+ return toolviper.utils.display.DataDict.html(self._coordinates)
158
+
159
+ @property
160
+ def node_mapping(self):
161
+ return toolviper.utils.display.DataDict.html(self._node_mapping)
162
+
163
+ @property
164
+ def graph(self):
165
+ return self._graph
166
+
167
+
168
+ @dataclasses.dataclass
169
+ class GraphNode:
170
+ """A class representing a node in a graph."""
171
+
172
+ parameters: dict
173
+ function: callable
174
+ result: dict | list | None
175
+ previous: dict | list | None
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: sd-dougu
3
+ Version: 0.0.1
4
+ Summary: Toolkit for Single Dish RAPDS Development and Processing
5
+ Author-email: Joshua Hoskins <joshua.hoskins@nao.ac.jp>
6
+ Requires-Python: <3.15,>=3.13
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: xarray
10
+ Requires-Dist: toolviper
11
+ Requires-Dist: graphviper
12
+ Provides-Extra: zarr
13
+ Requires-Dist: astropy; extra == "zarr"
14
+ Requires-Dist: toolviper>=0.1.3; extra == "zarr"
15
+ Requires-Dist: s3fs; extra == "zarr"
16
+ Requires-Dist: scipy; extra == "zarr"
17
+ Requires-Dist: xarray; extra == "zarr"
18
+ Requires-Dist: zarr<4,>=3; extra == "zarr"
19
+ Requires-Dist: numcodecs>=0.16; extra == "zarr"
20
+ Requires-Dist: pyarrow; extra == "zarr"
21
+ Requires-Dist: psutil; extra == "zarr"
22
+ Provides-Extra: asdm
23
+ Requires-Dist: astropy; extra == "asdm"
24
+ Requires-Dist: pyasdm; extra == "asdm"
25
+ Requires-Dist: toolviper; extra == "asdm"
26
+ Requires-Dist: xarray; extra == "asdm"
27
+ Provides-Extra: interactive
28
+ Requires-Dist: astropy; extra == "interactive"
29
+ Requires-Dist: toolviper; extra == "interactive"
30
+ Requires-Dist: s3fs; extra == "interactive"
31
+ Requires-Dist: scipy; extra == "interactive"
32
+ Requires-Dist: xarray; extra == "interactive"
33
+ Requires-Dist: zarr<4,>=3; extra == "interactive"
34
+ Requires-Dist: numcodecs>=0.16; extra == "interactive"
35
+ Requires-Dist: pyarrow; extra == "interactive"
36
+ Requires-Dist: psutil; extra == "interactive"
37
+ Requires-Dist: matplotlib; extra == "interactive"
38
+ Requires-Dist: prettytable; extra == "interactive"
39
+ Requires-Dist: jupyterlab; extra == "interactive"
40
+ Requires-Dist: ipykernel; extra == "interactive"
41
+ Requires-Dist: ipympl; extra == "interactive"
42
+ Requires-Dist: ipython; extra == "interactive"
43
+ Requires-Dist: jupyter-client; extra == "interactive"
44
+ Dynamic: license-file
45
+
46
+ # dougu
47
+ Toolbox for Single Dish Radio Astronomy
@@ -0,0 +1,6 @@
1
+ dougu/graph/graph.py,sha256=put9Hinlr2GzYP9jA0g9z5RSXzaXrWo2RvUPJh2Fx98,5323
2
+ sd_dougu-0.0.1.dist-info/licenses/LICENSE,sha256=vA5hjWOKkhtsS6a4YqujEfxvO6HU_yRdMx-SZJLMPek,1494
3
+ sd_dougu-0.0.1.dist-info/METADATA,sha256=Acn1maAhupgFMA5o5xtwSGT9vMx6GGstH6Oz0_X4Xis,1790
4
+ sd_dougu-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ sd_dougu-0.0.1.dist-info/top_level.txt,sha256=bPXrCxcrSxaUNN3bdRLwEuRXGHZz7w1j7aQcSBtTkeU,6
6
+ sd_dougu-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Mogsoft
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 @@
1
+ dougu