def __init__(self, i='?', readAndPlot=True): self.scalar = (float, int) self.TB = fileIO.FileIO('frequency') self.kerneled = False self.kernel = None self.convolved = False self.reducedImagesMade = False if readAndPlot: self.getImage(i)
def extractDataRaw(self): fio = fileIO.FileIO() rw = rawData.RawDataExtractor() ## obras = corpus.getComposer('bach', 'xml') ## obras = glob.glob("D:\BackUpDrive\Documentos\Masters\Master IA UNED\TFM\corpus\jazz\*.xml") ## obras = corpus.getComposer('monteverdi', 'mxl') #### SOLO CONTIENEN MELODIAS ## obras = corpus.getComposer('essenFolksong') ## obras = corpus.getComposer('oneills1850') ## obras = corpus.getComposer('ryansMammoth') composer = "bach" obras = corpus.getComposer(composer) ## PARSING DE LAS OBRAS ## dataRaw = rw.getRawDataH(obras[0:300]) ## fio.writeText(dataRaw[0] , 'raw/'+ fio.getFileNames(composer, "M")[0]) ## fio.writeText(dataRaw[1] , 'raw/'+ fio.getFileNames(composer, "m")[0]) dataRawR = rw.getRawDataR(obras[0:100]) fio.writeText(dataRawR[0], 'raw/' + fio.getFileNames(composer, "R")[0])
def initialize_run(self): # ## Create atmosphere: attributes are self.atm.gas, self.atm.cloud and self.atm.layerProperty self.atm = atm.Atmosphere(self.planet, mode=self.mode, config=self.config, log=self.log, **self.kwargs) self.atm.run() # ## Read in absorption modules: to change absorption, edit files under /constituents' self.alpha = alpha.Alpha(mode=self.mode, config=self.config, log=self.log, **self.kwargs) # ## Next compute radiometric properties - initialize bright and return data class self.bright = bright.Brightness(mode=self.mode, log=self.log, **self.kwargs) self.data_return = data_handling.DataReturn() # ## Create fileIO class self.fIO = fileIO.FileIO(self.output_type)
plotData.append(dataSourceModule.DatasourceList()) # Create GUI Controller (Handles exchange between GUI and objects which need to be controlled by the GUI) guiController = guiModule.Controller() guiController.debugPrint = False portManager = serialPortModule.PortManager(guiController) # Encoding/Decoding things packetizer = encodingModule.Packetizer(guiController) # Create Graph to handle data & data ranges graph = graphModule.Graph(guiController) for n in range(0, 8): graph.setChannelDataHandle(n, plotData[n]) fileIO = fileIOModule.FileIO(guiController, dataFromFile) #Sample Capture.txt = 4bytes, 4bytes, 2 bytes, 1 byte, 0 delimeter cobs encoded # Create GUI Frames gui.addFrame('portSelectFrame', guiModule.PortSelectFrame(gui, guiController)) gui.addFrame('graphFrame', guiModule.GraphFrame(gui, guiController, graph)) updateGraphFrame = gui.getFrame( 'graphFrame').update #avoid looking up 'graphFrame' every frame gui.addFrame('fileLoadingFrame', guiModule.FileLoadingFrame(gui, guiController)) gui.addFrame('encodingFrame', guiModule.EncodingFrame(gui, guiController)) gui.addFrame('channelFrame', guiModule.ChannelFrame(gui, guiController)) # Layout of GUI Frames gui.getFrame('graphFrame').grid(row=0, column=0,
def composePhrase(self, composerName, tonality, mode, firstH, secondH, firstR, secondR, anacruse): dt = datetime.now() random.seed(dt.microsecond) fio = fileIO.FileIO() h = Harmony() rt = Rhythm() ml = Melody() iteration = 0 #De momento solo funciona en 4 por 4 beats_per_measure = 4 #Longitud en compases de la frase fraseLenght = 8 semifraseLenght = int(fraseLenght / 2) ritmoLenght = int(beats_per_measure * fraseLenght / 4) durationChord = "quarter" if durationChord == "whole": numberOfChords = int(1 * semifraseLenght) elif durationChord == "half": numberOfChords = int(2 * semifraseLenght) elif durationChord == "quarter": numberOfChords = int(4 * semifraseLenght) elif durationChord == "eight": numberOfChords = int(8 * semifraseLenght) fio.getFileNames(composerName, mode) unigram = fio.load_obj(fio.getFileNames(composerName, mode)[5]) bigram = fio.load_obj(fio.getFileNames(composerName, mode)[1]) bigram_R = fio.load_obj(fio.getFileNames(composerName, "R")[1]) trigram = fio.load_obj(fio.getFileNames(composerName, mode)[2]) trigram_R = fio.load_obj(fio.getFileNames(composerName, "R")[2]) unigram_s = sorted(unigram.items(), key=operator.itemgetter(1), reverse=True) cadenceOK = False iteration = 0 while not cadenceOK: chords_A1 = h.getHarmony_from_Trigram(trigram, bigram, tonality, firstH, numberOfChords, durationChord) if "v" in chords_A1[1][-1].lower(): cadenceOK = True elif "iv" in chords_A1[1][-1].lower(): cadenceOK = True if "vi" in chords_A1[1][-1].lower(): cadenceOK = True iteration += 1 if iteration == 100: raise Exception("Error in the process: to many trials") iteration = 0 cadenceOK = False while not cadenceOK: chords_A2 = h.getHarmony_from_Trigram(trigram, bigram, tonality, secondH, numberOfChords, durationChord) if "i" == chords_A2[1][-1].lower(): cadenceOK = True iteration += 1 if iteration == 100: raise Exception("Error in the process: to many trials") rimto1 = None iteration = 0 while (rimto1 is None): rimto1 = rt.getRhythm_from_Trigram(trigram_R, firstR, secondR, ritmoLenght, anacruse, 0) iteration += 1 if iteration == 100: raise Exception("Error in the process: to many trials") rimto1b = None iteration = 0 while (rimto1b is None): rimto1b = rt.getRhythm_from_Trigram(trigram_R, firstR, secondR, ritmoLenght, False, 1.0) iteration += 1 if iteration == 100: raise Exception("Error in the process: to many trials") rimto1c = None iteration = 0 while (rimto1c is None): rimto1c = rt.getRhythm_from_Trigram(trigram_R, firstR, secondR, ritmoLenght, False, 2.0) iteration += 1 if iteration == 100: raise Exception("Error in the process: to many trials") ritmoCompleto = [] for r in rimto1[0]: ritmoCompleto.append(r) for r in rimto1b[0]: ritmoCompleto.append(r) for r in rimto1[0]: ritmoCompleto.append(ml.cloneFigure(r)) for r in rimto1c[0]: ritmoCompleto.append(r) acordesCompleto = [] for c in chords_A1[0]: acordesCompleto.append(c) for c in chords_A2[0]: acordesCompleto.append(c) melodyGenerated = ml.rhythm_to_Melody(ritmoCompleto, acordesCompleto) print(str(chords_A1[1]) + str(chords_A2[1])) return [acordesCompleto, melodyGenerated]
def composePhraseChoral(self, composerName, tonality, mode): dt = datetime.now() random.seed(dt.microsecond) fio = fileIO.FileIO() h = Harmony() rt = Rhythm() ml = Melody() iteration = 0 #De momento solo funciona en 4 por 4 beats_per_measure = 4 #Longitud en compases de la frase fraseLenght = 4 semifraseLenght = int(fraseLenght / 2) ritmoLenght = int(beats_per_measure * fraseLenght) durationChord = "quarter" if durationChord == "whole": numberOfChords = int(1 * fraseLenght) elif durationChord == "half": numberOfChords = int(2 * fraseLenght) elif durationChord == "quarter": numberOfChords = int(4 * fraseLenght) elif durationChord == "eight": numberOfChords = int(8 * fraseLenght) fio.getFileNames(composerName, mode) unigram = fio.load_obj(fio.getFileNames(composerName, mode)[5]) bigram = fio.load_obj(fio.getFileNames(composerName, mode)[1]) bigram_R = fio.load_obj(fio.getFileNames(composerName, "R")[1]) trigram = fio.load_obj(fio.getFileNames(composerName, mode)[2]) trigram_R = fio.load_obj(fio.getFileNames(composerName, "R")[2]) unigram_s = sorted(unigram.items(), key=operator.itemgetter(1), reverse=True) isOK = False iteration = 0 while not isOK: chordsA = h.getHarmony_from_Trigram(trigram, bigram, tonality, "I", numberOfChords, durationChord) if "II" in chordsA[1][-2] and "V" in chordsA[1][-1]: isOK = True iteration += 1 if iteration == 1000: raise Exception("Error in the process A: to many trials") print("harmony A..... OK") iteration = 0 isOK = False while not isOK: chordsB = h.getHarmony_from_Trigram(trigram, bigram, tonality, "I6", numberOfChords, durationChord) if chordsB[1][-2] == "V" and chordsB[1][-1] == "I": isOK = True iteration += 1 if iteration == 1000: raise Exception("Error in the process B: to many trials") print("harmony B..... OK") ritmoA = None iteration = 0 isOK = False while not isOK: ritmoA = rt.getRhythm_from_Trigram(trigram_R, "N1.0", "N1.0", ritmoLenght, False, 0) if ritmoA is not None: if ritmoA[1][-1] == "N1.0": isOK = True iteration += 1 if iteration == 1000: raise Exception("Error in the process RA: to many trials") print("rhythm A..... OK") ritmoB = None iteration = 0 isOK = False while not isOK: ritmoB = rt.getRhythm_from_Trigram(trigram_R, "N1.0", "N1.0", ritmoLenght, False, 0) if ritmoB is not None: if ritmoB[1][-1] == "N1.0": isOK = True iteration += 1 if iteration == 1000: raise Exception("Error in the process RB: to many trials") print("rhythm B..... OK") ritmoCompleto = [] for r in ritmoA[0]: ritmoCompleto.append(r) for r in ritmoB[0]: ritmoCompleto.append(r) acordesCompleto = [] for c in chordsA[0]: acordesCompleto.append(c) for c in chordsB[0]: acordesCompleto.append(c) melodyGenerated = ml.rhythm_to_Melody(ritmoCompleto, acordesCompleto) print(str(chordsA[1]) + str(chordsB[1])) return [acordesCompleto, melodyGenerated]
def startParsing(self, composerName, mode, maxTokens): try: #INICIALIZAR LAS CLASES fio = fileIO.FileIO() ng = ngram.Ngram() lp = smoothing.Smoothing() #LEER LOS DATOS EN CRUDO print(">>> Reading data raw") fileNames = fio.getFileNames(composerName, mode) dataRawFile = fileNames[0] dataRaw = fio.readText('raw/' + dataRawFile) ## TOKENIZACION print(">>> Tokenization") tokens = ng.getTokens(dataRaw) ## printFrequencyChart(tokens) ## return "ok" ## STOP WORDS print(">>> Removing stop words") tokens = ng.removeStopWords(tokens) ## GRAFICAS DE FRECUENCIAS ## printFrequencyChart(tokens) #FILTRADO DE LOS MAS FECUENTES print(">>> Filtering " + str(maxTokens) + " most frequent tokens") tokens = ng.filterMostFrequentTokens(tokens, maxTokens) ## UNIGRAMA print(">>> Counting unigram") unigram_count = ng.getUnigram(tokens) print(">>> Saving unigram") fio.save_obj(unigram_count, fileNames[5]) ## BIGRAMA print(">>> Counting bigram") bigram_count = ng.getBigram(tokens) bigram_prob = ng.calculateBigramProbability( unigram_count, bigram_count) ## TRIGRAMA print(">>> Counting trigram") trigram_count = ng.getTrigram(tokens) trigram_prob = ng.calculateTrigramProbability( unigram_count, trigram_count) ## SMOOTHING alfa = 0.0001 ## hacer mencion a un trabajo anterior el paper que indica una tecnica de smoothing apropiada print(">>> Laplace smoothing of bigram") bigram_prob_Laplace = lp.calculateBigramProbabilityLaplace( unigram_count, bigram_count, alfa) unigram_ZERO = lp.smoothingLaplaceBigramZERO( unigram_count, bigram_count, alfa) print(">>> Laplace smoothing of trigram") trigram_prob_Laplace = lp.calculateBigramProbabilityLaplace( unigram_count, trigram_count, alfa) bigram_ZERO = lp.smoothingLaplaceTrigramZERO( unigram_count, trigram_count, alfa) print(">>> Saving bigram") fio.save_obj(bigram_prob_Laplace, fileNames[1]) fio.save_obj(unigram_ZERO, fileNames[3]) print(">>> Saving trigram") fio.save_obj(trigram_prob_Laplace, fileNames[2]) fio.save_obj(bigram_ZERO, fileNames[4]) #PROCESO FINALIZADO print(">>> Process finished OK") except: print(">>> Process failed")