#NEWLINE# def _create_md_dict( clean_header ) : #NEWLINE# #INDENT# '\n    Populates the a dictionary with all information pertinent to the image\n    data set that was originally stored in the AmiraMesh file.\n\n    Parameters\n    ----------\n    clean_header : list of strings\n        This is the output from the _sort_amira_header function.\n\n    ' #NEWLINE# md_dict = { #NEWLINE# #INDENT# 'software_src' : clean_header [ 0 ] [ 1 ] , #NEWLINE# 'data_format' : clean_header [ 0 ] [ 2 ] , #NEWLINE# 'data_format_version' : clean_header [ 0 ] [ 3 ] , #NEWLINE# #UNINDENT# } #NEWLINE# if ( md_dict [ 'data_format' ] == '3D' ) : #NEWLINE# #INDENT# md_dict [ 'data_format' ] = clean_header [ 0 ] [ 3 ] #NEWLINE# md_dict [ 'data_format_version' ] = clean_header [ 0 ] [ 4 ] #NEWLINE# #UNINDENT# for header_line in clean_header : #NEWLINE# #INDENT# hl = header_line #NEWLINE# if ( 'define' in hl ) : #NEWLINE# #INDENT# hl = hl #NEWLINE# md_dict [ 'array_dimensions' ] = { #NEWLINE# #INDENT# 'x_dimension' : int ( hl [ ( hl . index ( 'define' ) + 2 ) ] ) , #NEWLINE# 'y_dimension' : int ( hl [ ( hl . index ( 'define' ) + 3 ) ] ) , #NEWLINE# 'z_dimension' : int ( hl [ ( hl . index ( 'define' ) + 4 ) ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'Content' in hl ) : #NEWLINE# #INDENT# md_dict [ 'data_type' ] = hl [ ( hl . index ( 'Content' ) + 2 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'CoordType' in hl ) : #NEWLINE# #INDENT# md_dict [ 'coord_type' ] = hl [ ( hl . index ( 'CoordType' ) + 1 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'BoundingBox' in hl ) : #NEWLINE# #INDENT# hl = hl #NEWLINE# md_dict [ 'bounding_box' ] = { #NEWLINE# #INDENT# 'x_min' : float ( hl [ ( hl . index ( 'BoundingBox' ) + 1 ) ] ) , #NEWLINE# 'x_max' : float ( hl [ ( hl . index ( 'BoundingBox' ) + 2 ) ] ) , #NEWLINE# 'y_min' : float ( hl [ ( hl . index ( 'BoundingBox' ) + 3 ) ] ) , #NEWLINE# 'y_max' : float ( hl [ ( hl . index ( 'BoundingBox' ) + 4 ) ] ) , #NEWLINE# 'z_min' : float ( hl [ ( hl . index ( 'BoundingBox' ) + 5 ) ] ) , #NEWLINE# 'z_max' : float ( hl [ ( hl . index ( 'BoundingBox' ) + 6 ) ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# bbox = [ md_dict [ 'bounding_box' ] [ 'x_min' ] , md_dict [ 'bounding_box' ] [ 'x_max' ] , md_dict [ 'bounding_box' ] [ 'y_min' ] , md_dict [ 'bounding_box' ] [ 'y_max' ] , md_dict [ 'bounding_box' ] [ 'z_min' ] , md_dict [ 'bounding_box' ] [ 'z_max' ] ] #NEWLINE# dims = [ md_dict [ 'array_dimensions' ] [ 'x_dimension' ] , md_dict [ 'array_dimensions' ] [ 'y_dimension' ] , md_dict [ 'array_dimensions' ] [ 'z_dimension' ] ] #NEWLINE# resolution_list = [ ] #NEWLINE# for index in np . arange ( len ( dims ) ) : #NEWLINE# #INDENT# if ( dims [ index ] > 1 ) : #NEWLINE# #INDENT# resolution_list . append ( ( ( bbox [ ( ( 2 * index ) + 1 ) ] - bbox [ ( 2 * index ) ] ) / ( dims [ index ] - 1 ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# resolution_list . append ( 0 ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( ( resolution_list [ 1 ] / resolution_list [ 0 ] ) > 0.99 ) and ( ( resolution_list [ 2 ] / resolution_list [ 0 ] ) > 0.99 ) and ( ( resolution_list [ 1 ] / resolution_list [ 0 ] ) < 1.01 ) and ( ( resolution_list [ 2 ] / resolution_list [ 0 ] ) < 1.01 ) ) : #NEWLINE# #INDENT# md_dict [ 'resolution' ] = { #NEWLINE# #INDENT# 'zyx_value' : resolution_list [ 0 ] , #NEWLINE# 'type' : 'isotropic' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# md_dict [ 'resolution' ] = { #NEWLINE# #INDENT# 'zyx_value' : ( resolution_list [ 2 ] , resolution_list [ 1 ] , resolution_list [ 0 ] ) , #NEWLINE# 'type' : 'anisotropic' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'Units' in hl ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# units = str ( hl [ ( hl . index ( 'Units' ) + 2 ) ] ) #NEWLINE# md_dict [ 'units' ] = units #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logging . debug ( 'Units value undefined in source data set. Reverting to default units value of pixels' ) #NEWLINE# md_dict [ 'units' ] = 'pixels' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'Coordinates' in hl ) : #NEWLINE# #INDENT# coords = str ( hl [ ( hl . index ( 'Coordinates' ) + 1 ) ] ) #NEWLINE# md_dict [ 'coordinates' ] = coords #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return md_dict