Skip to content

Commit 6a0db86

Browse files
Implement loaidng a Session from file
Issue #57
1 parent 996fcfb commit 6a0db86

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/openlifu/db/database.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import glob
1010
from typing import Literal, Optional
1111
from openlifu.plan import Protocol, Solution
12-
from openlifu.db import Subject
12+
from openlifu.db import Subject, Session
1313
OnConflictOpts = Literal['error', 'overwrite', 'skip']
1414

1515

@@ -425,7 +425,6 @@ def load_all_protocols(self):
425425
raise FileNotFoundError("Protocols file not found.")
426426

427427
def load_session(self, subject, session_id, options=None):
428-
raise NotImplementedError("Session.from_file is not yet implemented")
429428
if options is None:
430429
options = {}
431430
session_filename = self.get_session_filename(subject.id, session_id)

src/openlifu/db/session.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from openlifu.xdc import Transducer
66
from openlifu.util.strings import sanitize
77
import xarray
8+
import json
89

910
@dataclass
1011
class Session:
@@ -49,6 +50,17 @@ def __post_init__(self):
4950
else:
5051
self.markers = list(self.markers)
5152

53+
@staticmethod
54+
def from_file(filename):
55+
"""
56+
Create a Session from a file
57+
58+
:param filename: Name of the file to read
59+
:returns: Session object
60+
"""
61+
with open(filename, 'r') as f:
62+
return Session.from_dict(json.load(f))
63+
5264
@staticmethod
5365
def from_dict(d):
5466
"""

0 commit comments

Comments
 (0)