예제 #1
0
 def testCreateFertilizerDistribution(self):
     # inputs with values. Each feedstock and fertilizer should have a value, except aa for switch grass.
     inputs = self.createNewModel_returnInputs()
     i = Inputs() 
     fertDist = i.createFertilizerDistribution(inputs['fertilizers'])
     self.assertEqual(fertDist, {'CG': ['.2', '.2', '.2', '.2', '.2'], 'CS': ['.2', '.2', '.2', '.2', '.2'],
                                 'WS': ['.2', '.2', '.2', '.2', '.2'], 'SG': ['0', '.2', '.2', '.2', '.2']})
     
     
     # empty inputs. Should return None for each feedstock, b/c no fertilizers where entered.
     inputs = self.createNewModel_empty_returnInputs()
     i = Inputs()
     fertDist = i.createFertilizerDistribution(inputs['fertilizers'])
     self.assertEqual(fertDist, {'CG': None, 'CS': None,
                                 'WS': None, 'SG': None})
예제 #2
0
 def testCreateAllocation(self):
     # Inputs with values. CG is the value inputed.
     # CS and WE are 1-CG value.
     inputs = self.createNewModel_returnInputs()
     i = Inputs()
     alloc = i.createAllocation(inputs['alloc'])
     self.assertEqual(alloc['CG'], 0.25)
     self.assertEqual(alloc['CS'], 0.75)
     self.assertEqual(alloc['WS'], 0.75)
     
     # empty inputs. Should return the default values of allocating everything to cg.
     inputs = self.createNewModel_empty_returnInputs()
     i = Inputs()
     alloc = i.createAllocation(inputs['alloc'])
     self.assertEqual(alloc['CG'], 1)
     self.assertEqual(alloc['CS'], 0)
     self.assertEqual(alloc['WS'], 0)
예제 #3
0
 def testCreateOperations(self):
     # inputs with values. For each feedstock and operation should be True.
     inputs = self.createNewModel_returnInputs()
     i = Inputs() 
     operationDict = i.createOperations(inputs['operations'])
     self.assertEqual(operationDict, {'CS': {'H': True, 'N': True, 'T': True}, 
                      'WS': {'H': True, 'N': True, 'T': True},
                      'CG': {'H': True, 'N': True, 'T': True},
                      'SG': {'H': True, 'N': True, 'T': True}})
     
     # empty inputs. Should return False for each feedstock and operation.
     inputs = self.createNewModel_empty_returnInputs()
     i = Inputs()
     operationDict = i.createOperations(inputs['operations'])
     self.assertEqual(operationDict, {'CS': {'H': False, 'N': False, 'T': False}, 
                      'WS': {'H': False, 'N': False, 'T': False},
                      'CG': {'H': False, 'N': False, 'T': False},
                      'SG': {'H': False, 'N': False, 'T': False}})
예제 #4
0
 def testCreateRunCodes(self):
     # inputs with values. Should be all of the run_codes, b/c every box was selected.
     inputs = self.createNewModel_returnInputs()
     i = Inputs()
     run_codes, ferts, pestFeed = i.createRunCodes(inputs['checkBoxes'])
     allRunCodes = ['FR', 'CG_CH', 'CG_CN', 'CG_IC', 'CG_ID', 'CG_IG', 'CG_IL', 'CG_NH', 'CG_NN', 'CG_RH', 'CG_RN', 'CS_NT', 'CS_RT', 
                    'SG_H1', 'SG_H2', 'SG_H3', 'SG_H4', 'SG_H5', 'SG_H6', 'SG_H7', 'SG_H8', 'SG_H9', 'SG_H10', 
                    'SG_N1', 'SG_N2', 'SG_N3', 'SG_N4', 'SG_N5', 'SG_N6', 'SG_N7', 'SG_N8', 'SG_N9', 'SG_N10', 
                    'SG_T1', 'SG_T2', 'SG_T3', 'SG_T4', 'SG_T5', 'SG_T6', 'SG_T7', 'SG_T8', 'SG_T9', 'SG_T10', 
                    'WS_NT', 'WS_RT']
     self.assertEqual(run_codes, allRunCodes)
     self.assertEqual(ferts, {'CGF': True, 'CSF': True, 'SGF': True, 'WSF': True})
     self.assertEqual(pestFeed, {'CGP': True, 'SGP': True})
     
     # empty inputs. Should return an empty list, b/c no run_codes were selected.
     inputs = self.createNewModel_empty_returnInputs()
     i = Inputs()
     run_codes, ferts, pestFeed = i.createRunCodes(inputs['checkBoxes'])
     self.assertEqual(run_codes, [])
     self.assertEqual(ferts, {'CGF': False, 'CSF': False, 'SGF': False, 'WSF': False})
     self.assertEqual(pestFeed, {'CGP': False, 'SGP': False})
예제 #5
0
    def testCreateRunCodes(self):
        # inputs with values. Should be all of the run_codes, b/c every box was selected.
        inputs = self.createNewModel_returnInputs()
        i = Inputs()
        run_codes, ferts, pestFeed = i.createRunCodes(inputs['checkBoxes'])
        allRunCodes = [
            'FR', 'CG_CH', 'CG_CN', 'CG_IC', 'CG_ID', 'CG_IG', 'CG_IL',
            'CG_NH', 'CG_NN', 'CG_RH', 'CG_RN', 'CS_NT', 'CS_RT', 'SG_H1',
            'SG_H2', 'SG_H3', 'SG_H4', 'SG_H5', 'SG_H6', 'SG_H7', 'SG_H8',
            'SG_H9', 'SG_H10', 'SG_N1', 'SG_N2', 'SG_N3', 'SG_N4', 'SG_N5',
            'SG_N6', 'SG_N7', 'SG_N8', 'SG_N9', 'SG_N10', 'SG_T1', 'SG_T2',
            'SG_T3', 'SG_T4', 'SG_T5', 'SG_T6', 'SG_T7', 'SG_T8', 'SG_T9',
            'SG_T10', 'WS_NT', 'WS_RT'
        ]
        self.assertEqual(run_codes, allRunCodes)
        self.assertEqual(ferts, {
            'CGF': True,
            'CSF': True,
            'SGF': True,
            'WSF': True
        })
        self.assertEqual(pestFeed, {'CGP': True, 'SGP': True})

        # empty inputs. Should return an empty list, b/c no run_codes were selected.
        inputs = self.createNewModel_empty_returnInputs()
        i = Inputs()
        run_codes, ferts, pestFeed = i.createRunCodes(inputs['checkBoxes'])
        self.assertEqual(run_codes, [])
        self.assertEqual(ferts, {
            'CGF': False,
            'CSF': False,
            'SGF': False,
            'WSF': False
        })
        self.assertEqual(pestFeed, {'CGP': False, 'SGP': False})
예제 #6
0
    def testCreateOperations(self):
        # inputs with values. For each feedstock and operation should be True.
        inputs = self.createNewModel_returnInputs()
        i = Inputs()
        operationDict = i.createOperations(inputs['operations'])
        self.assertEqual(
            operationDict, {
                'CS': {
                    'H': True,
                    'N': True,
                    'T': True
                },
                'WS': {
                    'H': True,
                    'N': True,
                    'T': True
                },
                'CG': {
                    'H': True,
                    'N': True,
                    'T': True
                },
                'SG': {
                    'H': True,
                    'N': True,
                    'T': True
                }
            })

        # empty inputs. Should return False for each feedstock and operation.
        inputs = self.createNewModel_empty_returnInputs()
        i = Inputs()
        operationDict = i.createOperations(inputs['operations'])
        self.assertEqual(
            operationDict, {
                'CS': {
                    'H': False,
                    'N': False,
                    'T': False
                },
                'WS': {
                    'H': False,
                    'N': False,
                    'T': False
                },
                'CG': {
                    'H': False,
                    'N': False,
                    'T': False
                },
                'SG': {
                    'H': False,
                    'N': False,
                    'T': False
                }
            })
예제 #7
0
    def testCreateAllocation(self):
        # Inputs with values. CG is the value inputed.
        # CS and WE are 1-CG value.
        inputs = self.createNewModel_returnInputs()
        i = Inputs()
        alloc = i.createAllocation(inputs['alloc'])
        self.assertEqual(alloc['CG'], 0.25)
        self.assertEqual(alloc['CS'], 0.75)
        self.assertEqual(alloc['WS'], 0.75)

        # empty inputs. Should return the default values of allocating everything to cg.
        inputs = self.createNewModel_empty_returnInputs()
        i = Inputs()
        alloc = i.createAllocation(inputs['alloc'])
        self.assertEqual(alloc['CG'], 1)
        self.assertEqual(alloc['CS'], 0)
        self.assertEqual(alloc['WS'], 0)
예제 #8
0
    def testCreateFertilizerDistribution(self):
        # inputs with values. Each feedstock and fertilizer should have a value, except aa for switch grass.
        inputs = self.createNewModel_returnInputs()
        i = Inputs()
        fertDist = i.createFertilizerDistribution(inputs['fertilizers'])
        self.assertEqual(
            fertDist, {
                'CG': ['.2', '.2', '.2', '.2', '.2'],
                'CS': ['.2', '.2', '.2', '.2', '.2'],
                'WS': ['.2', '.2', '.2', '.2', '.2'],
                'SG': ['0', '.2', '.2', '.2', '.2']
            })

        # empty inputs. Should return None for each feedstock, b/c no fertilizers where entered.
        inputs = self.createNewModel_empty_returnInputs()
        i = Inputs()
        fertDist = i.createFertilizerDistribution(inputs['fertilizers'])
        self.assertEqual(fertDist, {
            'CG': None,
            'CS': None,
            'WS': None,
            'SG': None
        })
예제 #9
0
    def _runNewModel(self, inputs):
        self.statusBar().showMessage('Starting New Model')
        inputs = Inputs(inputs)
        # only used for validation purposes. Are boolean.
        self.validate.title(inputs.title)
        self.validate.runCodes(inputs.run_codes)
        self.validate.fertDist(inputs.fertDist)
        self.validate.ferts(inputs.ferts)
        self.validate.pest(inputs.pestFeed)

        print 'Fertilizer distribution.'
        print inputs.fertDist
        print 'Allocation from cg to ws and cs.'
        print inputs.alloc
        print 'run codes.'
        print inputs.run_codes
        print 'feed stocks using fertilizers.'
        print inputs.ferts
        print 'feed stocks using pesticides.'
        print inputs.pestFeed
        print 'Operations for feed stocks'
        print inputs.operations

        # make sure all of the variables to run the model have been created.
        if not self.validate.errors:
            self.statusBar().showMessage('Initiating Air Model.')
            # get db and add schema
            db = self.model.db
            db.schema = inputs.title
            # create the subprocess module that will run NONROAD in the background.
            self.qprocess = QtCore.QProcess(self)
            # send signal when subprocess has started.
            self.qprocess.started.connect(self._processStart)
            # when the subprocess is finished, it will send a signal to the controller to finish running the air model.
            self.qprocess.finished.connect(self._processSave)
            # read any new data.
            self.qprocess.readyReadStandardOutput.connect(self._processStatus)
            # send signal if a error has occured.
            self.qprocess.error.connect(self._processError)
            # create air model.
            self.airModel = Driver(inputs.title, inputs.run_codes, db)
            #self.airModel.setupNONROAD()
            # create progress bar before running NONROAD model, to keep track of progress.
            self.timer = 0
            #create a global fertilizer to pass to the model.
            self.fertDist = inputs.fertDist
            # weather each feed stock should calculate emmisions from fertilizers.
            self.ferts = inputs.ferts
            # weather some feedstocks should calculate emmisions from pesticides.
            self.pestFeed = inputs.pestFeed
            # which operations to use for run.
            self.operations = inputs.operations
            self.alloc = inputs.alloc
            # grab the total number of files that need to be ran.
            batchFiles = self.airModel.batch.getBatchFiles()
            self.bar = QtGui.QProgressBar()
            self.bar.setRange(self.timer, batchFiles)
            self.bar.setValue(self.timer)
            self.bar.setWindowTitle("NONROAD Progress")
            self.bar.show()
            # run NONROAD.
            #self.airModel.runNONROAD(self.qprocess)

            self.airModel.saveData(self.ferts, self.fertDist, self.pestFeed,
                                   self.operations, self.alloc)

        # if not able to validate inputs.
        else:
            self.statusBar().showMessage('ERROR: could not run model')
            # output errors in pop up boxes.
            for error in self.validate.getErrors():
                QtGui.QMessageBox.about(self, "Validation", error)
예제 #10
0
 def testTitle(self):
     inputs = self.createNewModel_returnInputs()
     i = Inputs(inputs)
     self.assertEqual(i.title, 'title')