Ejemplo n.º 1
0
def saveNormalizedFiles4AllUsers(listOfUsersNames, sizeSingleUserSpectrum, normalizedSpectrumOfAllUsers, outputPath, matInternalName ='fixed_spectrum_matrix'):
    for k in range(1, len(listOfUsersNames) + 1):
        indexStart = (k - 1) * sizeSingleUserSpectrum[1]
        indexEnd = (k) * sizeSingleUserSpectrum[1]
        new_spectrum = normalizedSpectrumOfAllUsers[:, indexStart: indexEnd]
        savePath = "".join([outputPath, listOfUsersNames[k - 1]])
        saver.saveMatrixAsMat(new_spectrum, savePath, matInternalName)
Ejemplo n.º 2
0
def cutSpectrumMat(audioRecordingId,
                   inputSpectrumFolder,
                   outputSpectrumSlicesFolder,
                   sizeSquareImages,
                   additionalText='_spectrum.mat',
                   structName='new_spectrum'):
    spectrumFilePath = "".join(
        [inputSpectrumFolder, audioRecordingId, additionalText])
    if (os.path.exists(spectrumFilePath)):
        spectrum_data = (loader.loadMatFiles(spectrumFilePath))[structName]
        sizeSpectrum = np.shape(spectrum_data)
        rst = sizeSpectrum[-1] % sizeSquareImages
        if (rst != 0):
            cols2add = sizeSquareImages - rst
            minimum = spectrum_data.min()
            spectrum_data = np.hstack([
                np.ones([sizeSpectrum[0], cols2add]) * minimum, spectrum_data
            ])
        numSlices = int((np.shape(spectrum_data)[1]) / sizeSquareImages)
        print("CREATING SLICES: nImages", numSlices, " for file: ",
              audioRecordingId)
        for sliceIndex in range(0, numSlices):
            indexColumnStart = (sliceIndex) * sizeSquareImages
            indexColumnEnd = ((sliceIndex + 1) * sizeSquareImages)
            spectrum_data_slice = spectrum_data[
                0:sizeSquareImages, indexColumnStart:indexColumnEnd]
            imgOutputPath = "".join([
                outputSpectrumSlicesFolder, "/", audioRecordingId, "_",
                str(sliceIndex), '.mat'
            ])
            saver.saveMatrixAsMat(spectrum_data_slice,
                                  imgOutputPath,
                                  nameMatrixMatlab=structName)
Ejemplo n.º 3
0
def saveNormalizedFunctionals4allUsers(listOfUsersNames, sizeSingleUserSamples, normalizedFunctionalsOfAllUsers, outputPath, matInternalName ='new_functionals', text2add = ''):
    for k in range(1, len(listOfUsersNames) + 1):
        indexStart = (k - 1) * sizeSingleUserSamples
        indexEnd = (k) * sizeSingleUserSamples
        new_functionals = normalizedFunctionalsOfAllUsers[indexStart: indexEnd, :]
        if('.arff' in listOfUsersNames[k - 1]):
            nameNormalizedFile = listOfUsersNames[k - 1].split('.arff')[0]
        else:
            nameNormalizedFile = listOfUsersNames[k - 1]
        new_functionals = new_functionals.transpose() #guardamos el traspuesta con features como filas para que la creación de imágenes sea más fácil
        savePath = "".join([outputPath, nameNormalizedFile,text2add])
        saver.saveMatrixAsMat(new_functionals, savePath, matInternalName)
Ejemplo n.º 4
0
def normPercentileZscorePerUser(input_file_path, typeOfNormalization, newSupValue, newInfValue, outputPath,text2add, percentile):
    functionals_data = (loader.loadMatFiles(input_file_path))['fixed_spectrum_matrix']
    output_spectrum_name = (input_file_path.split(settings.operative_system)[-1].split('.mat')[0]) + text2add
    #functionals_data_modi = np.reshape(functionals_data, [-1])
    # plt.figure()
    # plt.hist(functionals_data_modi, bins = 200)
    #plt.show()
    #nameFig = "".join([outputPath, (input_file_path.split('/')[-1].split('.mat')[0]), '_distribution.png'])
    #plt.savefig(nameFig)

    #zscore
    if (typeOfNormalization == 7):  # total of the whole audio file
        meanValue = functionals_data.mean()
        stdValue = functionals_data.std()
    else:
        print("Error in type of normalization")
        return -1
    zscore_data = getZscoreData(functionals_data, meanValue, stdValue) #no debería importar
    #zscore_data_modi = np.reshape(zscore_data, [-1])
    # plt.figure()
    # plt.hist(zscore_data_modi, bins = 200)
    #plt.show()
    #percentile
    percentileValue = np.percentile(zscore_data, percentile)
    zscore_data[zscore_data < percentileValue] = percentileValue

    # zscore_data_modiP = np.reshape(zscore_data, [-1])
    # plt.figure()
    # plt.hist(zscore_data_modiP, bins=200)
    # plt.show()
    #normalization
    if (typeOfNormalization == 7):  # total of the whole audio file
        minimumValue = zscore_data.min()
        maximumValue = zscore_data.max()
    else:
        print("Error in type of normalization")
        return -1
    new_spectrum = getNormalizedData(zscore_data, minimumValue, maximumValue, newSupValue=newSupValue, newInfValue=newInfValue)
    # img = Image.fromarray(new_spectrum[:, :].astype('uint8'), 'L')
    # imgOutputPath = '/home/cris/PycharmProjects/MasterProject/data/RESULTS/otrasPruebas/zscore.png'
    # img.save(imgOutputPath, "PNG")
    # plt.figure()
    # plt.imshow(new_spectrum)
    # plt.show()

    #new_spectrum_modi = np.reshape(new_spectrum, [-1])
    # plt.figure()
    # plt.hist(new_spectrum_modi, bins = 200)
    #plt.show()
    savePath = "".join([outputPath, output_spectrum_name])
    saver.saveMatrixAsMat(new_spectrum, savePath, 'fixed_spectrum_matrix')
    return meanValue, stdValue, minimumValue, maximumValue
Ejemplo n.º 5
0
def normalizationPerUser(input_file_path,typeOfNormalization,newSupValue,newInfValue,outputPath, text2add='_norm0255.mat', name = 'fixed_spectrum_matrix', matInternalName = 'fixed_spectrum_matrix'):
    functionals_data = (loader.loadMatFiles(input_file_path))[name]
    if (typeOfNormalization == 1):  # total of the whole audio file
        minimumValue = functionals_data.min()
        maximumValue = functionals_data.max()
    elif (typeOfNormalization == 2):  # min/max per frequency (160, 224 or 672 depending on number of FFT points)
        minimumValue = functionals_data.min(1)
        maximumValue = functionals_data.max(1)
        minimumValue = np.reshape(minimumValue, [-1, 1])
        maximumValue = np.reshape(maximumValue, [-1, 1])
    else:
        print("Error in type of normalization")
        return -1
    new_spectrum = getNormalizedData(functionals_data,minimumValue,maximumValue,newSupValue,newInfValue)
    #save data
    output_spectrum_name = (input_file_path.split('/')[-1].split('.mat')[0]) + text2add
    savePath = "".join([outputPath, output_spectrum_name])
    saver.saveMatrixAsMat(new_spectrum, savePath, matInternalName)
    return minimumValue,maximumValue
Ejemplo n.º 6
0
def normPercentilePerUser(input_file_path,typeOfNormalization,newSupValue,newInfValue,outputPath, text2add='_norm0255.mat', percentile = 25):
    functionals_data = (loader.loadMatFiles(input_file_path))['fixed_spectrum_matrix']
    minimumValue=[]
    maximumValue=[]
    percentileValue = np.percentile(functionals_data, percentile)
    functionals_data[functionals_data < percentileValue] = percentileValue
    if (typeOfNormalization == 5):  # total of the whole audio file
        minimumValue = functionals_data.min()
        maximumValue = functionals_data.max()
    else:
        print("Error in type of normalization")
        return -1
    output_spectrum_name = (input_file_path.split('/')[-1].split('.mat')[0]) + text2add
    new_spectrum = getNormalizedData(functionals_data, minimumValue, maximumValue, newSupValue, newInfValue)
    #img = Image.fromarray(new_spectrum[:, :].astype('uint8'), 'L')
    # imgOutputPath = '/home/cris/PycharmProjects/MasterProject/data/RESULTS/otrasPruebas/norm.png'
    # img.save(imgOutputPath, "PNG")
    savePath = "".join([outputPath, output_spectrum_name])
    saver.saveMatrixAsMat(new_spectrum, savePath, 'fixed_spectrum_matrix')
Ejemplo n.º 7
0
def zscorePerUser(input_file_path,typeOfNormalization,newSupValue,newInfValue,outputPath,zscoreThreshold=None, text2add='_zscore0255.mat', name = 'fixed_spectrum_matrix', newName ='fixed_spectrum_matrix' ):
    functionals_data = (loader.loadMatFiles(input_file_path))[name]
    meanValue = []
    stdValue = []
    minimumValue = []
    maximumValue = []
    if (typeOfNormalization == 3):  # total of the whole audio file
        meanValue = functionals_data.mean()
        stdValue = functionals_data.std()
    elif (typeOfNormalization == 4):  # min/max per frequency (224 or 672 depending on number of FFT points)
        meanValue = functionals_data.mean(1)
        stdValue = functionals_data.std(1)
        meanValue = np.reshape(meanValue, [-1, 1])
        stdValue = np.reshape(stdValue, [-1, 1])
    else:
        print("Error in type of normalization")
        return -1
    output_spectrum_name = (input_file_path.split(settings.operative_system)[-1].split('.mat')[0]) + text2add
    new_spectrum,minimumValue,maximumValue = getZscoreNormData(functionals_data, meanValue, stdValue, minimumValue, maximumValue, newSupValue, newInfValue, zscoreThreshold)
    savePath = "".join([outputPath, output_spectrum_name])
    saver.saveMatrixAsMat(new_spectrum, savePath, newName)
    return meanValue, stdValue, minimumValue, maximumValue