Skip to content

Commit 65a4fd0

Browse files
Allow Sessions to track volume ID instead of volume data
This is work towards #57 When loading a Session, I think it makes sense to allow the volume data to remain a "reference" to a file rather than load the actual data into memory. This way the users of the Session api can decide how they then want to handle volume I/O.
1 parent cc65b7d commit 65a4fd0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/openlifu/db/session.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Session:
2424
date: Date of the session
2525
targets: sonication targets
2626
markers: registration markers
27-
volume: volume
27+
volume: loaded volume data
2828
transducer: transducer
2929
attrs: Dictionary of attributes
3030
date_modified: Date of last modification
@@ -35,7 +35,8 @@ class Session:
3535
date: datetime = datetime.now()
3636
targets: List[Point] = field(default_factory=list)
3737
markers: List[Point] = field(default_factory=list)
38-
volume: xarray.DataArray = field(default_factory=xarray.DataArray)
38+
volume: Optional[xarray.DataArray] = None
39+
volume_id: Optional[str] = None
3940
transducer: Transducer = field(default_factory=Transducer)
4041
attrs: dict = field(default_factory=dict)
4142
date_modified: datetime = datetime.now()
@@ -81,8 +82,13 @@ def from_dict(d:Dict, db:'Database'):
8182
d['date'] = datetime.strptime(d['date'],DATE_FORMAT)
8283
if 'date_modified' in d:
8384
d['date_modified'] = datetime.strptime(d['date_modified'],DATE_FORMAT)
84-
if isinstance(d['volume'], dict):
85-
d['volume'] = xarray.DataArray.from_dict(d['volume'])
85+
if 'volume' in d:
86+
if isinstance(d['volume'], dict):
87+
d['volume'] = xarray.DataArray.from_dict(d['volume'])
88+
elif isinstance(d['volume'], str):
89+
d['volume_id'] = d['volume']
90+
# If we kept this key then it would assign a string to the volume attribute, which the wrong type:
91+
d.pop('volume')
8692
if isinstance(d['transducer'], dict):
8793
transducer_id = d['transducer']['id']
8894
transducer = Transducer.from_file(db.get_transducer_filename(transducer_id))

0 commit comments

Comments
 (0)