Skip to content

Commit 2e1b5c1

Browse files
committed
Changed 'upstream_data_directories' field in MachineConfig into a dictionary, and updated functions that use it to reflect this; changed 'find_upstream_visits' to return a nested dictionary where visits are grouped by instrument name
1 parent 5a57ddf commit 2e1b5c1

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/murfey/client/tui/screens.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,15 +685,23 @@ def on_button_pressed(self, event: Button.Pressed):
685685
self.app.push_screen("launcher")
686686

687687
if machine_data.get("upstream_data_directories"):
688-
upstream_downloads = capture_get(
688+
upstream_downloads: dict[str, dict[str, Path]] = capture_get(
689689
base_url=str(self.app._environment.url.geturl()),
690690
router_name="session_control.correlative_router",
691691
function_name="find_upstream_visits",
692692
token=token,
693693
session_id=self.app._environment.murfey_session,
694694
).json()
695+
# Pass flattened dict for backwards compatibility
695696
self.app.install_screen(
696-
UpstreamDownloads(upstream_downloads), "upstream-downloads"
697+
UpstreamDownloads(
698+
{
699+
visit_name: visit_dir
700+
for _, upstream_visits in upstream_downloads.items()
701+
for visit_name, visit_dir in upstream_visits.items()
702+
}
703+
),
704+
"upstream-downloads",
697705
)
698706
self.app.push_screen("upstream-downloads")
699707

@@ -759,15 +767,23 @@ def on_button_pressed(self, event: Button.Pressed):
759767
self.app.push_screen("directory-select")
760768

761769
if machine_data.get("upstream_data_directories"):
762-
upstream_downloads = capture_get(
770+
upstream_downloads: dict[str, dict[str, Path]] = capture_get(
763771
base_url=str(self.app._environment.url.geturl()),
764772
router_name="session_control.correlative_router",
765773
function_name="find_upstream_visits",
766774
token=token,
767775
session_id=self.app._environment.murfey_session,
768776
).json()
777+
# Pass a flattened dict for backwards compatibility
769778
self.app.install_screen(
770-
UpstreamDownloads(upstream_downloads), "upstream-downloads"
779+
UpstreamDownloads(
780+
{
781+
visit_name: visit_dir
782+
for _, upstream_visits in upstream_downloads.items()
783+
for visit_name, visit_dir in upstream_visits.items()
784+
}
785+
),
786+
"upstream-downloads",
771787
)
772788
self.app.push_screen("upstream-downloads")
773789

src/murfey/server/api/shared.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def get_foil_hole(session_id: int, fh_name: int, db) -> Dict[str, int]:
147147

148148

149149
def find_upstream_visits(session_id: int, db: SQLModelSession):
150+
"""
151+
Returns a nested dictionary, in which visits and the full paths to their directories
152+
are further grouped by instrument name.
153+
"""
150154
murfey_session = db.exec(
151155
select(MurfeySession).where(MurfeySession.id == session_id)
152156
).one()
@@ -155,12 +159,19 @@ def find_upstream_visits(session_id: int, db: SQLModelSession):
155159
machine_config = get_machine_config(instrument_name=instrument_name)[
156160
instrument_name
157161
]
158-
upstream_visits = {}
162+
upstream_visits: dict[str, dict[str, Path]] = {}
159163
# Iterates through provided upstream directories
160-
for p in machine_config.upstream_data_directories:
164+
for (
165+
upstream_instrument,
166+
upstream_data_dir,
167+
) in machine_config.upstream_data_directories.items():
161168
# Looks for visit name in file path
162-
for v in Path(p).glob(f"{visit_name.split('-')[0]}-*"):
163-
upstream_visits[v.name] = v / machine_config.processed_directory_name
169+
current_upstream_visits = {}
170+
for visit_path in Path(upstream_data_dir).glob(f"{visit_name.split('-')[0]}-*"):
171+
current_upstream_visits[visit_path.name] = (
172+
visit_path / machine_config.processed_directory_name
173+
)
174+
upstream_visits[upstream_instrument] = current_upstream_visits
164175
return upstream_visits
165176

166177

@@ -170,7 +181,7 @@ def get_upstream_tiff_dirs(visit_name: str, instrument_name: str) -> List[Path]:
170181
instrument_name
171182
]
172183
for directory_name in machine_config.upstream_data_tiff_locations:
173-
for p in machine_config.upstream_data_directories:
184+
for _, p in machine_config.upstream_data_directories.items():
174185
if (Path(p) / secure_filename(visit_name)).is_dir():
175186
processed_dir = Path(p) / secure_filename(visit_name) / directory_name
176187
tiff_dirs.append(processed_dir)

src/murfey/util/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MachineConfig(BaseModel): # type: ignore
5858
allow_removal: bool = False
5959

6060
# Upstream data download setup
61-
upstream_data_directories: list[Path] = [] # Previous sessions
61+
upstream_data_directories: dict[str, Path] = {} # Previous sessions
6262
upstream_data_download_directory: Optional[Path] = None # Set by microscope config
6363
upstream_data_tiff_locations: list[str] = ["processed"] # Location of CLEM TIFFs
6464

0 commit comments

Comments
 (0)