import numpy as np

from glotaran.builtin.models.kinetic_image.kinetic_image_matrix \
    import kinetic_image_matrix

from .spectral_irf import IrfSpectralGaussian


def kinetic_spectrum_matrix(dataset_descriptor=None, axis=None, index=None, irf=None):
    clp_label, matrix = kinetic_image_matrix(dataset_descriptor, axis, index, irf)

    if isinstance(dataset_descriptor.irf, IrfSpectralGaussian) \
       and dataset_descriptor.irf.coherent_artifact:
        irf_clp_label, irf_matrix = \
                dataset_descriptor.irf.calculate_coherent_artifact(index, axis)
        if matrix is None:
            clp_label = irf_clp_label
            matrix = irf_matrix
        else:
            clp_label += irf_clp_label
            matrix = np.concatenate((matrix, irf_matrix), axis=1)

    return (clp_label, matrix)
