66import shutil
77from enum import Enum
88from pathlib import Path
9- from typing import List , Optional
9+ from typing import Dict , List , Optional , Union
1010
1111import h5py
1212
2020from .user import User
2121
2222OnConflictOpts = Enum ('OnConflictOpts' , ['ERROR' , 'OVERWRITE' , 'SKIP' ])
23-
23+ PathLike = Union [ str , os . PathLike ]
2424
2525class Database :
2626 def __init__ (self , path : Optional [str ] = None ):
@@ -268,7 +268,13 @@ def write_subject(self, subject, on_conflict=OnConflictOpts.ERROR):
268268
269269 self .logger .info (f"Added subject with ID { subject_id } to the database." )
270270
271- def write_transducer (self , transducer , registration_surface_model_filepath : Optional [str ] = None , transducer_body_model_filepath : Optional [str ] = None , on_conflict : OnConflictOpts = OnConflictOpts .ERROR ) -> None :
271+ def write_transducer (
272+ self ,
273+ transducer ,
274+ registration_surface_model_filepath : Optional [PathLike ] = None ,
275+ transducer_body_model_filepath : Optional [PathLike ] = None ,
276+ on_conflict : OnConflictOpts = OnConflictOpts .ERROR ,
277+ ) -> None :
272278 """ Writes a transducer object to database and copies the affiliated transducer data files to the database if provided. When a transducer that is already present in the database is being re-written,
273279 the associated model data files do not need to be provided if they have previously been added to the database.
274280 Args:
@@ -706,7 +712,7 @@ def load_photoscan(self, subject_id, session_id, photoscan_id, load_data = False
706712 return photoscan , (model_data , texture_data )
707713 return photoscan
708714
709- def get_transducer_absolute_filepaths (self , transducer_id :str ) -> dict :
715+ def get_transducer_absolute_filepaths (self , transducer_id :str ) -> Dict [ str , Optional [ str ]] :
710716 """ Returns the absolute filepaths to the model data files i.e. transducer body and registration surface
711717 model files affiliated with the transducer, with ID `transducer_id`. Unlike `load_transducer`, which
712718 specifies the relative paths to the model datafiles along with other transducer attributes, this function
@@ -719,10 +725,12 @@ def get_transducer_absolute_filepaths(self, transducer_id:str) -> dict:
719725 dict: A dictionary containing the absolute filepaths to the affiliated transducer data files with the following possible keys:
720726 - "id" (str): transducer ID
721727 - "name" (str): transducer name
722- - "registration_surface_abspath" (str): absolute path to the transducer registration surface (open-surface mesh
728+ - "registration_surface_abspath" (str or None ): absolute path to the transducer registration surface (open-surface mesh
723729 used for transducer tracking registration). This key is only included if there *is* an affiliated registration surface.
724- - "transducer_body_abspath" (str): absolute path to the transducer body model (closed-surface mesh for visualizing the
730+ None if no registration surface is available.
731+ - "transducer_body_abspath" (str or None): absolute path to the transducer body model (closed-surface mesh for visualizing the
725732 transducer). This key is only included if there *is* an affiliated body model.
733+ None if no transducer body is available.
726734 """
727735 transducer_metadata_filepath = self .get_transducer_filename (transducer_id )
728736 with open (transducer_metadata_filepath ) as f :
@@ -732,9 +740,17 @@ def get_transducer_absolute_filepaths(self, transducer_id:str) -> dict:
732740 "name" : transducer ["name" ],
733741 }
734742 if "registration_surface_filename" in transducer and transducer ["registration_surface_filename" ] is not None :
735- transducer_filepaths_dict ["registration_surface_abspath" ] = Path (transducer_metadata_filepath ).parent / transducer ["registration_surface_filename" ]
743+ transducer_filepaths_dict ["registration_surface_abspath" ] = str (
744+ Path (transducer_metadata_filepath ).parent / transducer ["registration_surface_filename" ]
745+ )
746+ else :
747+ transducer_filepaths_dict ["registration_surface_abspath" ] = None
736748 if "transducer_body_filename" in transducer and transducer ["transducer_body_filename" ] is not None :
737- transducer_filepaths_dict ["transducer_body_abspath" ] = Path (transducer_metadata_filepath ).parent / transducer ["transducer_body_filename" ]
749+ transducer_filepaths_dict ["transducer_body_abspath" ] = str (
750+ Path (transducer_metadata_filepath ).parent / transducer ["transducer_body_filename" ]
751+ )
752+ else :
753+ transducer_filepaths_dict ["transducer_body_abspath" ] = None
738754 return transducer_filepaths_dict
739755
740756 def load_standoff (self , transducer_id , standoff_id = "standoff" ):
0 commit comments