def _mtag_eest_to_neo(self, nix_mtag, lazy): neo_attrs = self._nix_attr_to_neo(nix_mtag) neo_type = nix_mtag.type time_unit = nix_mtag.positions.unit if lazy: times = pq.Quantity(np.empty(0), time_unit) lazy_shape = np.shape(nix_mtag.positions) else: times = pq.Quantity(nix_mtag.positions, time_unit) lazy_shape = None if neo_type == "neo.epoch": if lazy: durations = pq.Quantity(np.empty(0), nix_mtag.extents.unit) labels = np.empty(0, dtype='S') else: durations = pq.Quantity(nix_mtag.extents, nix_mtag.extents.unit) labels = np.array(nix_mtag.positions.dimensions[0].labels, dtype="S") eest = Epoch(times=times, durations=durations, labels=labels, **neo_attrs) elif neo_type == "neo.event": if lazy: labels = np.empty(0, dtype='S') else: labels = np.array(nix_mtag.positions.dimensions[0].labels, dtype="S") eest = Event(times=times, labels=labels, **neo_attrs) elif neo_type == "neo.spiketrain": if "t_start" in neo_attrs: if "t_start.units" in neo_attrs: t_start_units = neo_attrs["t_start.units"] del neo_attrs["t_start.units"] else: t_start_units = time_unit t_start = pq.Quantity(neo_attrs["t_start"], t_start_units) del neo_attrs["t_start"] else: t_start = None if "t_stop" in neo_attrs: if "t_stop.units" in neo_attrs: t_stop_units = neo_attrs["t_stop.units"] del neo_attrs["t_stop.units"] else: t_stop_units = time_unit t_stop = pq.Quantity(neo_attrs["t_stop"], t_stop_units) del neo_attrs["t_stop"] else: t_stop = None if "sampling_interval.units" in neo_attrs: interval_units = neo_attrs["sampling_interval.units"] del neo_attrs["sampling_interval.units"] else: interval_units = None if "left_sweep.units" in neo_attrs: left_sweep_units = neo_attrs["left_sweep.units"] del neo_attrs["left_sweep.units"] else: left_sweep_units = None eest = SpikeTrain(times=times, t_start=t_start, t_stop=t_stop, **neo_attrs) if len(nix_mtag.features): wfda = nix_mtag.features[0].data wftime = self._get_time_dimension(wfda) if lazy: eest.waveforms = pq.Quantity(np.empty((0, 0, 0)), wfda.unit) eest.sampling_period = pq.Quantity(1, wftime.unit) eest.left_sweep = pq.Quantity(0, wftime.unit) else: eest.waveforms = pq.Quantity(wfda, wfda.unit) if interval_units is None: interval_units = wftime.unit eest.sampling_period = pq.Quantity( wftime.sampling_interval, interval_units) if left_sweep_units is None: left_sweep_units = wftime.unit if "left_sweep" in wfda.metadata: eest.left_sweep = pq.Quantity( wfda.metadata["left_sweep"], left_sweep_units) else: return None self._object_map[nix_mtag.id] = eest if lazy_shape: eest.lazy_shape = lazy_shape return eest
def _mtag_eest_to_neo(self, nix_mtag, lazy): neo_attrs = self._nix_attr_to_neo(nix_mtag) neo_type = nix_mtag.type time_unit = nix_mtag.positions.unit if lazy: times = pq.Quantity(np.empty(0), time_unit) lazy_shape = np.shape(nix_mtag.positions) else: times = pq.Quantity(nix_mtag.positions, time_unit) lazy_shape = None if neo_type == "neo.epoch": if lazy: durations = pq.Quantity(np.empty(0), nix_mtag.extents.unit) labels = np.empty(0, dtype='S') else: durations = pq.Quantity(nix_mtag.extents, nix_mtag.extents.unit) labels = np.array(nix_mtag.positions.dimensions[0].labels, dtype="S") eest = Epoch(times=times, durations=durations, labels=labels, **neo_attrs) elif neo_type == "neo.event": if lazy: labels = np.empty(0, dtype='S') else: labels = np.array(nix_mtag.positions.dimensions[0].labels, dtype="S") eest = Event(times=times, labels=labels, **neo_attrs) elif neo_type == "neo.spiketrain": if "t_start" in neo_attrs: if "t_start.units" in neo_attrs: t_start_units = neo_attrs["t_start.units"] del neo_attrs["t_start.units"] else: t_start_units = time_unit t_start = pq.Quantity(neo_attrs["t_start"], t_start_units) del neo_attrs["t_start"] else: t_start = None if "t_stop" in neo_attrs: if "t_stop.units" in neo_attrs: t_stop_units = neo_attrs["t_stop.units"] del neo_attrs["t_stop.units"] else: t_stop_units = time_unit t_stop = pq.Quantity(neo_attrs["t_stop"], t_stop_units) del neo_attrs["t_stop"] else: t_stop = None if "sampling_interval.units" in neo_attrs: interval_units = neo_attrs["sampling_interval.units"] del neo_attrs["sampling_interval.units"] else: interval_units = None if "left_sweep.units" in neo_attrs: left_sweep_units = neo_attrs["left_sweep.units"] del neo_attrs["left_sweep.units"] else: left_sweep_units = None eest = SpikeTrain(times=times, t_start=t_start, t_stop=t_stop, **neo_attrs) if len(nix_mtag.features): wfda = nix_mtag.features[0].data wftime = self._get_time_dimension(wfda) if lazy: eest.waveforms = pq.Quantity(np.empty((0, 0, 0)), wfda.unit) eest.sampling_period = pq.Quantity(1, wftime.unit) eest.left_sweep = pq.Quantity(0, wftime.unit) else: eest.waveforms = pq.Quantity(wfda, wfda.unit) if interval_units is None: interval_units = wftime.unit eest.sampling_period = pq.Quantity( wftime.sampling_interval, interval_units ) if left_sweep_units is None: left_sweep_units = wftime.unit if "left_sweep" in wfda.metadata: eest.left_sweep = pq.Quantity( wfda.metadata["left_sweep"], left_sweep_units ) else: return None self._neo_map[nix_mtag.name] = eest if lazy_shape: eest.lazy_shape = lazy_shape return eest