Beispiel #1
0
    def getSingleEventTable(self, event_name):
        """
        Returns pandas table containing all found events for given event name'
            * Primary mouse' meta data
            * Event start time
            * Event end time
            * Event duration
        Args:
            event_name (str): Event name e. g. Rearing
        Returns:
            DataFrame
        """
        data = defaultdict(list)
        for animal in self.getAnimalList():
            with mute_prints():
                eventTimeLine = EventTimeLine(self.conn,
                                                event_name,
                                                idA=animal.baseId,
                                                minFrame=self.detectionStartFrame,
                                                maxFrame=self.detectionEndFrame)

            for e in eventTimeLine.getEventList():
                data["RFID"]         .append(f"{animal.name}_{animal.RFID}")
                data["name"]         .append(f"{animal.name}")
                data["genotype"]     .append(f"{animal.genotype}")
                data["event_name"]   .append(event_name)
                data["start_sec"]    .append(e.startFrame / oneSecond)
                data["end_sec"]      .append(e.endFrame   / oneSecond)
                data["duration"]     .append(e.duration() / oneSecond)

        df = pd.DataFrame(data)
        df.insert(2, "time", pd.to_timedelta(df["start_sec"], unit="s"))

        return df.sort_values("time").reset_index(drop=True)
Beispiel #2
0
    def getDyadicGenotypeGroupedEventTable(self, event_list):
        """
        Returns pandas table containing all found events for given event name
        and the involved mice' genotype

            * Primary / secondary mice genotype
            * Event start time
            * Event end time
            * Event duration

        Args:computeEventFeatures
            event_name (str): Event name e. g. Rearing

        Returns:
            DataFrame
        """
        data = defaultdict(list)
        animal_list = self.getAnimalList()
        for a in animal_list:
            if a.genotype is None:
                print("Genotype for all mice needs to be set... (aborting)")

        for event_name in tqdm(event_list, desc="Event..."):

            for A in animal_list:
                for B in animal_list:
                    if A.baseId == B.baseId:
                        continue

                    with mute_prints():
                        eventTimeLine = EventTimeLine(
                            self.conn,
                            event_name,
                            idA=A.baseId,
                            idB=B.baseId,
                            minFrame=self.detectionStartFrame,
                            maxFrame=self.detectionEndFrame,
                        )

                    event_list = eventTimeLine.getEventList()

                    for e in event_list:
                        data["genotype_primary"].append(f"{A.genotype}")
                        data["genotype_secondary"].append(f"{B.genotype}")
                        data["event_name"].append(event_name)
                        data["start_sec"].append(e.startFrame / oneSecond)
                        data["end_sec"].append(e.endFrame / oneSecond)
                        data["duration"].append(e.duration() / oneSecond)

        df = pd.DataFrame(data)
        if len(df) == 0:
            return df
        df.insert(2, "time", pd.to_timedelta(df["start_sec"], unit="s"))

        return df.sort_values("time").reset_index(drop=True)
Beispiel #3
0
    for file in files:

        # connect to database
        connection = sqlite3.connect(file)

        # create an animalPool, which basically contains your animals
        animalPool = AnimalPool()

        # load infos about the animals
        animalPool.loadAnimals(connection)

        # load all detection (positions) of all animals for the first hour
        animalPool.loadDetection(start=0, end=oneHour)

        eventTimeLine = EventTimeLine(connection,
                                      "Oral-genital Contact",
                                      idA=1,
                                      idB=2,
                                      minFrame=0,
                                      maxFrame=oneHour)

        print("Event list for label ", eventTimeLine.eventNameWithId)
        print("for animal 1:", animalPool.getAnimalDictionnary()[1].RFID)
        print("for animal 2:", animalPool.getAnimalDictionnary()[2].RFID)
        print("Number of events:", len(eventTimeLine.getEventList()))

        print("start frame", "end frame", "duration(in frame)")
        for event in eventTimeLine.eventList:
            print(event.startFrame, event.endFrame, event.duration())
Beispiel #4
0
        detectionMoveTimeLine = EventTimeLine(connection,
                                              "Detection",
                                              idA=1,
                                              minFrame=minT,
                                              maxFrame=maxT)
        eventTimeLineList.append(detectionMoveTimeLine)

        eventTimeLineList.append(naiveMoveTimeLine)

        eventTimeLine = EventTimeLine(connection,
                                      "Move",
                                      idA=1,
                                      minFrame=minT,
                                      maxFrame=maxT)

        for event in eventTimeLine.getEventList():
            print(event)

        print("Total time corrected move: ",
              str(eventTimeLine.getTotalLength()))

        eventTimeLineList.append(eventTimeLine)

        eventTimeLine.plotTimeLine()

        plotMultipleTimeLine(eventTimeLineList)

        for i in range(0, 100):
            print("---")
            print(naiveMoveTimeLine.getEventList()[i])
            print(eventTimeLine.getEventList()[i])