qcodespp 0.1.0__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.
- qcodespp/__init__.py +77 -0
- qcodespp/actions.py +237 -0
- qcodespp/data/__init__.py +0 -0
- qcodespp/data/data_array.py +555 -0
- qcodespp/data/data_set.py +926 -0
- qcodespp/data/format.py +338 -0
- qcodespp/data/gnuplot_format.py +425 -0
- qcodespp/data/hdf5_format.py +537 -0
- qcodespp/data/hdf5_format_hickle.py +63 -0
- qcodespp/data/io.py +241 -0
- qcodespp/data/location.py +171 -0
- qcodespp/instrument_drivers/Keysight/Keysight_34450A.py +9 -0
- qcodespp/instrument_drivers/Keysight/__init__.py +0 -0
- qcodespp/instrument_drivers/Keysight/private/Keysight_344xxA.py +456 -0
- qcodespp/instrument_drivers/Keysight/private/__init__.py +0 -0
- qcodespp/instrument_drivers/Lakeshore/Model_340.py +483 -0
- qcodespp/instrument_drivers/Lakeshore/__init__.py +0 -0
- qcodespp/instrument_drivers/QDevil/159fit_params_high_latest.json +386 -0
- qcodespp/instrument_drivers/QDevil/159fit_params_low_latest.json +386 -0
- qcodespp/instrument_drivers/QDevil/QDAC2.py +3229 -0
- qcodespp/instrument_drivers/QDevil/QDAC2_Array.py +300 -0
- qcodespp/instrument_drivers/QDevil/QSwitch_elab.py +652 -0
- qcodespp/instrument_drivers/QDevil/__init__.py +0 -0
- qcodespp/instrument_drivers/ZI/ZIHF2LI.py +415 -0
- qcodespp/instrument_drivers/ZI/ZIMFLI.py +764 -0
- qcodespp/instrument_drivers/ZI/ZIMFLI_sync.py +108 -0
- qcodespp/instrument_drivers/ZI/ZIUHFLI.py +2179 -0
- qcodespp/instrument_drivers/ZI/__init__.py +1 -0
- qcodespp/instrument_drivers/__init__.py +0 -0
- qcodespp/instrument_drivers/cryogenic/CryogenicSMS120C.py +599 -0
- qcodespp/instrument_drivers/cryogenic/__init__.py +0 -0
- qcodespp/instrument_drivers/instrument_mocks.py +379 -0
- qcodespp/instrument_drivers/multiplexer_instrument.py +287 -0
- qcodespp/instrument_drivers/national_instruments/PXI_4461.py +451 -0
- qcodespp/instrument_drivers/national_instruments/PXI_4462.py +290 -0
- qcodespp/instrument_drivers/national_instruments/PXI_6259.py +436 -0
- qcodespp/instrument_drivers/national_instruments/PXI_6733.py +230 -0
- qcodespp/instrument_drivers/national_instruments/PXI_6733_e.py +243 -0
- qcodespp/instrument_drivers/national_instruments/__init__.py +0 -0
- qcodespp/instrument_drivers/oxford/__init__.py +0 -0
- qcodespp/instrument_drivers/oxford/mercuryiPS_serial.py +658 -0
- qcodespp/instrument_drivers/oxford/triton.py +434 -0
- qcodespp/instrument_drivers/tektronix/Keithley_2000_Scan.py +65 -0
- qcodespp/instrument_drivers/tektronix/Keithley_2182a.py +190 -0
- qcodespp/instrument_drivers/tektronix/Keithley_2400.py +158 -0
- qcodespp/instrument_drivers/tektronix/Keithley_2450.py +242 -0
- qcodespp/instrument_drivers/tektronix/Keithley_2700.py +397 -0
- qcodespp/instrument_drivers/tektronix/Keithley_6500.py +161 -0
- qcodespp/instrument_drivers/tektronix/__init__.py +0 -0
- qcodespp/instrument_drivers/yokogawa/GS200.py +513 -0
- qcodespp/instrument_drivers/yokogawa/__init__.py +0 -0
- qcodespp/loops.py +1342 -0
- qcodespp/measure.py +310 -0
- qcodespp/parameters.py +311 -0
- qcodespp/plotting/RemotePlot.py +469 -0
- qcodespp/plotting/RemotePlotClient.py +367 -0
- qcodespp/plotting/RemoteQtPlotWidgets.py +871 -0
- qcodespp/plotting/__init__.py +0 -0
- qcodespp/plotting/analysis_tools.py +195 -0
- qcodespp/plotting/colors.py +135 -0
- qcodespp/plotting/offline/__init__.py +0 -0
- qcodespp/plotting/offline/datatypes.py +999 -0
- qcodespp/plotting/offline/design.py +906 -0
- qcodespp/plotting/offline/design.ui +1578 -0
- qcodespp/plotting/offline/editor.py +2966 -0
- qcodespp/plotting/offline/filters.py +561 -0
- qcodespp/plotting/offline/fits.py +1171 -0
- qcodespp/plotting/offline/helpers.py +288 -0
- qcodespp/plotting/offline/iconGadget.png +0 -0
- qcodespp/plotting/offline/main.py +55 -0
- qcodespp/plotting/offline/popupwindows.py +1848 -0
- qcodespp/plotting/offline/qcodes_pp_extension.py +328 -0
- qcodespp/plotting/offline/sidebars.py +1108 -0
- qcodespp/station.py +290 -0
- qcodespp/utils/__init__.py +0 -0
- qcodespp/utils/helpers.py +618 -0
- qcodespp/utils/visa_helpers.py +61 -0
- qcodespp/version.py +12 -0
- qcodespp-0.1.0.dist-info/METADATA +91 -0
- qcodespp-0.1.0.dist-info/RECORD +82 -0
- qcodespp-0.1.0.dist-info/WHEEL +4 -0
- qcodespp-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import collections
|
|
3
|
+
|
|
4
|
+
from qcodes.utils.helpers import DelegateAttributes, full_class, warn_units
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class DataArray(DelegateAttributes):
|
|
8
|
+
|
|
9
|
+
"""
|
|
10
|
+
A container for one parameter in a qcodespp DataSetPP
|
|
11
|
+
|
|
12
|
+
A DataArray can either be a setpoint array or a measured parameter.
|
|
13
|
+
If this is a measured parameter, this object doesn't contain
|
|
14
|
+
the data of the setpoints it was measured at, but it references
|
|
15
|
+
the DataArray objects of these parameters. Those objects only have
|
|
16
|
+
the dimensionality at which they were set - ie the inner loop setpoint
|
|
17
|
+
the same dimensionality as the measured parameter, but the outer
|
|
18
|
+
loop setpoint(s) have lower dimensionality
|
|
19
|
+
|
|
20
|
+
When it's first created, a DataArray has no dimensionality,
|
|
21
|
+
.nest must be called for each dimension.
|
|
22
|
+
|
|
23
|
+
If preset_data is provided it is used to initialize the data, and the array
|
|
24
|
+
can still be nested around it (making many copies of the data).
|
|
25
|
+
Otherwise it is an error to nest an array that already has data.
|
|
26
|
+
|
|
27
|
+
Once the array is initialized, a DataArray acts a lot like a numpy array,
|
|
28
|
+
because we delegate attributes through to the numpy array
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
parameter (Optional[Parameter]): The parameter whose values will
|
|
32
|
+
populate this array, if any. Will copy ``name``, ``full_name``,
|
|
33
|
+
``label``, ``unit``, and ``snapshot`` from here unless you
|
|
34
|
+
provide them explicitly.
|
|
35
|
+
|
|
36
|
+
name (Optional[str]): The short name of this array.
|
|
37
|
+
TODO: use full_name as name, and get rid of short name
|
|
38
|
+
|
|
39
|
+
full_name (Optional[str]): The complete name of this array. If the
|
|
40
|
+
array is based on a parameter linked to an instrument, this is
|
|
41
|
+
typically '<instrument_name>_<param_name>'
|
|
42
|
+
|
|
43
|
+
label (Optional[str]): A description of the values in this array to
|
|
44
|
+
use for axis and colorbar labels on plots.
|
|
45
|
+
|
|
46
|
+
snapshot (Optional[dict]): Metadata snapshot to save with this array.
|
|
47
|
+
|
|
48
|
+
array_id (Optional[str]): A name for this array that's unique within
|
|
49
|
+
its ``DataSetPP``. Typically the full_name, but when the ``DataSetPP``
|
|
50
|
+
is constructed we will append '_<i>' (``i`` is an integer starting
|
|
51
|
+
from 1) if necessary to differentiate arrays with the same id.
|
|
52
|
+
TODO: this only happens for arrays provided to the DataSetPP
|
|
53
|
+
constructor, not those added with add_array. Fix this!
|
|
54
|
+
Also, do we really need array_id *and* full_name (let alone name
|
|
55
|
+
but I've already said we should remove this)?
|
|
56
|
+
|
|
57
|
+
set_arrays (Optional[Tuple[DataArray]]): If this array is being
|
|
58
|
+
created with shape already, you can provide one setpoint array
|
|
59
|
+
per dimension. The first should have one dimension, the second
|
|
60
|
+
two dimensions, etc.
|
|
61
|
+
|
|
62
|
+
shape (Optional[Tuple[int]]): The shape (as in numpy) of the array.
|
|
63
|
+
Will be prepended with new dimensions by any calls to ``nest``.
|
|
64
|
+
|
|
65
|
+
action_indices (Optional[Tuple[int]]): If used within a ``Loop``,
|
|
66
|
+
these are the indices at each level of nesting within the
|
|
67
|
+
``Loop`` of the loop action that's populating this array.
|
|
68
|
+
TODO: this shouldn't be in DataArray at all, the loop should
|
|
69
|
+
handle converting this to array_id internally (maybe it
|
|
70
|
+
already does?)
|
|
71
|
+
|
|
72
|
+
unit (Optional[str]): The unit of the values stored in this array.
|
|
73
|
+
|
|
74
|
+
units (Optional[str]): DEPRECATED, redirects to ``unit``.
|
|
75
|
+
|
|
76
|
+
is_setpoint (bool): True if this is a setpoint array, False if it
|
|
77
|
+
is measured. Default False.
|
|
78
|
+
|
|
79
|
+
preset_data (Optional[Union[ndarray, sequence]]): Contents of the
|
|
80
|
+
array, if already known (for example if this is a setpoint
|
|
81
|
+
array). ``shape`` will be inferred from this array instead of
|
|
82
|
+
from the ``shape`` argument.
|
|
83
|
+
|
|
84
|
+
data_type (Optional[Type] default = float): numpy array entries
|
|
85
|
+
must be of the same type. Float covers most instances, otherwise
|
|
86
|
+
string is best.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
# attributes of self to include in the snapshot
|
|
90
|
+
SNAP_ATTRS = (
|
|
91
|
+
'array_id',
|
|
92
|
+
'name',
|
|
93
|
+
'shape',
|
|
94
|
+
'unit',
|
|
95
|
+
'label',
|
|
96
|
+
'action_indices',
|
|
97
|
+
'is_setpoint',
|
|
98
|
+
'data_type')
|
|
99
|
+
|
|
100
|
+
# attributes of the parameter (or keys in the incoming snapshot)
|
|
101
|
+
# to copy to DataArray attributes, if they aren't set some other way
|
|
102
|
+
COPY_ATTRS_FROM_INPUT = (
|
|
103
|
+
'name',
|
|
104
|
+
'label',
|
|
105
|
+
'unit',
|
|
106
|
+
'data_type')
|
|
107
|
+
|
|
108
|
+
# keys in the parameter snapshot to omit from our snapshot
|
|
109
|
+
SNAP_OMIT_KEYS = (
|
|
110
|
+
'ts',
|
|
111
|
+
'value',
|
|
112
|
+
'__class__',
|
|
113
|
+
'set_arrays',
|
|
114
|
+
'shape',
|
|
115
|
+
'array_id',
|
|
116
|
+
'action_indices')
|
|
117
|
+
|
|
118
|
+
def __init__(self, parameter=None, name=None, full_name=None, label=None,
|
|
119
|
+
snapshot=None, array_id=None, set_arrays=(), shape=None,
|
|
120
|
+
action_indices=(), unit=None, units=None, is_setpoint=False,
|
|
121
|
+
preset_data=None,data_type=None):
|
|
122
|
+
self.name = name
|
|
123
|
+
self.full_name = full_name or name
|
|
124
|
+
self.label = label
|
|
125
|
+
self.shape = shape
|
|
126
|
+
if units is not None:
|
|
127
|
+
warn_units('DataArray', self)
|
|
128
|
+
if unit is None:
|
|
129
|
+
unit = units
|
|
130
|
+
self.unit = unit
|
|
131
|
+
self.array_id = array_id
|
|
132
|
+
self.is_setpoint = is_setpoint
|
|
133
|
+
self.action_indices = action_indices
|
|
134
|
+
self.set_arrays = set_arrays
|
|
135
|
+
if data_type is None and parameter:
|
|
136
|
+
try:
|
|
137
|
+
data_type = type(parameter.get_latest())
|
|
138
|
+
except:
|
|
139
|
+
data_type = float
|
|
140
|
+
if data_type not in [float, str]:
|
|
141
|
+
data_type = float
|
|
142
|
+
self.data_type=data_type
|
|
143
|
+
|
|
144
|
+
self._preset = False
|
|
145
|
+
|
|
146
|
+
# store a reference up to the containing DataSetPP
|
|
147
|
+
# this also lets us make sure a DataArray is only in one DataSetPP
|
|
148
|
+
self._data_set = None
|
|
149
|
+
|
|
150
|
+
self.last_saved_index = None
|
|
151
|
+
self.modified_range = None
|
|
152
|
+
|
|
153
|
+
self.ndarray = None
|
|
154
|
+
if snapshot is None:
|
|
155
|
+
snapshot = {}
|
|
156
|
+
self._snapshot_input = {}
|
|
157
|
+
|
|
158
|
+
if parameter is not None:
|
|
159
|
+
param_full_name = getattr(parameter, 'full_name', None)
|
|
160
|
+
if param_full_name and not full_name:
|
|
161
|
+
self.full_name = parameter.full_name
|
|
162
|
+
|
|
163
|
+
if hasattr(parameter, 'snapshot') and not snapshot:
|
|
164
|
+
snapshot = parameter.snapshot()
|
|
165
|
+
else:
|
|
166
|
+
# TODO: why is this in an else clause?
|
|
167
|
+
for attr in self.COPY_ATTRS_FROM_INPUT:
|
|
168
|
+
if (hasattr(parameter, attr) and
|
|
169
|
+
not getattr(self, attr, None)):
|
|
170
|
+
setattr(self, attr, getattr(parameter, attr))
|
|
171
|
+
|
|
172
|
+
for key, value in snapshot.items():
|
|
173
|
+
if key not in self.SNAP_OMIT_KEYS:
|
|
174
|
+
self._snapshot_input[key] = value
|
|
175
|
+
|
|
176
|
+
if (key in self.COPY_ATTRS_FROM_INPUT and
|
|
177
|
+
not getattr(self, key, None)):
|
|
178
|
+
setattr(self, key, value)
|
|
179
|
+
|
|
180
|
+
if not self.label:
|
|
181
|
+
self.label = self.name
|
|
182
|
+
|
|
183
|
+
if preset_data is not None:
|
|
184
|
+
self.init_data(preset_data)
|
|
185
|
+
elif shape is None:
|
|
186
|
+
self.shape = ()
|
|
187
|
+
|
|
188
|
+
if self.array_id is None and self.full_name:
|
|
189
|
+
# if no array_id is provided, use the full_name
|
|
190
|
+
self.array_id = self.full_name
|
|
191
|
+
|
|
192
|
+
@property
|
|
193
|
+
def data_set(self):
|
|
194
|
+
"""
|
|
195
|
+
The DataSetPP this array belongs to.
|
|
196
|
+
|
|
197
|
+
A DataArray can belong to at most one DataSetPP.
|
|
198
|
+
TODO: make this a weakref
|
|
199
|
+
"""
|
|
200
|
+
return self._data_set
|
|
201
|
+
|
|
202
|
+
@data_set.setter
|
|
203
|
+
def data_set(self, new_data_set):
|
|
204
|
+
if (self._data_set is not None and
|
|
205
|
+
new_data_set is not None and
|
|
206
|
+
self._data_set != new_data_set):
|
|
207
|
+
raise RuntimeError('A DataArray can only be part of one DataSetPP')
|
|
208
|
+
self._data_set = new_data_set
|
|
209
|
+
|
|
210
|
+
def nest(self, size, action_index=None, set_array=None):
|
|
211
|
+
"""
|
|
212
|
+
Nest this array inside a new outer loop.
|
|
213
|
+
|
|
214
|
+
You cannot call ``nest`` after ``init_data`` unless this is a
|
|
215
|
+
setpoint array.
|
|
216
|
+
TODO: is this restriction really useful? And should we maintain
|
|
217
|
+
a distinction between _preset and is_setpoint, or can wejust use
|
|
218
|
+
is_setpoint?
|
|
219
|
+
|
|
220
|
+
Args:
|
|
221
|
+
size (int): Length of the new loop.
|
|
222
|
+
|
|
223
|
+
action_index (Optional[int]): Within the outer loop at this
|
|
224
|
+
nesting level, which action does this array derive from?
|
|
225
|
+
|
|
226
|
+
set_array (Optional[DataArray]): The setpoints of the new outer
|
|
227
|
+
loop. If this DataArray *is* a setpoint array, you should
|
|
228
|
+
omit both ``action_index`` and ``set_array``, and it will
|
|
229
|
+
reference itself as the inner setpoint array.
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
DataArray: self, in case you want to construct the array with
|
|
233
|
+
chained method calls.
|
|
234
|
+
"""
|
|
235
|
+
if self.ndarray is not None and not self._preset:
|
|
236
|
+
raise RuntimeError('Only preset arrays can be nested after data '
|
|
237
|
+
'is initialized! {}'.format(self))
|
|
238
|
+
|
|
239
|
+
if set_array is None:
|
|
240
|
+
if self.set_arrays:
|
|
241
|
+
raise TypeError('a setpoint array must be its own inner loop')
|
|
242
|
+
set_array = self
|
|
243
|
+
|
|
244
|
+
self.shape = (size, ) + self.shape
|
|
245
|
+
|
|
246
|
+
if action_index is not None:
|
|
247
|
+
self.action_indices = (action_index, ) + self.action_indices
|
|
248
|
+
|
|
249
|
+
self.set_arrays = (set_array, ) + self.set_arrays
|
|
250
|
+
|
|
251
|
+
if self._preset:
|
|
252
|
+
inner_data = self.ndarray
|
|
253
|
+
self.ndarray = np.ndarray(self.shape)
|
|
254
|
+
# existing preset array copied to every index of the nested array.
|
|
255
|
+
for i in range(size):
|
|
256
|
+
self.ndarray[i] = inner_data
|
|
257
|
+
|
|
258
|
+
# update modified_range so the entire array still looks modified
|
|
259
|
+
self.modified_range = (0, self.ndarray.size - 1)
|
|
260
|
+
|
|
261
|
+
self._set_index_bounds()
|
|
262
|
+
|
|
263
|
+
return self
|
|
264
|
+
|
|
265
|
+
def init_data(self, data=None):
|
|
266
|
+
"""
|
|
267
|
+
Create the actual numpy array to hold data.
|
|
268
|
+
|
|
269
|
+
The array will be sized based on either ``self.shape`` or
|
|
270
|
+
data provided here.
|
|
271
|
+
|
|
272
|
+
Idempotent: will do nothing if the array already exists.
|
|
273
|
+
|
|
274
|
+
If data is provided, this array is marked as a preset
|
|
275
|
+
meaning it can still be nested around this data.
|
|
276
|
+
TODO: per above, perhaps remove this distinction entirely?
|
|
277
|
+
|
|
278
|
+
Args:
|
|
279
|
+
data (Optional[Union[ndarray, sequence]]): If provided,
|
|
280
|
+
we fill the array with this data. Otherwise the new
|
|
281
|
+
array will be filled with NaN.
|
|
282
|
+
|
|
283
|
+
Raises:
|
|
284
|
+
ValueError: if ``self.shape`` does not match ``data.shape``
|
|
285
|
+
ValueError: if the array was already initialized with a
|
|
286
|
+
different shape than we're about to create
|
|
287
|
+
"""
|
|
288
|
+
if data is not None:
|
|
289
|
+
if not isinstance(data, np.ndarray):
|
|
290
|
+
if isinstance(data, collections.abc.Iterator):
|
|
291
|
+
# faster than np.array(tuple(data)) (or via list)
|
|
292
|
+
# but requires us to assume float
|
|
293
|
+
data = np.fromiter(data)
|
|
294
|
+
else:
|
|
295
|
+
data = np.array(data)
|
|
296
|
+
|
|
297
|
+
if self.shape is None:
|
|
298
|
+
self.shape = data.shape
|
|
299
|
+
elif data.shape != self.shape:
|
|
300
|
+
raise ValueError('preset data must be a sequence '
|
|
301
|
+
'with shape matching the array shape',
|
|
302
|
+
data.shape, self.shape)
|
|
303
|
+
self.ndarray = data
|
|
304
|
+
self._preset = True
|
|
305
|
+
|
|
306
|
+
# mark the entire array as modified
|
|
307
|
+
self.modified_range = (0, data.size - 1)
|
|
308
|
+
|
|
309
|
+
elif self.ndarray is not None:
|
|
310
|
+
if self.ndarray.shape != self.shape:
|
|
311
|
+
raise ValueError('data has already been initialized, '
|
|
312
|
+
'but its shape doesn\'t match self.shape')
|
|
313
|
+
return
|
|
314
|
+
else:
|
|
315
|
+
self.ndarray = np.ndarray(self.shape)
|
|
316
|
+
self.clear()
|
|
317
|
+
self._set_index_bounds()
|
|
318
|
+
|
|
319
|
+
def _set_index_bounds(self):
|
|
320
|
+
self._min_indices = [0 for d in self.shape]
|
|
321
|
+
self._max_indices = [d - 1 for d in self.shape]
|
|
322
|
+
|
|
323
|
+
def clear(self):
|
|
324
|
+
"""Fill the (already existing) data array with nan."""
|
|
325
|
+
# only floats can hold nan values. I guess we could
|
|
326
|
+
# also raise an error in this case? But generally float is
|
|
327
|
+
# what people want anyway.
|
|
328
|
+
if self.data_type==str:
|
|
329
|
+
self.ndarray=self.ndarray.astype(np.dtypes.StringDType)
|
|
330
|
+
self.ndarray.fill('nan')
|
|
331
|
+
elif self.data_type==float:
|
|
332
|
+
self.ndarray=self.ndarray.astype(float)
|
|
333
|
+
self.ndarray.fill(float('nan'))
|
|
334
|
+
else:
|
|
335
|
+
raise TypeError('dtype must be float or str for ndarrays within DataArray')
|
|
336
|
+
|
|
337
|
+
def __setitem__(self, loop_indices, value):
|
|
338
|
+
"""
|
|
339
|
+
Set data values.
|
|
340
|
+
|
|
341
|
+
Follows numpy syntax, allowing indices of lower dimensionality than
|
|
342
|
+
the array, if value makes up the extra dimension(s)
|
|
343
|
+
|
|
344
|
+
Also update the record of modifications to the array. If you don't
|
|
345
|
+
want this overhead, you can access ``self.ndarray`` directly.
|
|
346
|
+
"""
|
|
347
|
+
if isinstance(loop_indices, collections.abc.Iterable):
|
|
348
|
+
min_indices = list(loop_indices)
|
|
349
|
+
max_indices = list(loop_indices)
|
|
350
|
+
else:
|
|
351
|
+
min_indices = [loop_indices]
|
|
352
|
+
max_indices = [loop_indices]
|
|
353
|
+
|
|
354
|
+
for i, index in enumerate(min_indices):
|
|
355
|
+
if isinstance(index, slice):
|
|
356
|
+
start, stop, step = index.indices(self.shape[i])
|
|
357
|
+
min_indices[i] = start
|
|
358
|
+
max_indices[i] = start + (
|
|
359
|
+
((stop - start - 1)//step) * step)
|
|
360
|
+
|
|
361
|
+
min_li = self.flat_index(min_indices, self._min_indices)
|
|
362
|
+
max_li = self.flat_index(max_indices, self._max_indices)
|
|
363
|
+
self._update_modified_range(min_li, max_li)
|
|
364
|
+
|
|
365
|
+
self.ndarray.__setitem__(loop_indices, value)
|
|
366
|
+
|
|
367
|
+
def __getitem__(self, loop_indices):
|
|
368
|
+
return self.ndarray[loop_indices]
|
|
369
|
+
|
|
370
|
+
delegate_attr_objects = ['ndarray']
|
|
371
|
+
|
|
372
|
+
def __len__(self):
|
|
373
|
+
"""
|
|
374
|
+
Array length.
|
|
375
|
+
|
|
376
|
+
Must be explicitly delegated, because len() will look for this
|
|
377
|
+
attribute to already exist.
|
|
378
|
+
"""
|
|
379
|
+
return len(self.ndarray)
|
|
380
|
+
|
|
381
|
+
def flat_index(self, indices, index_fill=None):
|
|
382
|
+
"""
|
|
383
|
+
Generate the raveled index for the given indices.
|
|
384
|
+
|
|
385
|
+
This is the index you would have if the array is reshaped to 1D,
|
|
386
|
+
looping over the indices from inner to outer.
|
|
387
|
+
|
|
388
|
+
Args:
|
|
389
|
+
indices (sequence): indices of an element or slice of this array.
|
|
390
|
+
|
|
391
|
+
index_fill (sequence, optional): extra indices to use if
|
|
392
|
+
``indices`` has less dimensions than the array, ie it points
|
|
393
|
+
to a slice rather than a single element. Use zeros to get the
|
|
394
|
+
beginning of this slice, and [d - 1 for d in shape] to get the
|
|
395
|
+
end of the slice.
|
|
396
|
+
|
|
397
|
+
Returns:
|
|
398
|
+
int: the resulting flat index.
|
|
399
|
+
"""
|
|
400
|
+
if len(indices) < len(self.shape):
|
|
401
|
+
indices = indices + index_fill[len(indices):]
|
|
402
|
+
return np.ravel_multi_index(tuple(zip(indices)), self.shape)[0]
|
|
403
|
+
|
|
404
|
+
def _update_modified_range(self, low, high):
|
|
405
|
+
if self.modified_range:
|
|
406
|
+
self.modified_range = (min(self.modified_range[0], low),
|
|
407
|
+
max(self.modified_range[1], high))
|
|
408
|
+
else:
|
|
409
|
+
self.modified_range = (low, high)
|
|
410
|
+
|
|
411
|
+
def mark_saved(self, last_saved_index):
|
|
412
|
+
"""
|
|
413
|
+
Mark certain outstanding modifications as saved.
|
|
414
|
+
|
|
415
|
+
Args:
|
|
416
|
+
last_saved_index (int): The flat index of the last point
|
|
417
|
+
saved. If ``modified_range`` extends beyond this, the
|
|
418
|
+
data past ``last_saved_index`` will still be marked
|
|
419
|
+
modified, otherwise ``modified_range`` is cleared
|
|
420
|
+
entirely.
|
|
421
|
+
"""
|
|
422
|
+
if self.modified_range:
|
|
423
|
+
if last_saved_index >= self.modified_range[1]:
|
|
424
|
+
self.modified_range = None
|
|
425
|
+
else:
|
|
426
|
+
self.modified_range = (max(self.modified_range[0],
|
|
427
|
+
last_saved_index + 1),
|
|
428
|
+
self.modified_range[1])
|
|
429
|
+
self.last_saved_index = last_saved_index
|
|
430
|
+
|
|
431
|
+
def clear_save(self):
|
|
432
|
+
"""
|
|
433
|
+
Make previously saved parts of this array look unsaved (modified).
|
|
434
|
+
|
|
435
|
+
This can be used to force overwrite or rewrite, like if we're
|
|
436
|
+
moving or copying the ``DataSetPP``.
|
|
437
|
+
"""
|
|
438
|
+
if self.last_saved_index is not None:
|
|
439
|
+
self._update_modified_range(0, self.last_saved_index)
|
|
440
|
+
|
|
441
|
+
self.last_saved_index = None
|
|
442
|
+
|
|
443
|
+
def get_synced_index(self):
|
|
444
|
+
"""
|
|
445
|
+
Get the last index which has been synced from the server.
|
|
446
|
+
|
|
447
|
+
Will also initialize the array if this hasn't happened already.
|
|
448
|
+
TODO: seems hacky to init_data here.
|
|
449
|
+
|
|
450
|
+
Returns:
|
|
451
|
+
int: the last flat index which has been synced from the server,
|
|
452
|
+
or -1 if no data has been synced.
|
|
453
|
+
"""
|
|
454
|
+
if not hasattr(self, 'synced_index'):
|
|
455
|
+
self.init_data()
|
|
456
|
+
self.synced_index = -1
|
|
457
|
+
|
|
458
|
+
return self.synced_index
|
|
459
|
+
|
|
460
|
+
def get_changes(self, synced_index):
|
|
461
|
+
"""
|
|
462
|
+
Find changes since the last sync of this array.
|
|
463
|
+
|
|
464
|
+
Args:
|
|
465
|
+
synced_index (int): The last flat index which has already
|
|
466
|
+
been synced.
|
|
467
|
+
|
|
468
|
+
Returns:
|
|
469
|
+
Union[dict, None]: None if there is no new data. If there is,
|
|
470
|
+
returns a dict with keys:
|
|
471
|
+
start (int): the flat index of the first returned value.
|
|
472
|
+
stop (int): the flat index of the last returned value.
|
|
473
|
+
vals (List[float]): the new values
|
|
474
|
+
"""
|
|
475
|
+
latest_index = self.last_saved_index
|
|
476
|
+
if latest_index is None:
|
|
477
|
+
latest_index = -1
|
|
478
|
+
if self.modified_range:
|
|
479
|
+
latest_index = max(latest_index, self.modified_range[1])
|
|
480
|
+
|
|
481
|
+
vals = [
|
|
482
|
+
self.ndarray[np.unravel_index(i, self.ndarray.shape)]
|
|
483
|
+
for i in range(synced_index + 1, latest_index + 1)
|
|
484
|
+
]
|
|
485
|
+
|
|
486
|
+
if vals:
|
|
487
|
+
return {
|
|
488
|
+
'start': synced_index + 1,
|
|
489
|
+
'stop': latest_index,
|
|
490
|
+
'vals': vals
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
def apply_changes(self, start, stop, vals):
|
|
494
|
+
"""
|
|
495
|
+
Insert new synced values into the array.
|
|
496
|
+
|
|
497
|
+
To be be called in a ``PULL_FROM_SERVER`` ``DataSetPP`` using results
|
|
498
|
+
returned by ``get_changes`` from the ``DataServer``.
|
|
499
|
+
|
|
500
|
+
TODO: check that vals has the right length?
|
|
501
|
+
|
|
502
|
+
Args:
|
|
503
|
+
start (int): the flat index of the first new value.
|
|
504
|
+
stop (int): the flat index of the last new value.
|
|
505
|
+
vals (List[float]): the new values
|
|
506
|
+
"""
|
|
507
|
+
for i, val in enumerate(vals):
|
|
508
|
+
index = np.unravel_index(i + start, self.ndarray.shape)
|
|
509
|
+
self.ndarray[index] = val
|
|
510
|
+
self.synced_index = stop
|
|
511
|
+
|
|
512
|
+
def __repr__(self):
|
|
513
|
+
array_id_or_none = ' {}'.format(self.array_id) if self.array_id else ''
|
|
514
|
+
return '{}[{}]:{}\n{}'.format(self.__class__.__name__,
|
|
515
|
+
','.join(map(str, self.shape)),
|
|
516
|
+
array_id_or_none, repr(self.ndarray))
|
|
517
|
+
|
|
518
|
+
def snapshot(self, update=False):
|
|
519
|
+
"""JSON representation of this DataArray."""
|
|
520
|
+
snap = {'__class__': full_class(self)}
|
|
521
|
+
|
|
522
|
+
snap.update(self._snapshot_input)
|
|
523
|
+
|
|
524
|
+
for attr in self.SNAP_ATTRS:
|
|
525
|
+
snap[attr] = getattr(self, attr)
|
|
526
|
+
|
|
527
|
+
return snap
|
|
528
|
+
|
|
529
|
+
def fraction_complete(self):
|
|
530
|
+
"""
|
|
531
|
+
Get the fraction of this array which has data in it.
|
|
532
|
+
|
|
533
|
+
Or more specifically, the fraction of the latest point in the array
|
|
534
|
+
where we have touched it.
|
|
535
|
+
|
|
536
|
+
Returns:
|
|
537
|
+
float: fraction of array which is complete, from 0.0 to 1.0
|
|
538
|
+
"""
|
|
539
|
+
if self.ndarray is None:
|
|
540
|
+
return 0.0
|
|
541
|
+
|
|
542
|
+
last_index = -1
|
|
543
|
+
if self.last_saved_index is not None:
|
|
544
|
+
last_index = max(last_index, self.last_saved_index)
|
|
545
|
+
if self.modified_range is not None:
|
|
546
|
+
last_index = max(last_index, self.modified_range[1])
|
|
547
|
+
if getattr(self, 'synced_index', None) is not None:
|
|
548
|
+
last_index = max(last_index, self.synced_index)
|
|
549
|
+
|
|
550
|
+
return (last_index + 1) / self.ndarray.size
|
|
551
|
+
|
|
552
|
+
@property
|
|
553
|
+
def units(self):
|
|
554
|
+
warn_units('DataArray', self)
|
|
555
|
+
return self.unit
|