@@ -63,7 +63,7 @@ def _check_setup(vs):
6363 if overwrite_data :
6464 vs .find ('size' ).text = '{} {} {}' .format (nx , ny , nz )
6565 else :
66- raise ValueError ("Incompatible dataset size" )
66+ raise ValueError (f "Incompatible dataset size: { shape_exp } , { ( nx , ny , nz ) } " )
6767
6868 # check the voxel size
6969 vox = vs .find ('voxelSize' )
@@ -589,7 +589,7 @@ def _check_affine(trafo):
589589 for aff in affine .values ():
590590 _check_affine (aff )
591591 else :
592- raise ValueError ("Invalid type for affine transformatin , expect list or dict, got %s" % type (affine ))
592+ raise ValueError ("Invalid type for affine transformation , expect list or dict, got %s" % type (affine ))
593593
594594
595595def _write_transformation (vregs , setup_id , timepoint , affine , resolution , overwrite ):
@@ -784,6 +784,19 @@ def get_resolution(xml_path, setup_id):
784784 raise ValueError ("Could not find setup %i" % setup_id )
785785
786786
787+ def get_size (xml_path , setup_id ):
788+ tree = ET .parse (xml_path )
789+ root = tree .getroot ()
790+ seqdesc = root .find ('SequenceDescription' )
791+ viewsets = seqdesc .find ('ViewSetups' )
792+ vsetups = viewsets .findall ('ViewSetup' )
793+ for vs in vsetups :
794+ if vs .find ('id' ).text == str (setup_id ):
795+ size = vs .find ('size' ).text
796+ return tuple (int (siz ) for siz in size .split ())[::- 1 ]
797+ raise ValueError ("Could not find setup %i" % setup_id )
798+
799+
787800def get_data_path (xml_path , return_absolute_path = False ):
788801 """ Get path to the data.
789802
@@ -805,3 +818,45 @@ def get_data_path(xml_path, return_absolute_path=False):
805818 path = os .path .join (os .path .split (xml_path )[0 ], path )
806819 path = os .path .abspath (os .path .relpath (path ))
807820 return path
821+
822+
823+ #
824+ # helper functions to write additional xml metadata
825+ #
826+
827+
828+ def write_size_and_resolution (xml_path , setup_id , size , resolution ):
829+ """ Write size and resolution data.
830+ """
831+
832+ if size is not None and len (size ) != 3 :
833+ raise ValueError (f"Expected size of length 3 instead of { len (size )} " )
834+ if resolution is not None and len (resolution ) != 3 :
835+ raise ValueError (f"Expected resolution of length 3 instead of { len (resolution )} " )
836+
837+ tree = ET .parse (xml_path )
838+ root = tree .getroot ()
839+ seqdesc = root .find ('SequenceDescription' )
840+ viewsets = seqdesc .find ('ViewSetups' )
841+ vsetups = viewsets .findall ('ViewSetup' )
842+
843+ found_setup = False
844+ for vs in vsetups :
845+ if vs .find ('id' ).text == str (setup_id ):
846+ size_elem = vs .find ('size' )
847+ if size is not None :
848+ size_elem .text = ' ' .join (map (str , size [::- 1 ]))
849+
850+ res_elem = vs .find ('voxelSize' ).find ('size' )
851+ if resolution is not None :
852+ res_elem .text = ' ' .join (map (str , resolution [::- 1 ]))
853+
854+ found_setup = True
855+
856+ if found_setup :
857+ # write the xml
858+ indent_xml (root )
859+ tree = ET .ElementTree (root )
860+ tree .write (xml_path )
861+ else :
862+ raise ValueError ("Could not find setup %i" % setup_id )
0 commit comments