# Path: pymicro/external/tifffile.py
# def imsave(file, data, **kwargs):
#     """Write image data to TIFF file.
# 
#     Refer to the TiffWriter class and member functions for documentation.
# 
#     Parameters
#     ----------
#     file : str or binary stream
#         File name or writable binary stream, such as a open file or BytesIO.
#     data : array_like
#         Input image. The last dimensions are assumed to be image depth,
#         height, width, and samples.
#     kwargs : dict
#         Parameters 'append', 'byteorder', 'bigtiff', 'software', and 'imagej',
#         are passed to the TiffWriter class.
#         Parameters 'photometric', 'planarconfig', 'resolution', 'compress',
#         'colormap', 'tile', 'description', 'datetime', 'metadata', 'contiguous'
#         and 'extratags' are passed to the TiffWriter.save function.
# 
#     Examples
#     --------
#     >>> data = numpy.random.rand(2, 5, 3, 301, 219)
#     >>> imsave('temp.tif', data, compress=6, metadata={'axes': 'TZCYX'})
# 
#     """
#     tifargs = parse_kwargs(kwargs, 'append', 'bigtiff', 'byteorder',
#                            'software', 'imagej')
# 
#     if 'bigtiff' not in tifargs and 'imagej' not in tifargs and (
#             data.size*data.dtype.itemsize > 2000*2**20):
#         tifargs['bigtiff'] = True
# 
#     with TiffWriter(file, **tifargs) as tif:
#         tif.save(data, **kwargs)
# 
# def imread(files, **kwargs):
#     """Return image data from TIFF file(s) as numpy array.
# 
#     Refer to the TiffFile class and member functions for documentation.
# 
#     Parameters
#     ----------
#     files : str, binary stream, or sequence
#         File name, seekable binary stream, glob pattern, or sequence of
#         file names.
#     kwargs : dict
#         Parameters 'multifile', 'multifile_close', 'pages', 'fastij', and
#         'is_ome' are passed to the TiffFile class.
#         The 'pattern' parameter is passed to the TiffSequence class.
#         Other parameters are passed to the asarray functions.
#         The first image series is returned if no arguments are provided.
# 
#     Examples
#     --------
#     >>> imsave('temp.tif', numpy.random.rand(3, 4, 301, 219))
#     >>> im = imread('temp.tif', key=0)
#     >>> im.shape
#     (4, 301, 219)
#     >>> ims = imread(['temp.tif', 'temp.tif'])
#     >>> ims.shape
#     (2, 3, 4, 301, 219)
# 
#     """
#     kwargs_file = parse_kwargs(kwargs, 'multifile', 'multifile_close',
#                                'pages', 'fastij', 'is_ome')
#     kwargs_seq = parse_kwargs(kwargs, 'pattern')
# 
#     if isinstance(files, basestring) and any(i in files for i in '?*'):
#         files = glob.glob(files)
#     if not files:
#         raise ValueError('no files found')
#     if not hasattr(files, 'seek') and len(files) == 1:
#         files = files[0]
# 
#     if isinstance(files, basestring) or hasattr(files, 'seek'):
#         with TiffFile(files, **kwargs_file) as tif:
#             return tif.asarray(**kwargs)
#     else:
#         with TiffSequence(files, **kwargs_seq) as imseq:
#             return imseq.asarray(**kwargs)
# 
# Path: config.py
# PYMICRO_EXAMPLES_DATA_DIR = os.path.join(PYMICRO_ROOT_DIR, 'examples', 'data')


import unittest
import numpy as np
import os
from pymicro.file.file_utils import *
from pymicro.external.tifffile import imsave, imread
from config import PYMICRO_EXAMPLES_DATA_DIR


class file_utils_Tests(unittest.TestCase):

    def setUp(self):
        print('testing the file_utils module')
        self.data = (255 * np.random.rand(20, 30, 10)).astype(np.uint8)
        HST_write(self.data, 'temp_20x30x10_uint8.raw')
        data = np.zeros((3, 4, 5), dtype=bool)
        data[0, 1, 2] = True
        data[1, 2, 3] = True
        data[2, 3, 4] = True
        HST_write(data, 'test_bool_write.raw', pack_binary=True)
        HST_write(data, 'test_bool_write_as_uint8.raw', pack_binary=False)
        # craft a custom info file without the DATA_TYPE info
        f = open('temp.info', 'w')
        f.write('! PyHST_SLAVE VOLUME INFO FILE\n')
        f.write('NUM_X = 953\n')
        f.write('NUM_Y = 542\n')
        f.write('NUM_Z = 104\n')
        f.close()

    def test_edf_info(self):
        infos = edf_info(os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 'sam8_dct0_cen_full0000.edf'))
        self.assertEqual(infos['DataType'], 'FloatValue')

    def test_edf_read(self):

# Path: pymicro/external/tifffile.py
# def imsave(file, data, **kwargs):
#     """Write image data to TIFF file.
# 
#     Refer to the TiffWriter class and member functions for documentation.
# 
#     Parameters
#     ----------
#     file : str or binary stream
#         File name or writable binary stream, such as a open file or BytesIO.
#     data : array_like
#         Input image. The last dimensions are assumed to be image depth,
#         height, width, and samples.
#     kwargs : dict
#         Parameters 'append', 'byteorder', 'bigtiff', 'software', and 'imagej',
#         are passed to the TiffWriter class.
#         Parameters 'photometric', 'planarconfig', 'resolution', 'compress',
#         'colormap', 'tile', 'description', 'datetime', 'metadata', 'contiguous'
#         and 'extratags' are passed to the TiffWriter.save function.
# 
#     Examples
#     --------
#     >>> data = numpy.random.rand(2, 5, 3, 301, 219)
#     >>> imsave('temp.tif', data, compress=6, metadata={'axes': 'TZCYX'})
# 
#     """
#     tifargs = parse_kwargs(kwargs, 'append', 'bigtiff', 'byteorder',
#                            'software', 'imagej')
# 
#     if 'bigtiff' not in tifargs and 'imagej' not in tifargs and (
#             data.size*data.dtype.itemsize > 2000*2**20):
#         tifargs['bigtiff'] = True
# 
#     with TiffWriter(file, **tifargs) as tif:
#         tif.save(data, **kwargs)
# 
# def imread(files, **kwargs):
#     """Return image data from TIFF file(s) as numpy array.
# 
#     Refer to the TiffFile class and member functions for documentation.
# 
#     Parameters
#     ----------
#     files : str, binary stream, or sequence
#         File name, seekable binary stream, glob pattern, or sequence of
#         file names.
#     kwargs : dict
#         Parameters 'multifile', 'multifile_close', 'pages', 'fastij', and
#         'is_ome' are passed to the TiffFile class.
#         The 'pattern' parameter is passed to the TiffSequence class.
#         Other parameters are passed to the asarray functions.
#         The first image series is returned if no arguments are provided.
# 
#     Examples
#     --------
#     >>> imsave('temp.tif', numpy.random.rand(3, 4, 301, 219))
#     >>> im = imread('temp.tif', key=0)
#     >>> im.shape
#     (4, 301, 219)
#     >>> ims = imread(['temp.tif', 'temp.tif'])
#     >>> ims.shape
#     (2, 3, 4, 301, 219)
# 
#     """
#     kwargs_file = parse_kwargs(kwargs, 'multifile', 'multifile_close',
#                                'pages', 'fastij', 'is_ome')
#     kwargs_seq = parse_kwargs(kwargs, 'pattern')
# 
#     if isinstance(files, basestring) and any(i in files for i in '?*'):
#         files = glob.glob(files)
#     if not files:
#         raise ValueError('no files found')
#     if not hasattr(files, 'seek') and len(files) == 1:
#         files = files[0]
# 
#     if isinstance(files, basestring) or hasattr(files, 'seek'):
#         with TiffFile(files, **kwargs_file) as tif:
#             return tif.asarray(**kwargs)
#     else:
#         with TiffSequence(files, **kwargs_seq) as imseq:
#             return imseq.asarray(**kwargs)
# 
# Path: config.py
# PYMICRO_EXAMPLES_DATA_DIR = os.path.join(PYMICRO_ROOT_DIR, 'examples', 'data')


# Path: pymicro/file/tests/test_tiff.py
import unittest
import numpy as np
import os
from pymicro.file.file_utils import *
from pymicro.external.tifffile import imsave, imread
from config import PYMICRO_EXAMPLES_DATA_DIR



class file_utils_Tests(unittest.TestCase):

    def setUp(self):
        print('testing the file_utils module')
        self.data = (255 * np.random.rand(20, 30, 10)).astype(np.uint8)
        HST_write(self.data, 'temp_20x30x10_uint8.raw')
        data = np.zeros((3, 4, 5), dtype=bool)
        data[0, 1, 2] = True
        data[1, 2, 3] = True
        data[2, 3, 4] = True
        HST_write(data, 'test_bool_write.raw', pack_binary=True)
        HST_write(data, 'test_bool_write_as_uint8.raw', pack_binary=False)
        # craft a custom info file without the DATA_TYPE info
        f = open('temp.info', 'w')
        f.write('! PyHST_SLAVE VOLUME INFO FILE\n')
        f.write('NUM_X = 953\n')
        f.write('NUM_Y = 542\n')
        f.write('NUM_Z = 104\n')
        f.close()

    def test_edf_info(self):
        infos = edf_info(os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 'sam8_dct0_cen_full0000.edf'))
        self.assertEqual(infos['DataType'], 'FloatValue')

    def test_edf_read(self):

        im = edf_read(os.path.join(PYMICRO_EXAMPLES_DATA_DIR, 'sam8_dct0_cen_full0000.edf'))