Skip to content
Snippets Groups Projects
FFT_presenter.py 3.64 KiB
Newer Older
from __future__ import (absolute_import, division, print_function)
class FFTPresenter(object):
    def __init__(self,view,alg,load):
        self.view=view
        self.alg=alg
        self.load=load
        # set data
        self.getWorkspaceNames()
        #connect
        self.view.tableClickSignal.connect(self.tableClicked)
        self.view.buttonSignal.connect(self.handleButton)
        self.view.phaseCheckSignal.connect(self.phaseCheck)
        self.alg.started.connect(self.deactivate)
        self.alg.finished.connect(self.activate)

    def activate(self):
        self.view.activateButton()

    def deactivate(self):
        self.view.deactivateButton()
    # only get ws that are groups or pairs
    def getWorkspaceNames(self):
        runName,options = self.load.getCurrentWS()
        final_options = []
        for pick in options:
            if ";" in pick and "Raw" not in pick and runName in pick:
                final_options.append(pick)
        self.view.addItems(final_options)
    def phaseCheck(self):
        self.view.phaseQuadChanged()
        #check if a phase table exists
        if mantid.AnalysisDataService.doesExist("PhaseTable"):
           self.view.setPhaseBox()
    def tableClicked(self,row,col):
        if row == self.view.getImBoxRow() and col == 1 and self.view.getWS() !="PhaseQuad":
            self.view.changedHideUnTick(self.view.getImBox(),self.view.getImBoxRow()+1)
        elif  row == self.view.getShiftBoxRow() and col == 1:
            self.view.changed(self.view.getShiftBox(),self.view.getShiftBoxRow()+1)

        inputs={}
        inputs["Run"]=self.load.getRunName()
        #do apodization and padding to real data
        preInputs=self.view.initAdvanced()

        if self.view.getWS() == "PhaseQuad":
            phaseTable={}
            phaseTable["newTable"]= self.view.isNewPhaseTable()
            phaseTable["axis"]=self.view.getAxis()
            phaseTable["Instrument"]=self.load.getInstrument()
            inputs["phaseTable"]=phaseTable
            #model.makePhaseQuadTable(axis,self.load.getInstrument())
            #self.model.PhaseQuad()
            self.view.RePhaseAdvanced(preInputs)
        else:
            self.view.ReAdvanced(preInputs)
            if self.view.isRaw():
                self.view.addRaw(preInputs,"InputWorkspace")
        inputs["preRe"]=preInputs
        #model.preAlg(preInputs)
        #do apodization and padding to complex data
        if self.view.isComplex() and self.view.getWS()!="PhaseQuad":
            ImPreInputs=self.view.initAdvanced()
            self.view.ImAdvanced(ImPreInputs)
            if self.view.isRaw():
                self.view.addRaw(ImPreInputs,"InputWorkspace")
            #model.preAlg(preInputs)
            inputs["preIm"]=ImPreInputs
        #do FFT to transformed data
        FFTInputs = self.get_FFT_input()
        if self.view.getWS()=="PhaseQuad":
            self.view.getFFTRePhase(FFTInputs)
            if self.view.isComplex():
                self.view.getFFTImPhase(FFTInputs)
        else:
            if self.view.isRaw():
                self.view.addRaw(FFTInputs,"OutputWorkspace")
        #model.FFTAlg(FFTInputs)
        inputs["FFT"]=FFTInputs
        self.alg.loadData(inputs)
        self.alg.start()
Anthony Lim's avatar
Anthony Lim committed
    def get_FFT_input(self):
        FFTInputs=self.view.initFFTInput()
        if  self.view.isAutoShift():
            FFTInputs["AutoShift"]=True
            self.view.addFFTShift(FFTInputs)
        if self.view.isComplex():
            self.view.addFFTComplex(FFTInputs)
        return FFTInputs