Ejemplo n.º 1
0
    def defineCharacteristics(self):
        self.name = 'Distance matrix'
        self.group = 'Vector analysis tools'

        self.addParameter(
            ParameterVector(self.INPUT_LAYER, 'Input point layer',
                            [ParameterVector.VECTOR_TYPE_POINT]))
        self.addParameter(
            ParameterTableField(self.INPUT_FIELD, 'Input unique ID field',
                                self.INPUT_LAYER,
                                ParameterTableField.DATA_TYPE_ANY))
        self.addParameter(
            ParameterVector(self.TARGET_LAYER, 'Target point layer',
                            ParameterVector.VECTOR_TYPE_POINT))
        self.addParameter(
            ParameterTableField(self.TARGET_FIELD, 'Target unique ID field',
                                self.TARGET_LAYER,
                                ParameterTableField.DATA_TYPE_ANY))
        self.addParameter(
            ParameterSelection(self.MATRIX_TYPE, 'Output matrix type',
                               self.MAT_TYPES, 0))
        self.addParameter(
            ParameterNumber(self.NEAREST_POINTS,
                            'Use only the nearest (k) target points', 0, 9999,
                            0))

        self.addOutput(OutputTable(self.DISTANCE_MATRIX, 'Distance matrix'))
Ejemplo n.º 2
0
    def defineCharacteristics(self):
        self.name = 'MAXENT (ParameterPreperation)'
        self.cmdName = 'maxent_param'
        self.group = 'Species Distribution Modelling'

        self.addParameter(ParameterSelection(self.OUT_F, "Output Format", self.of, 0))
        self.addParameter(ParameterBoolean(self.RESP, 'Create Response Curves',False))
        self.addParameter(ParameterBoolean(self.RESP_EXP, 'Show exponent in Response Curves',False))
        self.addParameter(ParameterBoolean(self.PIC, 'Create pictures for each grid',True))
        self.addParameter(ParameterBoolean(self.JACK, 'Measure Importance by jackknifing',False))
        self.addParameter(ParameterBoolean(self.RANDOM, 'Random seed',False))
        self.addParameter(ParameterBoolean(self.LOGSCALE, 'Display Pictures on a logscale',False))
        self.addParameter(ParameterBoolean(self.CLAMPGRID, 'Write Grid of spatial Clamping',True))
        self.addParameter(ParameterBoolean(self.MESS, 'Write MESS grid',True))
        self.addParameter(ParameterNumber(self.RANDOM_POINTS, 'Percentage of presence localities to be randomly set aside as test points',0,None,0))
        self.addParameter(ParameterNumber(self.BETA_MULT, 'Multiply all automatic regularization parameters by this number.',1.0,None,1.0))
        self.addParameter(ParameterNumber(self.REPLICATES, 'Number of Replicates for crossvalidation',False,True,1))
        self.addParameter(ParameterSelection(self.REPLICATE_TYPE, "What Type of Replicate", self.R_TYPE, 0))
        self.addParameter(ParameterBoolean(self.LINEAR, 'Allow linear features to be used',True))
        self.addParameter(ParameterBoolean(self.QUADRATIC, 'Allow quadratic features to be used',True))
        self.addParameter(ParameterBoolean(self.PRODUCT, 'Allow product features to be used',True))
        self.addParameter(ParameterBoolean(self.THRESHOLD, 'Allow threshold features to be used',True))
        self.addParameter(ParameterBoolean(self.HINGE, 'Allow hinge features to be used',True))
        self.addParameter(ParameterBoolean(self.FADEBYCLAMPING, 'Reduce prediction by the difference between clamped and non-clamped output',False))
        self.addParameter(ParameterBoolean(self.EXTRAPOLATE, 'Predicts to regions out of environmental space',True))
        self.addParameter(ParameterBoolean(self.PLOTS, 'Write various plots for inclusion in .html output',True))
        self.addParameter(ParameterNumber(self.MAXITERATIONS, 'Stop training after this many iterations of the optimization algorithm',1,None,500))
        self.addParameter(ParameterNumber(self.CONVG_THRESH, 'Stop training when the drop in log loss per iteration drops below this number',False,True,0.00001))
        self.addParameter(ParameterNumber(self.PROC, 'Number of processor threads to use',False,True,1))
        self.addParameter(ParameterNumber(self.DEF_PREV, 'Default prevalence of the species: probability of presence at ordinary occurrence points.',False,True,0.5))
#        self.addParameter(ParameterSelection(self.APPLY_THRESH, "Apply a threshold rule",""))
        self.addParameter(ParameterNumber(self.CONVG_THRESH, 'Stop training when the drop in log loss per iteration drops below this number',False,True,0.00001))
        self.addParameter(ParameterBoolean(self.PERSPECRES, 'Create Per Species results',True))  
              
        self.addOutput(OutputTable(self.OUT_PARAM,'MAXENT_Parameters'))                
Ejemplo n.º 3
0
 def defineCharacteristics(self):
     self.name = "Raster layer histogram"
     self.group = "Graphics"
     self.addParameter(ParameterRaster(self.INPUT, "Input layer"))
     self.addParameter(ParameterNumber(self.BINS, "Number of bins", 2, None, 10))
     self.addOutput(OutputHTML(self.PLOT, "Output plot"))
     self.addOutput(OutputTable(self.TABLE, "Output table"))
Ejemplo n.º 4
0
    def defineCharacteristics(self):
        self.name = 'gdal2xyz'
        self.group = '[GDAL] Conversion'
        self.addParameter(ParameterRaster(self.INPUT, 'Input layer', False))
        self.addParameter(ParameterNumber(self.BAND, 'Band number', 1, 9999,
                                          1))

        self.addOutput(OutputTable(self.OUTPUT, 'Output file'))
Ejemplo n.º 5
0
 def defineCharacteristics(self):
     self.name = 'Cloud Metrics'
     self.group = 'Points'
     self.addParameter(ParameterFile(self.INPUT, 'Input las layer'))
     self.addOutput(
         OutputTable(self.OUTPUT,
                     'Output file with tabular metric information'))
     self.addAdvancedModifiers()
Ejemplo n.º 6
0
 def defineCharacteristics(self):
     self.name = 'Raster layer histogram'
     self.group = 'Graphics'
     self.addParameter(ParameterRaster(self.INPUT, 'Input layer'))
     self.addParameter(
         ParameterNumber(self.BINS, 'Number of bins', 2, None, 10))
     self.addOutput(OutputHTML(self.PLOT, 'Output plot'))
     self.addOutput(OutputTable(self.TABLE, 'Output table'))
Ejemplo n.º 7
0
 def defineCharacteristics(self):
     self.name = 'Grid Metrics'
     self.group = 'Points'
     self.addParameter(ParameterFile(self.INPUT, 'Input las layer'))
     self.addParameter(ParameterFile(self.GROUND, 'Input ground DTM layer'))
     self.addParameter(ParameterNumber(self.HEIGHT, 'Height break'))
     self.addParameter(ParameterNumber(self.CELLSIZE, 'Cellsize'))
     self.addOutput(
         OutputTable(self.OUTPUT, 'Output table with grid metrics'))
     self.addAdvancedModifiers()
Ejemplo n.º 8
0
 def defineCharacteristics(self):
     self.name = "Grid Metrics"
     self.group = "Points"
     self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
     self.addParameter(ParameterFile(self.GROUND, "Input ground DTM layer"))
     self.addParameter(ParameterNumber(self.HEIGHT, "Height break"))
     self.addParameter(ParameterNumber(self.CELLSIZE, "Cellsize"))
     self.addOutput(
         OutputTable(self.OUTPUT, "Output table with grid metrics"))
     self.addAdvancedModifiers()
Ejemplo n.º 9
0
 def defineCharacteristics(self):
     self.name = 'Canopy Maxima'
     self.group = 'Points'
     self.addParameter(ParameterFile(self.INPUT, 'Input las layer'))
     self.addParameter(ParameterFile(self.GROUND,
         'Input ground DTM layer [optional, leave blank if not using it]'))
     self.addParameter(ParameterNumber(self.THRESHOLD, 'Minimum threshold',
                       0, None, 10.0))
     self.addOutput(OutputTable(self.OUTPUT, 'Output file with maxima'))
     self.addAdvancedModifiers()
Ejemplo n.º 10
0
    def defineCharacteristics(self):
        self.name = 'Calculate Niche Overlap Statistics'
        self.cmdName = 'nicheoverlap'
        self.group = 'Data Analysis'

        self.addParameter(
            ParameterMultipleInput(self.ENV, 'Prediction layers',
                                   ParameterMultipleInput.TYPE_RASTER, False))
        self.addParameter(ParameterSelection(self.METRIC, "Metric", self.m, 0))

        self.addOutput(OutputTable(self.RESULTS, 'Result output'))
Ejemplo n.º 11
0
    def defineCharacteristics(self):
        self.name = 'Simulate flow in storm water conveyance systems'
        self.group = 'Simulation'

        self.addParameter(ParameterString(self.TITLE, 'Title', 'Swmm Simulation'))

        self.addParameter(ParameterTable(self.OPTIONS, 'Analysis options', True))
        self.addParameter(ParameterTable(self.REPORT, 'Output reporting instructions', True))
        self.addParameter(ParameterTable(self.FILES, 'Interface file options', True))
        self.addParameter(ParameterTable(self.RAINGAGES, 'Rain gage information', True))
        self.addParameter(ParameterTable(self.HYDROGRAPHS, 'Unit hydrograph data used to construct RDII inflows', True))
        self.addParameter(ParameterTable(self.EVAPORATION, 'Evaporation data', True))
        self.addParameter(ParameterTable(self.TEMPERATURE, 'Air temperature and snow melt data', True))
        self.addParameter(ParameterVector(self.SUBCATCHMENTS, 'Basic subcatchment information', [ParameterVector.VECTOR_TYPE_POLYGON], True))
        self.addParameter(ParameterTable(self.SUBAREAS, 'Subcatchment impervious/pervious sub-area data', True))
        self.addParameter(ParameterTable(self.INFILTRATION, 'Subcatchment infiltration parameters', True))
        self.addParameter(ParameterTable(self.LID_CONTROLS, 'Low impact development control information', True))
        self.addParameter(ParameterTable(self.LID_USAGE, 'Assignment of LID controls to subcatchments', True))
        self.addParameter(ParameterTable(self.AQUIFERS, 'Groundwater aquifer parameters', True))
        self.addParameter(ParameterTable(self.GROUNDWATER, 'Subcatchment groundwater parameters', True))
        self.addParameter(ParameterTable(self.SNOWPACKS, 'Subcatchment snow pack parameters', True))
        self.addParameter(ParameterVector(self.JUNCTIONS, 'Junction node information', [ParameterVector.VECTOR_TYPE_POINT], True))
        self.addParameter(ParameterTable(self.OUTFALLS, 'Outfall node information', True))
        self.addParameter(ParameterVector(self.DIVIDERS, 'Flow divider node information', [ParameterVector.VECTOR_TYPE_POINT], True))
        self.addParameter(ParameterVector(self.STORAGE, 'Storage node information', [ParameterVector.VECTOR_TYPE_POINT], True))
        self.addParameter(ParameterVector(self.CONDUITS, 'Conduit link information', [ParameterVector.VECTOR_TYPE_LINE], True))
        self.addParameter(ParameterVector(self.PUMPS, 'Pump link information', [ParameterVector.VECTOR_TYPE_POINT], True))
        self.addParameter(ParameterVector(self.ORIFICES, 'Orifice link information', [ParameterVector.VECTOR_TYPE_POINT], True))
        self.addParameter(ParameterVector(self.WEIRS, 'Weir link information', [ParameterVector.VECTOR_TYPE_POINT], True))
        self.addParameter(ParameterVector(self.OUTLETS, 'Outlet link information', [ParameterVector.VECTOR_TYPE_POINT], True))
        self.addParameter(ParameterTable(self.XSECTIONS, 'Conduit, orifice, and weir cross-section geometry', True))
        self.addParameter(ParameterTable(self.TRANSECTS, 'Transect geometry for conduits with irregular cross-sections', True))
        self.addParameter(ParameterTable(self.LOSSES, 'Conduit entrance/exit losses and flap valves', True))
        self.addParameter(ParameterTable(self.CONTROLS, 'Rules that control pump and regulator operation', True))
        self.addParameter(ParameterTable(self.POLLUTANTS, 'Pollutant information', True))
        self.addParameter(ParameterTable(self.LANDUSES, 'Land use categories', True))
        self.addParameter(ParameterTable(self.COVERAGES, 'Assignment of land uses to subcatchments', True))
        self.addParameter(ParameterTable(self.BUILDUP, 'Buildup functions for pollutants and land uses', True))
        self.addParameter(ParameterTable(self.WASHOFF, 'Washoff functions for pollutants and land uses', True))
        self.addParameter(ParameterTable(self.TREATMENT, 'Pollutant removal functions at conveyance system nodes', True))
        self.addParameter(ParameterTable(self.INFLOWS, 'External hydrograph/pollutograph inflow at nodes', True))
        self.addParameter(ParameterTable(self.DWF, 'Baseline dry weather sanitary inflow at nodes', True))
        self.addParameter(ParameterTable(self.PATTERNS, 'Periodic variation in dry weather inflow', True))
        self.addParameter(ParameterTable(self.RDII, 'Rainfall-dependent I/I information at nodes', True))
        self.addParameter(ParameterTable(self.LOADINGS, 'Initial pollutant loads on subcatchments', True))
        self.addParameter(ParameterTable(self.CURVES, 'x-y tabular data referenced in other sections', True))
        self.addParameter(ParameterTable(self.TIMESERIES, 'Time series data referenced in other sections', True))


        self.addOutput(OutputVector(self.NODE_OUTPUT, 'Node output layer'))
        self.addOutput(OutputTable(self.NODE_TABLE_OUTPUT, 'Node output table'))
        self.addOutput(OutputVector(self.LINK_OUTPUT, 'Link output layer'))
        pass
Ejemplo n.º 12
0
    def defineCharacteristics(self):
        self.name = 'Logistic Regression'
        self.cmdName = 'logisticreg'
        self.group = 'Species Distribution Modelling'

        self.addParameter(
            ParameterVector(
                self.SPECIES, 'Species localities',
                [ParameterVector.VECTOR_TYPE_POINT, ParameterTable],
                False))  # Allow point
        self.addParameter(
            ParameterMultipleInput(self.ENV, 'Environmental layers',
                                   ParameterMultipleInput.TYPE_RASTER, False))

        self.addOutput(OutputRaster(self.OUT_PRED, 'Output Prediction'))
        self.addOutput(OutputTable(self.OUT_PRED_RES, 'Stats'))
Ejemplo n.º 13
0
    def defineCharacteristics(self):
        self.name = 'Statistics by categories'
        self.group = 'Vector table tools'

        self.addParameter(ParameterVector(self.INPUT_LAYER,
                          'Input vector layer',
                          [ParameterVector.VECTOR_TYPE_ANY], False))
        self.addParameter(ParameterTableField(self.VALUES_FIELD_NAME,
                          'Field to calculate statistics on',
                          self.INPUT_LAYER,
                          ParameterTableField.DATA_TYPE_NUMBER))
        self.addParameter(ParameterTableField(self.CATEGORIES_FIELD_NAME,
                          'Field with categories', self.INPUT_LAYER,
                          ParameterTableField.DATA_TYPE_ANY))

        self.addOutput(OutputTable(self.OUTPUT, 'Statistics'))
Ejemplo n.º 14
0
    def processParameterLine(self, line):
        param = None
        out = None
        line = line.replace("#", "")
        if line.lower().strip().startswith("showplots"):
            self.showPlots = True
            self.addOutput(OutputHTML(RAlgorithm.RPLOTS, "R Plots"))
            return
        if line.lower().strip().startswith("dontuserasterpackage"):
            self.useRasterPackage = False
            return
        if line.lower().strip().startswith("passfilenames"):
            self.passFileNames = True
            return
        tokens = line.split("=")
        desc = self.createDescriptiveName(tokens[0])
        if tokens[1].lower().strip() == "group":
            self.group = tokens[0]
            return
        if tokens[1].lower().strip().startswith("raster"):
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "vector":
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif tokens[1].lower().strip() == "table":
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip().startswith("multiple raster"):
            param = ParameterMultipleInput(tokens[0], desc,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == "multiple vector":
            param = ParameterMultipleInput(
                tokens[0], desc, ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith("selection"):
            options = tokens[1].strip()[len("selection"):].split(";")
            param = ParameterSelection(tokens[0], desc, options)
        elif tokens[1].lower().strip().startswith("boolean"):
            default = tokens[1].strip()[len("boolean") + 1:]
            param = ParameterBoolean(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith("number"):
            try:
                default = float(tokens[1].strip()[len("number") + 1:])
                param = ParameterNumber(tokens[0], desc, default=default)
            except:
                raise WrongScriptException("Could not load R script:" +
                                           self.descriptionFile +
                                           ".\n Problem with line \"" + line +
                                           "\"")
        elif tokens[1].lower().strip().startswith("field"):
            field = tokens[1].strip()[len("field") + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0], tokens[0], field)
        elif tokens[1].lower().strip() == "extent":
            param = ParameterExtent(tokens[0], desc)
        elif tokens[1].lower().strip() == "file":
            param = ParameterFile(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "folder":
            param = ParameterFile(tokens[0], desc, True)
        elif tokens[1].lower().strip().startswith("string"):
            default = tokens[1].strip()[len("string") + 1:]
            param = ParameterString(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith("output raster"):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith("output vector"):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith("output table"):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith("output file"):
            out = OutputFile()

        if param != None:
            self.addParameter(param)
        elif out != None:
            out.name = tokens[0]
            out.description = tokens[0]
            self.addOutput(out)
        else:
            raise WrongScriptException("Could not load R script:" +
                                       self.descriptionFile +
                                       ".\n Problem with line \"" + line +
                                       "\"")
Ejemplo n.º 15
0
    def processParameterLine(self, line):
        param = None
        out = None
        line = line.replace("#", "")
        # If the line is in the format of the text description files for normal algorithms,
        # then process it using parameter and output factories
        if '|' in line:
            self.processDescriptionParameterLine(line)
            return
        tokens = line.split("=")
        desc = self.createDescriptiveName(tokens[0])
        if tokens[1].lower().strip() == "group":
            self.group = tokens[0]
            return
        if tokens[1].lower().strip() == "name":
            self.name = tokens[0]
            return
        if tokens[1].lower().strip() == "raster":
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "vector":
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif tokens[1].lower().strip() == "table":
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "multiple raster":
            param = ParameterMultipleInput(tokens[0], desc,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == "multiple vector":
            param = ParameterMultipleInput(
                tokens[0], desc, ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith("selection"):
            options = tokens[1].strip()[len("selection"):].split(";")
            param = ParameterSelection(tokens[0], desc, options)
        elif tokens[1].lower().strip().startswith("boolean"):
            default = tokens[1].strip()[len("boolean") + 1:]
            param = ParameterBoolean(tokens[0], desc, default)
        elif tokens[1].lower().strip() == "extent":
            param = ParameterExtent(tokens[0], desc)
        elif tokens[1].lower().strip() == "file":
            param = ParameterFile(tokens[0], desc, False)
        elif tokens[1].lower().strip() == "folder":
            param = ParameterFile(tokens[0], desc, True)
        elif tokens[1].lower().strip().startswith("number"):
            default = tokens[1].strip()[len("number") + 1:]
            param = ParameterNumber(tokens[0], desc, default=default)
        elif tokens[1].lower().strip().startswith("field"):
            field = tokens[1].strip()[len("field") + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0], tokens[0], field)
        elif tokens[1].lower().strip().startswith("string"):
            default = tokens[1].strip()[len("string") + 1:]
            param = ParameterString(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith("output raster"):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith("output vector"):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith("output table"):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith("output html"):
            out = OutputHTML()
        elif tokens[1].lower().strip().startswith("output file"):
            out = OutputFile()
        elif tokens[1].lower().strip().startswith("output number"):
            out = OutputNumber()
        elif tokens[1].lower().strip().startswith("output string"):
            out = OutputString()

        if param != None:
            self.addParameter(param)
        elif out != None:
            out.name = tokens[0]
            out.description = tokens[0]
            self.addOutput(out)
        else:
            raise WrongScriptException("Could not load script:" +
                                       self.descriptionFile +
                                       ".\n Problem with line \"" + line +
                                       "\"")
Ejemplo n.º 16
0
 def defineCharacteristics(self):
     self.name = "Cloud Metrics"
     self.group = "Points"
     self.addParameter(ParameterFile(self.INPUT, "Input las layer"))
     self.addOutput(OutputTable(self.OUTPUT, "Output file with tabular metric information"))
     self.addAdvancedModifiers()
Ejemplo n.º 17
0
    def processParameterLine(self, line):
        param = None
        out = None
        line = line.replace('#', '')

        # If the line is in the format of the text description files for
        # normal algorithms, then process it using parameter and output
        # factories
        if '|' in line:
            self.processDescriptionParameterLine(line)
            return
        if line == "nomodeler":
            self.showInModeler = False
        tokens = line.split('=', 1)
        desc = self.createDescriptiveName(tokens[0])
        if tokens[1].lower().strip() == 'group':
            self.group = tokens[0]
            return
        if tokens[1].lower().strip() == 'name':
            self.name = tokens[0]
            return
        if tokens[1].lower().strip() == 'raster':
            param = ParameterRaster(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'vector':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_ANY])
        elif tokens[1].lower().strip() == 'vector point':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POINT])
        elif tokens[1].lower().strip() == 'vector line':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_LINE])
        elif tokens[1].lower().strip() == 'vector polygon':
            param = ParameterVector(tokens[0], desc,
                                    [ParameterVector.VECTOR_TYPE_POLYGON])
        elif tokens[1].lower().strip() == 'table':
            param = ParameterTable(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'multiple raster':
            param = ParameterMultipleInput(tokens[0], desc,
                                           ParameterMultipleInput.TYPE_RASTER)
            param.optional = False
        elif tokens[1].lower().strip() == 'multiple vector':
            param = ParameterMultipleInput(
                tokens[0], desc, ParameterMultipleInput.TYPE_VECTOR_ANY)
            param.optional = False
        elif tokens[1].lower().strip().startswith('selection'):
            options = tokens[1].strip()[len('selection '):].split(';')
            param = ParameterSelection(tokens[0], desc, options)
        elif tokens[1].lower().strip().startswith('boolean'):
            default = tokens[1].strip()[len('boolean') + 1:]
            param = ParameterBoolean(tokens[0], desc, default)
        elif tokens[1].lower().strip() == 'extent':
            param = ParameterExtent(tokens[0], desc)
        elif tokens[1].lower().strip() == 'file':
            param = ParameterFile(tokens[0], desc, False)
        elif tokens[1].lower().strip() == 'folder':
            param = ParameterFile(tokens[0], desc, True)
        elif tokens[1].lower().strip().startswith('number'):
            default = tokens[1].strip()[len('number') + 1:]
            param = ParameterNumber(tokens[0], desc, default=default)
        elif tokens[1].lower().strip().startswith('field'):
            field = tokens[1].strip()[len('field') + 1:]
            found = False
            for p in self.parameters:
                if p.name == field:
                    found = True
                    break
            if found:
                param = ParameterTableField(tokens[0], desc, field)
        elif tokens[1].lower().strip().startswith('string'):
            default = tokens[1].strip()[len('string') + 1:]
            param = ParameterString(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('longstring'):
            default = tokens[1].strip()[len('longstring') + 1:]
            param = ParameterString(tokens[0], desc, default, multiline=True)
        elif tokens[1].lower().strip().startswith('crs'):
            default = tokens[1].strip()[len('crs') + 1:]
            if not default:
                default = 'EPSG:4326'
            param = ParameterCrs(tokens[0], desc, default)
        elif tokens[1].lower().strip().startswith('output raster'):
            out = OutputRaster()
        elif tokens[1].lower().strip().startswith('output vector'):
            out = OutputVector()
        elif tokens[1].lower().strip().startswith('output table'):
            out = OutputTable()
        elif tokens[1].lower().strip().startswith('output html'):
            out = OutputHTML()
        elif tokens[1].lower().strip().startswith('output file'):
            out = OutputFile()
            subtokens = tokens[1].split(' ')
            if len(subtokens > 2):
                out.ext = subtokens[2]
        elif tokens[1].lower().strip().startswith('output directory'):
            out = OutputDirectory()
        elif tokens[1].lower().strip().startswith('output number'):
            out = OutputNumber()
        elif tokens[1].lower().strip().startswith('output string'):
            out = OutputString()

        if param is not None:
            self.addParameter(param)
        elif out is not None:
            out.name = tokens[0]
            out.description = desc
            self.addOutput(out)
        else:
            raise WrongScriptException(
                'Could not load script:' + self.descriptionFile
                or '' + '.\n Problem with line "' + line + '"')
Ejemplo n.º 18
0
 def processParameterLine(self, line):
     param = None
     out = None
     line = line.replace('#', '')
     if line.lower().strip().startswith('report'):
         self.report = True
         self.addOutput(OutputHTML(RAlgorithm.KNITR_REPORT, 'HTML Report'))
         return
     if line.lower().strip().startswith('showplots'):
         self.showPlots = True
         self.addOutput(OutputHTML(RAlgorithm.RPLOTS, 'R Plots'))
         return
     if line.lower().strip().startswith('dontuserasterpackage'):
         self.useRasterPackage = False
         return
     if line.lower().strip().startswith('passfilenames'):
         self.passFileNames = True
         return
     if line.lower().strip().startswith('shapefilespackage'):
         self.useShapefilesPackage = True
         return
     tokens = line.split('=')
     desc = self.createDescriptiveName(tokens[0])
     if tokens[1].lower().strip() == 'group':
         self.group = tokens[0]
         return
     if tokens[1].lower().strip().startswith('raster'):
         param = ParameterRaster(tokens[0], desc, False)
     elif tokens[1].lower().strip() == 'vector':
         param = ParameterVector(tokens[0], desc,
                                 [ParameterVector.VECTOR_TYPE_ANY])
     elif tokens[1].lower().strip() == 'table':
         param = ParameterTable(tokens[0], desc, False)
     elif tokens[1].lower().strip().startswith('multiple raster'):
         param = ParameterMultipleInput(tokens[0], desc,
                 ParameterMultipleInput.TYPE_RASTER)
         param.optional = False
     elif tokens[1].lower().strip() == 'multiple vector':
         param = ParameterMultipleInput(tokens[0], desc,
                 ParameterMultipleInput.TYPE_VECTOR_ANY)
         param.optional = False
     elif tokens[1].lower().strip().startswith('selection'):
         options = tokens[1].strip()[len('selection'):].split(';')
         param = ParameterSelection(tokens[0], desc, options)
     elif tokens[1].lower().strip().startswith('boolean'):
         default = tokens[1].strip()[len('boolean') + 1:]
         param = ParameterBoolean(tokens[0], desc, default)
     elif tokens[1].lower().strip().startswith('number'):
         try:
             default = float(tokens[1].strip()[len('number') + 1:])
             param = ParameterNumber(tokens[0], desc, default=default)
         except:
             raise WrongScriptException('Could not load R script:'
                     + self.descriptionFile + '.\n Problem with line "'
                     + line + '"')
     elif tokens[1].lower().strip().startswith('field'):
         field = tokens[1].strip()[len('field') + 1:]
         found = False
         for p in self.parameters:
             if p.name == field:
                 found = True
                 break
         if found:
             param = ParameterTableField(tokens[0], desc, field)
     elif tokens[1].lower().strip() == 'extent':
         param = ParameterExtent(tokens[0], desc)
     elif tokens[1].lower().strip() == 'file':
         param = ParameterFile(tokens[0], desc, False)
     elif tokens[1].lower().strip() == 'folder':
         param = ParameterFile(tokens[0], desc, True)
     elif tokens[1].lower().strip().startswith('string'):
         default = tokens[1].strip()[len('string') + 1:]
         param = ParameterString(tokens[0], desc, default)
     elif tokens[1].lower().strip().startswith('output raster'):
         out = OutputRaster()
     elif tokens[1].lower().strip().startswith('output vector'):
         out = OutputVector()
     elif tokens[1].lower().strip().startswith('output table'):
         out = OutputTable()
     elif tokens[1].lower().strip().startswith('output file'):
         out = OutputFile()
     elif tokens[1].lower().strip().startswith('output string'):
         out = OutputString()
         self.outputStringExist = True
         self.outputStringName = tokens[0]
     elif tokens[1].lower().strip().startswith('output number'):
         out = OutputNumber()
         self.outputNumberBool = True
         self.outputNumberName = tokens[0]
         
     if param is not None:
         self.addParameter(param)
     elif out is not None:
         out.name = tokens[0]
         out.description = tokens[0]
         self.addOutput(out)
     else:
         raise WrongScriptException('Could not load R script:'
                                    + self.descriptionFile
                                    + '.\n Problem with line "' + line + '"'
                                    )