def should_import_epochs(self): expt2 = self.ctx.insertProject("project2","project2",DateTime()).insertExperiment("purpose", DateTime()) protocol2 = self.ctx.insertProtocol("protocol", "description") epoch_start = DateTime() epoch = expt2.insertEpoch(Maps.newHashMap(), Maps.newHashMap(), epoch_start, DateTime(), protocol2, to_map({}), to_map({})) segment = self.block.segments[0] neoepoch = neo.core.epoch.Epoch(10 * pq.ms, 100 * pq.ms, "epoch1") segment.epochs.append(neoepoch) try: import_timeline_annotations(epoch, segment, epoch_start) annotations = list(iterable(epoch.getUserTimelineAnnotations(self.ctx.getAuthenticatedUser()))) assert_equals(1, len(annotations)) assert_equals(epoch_start.plusMillis(10).getMillis(), annotations[0].getStart().getMillis()) assert_equals(epoch_start.plusMillis(10).plusMillis(100).getMillis(), annotations[0].getEnd().get().getMillis()) finally: segment.epochs.remove(neoepoch)
def should_import_events(self): expt2 = self.ctx.insertProject("project2","project2",DateTime()).insertExperiment("purpose", DateTime()) protocol2 = self.ctx.insertProtocol("protocol", "description") epoch_start = DateTime() epoch = expt2.insertEpoch(Maps.newHashMap(), Maps.newHashMap(), epoch_start, DateTime(), protocol2, to_map(dict()), to_map(dict())) segment = self.block.segments[0] event_ms = 10 event1 = Event(event_ms * pq.ms, "event1", name = "event1") segment.events.append(event1) try: import_timeline_annotations(epoch, segment, epoch_start) annotations = list(iterable(epoch.getUserTimelineAnnotations(self.ctx.getAuthenticatedUser()))) assert(epoch_start.plusMillis(event_ms).equals(annotations[0].getStart())) assert_equals(1, len(annotations)) finally: segment.events.remove(event1)
def should_use_existing_sources(self): expt2 = self.ctx.insertProject("project2","project2",DateTime()).insertExperiment("purpose", DateTime()) protocol2 = self.ctx.insertProtocol("protocol", "description") import_csv(self.ctx, container_uri=expt2.getURI().toString(), protocol_uri=protocol2.getURI().toString(), files=[EXAMPLE_FIELD_DATA_CSV]) expected_source_names = np.unique(self.df.Site) sources = self.ctx.getTopLevelSources() assert_equals(len(expected_source_names), len(list(iterable(sources))))
def should_import_event_arrays(self): expt2 = self.ctx.insertProject("project2","project2",DateTime()).insertExperiment("purpose", DateTime()) protocol2 = self.ctx.insertProtocol("protocol", "description") epoch_start = DateTime() epoch = expt2.insertEpoch(Maps.newHashMap(), Maps.newHashMap(), epoch_start, DateTime(), protocol2, to_map({}), to_map({})) segment = self.block.segments[0] event_ms = [10, 12] event_array = EventArray(times=np.array(event_ms) * pq.ms, labels=['event1', 'event2']) segment.eventarrays.append(event_array) try: import_timeline_annotations(epoch, segment, epoch_start) annotations = list(iterable(epoch.getUserTimelineAnnotations(self.ctx.getAuthenticatedUser()))) assert_equals(2, len(annotations)) event_starts = [a.getStart() for a in annotations] for ms in event_ms: found = False for s in event_starts: if epoch_start.plusMillis(ms).equals(s): found = True if not found: assert_true(False, "event start time doesn't match") finally: segment.eventarrays.remove(event_array)
def should_call_via_main(self): expt2 = self.ctx.insertProject("project2","project2",DateTime()).insertExperiment("purpose", DateTime()) protocol2 = self.ctx.insertProtocol("protocol", "description") number_of_days = np.unique(np.asarray(self.df.index)).size args = ['--timezone=America/New_York', '--container={}'.format(str(expt2.getURI().toString())), '--protocol={}'.format(str(protocol2.getURI().toString())), EXAMPLE_FIELD_DATA_CSV, ] main(args, dsc=self.dsc) assert_equals(number_of_days, len(list(iterable(expt2.getEpochGroups()))))
def should_use_existing_site_epoch_when_present(self): expt2 = self.ctx.insertProject("project2","project2",DateTime()).insertExperiment("purpose", DateTime()) protocol2 = self.ctx.insertProtocol("protocol", "description") import_csv(self.ctx, container_uri=expt2.getURI().toString(), protocol_uri=protocol2.getURI().toString(), files=[EXAMPLE_FIELD_DATA_CSV]) import_csv(self.ctx, container_uri=expt2.getURI().toString(), protocol_uri=protocol2.getURI().toString(), files=[EXAMPLE_FIELD_DATA_CSV]) self.check_epoch_per_site(expt2)
def _make_day_ends(python_datetime, tzone): """Makes a midnight,end-of-day DateTime pair from Python datetime and timezone ID""" d = DateTime(python_datetime.isoformat(), DateTimeZone.forID(tzone)) return (d.toDateMidnight().toDateTime(), d.plusDays(1).minusSeconds(1))
def make_experiment_fixture(cls): ctx = cls.dsc.getContext() project = ctx.insertProject("name", "description", DateTime()) expt = project.insertExperiment("purpose", DateTime()) protocol = ctx.insertProtocol("protocol", "description") return ctx, expt, protocol
def _make_day_ends(python_datetime, tzone): """Makes a midnight,end-of-day DateTime pair from Python datetime and timezone ID""" d = DateTime(python_datetime.isoformat(), DateTimeZone.forID(tzone)) return (d.toDateMidnight().toDateTime(), d.plusDays(1).minusSeconds(1))