diff --git a/CHANGELOG.md b/CHANGELOG.md index 39db160..6256f03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,13 +8,31 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased -[Compare with latest](https://github.com/AllenInstitute/npc_lims/compare/v0.1.175...HEAD) +[Compare with latest](https://github.com/AllenInstitute/npc_lims/compare/v0.1.176...HEAD) + +### Added + +- Add sessions from notebook ([cd40392](https://github.com/AllenInstitute/npc_lims/commit/cd40392c77a6ca66c12c2111e893d4f04b884e08) by bjhardcastle). ### Fixed -- Fix previous ([f12d318](https://github.com/AllenInstitute/npc_lims/commit/f12d3184042d16e98918a4f64b62fefbe24ea77c) by bjhardcastle). +- Fix type ([11aaf3b](https://github.com/AllenInstitute/npc_lims/commit/11aaf3b36b4e396127748b535d57f0e4897c90a0) by bjhardcastle). +- Fix getting `is_templeton` from tracked_sessions.yaml ([05e9d84](https://github.com/AllenInstitute/npc_lims/commit/05e9d848d998154b9da7ac545a28f19169200ced) by bjhardcastle). + +### Removed + +- Remove duplicate sessions ([c90c4d0](https://github.com/AllenInstitute/npc_lims/commit/c90c4d0c78f3de5999cec9d86dfbc3b95e5d2091) by bjhardcastle). +- Remove hard-coded sorted data asset for session ([95dec71](https://github.com/AllenInstitute/npc_lims/commit/95dec71033c9bda9064f818060fb0d01a61f368c) by bjhardcastle). +## [v0.1.176](https://github.com/AllenInstitute/npc_lims/releases/tag/v0.1.176) - 2024-09-21 + +[Compare with v0.1.175](https://github.com/AllenInstitute/npc_lims/compare/v0.1.175...v0.1.176) + +### Fixed + +- Fix previous ([f12d318](https://github.com/AllenInstitute/npc_lims/commit/f12d3184042d16e98918a4f64b62fefbe24ea77c) by bjhardcastle). + ## [v0.1.175](https://github.com/AllenInstitute/npc_lims/releases/tag/v0.1.175) - 2024-09-18 [Compare with v0.1.174](https://github.com/AllenInstitute/npc_lims/compare/v0.1.174...v0.1.175) diff --git a/npc_lims b/npc_lims index f12d318..11aaf3b 160000 --- a/npc_lims +++ b/npc_lims @@ -1 +1 @@ -Subproject commit f12d3184042d16e98918a4f64b62fefbe24ea77c +Subproject commit 11aaf3b36b4e396127748b535d57f0e4897c90a0 diff --git a/pyproject.toml b/pyproject.toml index 2733456..339edeb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "npc_lims" -version = "0.1.176" +version = "0.1.177" description = "Tools to fetch and update paths, metadata and state for Mindscope Neuropixels sessions, in the cloud." authors = [ { name = "Arjun Sridhar", email = "arjun.sridhar@alleninstitute.org" }, diff --git a/src/npc_lims/status/tracked_sessions.py b/src/npc_lims/status/tracked_sessions.py index a19a5db..56d19d6 100644 --- a/src/npc_lims/status/tracked_sessions.py +++ b/src/npc_lims/status/tracked_sessions.py @@ -590,14 +590,14 @@ def _get_session_info_from_file(ttl_hash: int | None = None) -> tuple[SessionInf f"Add loader for {_TRACKED_SESSIONS_FILE.suffix}" ) # pragma: no cover + def _add_session_to_file( - platform: Literal['ephys', 'behavior', 'behavior_with_sync'], - project: Literal['DynamicRouting', 'TempletonPilotSession'], - k: str, v: dict[str, Any], + platform: Literal["ephys", "behavior", "behavior_with_sync"], + project: Literal["DynamicRouting", "TempletonPilotSession"], + k: str, + v: dict[str, Any], ) -> None: - f = yaml.load( - _TRACKED_SESSIONS_FILE.read_bytes(), Loader=yaml.FullLoader - ) + f = yaml.load(_TRACKED_SESSIONS_FILE.read_bytes(), Loader=yaml.FullLoader) if any(k in entry for entry in f[platform][project]): print(f"Session {k} already exists in {_TRACKED_SESSIONS_FILE} - skipping") return @@ -614,47 +614,60 @@ def _add_session_to_file( new[platform][project].append({k: v}) new_path.write_text(yaml.dump(new)) + def add_tracked_ephys_sessions_from_spreadsheet( - csv_path: str | upath.UPath = "C:/Users/ben.hardcastle/OneDrive - Allen Institute/Shared Documents - Dynamic Routing/Mouse and experiment tracking/Ephys Experiment Tracking.csv" + csv_path: ( + str | upath.UPath + ) = "C:/Users/ben.hardcastle/OneDrive - Allen Institute/Shared Documents - Dynamic Routing/Mouse and experiment tracking/Ephys Experiment Tracking.csv", ) -> None: try: import polars as pl except ImportError: - raise ImportError("Optional dependencies are required to use this function: reinstall with `pip install npc_lims[polars]`") - df = ( - pl.read_csv(csv_path, infer_schema_length=1000) - .with_columns( - pl.col('Date').cum_count().over('Mouse').alias("day"), + raise ImportError( + "Optional dependencies are required to use this function: reinstall with `pip install npc_lims[polars]`" ) + df = pl.read_csv(csv_path, infer_schema_length=1000).with_columns( + pl.col("Date").cum_count().over("Mouse").alias("day"), ) upath.UPath("new_sessions.yaml").unlink(missing_ok=True) - project = 'DynamicRouting' - platform = 'ephys' + project = "DynamicRouting" + platform = "ephys" for row in df.iter_rows(named=True): info = {} session_kwargs = {} - dc = row['Date'].split('/') - date: str = f"{dc[2]}{'0' if len(dc[0])<2 else ''}{dc[0]}{'0' if len(dc[1]) < 2 else ''}{dc[1]}" + dc = row["Date"].split("/") + date: str = ( + f"{dc[2]}{'0' if len(dc[0])<2 else ''}{dc[0]}{'0' if len(dc[1]) < 2 else ''}{dc[1]}" + ) session_id = f"{row['Mouse']}_{date}" - k: str = f'//allen/programs/mindscope/workgroups/dynamicrouting/PilotEphys/Task 2 pilot/DRpilot_{row["Mouse"]}_{date}' - probes = ''.join(npc_session.extract_probe_letter(v) or '' for v in row['Probes in brain']) + k: str = ( + f'//allen/programs/mindscope/workgroups/dynamicrouting/PilotEphys/Task 2 pilot/DRpilot_{row["Mouse"]}_{date}' + ) + probes = "".join( + npc_session.extract_probe_letter(v) or "" for v in row["Probes in brain"] + ) if not probes: print(f"Skipping {session_id} - no probes") continue - session_kwargs['probe_letters_to_skip'] = ''.join(letter for letter in 'ABCDEF' if letter not in probes) - if (x := row.get('Injection substance', '')) or row.get('is perturbation experiment', None) is not None: + session_kwargs["probe_letters_to_skip"] = "".join( + letter for letter in "ABCDEF" if letter not in probes + ) + if (x := row.get("Injection substance", "")) or row.get( + "is perturbation experiment", None + ) is not None: if x: - if 'control' in x.lower() or 'acsf' in x.lower(): - session_kwargs['is_injection_control'] = True # type: ignore [assignment] + if "control" in x.lower() or "acsf" in x.lower(): + session_kwargs["is_injection_control"] = True # type: ignore [assignment] else: - session_kwargs['is_injection_perturbation'] = True # type: ignore [assignment] + session_kwargs["is_injection_perturbation"] = True # type: ignore [assignment] else: - session_kwargs['is_perturbation'] = 'unknown_type' - - info['day'] = row['day'] - info['session_kwargs'] = session_kwargs - _add_session_to_file(platform, project, k, info) # type: ignore [arg-type] - + session_kwargs["is_perturbation"] = "unknown_type" + + info["day"] = row["day"] + info["session_kwargs"] = session_kwargs + _add_session_to_file(platform, project, k, info) # type: ignore [arg-type] + + def _session_info_from_file_contents(contents: FileContents) -> tuple[SessionInfo, ...]: sessions: MutableSequence[SessionInfo] = [] for session_type, projects in contents.items():