#NEWLINE# def _amira_data_to_numpy( am_data , header_dict , flip_z = True ) : #NEWLINE# #INDENT# '\n    Transform output of `_read_amira` to a numpy array of the dtype listed in\n    the AmiraMesh header dictionary.  The standard format for Avizo Binary\n    files is IEEE binary. Big or little endian-ness is stipulated in the header\n    information, and is be assessed and taken into account by this function as\n    well, during the conversion process.\n\n    Parameters\n    ----------\n    am_data : str\n        String object containing all of the image array data, formatted as IEEE\n        binary. Current dType options include:\n            float\n            short\n            ushort\n            byte\n\n    header_dict : dict\n        Metadata dictionary containing all relevant attributes pertaining to\n        the image array. This metadata dictionary is the output from the\n        function `_create_md_dict`.\n\n    flip_z : bool, optional.\n        Defaults to True\n        This option is included because the .am data sets evaluated thus far\n        have opposite z-axis indexing than numpy arrays. This switch currently\n        defaults to "True" in order to ensure that z-axis indexing remains\n        consistent with data processed using Avizo.\n        Setting this switch to "True" will flip the z-axis during processing,\n        and a value of "False" will keep the array is initially assigned during\n        the array reshaping step.\n\n    Returns\n    -------\n    output : ndarray\n        Numpy ndarray containing the image data converted from the AmiraMesh\n        file. This data array is ready for further processing using the NSLS-II\n        function library, or other operations able to operate on numpy arrays.\n    ' #NEWLINE# Zdim = header_dict [ 'array_dimensions' ] [ 'z_dimension' ] #NEWLINE# Ydim = header_dict [ 'array_dimensions' ] [ 'y_dimension' ] #NEWLINE# Xdim = header_dict [ 'array_dimensions' ] [ 'x_dimension' ] #NEWLINE# am_format_dict = { #NEWLINE# #INDENT# 'BINARY-LITTLE-ENDIAN' : '<' , #NEWLINE# 'BINARY' : '>' , #NEWLINE# 'ASCII' : 'unknown' , #NEWLINE# #UNINDENT# } #NEWLINE# am_dtype_dict = { #NEWLINE# #INDENT# 'float' : 'f4' , #NEWLINE# 'short' : 'h4' , #NEWLINE# 'ushort' : 'H4' , #NEWLINE# 'byte' : 'b' , #NEWLINE# #UNINDENT# } #NEWLINE# if ( header_dict [ 'data_format' ] == 'BINARY-LITTLE-ENDIAN' ) : #NEWLINE# #INDENT# data_strip = am_data . strip ( '\n' ) #NEWLINE# flt_values = np . fromstring ( data_strip , ( am_format_dict [ header_dict [ 'data_format' ] ] + am_dtype_dict [ header_dict [ 'data_type' ] ] ) ) #NEWLINE# #UNINDENT# if ( header_dict [ 'data_format' ] == 'ASCII' ) : #NEWLINE# #INDENT# data_strip = am_data . translate ( None , '\n' ) #NEWLINE# string_list = data_strip . split ( ' ' ) #NEWLINE# string_list = string_list [ 0 : ( len ( string_list ) - 2 ) ] #NEWLINE# flt_values = np . array ( string_list ) . astype ( am_dtype_dict [ header_dict [ 'data_type' ] ] ) #NEWLINE# #UNINDENT# flt_values . resize ( Zdim , Ydim , Xdim ) #NEWLINE# output = flt_values #NEWLINE# if flip_z : #NEWLINE# #INDENT# output = flt_values [ : : ( - 1 ) , ... , ... ] #NEWLINE# #UNINDENT# return output