示例#1
0
    def build_startupfiles(self):
        """
        Set up collection of required stratup files for OCCAM.

        - startup
        - model
        """
        
        #use MTPy core tool for building start files
        import MTpy.core.OCCAMTools as OCCAMTools
        reload(OCCAMTools)

        D=self.parameters
        
        datafile = D['datafile'] 

        #1. make startup file 
        self._setup_startupfile()


        #2. make model file
        m_fn,i_fn,s_fn = OCCAMTools.makeModel(datafile,\
                                                niter=int(float(D['n_iterations'])),\
                                                targetrms=float(D['target_rms']),\
                                                nlayers=int(float(D['n_layers'])),\
                                                nlperdec=int(float(D['decade_layers'])),\
                                                z1layer=int(float(D['thickness1'])),\
                                                bwidth=int(float(D['max_blockwidth'])),\
                                                trigger=float(D['mergethreshold']),\
                                                #savepath=self.ui.wd,\
                                                rhostart=float(D['rho0']),\
                                                #occampath=D['makemodel_exe']\
                                                cwd=self.ui.wd,\
                                                #makemodelexe=D['makemodel_exe'],
                                                modelname=D['modelname'],
                                                use_existing_startup=D['check_usestartupfile'],\
                                                existing_startup_file=D['startupfn']\
                                                )

        if op.isfile(m_fn) and op.isfile(i_fn) and op.isfile(s_fn):
            if D['check_usestartupfile']:
                messagetext = "<P><b><FONT COLOR='#008080'>Old startup  read in:</FONT></b></P><br>%s"%(s_fn)
                QtGui.QMessageBox.about(self, "Startup file", messagetext )
                messagetext = "<P><b><FONT COLOR='#008080'>Input files generated:</FONT></b></P><br>%s<br>%s"%(m_fn,i_fn)
                D['startupfile'] = existing_startup_file
            
            else:
                messagetext = "<P><b><FONT COLOR='#008080'>Input files generated:</FONT></b></P><br>%s<br>%s<br>%s"%(m_fn,i_fn,s_fn)
        else:
            messagetext = "<P><b><FONT COLOR='#800000'>Error: %i No startup files generated!  </FONT></b></P> "
        
        QtGui.QMessageBox.about(self, "Startup files generation", messagetext )

        return
示例#2
0
    def build_datafile(self):
        """
        Build OCCAM data file, or use existing one (if field is checked in GUI) 
        """

        D = self.parameters

        #print D['check_usedatafile']
        #print D['olddatafile']

        checkfilename = D['olddatafile']
        #print op.isfile(checkfilename)


        #Try to load old data file, if box is checked
        if D['check_usedatafile']:
            checkfilename = D['olddatafile']
            if op.isfile(checkfilename):
                messagetext = "<P><b><FONT COLOR='#008080'>Existing data file loaded successfully:</FONT></b></P><br>%s"%checkfilename
                D['datafilename'] = D['olddatafile']
                D['datafile']     = D['olddatafile']
            else:
                messagetext = "<P><b><FONT COLOR='#800000'>Error: %i No old data file found!  </FONT></b></P> "
                    
            QtGui.QMessageBox.about(self, "Data file", messagetext )
                    
            return

        #Otherwise set up new data filename
        
        outfilename = D['datafilename']
        edidirectory= D['edis_dir']

        def make_stationlist(listfilename):
            """
            Read in stations from file.

            """
            FH=file(listfilename,'r')
            raw_string=FH.read()
            FH.close()
            raw_list1 = raw_string.strip().split()
            raw_list2 = []
            for i in raw_list1:
                if len(i.split(','))==1:
                    raw_list2.append(i)
                else:
                    for j in i.split(','):
                        raw_list2.append(j)
            return raw_list2

        #define internal station list 
        stationlist=None
        if D['check_usestations']:
            stationlist = make_stationlist(D['stationlist_file'])

        #read in error floors-----------------------------------------
        if int(float(D['useDataError_ResXY'])): 
            resxy='data'
        else:
            resxy=float(D['Error_ResXY'] )    


        if int(float(D['useDataError_ResYX'])):
            resyx='data'
        else:
            resyx=float(D['Error_ResYX'] )
    

        if int(float(D['useDataError_PhaseXY'])):
            phasexy='data'
        else:
            phasexy=float(D['Error_PhaseXY'])

        if int(float(D['useDataError_PhaseYX'])):
            phaseyx='data'
        else:
            phaseyx=float(D['Error_PhaseYX'])


        #TIPPER--------------------------------------------------
        tippererror=None
        if D['check_includeTipper']:
            tippererror = float(D['Error_Tipper'])

        #define modes used ------------------------------------------
        _modedict = {'0':'both' , '1':'TM', '2':'TE' }
        mode4modelling = _modedict[str(D['mode'])]
       
        #define orientation -----------------------------------------
        _oridict = {'0':'ns' , '1':'ew' }
        lineorientation = _oridict[str(D['orientation'])]
        
        #make data file  -------------------------------------------
        
        #use MTPy core module for generating the new data file
        import MTpy.core.OCCAMTools as OCCAMTools
        
        checkfilename = OCCAMTools.make2DdataFile(edidirectory,\
                                    savepath=outfilename,\
                                    mmode= mode4modelling,\
                                    stationlst=stationlist,\
                                    title=None,\
                                    thetar=float(D['strike']),\
                                    resxyerr=resxy,\
                                    resyxerr=resyx,\
                                    phasexyerr=phasexy,\
                                    phaseyxerr=phaseyx,\
                                    ss=3*' ',\
                                    fmt='%2.6f',\
                                    freqstep=int(float(D['freqsteps'])),\
                                    plotyn='n',\
                                    lineori=lineorientation,\
                                    tippererr=tippererror  \
                                    )

        #check, if generation was successfull and show message box
        if op.isfile(checkfilename):
            messagetext = "<P><b><FONT COLOR='#008080'>Data file generation successful:</FONT></b></P><br>%s"%checkfilename
            D['datafile'] = checkfilename
        else:
            messagetext = "<P><b><FONT COLOR='#800000'>Error: %i No data file generated!  </FONT></b></P> "
            
        QtGui.QMessageBox.about(self, "Data file", messagetext )