# Path: dicom2nifti/exceptions.py
# class ConversionValidationError(Exception):
#     """
#     Custom error type to distinguish between know validations and script errors
#     """
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(ConversionValidationError, self).__init__(message)
# 
# class ConversionError(Exception):
#     """
#     Custom error type to distinguish between know validations and script errors
#     """
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(ConversionError, self).__init__(message)


import os
import re
import traceback
import logging
import nibabel
import numpy
import dicom2nifti.common as common
import dicom2nifti.convert_generic as convert_generic
from pydicom.tag import Tag
from dicom2nifti.exceptions import ConversionValidationError, ConversionError
    # For each slice / mosaic create a data volume block
    data_blocks = []
    for index in range(0, len(sorted_mosaics)):
        data_blocks.append(_mosaic_to_block(sorted_mosaics[index]))

    # Add the data_blocks together to one 4d block
    size_x = numpy.shape(data_blocks[0])[0]
    size_y = numpy.shape(data_blocks[0])[1]
    size_z = numpy.shape(data_blocks[0])[2]
    size_t = len(data_blocks)
    full_block = numpy.zeros((size_x, size_y, size_z, size_t), dtype=data_blocks[0].dtype)
    for index in range(0, size_t):
        full_block[:, :, :, index] = data_blocks[index]

    # Apply the rescaling if needed
    common.apply_scaling(full_block, sorted_mosaics[0])

    return full_block


def _get_sorted_mosaics(dicom_input):
    """
    Search all mosaics in the dicom directory, sort and validate them
    """
    # Order all dicom files by acquisition number
    sorted_mosaics = sorted(dicom_input, key=lambda x: x.AcquisitionNumber)

    for index in range(0, len(sorted_mosaics) - 1):
        # Validate that there are no duplicate AcquisitionNumber
        if sorted_mosaics[index].AcquisitionNumber >= sorted_mosaics[index + 1].AcquisitionNumber:

# Path: dicom2nifti/exceptions.py
# class ConversionValidationError(Exception):
#     """
#     Custom error type to distinguish between know validations and script errors
#     """
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(ConversionValidationError, self).__init__(message)
# 
# class ConversionError(Exception):
#     """
#     Custom error type to distinguish between know validations and script errors
#     """
# 
#     def __init__(self, message):
#         # Call the base class constructor with the parameters it needs
#         super(ConversionError, self).__init__(message)


# Path: dicom2nifti/convert_siemens.py
import os
import re
import traceback
import logging
import nibabel
import numpy
import dicom2nifti.common as common
import dicom2nifti.convert_generic as convert_generic
from pydicom.tag import Tag
from dicom2nifti.exceptions import ConversionValidationError, ConversionError

    # For each slice / mosaic create a data volume block
    data_blocks = []
    for index in range(0, len(sorted_mosaics)):
        data_blocks.append(_mosaic_to_block(sorted_mosaics[index]))

    # Add the data_blocks together to one 4d block
    size_x = numpy.shape(data_blocks[0])[0]
    size_y = numpy.shape(data_blocks[0])[1]
    size_z = numpy.shape(data_blocks[0])[2]
    size_t = len(data_blocks)
    full_block = numpy.zeros((size_x, size_y, size_z, size_t), dtype=data_blocks[0].dtype)
    for index in range(0, size_t):
        full_block[:, :, :, index] = data_blocks[index]

    # Apply the rescaling if needed
    common.apply_scaling(full_block, sorted_mosaics[0])

    return full_block


def _get_sorted_mosaics(dicom_input):
    """
    Search all mosaics in the dicom directory, sort and validate them
    """
    # Order all dicom files by acquisition number
    sorted_mosaics = sorted(dicom_input, key=lambda x: x.AcquisitionNumber)

    for index in range(0, len(sorted_mosaics) - 1):
        # Validate that there are no duplicate AcquisitionNumber
        if sorted_mosaics[index].AcquisitionNumber >= sorted_mosaics[index + 1].AcquisitionNumber:

            raise ConversionValidationError("INCONSISTENT_ACQUISITION_NUMBERS")