def check_up_to_date(subj_path, df): """ Check which sessions on local file system are missing from the computed training table :param subj_path: :return: """ session_dates = subj_path.glob('*') df_session = pd.DataFrame() for sess_date in session_dates: sess_paths = list(sess_date.glob('00*')) date = sess_date.stem if len(sess_paths) > 0: for sess in sess_paths: if is_session_path(sess): df_session = pd.concat([ df_session, pd.DataFrame({ 'date': date, 'session_path': str(sess) }, index=[0]) ], ignore_index=True) if df is None: return df_session else: # recorded_session_paths = df['session_path'].values isin, _ = ismember(df_session.date.unique(), df.date.unique()) missing_dates = df_session.date.unique()[~isin] return df_session[df_session['date'].isin(missing_dates)].sort_values( 'date')
def rename_session(session_path: str) -> Path: """ Rename a session. Prompts the user for the new subject name, data and number then moves session path to new session path. :param session_path: A session path to rename :return: The renamed session path """ session_path = get_session_path(session_path) if session_path is None: raise ValueError('Session path not valid ALF session folder') mouse = session_path.parts[-3] date = session_path.parts[-2] sess = session_path.parts[-1] new_mouse = input( f"Please insert subject NAME [current value: {mouse}]> ") or mouse new_date = input( f"Please insert new session DATE [current value: {date}]> ") or date new_sess = input( f"Please insert new session NUMBER [current value: {sess}]> ") or sess new_session_path = Path( *session_path.parts[:-3]) / new_mouse / new_date / new_sess.zfill(3) assert is_session_path(new_session_path), 'invalid subject, date or number' shutil.move(str(session_path), str(new_session_path)) print(session_path, "--> renamed to:") print(new_session_path) return new_session_path
def __init__(self, session_path, lazy=False, one=None, download_data=False, bpod_only=False): """ A class for extracting the task data required to perform task quality control :param session_path: a valid session path :param lazy: if True, the data are not extracted immediately :param one: an instance of ONE, used to download the raw data if download_data is True :param download_data: if True, any missing raw data is downloaded via ONE :param bpod_only: extract from from raw Bpod data only, even for FPGA sessions """ if not is_session_path(session_path): raise ValueError('Invalid session path') self.session_path = session_path self.one = one self.log = _logger self.data = None self.settings = None self.raw_data = None self.frame_ttls = self.audio_ttls = self.bpod_ttls = None self.type = None self.wheel_encoding = None self.bpod_only = bpod_only if download_data: self.one = one or ONE() self._ensure_required_data() if not lazy: self.load_raw_data() self.extract_data()
def __init__(self, session_path_or_eid, **kwargs): """ :param session_path_or_eid: A session eid or path :param log: A logging.Logger instance, if None the 'ibllib' logger is used :param one: An ONE instance for fetching and setting the QC on Alyx """ # When an eid is provided, we will download the required data by default (if necessary) self.download_data = not is_session_path(session_path_or_eid) super().__init__(session_path_or_eid, **kwargs) # Data self.extractor = None # Metrics and passed trials self.metrics = None self.passed = None
def __init__(self, session_path_or_eid, side, **kwargs): """ :param session_path_or_eid: A session eid or path :param side: The camera to run QC on :param log: A logging.Logger instance, if None the 'ibllib' logger is used :param one: An ONE instance for fetching and setting the QC on Alyx """ # Make sure the type of camera is chosen self.side = side # When an eid is provided, we will download the required data by default (if necessary) download_data = not is_session_path(session_path_or_eid) self.download_data = kwargs.pop('download_data', download_data) super().__init__(session_path_or_eid, **kwargs) self.data = Bunch() # QC outcomes map self.metrics = None
def __init__(self, session_path_or_eid, camera, **kwargs): """ :param session_path_or_eid: A session id or path :param camera: The camera to run QC on, if None QC is run for all three cameras :param n_samples: The number of frames to sample for the position and brightness QC :param stream: If true and local video files not available, the data are streamed from the remote source. :param log: A logging.Logger instance, if None the 'ibllib' logger is used :param one: An ONE instance for fetching and setting the QC on Alyx """ # When an eid is provided, we will download the required data by default (if necessary) download_data = not is_session_path(session_path_or_eid) self.download_data = kwargs.pop('download_data', download_data) self.stream = kwargs.pop('stream', None) self.n_samples = kwargs.pop('n_samples', 100) super().__init__(session_path_or_eid, **kwargs) # Data self.label = assert_valid_label(camera) filename = f'_iblrig_{self.label}Camera.raw*.mp4' raw_video_path = self.session_path.joinpath('raw_video_data') self.video_path = next(raw_video_path.glob(filename), None) # If local video doesn't exist, change video path to URL if not self.video_path and self.stream is not False and self.one is not None: try: self.stream = True self.video_path = self.one.path2url(raw_video_path / filename.replace('*', '')) except (StopIteration, ALFObjectNotFound): _log.error('No remote or local video file found') self.video_path = None logging.disable(logging.CRITICAL) self._type = get_session_extractor_type(self.session_path) or None logging.disable(logging.NOTSET) keys = ('count', 'pin_state', 'audio', 'fpga_times', 'wheel', 'video', 'frame_samples', 'timestamps', 'camera_times', 'bonsai_times') self.data = Bunch.fromkeys(keys) self.frame_samples_idx = None # QC outcomes map self.metrics = None self.outcome = 'NOT_SET'
def _set_eid_or_path(self, session_path_or_eid): """Parse a given eID or session path If a session UUID is given, resolves and stores the local path and vice versa :param session_path_or_eid: A session eid or path :return: """ self.eid = None if is_uuid_string(str(session_path_or_eid)): self.eid = session_path_or_eid # Try to set session_path if data is found locally self.session_path = self.one.eid2path(self.eid) elif is_session_path(session_path_or_eid): self.session_path = Path(session_path_or_eid) if self.one is not None: self.eid = self.one.path2eid(self.session_path) if not self.eid: self.log.warning( 'Failed to determine eID from session path') else: self.log.error( 'Cannot run QC: an experiment uuid or session path is required' ) raise ValueError("'session' must be a valid session path or uuid")