Beispiel #1
0
    def load_pos_data(self,
                      pname: Path,
                      ppm: int = 300,
                      jumpmax: int = 100) -> None:
        # Only sub-class that doesn't use this is OpenEphysNWB
        # which needs updating
        # TODO: Update / overhaul OpenEphysNWB
        # Load the start time from the sync_messages file
        recording_start_time = 0
        if self.sync_message_file is not None:
            with open(self.sync_message_file, "r") as f:
                sync_strs = f.read()
            sync_lines = sync_strs.split("\n")
            for line in sync_lines:
                if "subProcessor: 0" in line:
                    idx = line.find("start time: ")
                    start_val = line[idx + len("start time: "):-1]
                    tmp = start_val.split("@")
                    recording_start_time = float(tmp[0])  # in samples
        if self.path2PosData is not None:
            pos_data_type = getattr(self, "pos_data_type", "PosTracker")
            if pos_data_type == "PosTracker":
                print("Loading PosTracker data...")
                pos_data = np.load(
                    os.path.join(self.path2PosData, "data_array.npy"))
            if pos_data_type == "TrackingPlugin":
                print("Loading Tracking Plugin data...")
                pos_data = loadTrackingPluginData(
                    os.path.join(self.path2PosData, "data_array.npy"))
            pos_ts = np.load(os.path.join(self.path2PosData, "timestamps.npy"))
            pos_ts = np.ravel(pos_ts)
            pos_timebase = getattr(self, "pos_timebase", 3e4)
            sample_rate = np.floor(1 / np.mean(np.diff(pos_ts) / pos_timebase))
            xyTS = pos_ts - recording_start_time
            # xyTS = xyTS / pos_timebase  # convert to seconds
            if self.sync_message_file is not None:
                recording_start_time = xyTS[0]

            P = PosCalcsGeneric(
                pos_data[:, 0],
                pos_data[:, 1],
                cm=True,
                ppm=ppm,
                jumpmax=jumpmax,
            )
            P.xyTS = xyTS
            P.sample_rate = sample_rate
            P.postprocesspos({"SampleRate": sample_rate})
            print("Loaded pos data")
            self.PosCalcs = P
        else:
            warnings.warn("Could not find the pos data. \
                Make sure there is a pos_data folder with data_array.npy \
                and timestamps.npy in")
        self.recording_start_time = recording_start_time
Beispiel #2
0
 def load_pos_data(self,
                   pname: Path,
                   ppm: int = 300,
                   jumpmax: int = 100) -> None:
     if self.PosCalcs is None:
         try:
             AxonaPos = Pos(self.pname)
             P = PosCalcsGeneric(
                 AxonaPos.led_pos[0, :],
                 AxonaPos.led_pos[1, :],
                 cm=True,
                 ppm=self.ppm,
             )
             P.xyTS = Pos.ts
             P.sample_rate = AxonaPos.getHeaderVal(AxonaPos.header,
                                                   "sample_rate")
             P.postprocesspos()
             print("Loaded pos data")
             self.PosCalcs = P
         except IOError:
             print("Couldn't load the pos data")