Skip to content

Commit 7b17ec4

Browse files
peterhollenderebrahimebrahim
authored andcommitted
Remove system references from Database.py
Closes #425
1 parent 19a3d26 commit 7b17ec4

1 file changed

Lines changed: 1 addition & 82 deletions

File tree

src/openlifu/db/database.py

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -385,32 +385,6 @@ def write_transducer(
385385

386386
self.logger.info(f"Added transducer with ID {transducer_id} to the database.")
387387

388-
def write_system(self, system, on_conflict=OnConflictOpts.ERROR):
389-
system_id = system.id
390-
system_ids = self.get_system_ids()
391-
392-
if system_id in system_ids:
393-
if on_conflict == OnConflictOpts.ERROR:
394-
raise ValueError(f"Ultrasound system with ID {system_id} already exists in the database.")
395-
elif on_conflict == OnConflictOpts.OVERWRITE:
396-
self.logger.info(f"Overwriting ultrasound system with ID {system_id} in the database.")
397-
elif on_conflict == OnConflictOpts.SKIP:
398-
self.logger.info(f"Skipping ultrasound system with ID {system_id} as it already exists.")
399-
return
400-
else:
401-
raise ValueError("Invalid 'on_conflict' option. Use 'error', 'overwrite', or 'skip'.")
402-
403-
system_data = system.to_json()
404-
system_filename = self.get_system_filename(system_id)
405-
with open(system_filename, "w") as f:
406-
json.dump(system_data, f)
407-
408-
if system_id not in system_ids:
409-
system_ids.append(system_id)
410-
self.write_system_ids(system_ids)
411-
412-
self.logger.info(f"Added ultrasound system with ID {system_id} to the database.")
413-
414388
def write_volume(self, subject_id, volume_id, volume_name, volume_data_filepath, on_conflict=OnConflictOpts.ERROR):
415389
if not Path(volume_data_filepath).exists():
416390
raise ValueError(f'Volume data filepath does not exist: {volume_data_filepath}')
@@ -608,18 +582,6 @@ def get_subject_table(self, options=None):
608582
# Implement the logic to get subject table
609583
raise NotImplementedError("Method not yet implemented")
610584

611-
def get_connected_systems(self):
612-
connected_system_filename = self.get_connected_system_filename()
613-
614-
if os.path.isfile(connected_system_filename):
615-
with open(connected_system_filename) as file:
616-
connected_systems = file.read().strip().split(',')
617-
self.logger.info("Connected systems: %s", connected_systems)
618-
return connected_systems
619-
else:
620-
self.logger.warning("Connected systems file not found.")
621-
return []
622-
623585
def get_connected_transducer(self, options=None):
624586
connected_transducer_filename = self.get_connected_transducer_filename()
625587

@@ -739,33 +701,6 @@ def get_subject_ids(self):
739701
self.logger.warning("Subjects file not found.")
740702
return []
741703

742-
def get_system_ids(self):
743-
systems_filename = self.get_systems_filename()
744-
745-
if os.path.isfile(systems_filename):
746-
with open(systems_filename) as file:
747-
system_data = json.load(file)
748-
system_ids = system_data.get("system_ids", [])
749-
self.logger.info("System IDs: %s", system_ids)
750-
return system_ids
751-
else:
752-
self.logger.warning("Systems file not found.")
753-
return []
754-
755-
def get_system_info(self, sys_id):
756-
raise NotImplementedError("UltrasoundSystem is not yet implemented")
757-
system_filename = self.get_system_filename(sys_id)
758-
759-
if os.path.isfile(system_filename):
760-
with open(system_filename) as file:
761-
system_data = json.load(file)
762-
system_info = UltrasoundSystem.from_dict(system_data)
763-
self.logger.info("System info for system %s: %s", sys_id, system_info)
764-
return system_info
765-
else:
766-
self.logger.warning("System info file not found for system %s.", sys_id)
767-
return None
768-
769704
def get_transducer_ids(self):
770705
transducers_filename = self.get_transducers_filename()
771706

@@ -902,13 +837,6 @@ def load_standoff(self, transducer_id, standoff_id="standoff"):
902837
standoff = Standoff.from_file(standoff_filename)
903838
return standoff
904839

905-
def load_system(self, sys_id=None):
906-
raise NotImplementedError("UltrasoundSystem is not yet implemented")
907-
sys_id = sys_id or self.get_connected_systems()
908-
sys_filename = self.get_system_filename(sys_id)
909-
sys = UltrasoundSystem.from_file(sys_filename)
910-
return sys
911-
912840
def load_transducer(self, transducer_id, convert_array:bool = True) -> Transducer|TransducerArray:
913841
"""Given a transducer_id, reads the corresponding transducer file from database and returns a transducer object.
914842
Note: the transducer object includes the relative path to the affiliated transducer model data. `get_transducer_absolute_filepaths`, should
@@ -1056,9 +984,6 @@ def set_connected_transducer(self, trans, options=None):
1056984
with open(filename, 'w') as f:
1057985
f.write(trans_id)
1058986

1059-
def get_connected_system_filename(self):
1060-
return Path(self.path) / "systems" / "connected_system.txt"
1061-
1062987
def get_connected_transducer_filename(self):
1063988
return Path(self.path) / 'transducers' / 'connected_transducer.txt'
1064989

@@ -1130,12 +1055,6 @@ def get_subject_filename(self, subject_id):
11301055
def get_subjects_filename(self):
11311056
return Path(self.path) / 'subjects' / 'subjects.json'
11321057

1133-
def get_systems_filename(self):
1134-
return Path(self.path) / 'systems' / 'systems.json'
1135-
1136-
def get_system_filename(self, system_id):
1137-
return Path(self.path) / 'systems' / system_id / f'{system_id}.json'
1138-
11391058
def get_transducer_filename(self, transducer_id):
11401059
return Path(self.path) / 'transducers' / transducer_id / f'{transducer_id}.json'
11411060

@@ -1254,7 +1173,7 @@ def initialize_empty_database(database_filepath : PathLike) -> Database:
12541173
Initializes an empty database at the given database_filepath
12551174
"""
12561175
database_filepath = Path(database_filepath)
1257-
subdirs = ["protocols", "users", "subjects", "transducers", "systems"]
1176+
subdirs = ["protocols", "users", "subjects", "transducers"]
12581177
for subdir in subdirs:
12591178
(database_filepath / subdir).mkdir(parents=True, exist_ok=True)
12601179

0 commit comments

Comments
 (0)