@@ -337,9 +337,6 @@ def __init__(self, image_group, tags=None, unique_id=None, file=None):
337337 self .unique_id = image_group ["UniqueID" ]
338338 self .file = file
339339
340- def __str__ (self ):
341- return f"Image: { self .image_data ['Data' ].shape } "
342-
343340 @property
344341 def ndim (self ):
345342 return len (self .image_data ["Data" ].shape )
@@ -380,9 +377,6 @@ def signal_dimensions(self):
380377 "Meta Data.Format attribute in the ImageTags group."
381378 )
382379
383- def navigation_dimensions (self ):
384- return self .ndim - self .signal_dimensions ()
385-
386380 def get_axis_dict (self , axis ):
387381 """
388382 Get the calibration data for a given axis.
@@ -463,9 +457,13 @@ def update_dimension(self, axis, length=None):
463457 """
464458 Update the dimension of the image for a given axis.
465459
466- This is two places in the DM5 file???
467-
468- Under Calibrations and under Dimension. I think that only the Calibrations should be updated.
460+ Parameters
461+ ----------
462+ axis : int
463+ The axis to update the dimension for (Starting from 0 in array order). This will be reversed to match DM's
464+ axis order.
465+ length : int, optional
466+ The length of the axis.
469467
470468 """
471469 axis = self .ndim - axis - 1
@@ -485,6 +483,12 @@ def _get_dimension(self, axis):
485483 def get_data (self , lazy = False ):
486484 """
487485 Get the image data.
486+
487+ Parameters
488+ ----------
489+ lazy : bool, optional
490+ Whether to return a dask array or a numpy
491+
488492 """
489493 if lazy :
490494 return da .from_array (self .image_data ["Data" ])
@@ -494,6 +498,11 @@ def get_data(self, lazy=False):
494498 def update_data (self , data ):
495499 """
496500 Update the image data.
501+
502+ Parameters
503+ ----------
504+ data : np.ndarray or da.Array
505+ The new image data.
497506 """
498507 HyperspyWriter .overwrite_dataset (self .image_data , data , "Data" )
499508 self .image_data .attrs .update (
@@ -522,7 +531,7 @@ def get_metadata(self):
522531 if "Microscope Info" in original_metadata :
523532 metadata ["Acquisition_instrument" ] = {}
524533 metadata ["Acquisition_instrument" ]["TEM" ] = {}
525- metadata ["Acquisition_instrument" ]["TEM" ]["beam_energy " ] = (
534+ metadata ["Acquisition_instrument" ]["TEM" ]["beam_energy" ] = (
526535 original_metadata ["Microscope Info" ].get ("Voltage" , 0 ) / 1000
527536 )
528537 metadata ["Acquisition_instrument" ]["TEM" ]["acquisition_mode" ] = (
@@ -534,18 +543,28 @@ def get_metadata(self):
534543 metadata ["Acquisition_instrument" ]["TEM" ]["camera_length" ] = (
535544 original_metadata ["Microscope Info" ].get ("STEM Camera Length" , 0 )
536545 )
537- metadata ["Acquisition_instrument" ] = original_metadata ["Microscope Info" ]
538- metadata ["Acquisition_instrument" ] = {}
539546 return metadata , original_metadata
540547
541548 def update_metadata (
542549 self , metadata = None , signal_dimensions = None , navigation_dimensions = None
543550 ):
544551 """
545552 Update the metadata for the image.
553+
554+ Parameters
555+ ----------
556+ metadata : dict, optional
557+ The metadata to update.
558+ signal_dimensions : int, optional
559+ The number of signal dimensions.
560+ navigation_dimensions : int, optional
561+ The number of navigation dimensions.
546562 """
547563 if metadata is None :
548564 metadata = {}
565+ if navigation_dimensions is None and signal_dimensions is None :
566+ signal_dimensions = self .ndim
567+ navigation_dimensions = 0
549568 formatted_metadata = {}
550569
551570 formatted_metadata ["Acquisition" ] = {}
@@ -569,26 +588,35 @@ def update_metadata(
569588 if navigation_dimensions > 0 :
570589 formatted_metadata ["Meta Data" ]["IsSequence" ] = "true"
571590 dict2group (formatted_metadata , self .image_tags )
591+
592+ # Update Microscope Info
593+ if (
594+ "Acquisition_instrument" in metadata
595+ and "TEM" in metadata ["Acquisition_instrument" ]
596+ ):
597+ self .image_tags .create_group ("Microscope Info" )
598+ microscope_info_dict = {
599+ "Voltage" : metadata ["Acquisition_instrument" ]["TEM" ].get (
600+ "beam_energy" , 0
601+ )
602+ * 1000 ,
603+ "Illumination Mode" : metadata ["Acquisition_instrument" ]["TEM" ].get (
604+ "acquisition_mode" , "Unknown"
605+ ),
606+ "Indicated Magnification" : metadata ["Acquisition_instrument" ][
607+ "TEM"
608+ ].get ("magnification" , 0 ),
609+ "STEM Camera Length" : metadata ["Acquisition_instrument" ]["TEM" ].get (
610+ "camera_length" , 0
611+ ),
612+ }
613+
614+ dict2group (microscope_info_dict , self .image_tags ["Microscope Info" ])
615+
572616 self .image_tags .create_group ("UserTags" )
573617 dict2group (metadata , self .image_tags ["UserTags" ])
574618 return
575619
576- def to_signal_dict (self ):
577- """
578- Convert the image to a Hyperspy signal dictionary.
579- """
580- data = self .get_data ()
581- metadata , original_metadata = self .get_metadata ()
582- axes = []
583- for axis in range (len (data .shape )):
584- axes .append (self .get_axis_dict (axis ))
585- return {
586- "data" : data ,
587- "metadata" : metadata ,
588- "original_metadata" : original_metadata ,
589- "axes" : axes ,
590- }
591-
592620
593621def dict2group (dictionary , group ):
594622 for key , value in dictionary .items ():
0 commit comments