def processAlgorithm(self, progress): if system.isWindows(): path = CircuitscapeUtils.circuitscapePath() if path == '': raise GeoAlgorithmExecutionException( 'Circuitscape folder is not configured.\nPlease ' 'configure it before running Circuitscape algorithms.') resistance = self.getParameterValue(self.RESISTANCE_MAP) useConductance = str(not self.getParameterValue(self.IS_CONDUCTANCES)) currentSources = self.getParameterValue(self.CURRENT_SOURCE) groundPoints = self.getParameterValue(self.GROUND_POINT) gpConductance = str(not self.getParameterValue(self.GP_CONDUCTANCES)) writeCurrent = str(self.getParameterValue(self.WRITE_CURRENT_MAP)) writeVoltage = str(self.getParameterValue(self.WRITE_VOLTAGE_MAP)) # advanced parameters mode = self.MODES_DICT[self.getParameterValue(self.MODE)] unitCurrents = str(self.getParameterValue(self.UNIT_CURRENTS)) directConnections = str(self.getParameterValue( self.DIRECT_CONNECTIONS)) mask = self.getParameterValue(self.MASK) shortCircuit = self.getParameterValue(self.SHORT_CIRCUIT) baseName = self.getParameterValue(self.BASENAME) directory = self.getOutputValue(self.DIRECTORY) progress.setInfo('basename: %s' % baseName) progress.setInfo('directory: %s' % directory) basePath = os.path.join(directory, baseName) iniPath = CircuitscapeUtils.writeConfiguration() cfg = ConfigParser.SafeConfigParser() cfg.read(iniPath) commands = self.prepareInputs() # set parameters cfg.set('Circuitscape mode', 'scenario', 'advanced') cfg.set('Habitat raster or graph', 'habitat_map_is_resistances', useConductance) if resistance in self.exportedLayers.keys(): resistance = self.exportedLayers[resistance] cfg.set('Habitat raster or graph', 'habitat_file', resistance) if currentSources in self.exportedLayers.keys(): currentSources = self.exportedLayers[currentSources] cfg.set('Options for advanced mode', 'source_file', currentSources) if groundPoints in self.exportedLayers.keys(): groundPoints = self.exportedLayers[groundPoints] cfg.set('Options for advanced mode', 'ground_file', groundPoints) cfg.set('Options for advanced mode', 'ground_file_is_resistances', gpConductance) cfg.set('Options for advanced mode', 'remove_src_or_gnd', unitCurrents) cfg.set('Options for advanced mode', 'use_direct_grounds', directConnections) if mask is not None: if mask in self.exportedLayers.keys(): mask = self.exportedLayers[mask] cfg.set('Mask file', 'mask_file', mask) cfg.set('Mask file', 'use_mask', 'True') if shortCircuit is not None: if shortCircuit in self.exportedLayers.keys(): shortCircuit = self.exportedLayers[shortCircuit] cfg.set('Short circuit regions (aka polygons)', 'polygon_file', shortCircuit) cfg.set('Short circuit regions (aka polygons)', 'use_polygons', 'True') cfg.set('Output options', 'write_cur_maps', writeCurrent) cfg.set('Output options', 'write_volt_maps', writeVoltage) cfg.set('Output options', 'output_file', basePath) # write configuration back to file with open(iniPath, 'wb') as f: cfg.write(f) if system.isWindows(): commands.append('"' + os.path.join(path, 'cs_run.exe') + '" ' + iniPath) else: commands.append('csrun.py ' + iniPath) CircuitscapeUtils.createBatchJobFileFromCommands(commands) loglines = [] loglines.append('Circuitscape execution commands') for line in commands: progress.setCommand(line) loglines.append(line) if ProcessingConfig.getSetting(CircuitscapeUtils.LOG_COMMANDS): ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines) CircuitscapeUtils.executeCircuitscape(commands, progress)
def processAlgorithm(self, progress): if system.isWindows(): path = CircuitscapeUtils.circuitscapePath() if path == '': raise GeoAlgorithmExecutionException( 'Circuitscape folder is not configured.\nPlease ' 'configure it before running Circuitscape algorithms.') resistance = self.getParameterValue(self.RESISTANCE_MAP) useConductance = str(not self.getParameterValue(self.IS_CONDUCTANCES)) focal = self.getParameterValue(self.FOCAL_NODE) writeCurrent = str(self.getParameterValue(self.WRITE_CURRENT_MAP)) writeVoltage = str(self.getParameterValue(self.WRITE_VOLTAGE_MAP)) # advanced parameters mask = self.getParameterValue(self.MASK) shortCircuit = self.getParameterValue(self.SHORT_CIRCUIT) focalPairs = self.getParameterValue(self.EXCLUDE_INCLUDE) lowMemory = str(self.getParameterValue(self.LOW_MEMORY)) baseName = self.getParameterValue(self.BASENAME) directory = self.getOutputValue(self.DIRECTORY) progress.setInfo('basename: %s' % baseName) progress.setInfo('directory: %s' % directory) basePath = os.path.join(directory, baseName) iniPath = CircuitscapeUtils.writeConfiguration() cfg = ConfigParser.SafeConfigParser() cfg.read(iniPath) commands = self.prepareInputs() # set parameters cfg.set('Circuitscape mode', 'scenario', 'pairwise') cfg.set('Habitat raster or graph', 'habitat_map_is_resistances', useConductance) if resistance in self.exportedLayers.keys(): resistance = self.exportedLayers[resistance] cfg.set('Habitat raster or graph', 'habitat_file', resistance) if focal in self.exportedLayers.keys(): focal = self.exportedLayers[focal] cfg.set('Options for pairwise and one-to-all and all-to-one modes', 'point_file', focal) if focalPairs is not None: cfg.set('Options for pairwise and one-to-all and all-to-one modes', 'included_pairs_file', focalPairs) cfg.set('Options for pairwise and one-to-all and all-to-one modes', 'use_included_pairs', 'True') if mask is not None: if mask in self.exportedLayers.keys(): mask = self.exportedLayers[mask] cfg.set('Mask file', 'mask_file', mask) cfg.set('Mask file', 'use_mask', 'True') if shortCircuit is not None: if shortCircuit in self.exportedLayers.keys(): shortCircuit = self.exportedLayers[shortCircuit] cfg.set('Short circuit regions (aka polygons)', 'polygon_file', shortCircuit) cfg.set('Short circuit regions (aka polygons)', 'use_polygons', 'True') cfg.set('Calculation options', 'low_memory_mode', lowMemory) cfg.set('Output options', 'write_cur_maps', writeCurrent) cfg.set('Output options', 'write_volt_maps', writeVoltage) cfg.set('Output options', 'output_file', basePath) # write configuration back to file with open(iniPath, 'wb') as f: cfg.write(f) if system.isWindows(): commands.append('"' + os.path.join(path, 'cs_run.exe') + '" ' + iniPath) else: commands.append('csrun.py ' + iniPath) CircuitscapeUtils.createBatchJobFileFromCommands(commands) loglines = [] loglines.append('Circuitscape execution commands') for line in commands: progress.setCommand(line) loglines.append(line) if ProcessingConfig.getSetting(CircuitscapeUtils.LOG_COMMANDS): ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines) CircuitscapeUtils.executeCircuitscape(commands, progress)
def processAlgorithm(self, progress): if system.isWindows(): path = CircuitscapeUtils.circuitscapePath() if path == '': raise GeoAlgorithmExecutionException( 'Circuitscape folder is not configured.\nPlease ' 'configure it before running Circuitscape algorithms.') resistance = self.getParameterValue(self.RESISTANCE_MAP) useConductance = str(not self.getParameterValue(self.IS_CONDUCTANCES)) focal = self.getParameterValue(self.FOCAL_NODE) writeCurrent = str(self.getParameterValue(self.WRITE_CURRENT_MAP)) writeVoltage = str(self.getParameterValue(self.WRITE_VOLTAGE_MAP)) # advanced parameters mask = self.getParameterValue(self.MASK) shortCircuit = self.getParameterValue(self.SHORT_CIRCUIT) focalPairs = self.getParameterValue(self.EXCLUDE_INCLUDE) lowMemory = str(self.getParameterValue(self.LOW_MEMORY)) baseName = self.getParameterValue(self.BASENAME) directory = self.getOutputValue(self.DIRECTORY) progress.setInfo('basename: %s' % baseName) progress.setInfo('directory: %s' % directory) basePath = os.path.join(directory, baseName) iniPath = CircuitscapeUtils.writeConfiguration() cfg = ConfigParser.SafeConfigParser() cfg.read(iniPath) commands = self.prepareInputs() # set parameters cfg.set('Circuitscape mode', 'scenario', 'pairwise') cfg.set('Habitat raster or graph', 'habitat_map_is_resistances', useConductance) if resistance in self.exportedLayers.keys(): resistance = self.exportedLayers[resistance] cfg.set('Habitat raster or graph', 'habitat_file', resistance) if focal in self.exportedLayers.keys(): focal = self.exportedLayers[focal] cfg.set('Options for pairwise and one-to-all and all-to-one modes', 'point_file', focal) if focalPairs is not None: cfg.set('Options for pairwise and one-to-all and all-to-one modes', 'included_pairs_file', focalPairs) cfg.set('Options for pairwise and one-to-all and all-to-one modes', 'use_included_pairs', 'True') if mask is not None: if mask in self.exportedLayers.keys(): mask = self.exportedLayers[mask] cfg.set('Mask file', 'mask_file', mask) cfg.set('Mask file', 'use_mask', 'True') if shortCircuit is not None: if shortCircuit in self.exportedLayers.keys(): shortCircuit = self.exportedLayers[shortCircuit] cfg.set('Short circuit regions (aka polygons)', 'polygon_file', shortCircuit) cfg.set('Short circuit regions (aka polygons)', 'use_polygons', 'True') cfg.set('Calculation options', 'low_memory_mode', lowMemory) cfg.set('Output options', 'write_cur_maps', writeCurrent) cfg.set('Output options', 'write_volt_maps', writeVoltage) cfg.set('Output options', 'output_file', basePath) # write configuration back to file with open(iniPath, 'wb') as f: cfg.write(f) if system.isWindows(): commands.append( '"' + os.path.join(path, 'cs_run.exe') + '" ' + iniPath) else: commands.append('csrun.py ' + iniPath) CircuitscapeUtils.createBatchJobFileFromCommands(commands) loglines = [] loglines.append('Circuitscape execution commands') for line in commands: progress.setCommand(line) loglines.append(line) if ProcessingConfig.getSetting(CircuitscapeUtils.LOG_COMMANDS): ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines) CircuitscapeUtils.executeCircuitscape(commands, progress)
def processAlgorithm(self, progress): if system.isWindows(): path = CircuitscapeUtils.circuitscapePath() if path == '': raise GeoAlgorithmExecutionException( 'Circuitscape folder is not configured.\nPlease ' 'configure it before running Circuitscape algorithms.') resistance = self.getParameterValue(self.RESISTANCE_MAP) useConductance = str(not self.getParameterValue(self.IS_CONDUCTANCES)) currentSources = self.getParameterValue(self.CURRENT_SOURCE) groundPoints = self.getParameterValue(self.GROUND_POINT) gpConductance = str(not self.getParameterValue(self.GP_CONDUCTANCES)) writeCurrent = str(self.getParameterValue(self.WRITE_CURRENT_MAP)) writeVoltage = str(self.getParameterValue(self.WRITE_VOLTAGE_MAP)) # advanced parameters mode = self.MODES_DICT[self.getParameterValue(self.MODE)] unitCurrents = str(self.getParameterValue(self.UNIT_CURRENTS)) directConnections = str( self.getParameterValue(self.DIRECT_CONNECTIONS)) mask = self.getParameterValue(self.MASK) shortCircuit = self.getParameterValue(self.SHORT_CIRCUIT) baseName = self.getParameterValue(self.BASENAME) directory = self.getOutputValue(self.DIRECTORY) progress.setInfo('basename: %s' % baseName) progress.setInfo('directory: %s' % directory) basePath = os.path.join(directory, baseName) iniPath = CircuitscapeUtils.writeConfiguration() cfg = ConfigParser.SafeConfigParser() cfg.read(iniPath) commands = self.prepareInputs() # set parameters cfg.set('Circuitscape mode', 'scenario', 'advanced') cfg.set('Habitat raster or graph', 'habitat_map_is_resistances', useConductance) if resistance in self.exportedLayers.keys(): resistance = self.exportedLayers[resistance] cfg.set('Habitat raster or graph', 'habitat_file', resistance) if currentSources in self.exportedLayers.keys(): currentSources = self.exportedLayers[currentSources] cfg.set('Options for advanced mode', 'source_file', currentSources) if groundPoints in self.exportedLayers.keys(): groundPoints = self.exportedLayers[groundPoints] cfg.set('Options for advanced mode', 'ground_file', groundPoints) cfg.set('Options for advanced mode', 'ground_file_is_resistances', gpConductance) cfg.set('Options for advanced mode', 'remove_src_or_gnd', unitCurrents) cfg.set('Options for advanced mode', 'use_direct_grounds', directConnections) if mask is not None: if mask in self.exportedLayers.keys(): mask = self.exportedLayers[mask] cfg.set('Mask file', 'mask_file', mask) cfg.set('Mask file', 'use_mask', 'True') if shortCircuit is not None: if shortCircuit in self.exportedLayers.keys(): shortCircuit = self.exportedLayers[shortCircuit] cfg.set('Short circuit regions (aka polygons)', 'polygon_file', shortCircuit) cfg.set('Short circuit regions (aka polygons)', 'use_polygons', 'True') cfg.set('Output options', 'write_cur_maps', writeCurrent) cfg.set('Output options', 'write_volt_maps', writeVoltage) cfg.set('Output options', 'output_file', basePath) # write configuration back to file with open(iniPath, 'wb') as f: cfg.write(f) if system.isWindows(): commands.append( '"' + os.path.join(path, 'cs_run.exe') + '" ' + iniPath) else: commands.append('csrun.py ' + iniPath) CircuitscapeUtils.createBatchJobFileFromCommands(commands) loglines = [] loglines.append('Circuitscape execution commands') for line in commands: progress.setCommand(line) loglines.append(line) if ProcessingConfig.getSetting(CircuitscapeUtils.LOG_COMMANDS): ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines) CircuitscapeUtils.executeCircuitscape(commands, progress)