def add_data(self, name, data, time=None, timestamps=None, seq_num=None, uid=None): """ Add data to an existing stream. Parameters ---------- name : string Name of a stream previously created using :meth:`add_stream` data : xarray.Dataset, pandas.DataFrame, or dict-of-arrays-or-lists time : array, optional POSIX epoch times. By default, an array of the current time is used. timestamps : xarray.Dataset, pandas.DataFrame, or dict-of-arrays-or-lists Individual timestamps for every element in data. This level of detail is sometimes available from data acquisition systems, but it is rarely available or useful in other contexts. seq_num : array, optional Sequence numbers. uid : string, optional By default, a UUID4 is generated. Raises ------ StreamDoesNotExist If stream with the given name has not yet been created using :meth:`add_stream`. EventModelRuntimeErrror If the run has been closed. """ if name not in self._streams: raise StreamDoesNotExist( "First use the method `add_stream` to create a stream named " f"{name!r}. You can add data there and/or add it later separately " "using this method, `add_data`.") if self.closed: raise event_model.EventModelRuntimeError("Run is closed.") import time as time_module len_ = len(data[next(iter(data))]) now = time_module.time() if time is None: time = [now] * len_ if timestamps is None: timestamps = {k: [now] * len_ for k in data} if seq_num is None: seq_num = list(range(len_)) bundle = self._streams[name] doc = bundle.compose_event_page( time=time, data=_normalize_dataframe_like(data), timestamps=_normalize_dataframe_like(timestamps), seq_num=seq_num, uid=uid, ) self._cache.event_page(doc)
def update_configuration(self, name, configuration): """ Update the configuration in a stream. This issues a new Event Descriptor for a stream. Paramters --------- name : string configuration : dict See add_stream for expected structure. Raises ------ StreamDoesNotExist If stream with the given name has not yet been created using :meth:`add_stream`. EventModelRuntimeErrror If the run has been closed. """ if self.closed: raise event_model.EventModelRuntimeError("Run is closed.") if name not in self._streams: raise StreamDoesNotExist( "First use the method `add_stream` to create a stream named " f"{name!r}.") # Fill in everything except configuration using the previous Event # Descriptor in this stream. old_bundle = self._streams[name] doc = old_bundle.descriptor_doc bundle = self._compose_descriptor( name=doc["name"], data_keys=doc["data_keys"], time=doc["time"], object_keys=doc["object_keys"], configuration=configuration, hints=doc["hints"], ) self._streams[name] = bundle self._cache.descriptor(bundle.descriptor_doc)
def close(self, exit_status="success", reason="", uid=None, time=None): """ Mark the Run as complete. It will not be possible to add new streams or new data once this is called. Parameters ---------- exit_status : {"success", "abort", "fail"}, optional reason : string, optional uid : string, optional By default, a UUID4 is generated. time : float POSIX epoch time. By default, the current time is used. """ if self.closed: raise event_model.EventModelRuntimeError("Run is already closed.") doc = self._run_bundle.compose_stop(exit_status=exit_status, reason=reason, uid=uid, time=time) self._cache.stop(doc)