Repository navigation
Expand file tree
/
Copy pathbuffer_data_models.py
More file actions
195 lines (137 loc) · 5.92 KB
/
Copy pathbuffer_data_models.py
File metadata and controls
195 lines (137 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
""" Buffer equivalents of memory data models
To create from an existing model in the buffer, make some changes, and then sync to buffer::
my_buffer_skymodel = BufferSkyModel(conf["buffer"], conf["inputs"]["skymodel"])
my_memory_skymodel = my_buffer_skymodel.memory_data_model
... do some stuff
my_memory_skymodel.sync()
To create a new buffer for a memory_data_model::
my_buffer_skymodel = BufferSkyModel(conf["buffer"], conf["inputs"]["skymodel"], my_memory_skymodel)
my_memory_skymodel.sync()
An explicit sync is required in both cases
"""
import collections
import logging
from data_models.data_model_helpers import buffer_data_model_to_memory, memory_data_model_to_buffer
from data_models.memory_data_models import Image, BlockVisibility, SkyModel, GainTable, GridData, \
ConvolutionFunction, PointingTable
log = logging.getLogger(__name__)
class BufferDataModel():
"""Buffer version of data model
To create from an existing model in the buffer, make some changes, and then sync to buffer::
my_buffer_skymodel = BufferSkyModel(conf["buffer"], conf["inputs"]["skymodel"])
my_memory_skymodel = my_buffer_skymodel.memory_data_model()
... do some stuff
my_memory_skymodel.sync()
To create a new buffer for a memory_data_model::
my_buffer_skymodel = BufferSkyModel(conf["buffer"], conf["inputs"]["skymodel"], my_memory_skymodel)
my_memory_skymodel.sync()
An explicit sync is required in both cases.
"""
def __init__(self, json_buffer, json_model, mdm=None):
"""
:param json_buffer: Description of buffer in JSON
:param json_model: Description of model in buffer in JSON
:param mdm: memory data model (can be a list or a single data model)
"""
self.json_buffer = json_buffer
self.json_model = json_model
if mdm is not None:
self._memory_data_model = mdm
else:
self._memory_data_model = buffer_data_model_to_memory(self.json_buffer, self.json_model)
@property
def memory_data_model(self):
return self._memory_data_model
@property
def type(self):
return type(self._memory_data_model)
def assert_type(self, memory_data_model_type):
if isinstance(self._memory_data_model, collections.Iterable):
for m in self._memory_data_model:
assert isinstance(m, memory_data_model_type), "Expected %s, actual %s" % (memory_data_model_type,
type(m))
else:
assert isinstance(self._memory_data_model, memory_data_model_type), \
"Expected %s, actual %s" % (memory_data_model_type, type(self._memory_data_model))
def sync(self):
""" Save to buffer
:return:
"""
memory_data_model_to_buffer(self._memory_data_model, self.json_buffer, self.json_model)
class BufferImage(BufferDataModel):
"""Buffer version of memory data model Image
"""
def __init__(self, json_buffer, json_model, mdm=None):
"""
:param json_buffer: JSON description of buffer
:param json_model: JSON descriptiomn of model
:return: Image
"""
BufferDataModel.__init__(self, json_buffer, json_model, mdm)
self.assert_type(Image)
class BufferGridData(BufferDataModel):
"""Buffer version of memory data model GridData
"""
def __init__(self, json_buffer, json_model, mdm=None):
"""
:param json_buffer: JSON description of buffer
:param json_model: JSON descriptiomn of model
:return: Image
"""
BufferDataModel.__init__(self, json_buffer, json_model, mdm)
self.assert_type(GridData)
class BufferConvolutionFunction(BufferDataModel):
"""Buffer version of memory data model ConvolutionFunction
"""
def __init__(self, json_buffer, json_model, mdm=None):
"""
:param json_buffer: JSON description of buffer
:param json_model: JSON descriptiomn of model
:return: Image
"""
BufferDataModel.__init__(self, json_buffer, json_model, mdm)
self.assert_type(ConvolutionFunction)
class BufferBlockVisibility(BufferDataModel):
"""Buffer version of memory data model BlockVisibility
"""
def __init__(self, json_buffer, json_model, mdm=None):
"""
:param json_buffer: JSON description of buffer
:param json_model: JSON descriptiomn of model
:return: Image
"""
BufferDataModel.__init__(self, json_buffer, json_model, mdm)
self.assert_type(BlockVisibility)
class BufferSkyModel(BufferDataModel):
"""Buffer version of memory data model SkyModel
"""
def __init__(self, json_buffer, json_model, mdm=None):
"""
:param json_buffer: JSON description of buffer
:param json_model: JSON descriptiomn of model
:return: Image
"""
BufferDataModel.__init__(self, json_buffer, json_model, mdm)
self.assert_type(SkyModel)
class BufferGainTable(BufferDataModel):
"""Buffer version of memory data model GainTable
"""
def __init__(self, json_buffer, json_model, mdm=None):
"""
:param json_buffer: JSON description of buffer
:param json_model: JSON descriptiomn of model
:return: Image
"""
BufferDataModel.__init__(self, json_buffer, json_model, mdm)
self.assert_type(GainTable)
class BufferPointingTable(BufferDataModel):
"""Buffer version of memory data model GainTable
"""
def __init__(self, json_buffer, json_model, mdm=None):
"""
:param json_buffer: JSON description of buffer
:param json_model: JSON descriptiomn of model
:return: Image
"""
BufferDataModel.__init__(self, json_buffer, json_model, mdm)
self.assert_type(PointingTable)