def __init__(self, name, instrument=None, label=None, unit=None, units=None, vals=None, docstring=None, snapshot_get=True, snapshot_value=True, metadata=None): super().__init__(name, instrument, snapshot_get, metadata, snapshot_value=snapshot_value) self._meta_attrs.extend(['label', 'unit', '_vals']) self.label = name if label is None else label if units is not None: warn_units('Parameter', self) if unit is None: unit = units self.unit = unit if unit is not None else '' self.set_validator(vals) # generate default docstring self.__doc__ = os.linesep.join(( 'Parameter class:', '', '* `name` %s' % self.name, '* `label` %s' % self.label, '* `unit` %s' % self.unit, '* `vals` %s' % repr(self._vals))) if docstring is not None: self.__doc__ = os.linesep.join(( docstring, '', self.__doc__))
def __init__(self, parameters, name, label=None, unit=None, units=None, aggregator=None): super().__init__() # TODO(giulioungaretti)temporary hack # starthack # this is a dummy parameter # that mimicks the api that a normal parameter has self.parameter = lambda: None self.parameter.full_name = name self.parameter.name = name self.parameter.label = label if units is not None: warn_units('CombinedParameter', self) if unit is None: unit = units self.parameter.unit = unit # endhack self.parameters = parameters self.sets = [parameter.set for parameter in self.parameters] self.dimensionality = len(self.sets) if aggregator: self.f = aggregator setattr(self, 'aggregate', self._aggregate)
def __init__(self, parameter=None, name=None, full_name=None, label=None, snapshot=None, array_id=None, set_arrays=(), shape=None, action_indices=(), unit=None, units=None, is_setpoint=False, preset_data=None): self.name = name self.full_name = full_name or name self.label = label self.shape = shape if units is not None: warn_units('DataArray', self) if unit is None: unit = units self.unit = unit self.array_id = array_id self.is_setpoint = is_setpoint self.action_indices = action_indices self.set_arrays = set_arrays self._preset = False # store a reference up to the containing DataSet # this also lets us make sure a DataArray is only in one DataSet self._data_set = None self.last_saved_index = None self.modified_range = None self.ndarray = None if snapshot is None: snapshot = {} self._snapshot_input = {} if parameter is not None: param_full_name = getattr(parameter, 'full_name', None) if param_full_name and not full_name: self.full_name = parameter.full_name if hasattr(parameter, 'snapshot') and not snapshot: snapshot = parameter.snapshot() else: # TODO: why is this in an else clause? for attr in self.COPY_ATTRS_FROM_INPUT: if (hasattr(parameter, attr) and not getattr(self, attr, None)): setattr(self, attr, getattr(parameter, attr)) for key, value in snapshot.items(): if key not in self.SNAP_OMIT_KEYS: self._snapshot_input[key] = value if (key in self.COPY_ATTRS_FROM_INPUT and not getattr(self, key, None)): setattr(self, key, value) if not self.label: self.label = self.name if preset_data is not None: self.init_data(preset_data) elif shape is None: self.shape = ()
def units(self): warn_units('DataArray', self) return self.unit
def units(self): warn_units('ArrayParameter', self) return self.unit
def __init__(self, name, shape, instrument=None, label=None, unit=None, units=None, setpoints=None, setpoint_names=None, setpoint_labels=None, setpoint_units=None, docstring=None, snapshot_get=True, snapshot_value=True, metadata=None): super().__init__(name, instrument, snapshot_get, metadata, snapshot_value=snapshot_value) if self.has_set: # TODO (alexcjohnson): can we support, ala Combine? raise AttributeError('ArrayParameters do not support set ' 'at this time.') self._meta_attrs.extend(['setpoint_names', 'setpoint_labels', 'setpoint_units', 'label', 'unit']) self.label = name if label is None else label if units is not None: warn_units('ArrayParameter', self) if unit is None: unit = units self.unit = unit if unit is not None else '' nt = type(None) if not is_sequence_of(shape, int): raise ValueError('shapes must be a tuple of ints, not ' + repr(shape)) self.shape = shape # require one setpoint per dimension of shape sp_shape = (len(shape),) sp_types = (nt, DataArray, collections.Sequence, collections.Iterator) if (setpoints is not None and not is_sequence_of(setpoints, sp_types, shape=sp_shape)): raise ValueError('setpoints must be a tuple of arrays') if (setpoint_names is not None and not is_sequence_of(setpoint_names, (nt, str), shape=sp_shape)): raise ValueError('setpoint_names must be a tuple of strings') if (setpoint_labels is not None and not is_sequence_of(setpoint_labels, (nt, str), shape=sp_shape)): raise ValueError('setpoint_labels must be a tuple of strings') if (setpoint_units is not None and not is_sequence_of(setpoint_units, (nt, str), shape=sp_shape)): raise ValueError('setpoint_units must be a tuple of strings') self.setpoints = setpoints self.setpoint_names = setpoint_names self.setpoint_labels = setpoint_labels self.setpoint_units = setpoint_units self.__doc__ = os.linesep.join(( 'Parameter class:', '', '* `name` %s' % self.name, '* `label` %s' % self.label, '* `unit` %s' % self.unit, '* `shape` %s' % repr(self.shape))) if docstring is not None: self.__doc__ = os.linesep.join(( docstring, '', self.__doc__))