[GRASS-SVN] r67982 - in grass-addons/grass7/raster/r.futures: r.futures.calib r.futures.pga r.futures.potential
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 29 20:19:54 PST 2016
Author: annakrat
Date: 2016-02-29 20:19:54 -0800 (Mon, 29 Feb 2016)
New Revision: 67982
Modified:
grass-addons/grass7/raster/r.futures/r.futures.calib/r.futures.calib.py
grass-addons/grass7/raster/r.futures/r.futures.pga/main.c
grass-addons/grass7/raster/r.futures/r.futures.potential/r.futures.potential.py
Log:
r.futures: reorder options in PGA; better solution for null values in Potential, add parser rules in calibration module
Modified: grass-addons/grass7/raster/r.futures/r.futures.calib/r.futures.calib.py
===================================================================
--- grass-addons/grass7/raster/r.futures/r.futures.calib/r.futures.calib.py 2016-03-01 02:45:32 UTC (rev 67981)
+++ grass-addons/grass7/raster/r.futures/r.futures.calib/r.futures.calib.py 2016-03-01 04:19:54 UTC (rev 67982)
@@ -9,7 +9,7 @@
#
# PURPOSE: FUTURES patches calibration tool
#
-# COPYRIGHT: (C) 2015 by the GRASS Development Team
+# COPYRIGHT: (C) 2016 by the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
@@ -38,7 +38,7 @@
#% type: integer
#% key: repeat
#% description: How many times is the simulation repeated
-#% required: yes
+#% required: no
#% answer: 10
#% guisection: Calibration
#%end
@@ -46,7 +46,7 @@
#% key: compactness_mean
#% type: double
#% description: Patch compactness mean to be tested
-#% required: yes
+#% required: no
#% multiple: yes
#% guisection: Calibration
#%end
@@ -54,7 +54,7 @@
#% type: double
#% key: compactness_range
#% description: Patch compactness range to be tested
-#% required: yes
+#% required: no
#% multiple: yes
#% guisection: Calibration
#%end
@@ -64,7 +64,7 @@
#% description: Patch size discount factor
#% key: discount_factor
#% multiple: yes
-#% required: yes
+#% required: no
#% guisection: Calibration
#%end
#%option
@@ -84,7 +84,7 @@
#%option G_OPT_F_OUTPUT
#% key: calibration_results
#% description: Output file with calibration results
-#% required: yes
+#% required: no
#% guisection: Calibration
#%end
#%option
@@ -97,7 +97,7 @@
#%end
#%option G_OPT_R_INPUT
#% key: development_pressure
-#% required: yes
+#% required: no
#% description: Raster map of development pressure
#% guisection: PGA
#%end
@@ -110,7 +110,7 @@
#%end
#%option G_OPT_R_INPUTS
#% key: predictors
-#% required: yes
+#% required: no
#% multiple: yes
#% description: Names of predictor variable raster maps
#% guisection: PGA
@@ -119,12 +119,12 @@
#% key: n_dev_neighbourhood
#% type: integer
#% description: Size of square used to recalculate development pressure
-#% required: yes
+#% required: no
#% guisection: PGA
#%end
#%option G_OPT_F_INPUT
#% key: devpot_params
-#% required: yes
+#% required: no
#% multiple: yes
#% label: Development potential parameters for each region
#% description: Each line should contain region ID followed by parameters. Values are separated by whitespace (spaces or tabs). First line is ignored, so it can be used for header
@@ -132,14 +132,14 @@
#%end
#%option G_OPT_F_INPUT
#% key: incentive_table
-#% required: yes
+#% required: no
#% description: File containing incentive lookup table (infill vs. sprawl)
#% guisection: PGA
#%end
#%option
#% key: num_neighbors
#% type: integer
-#% required: yes
+#% required: no
#% multiple: no
#% options: 4,8
#% answer: 4
@@ -149,7 +149,7 @@
#%option
#% key: seed_search
#% type: integer
-#% required: yes
+#% required: no
#% multiple: no
#% options: 1,2
#% answer: 2
@@ -159,7 +159,7 @@
#%option
#% key: development_pressure_approach
#% type: string
-#% required: yes
+#% required: no
#% multiple: no
#% options: occurrence,gravity,kernel
#% answer: gravity
@@ -169,7 +169,7 @@
#%option
#% key: gamma
#% type: double
-#% required: yes
+#% required: no
#% multiple: no
#% description: Influence of distance between neighboring cells
#% guisection: PGA
@@ -177,9 +177,9 @@
#%option
#% key: scaling_factor
#% type: double
-#% required: yes
+#% required: no
#% multiple: no
-#% description: Scaling factor
+#% description: Scaling factor of development pressure
#% guisection: PGA
#%end
#%option
@@ -198,12 +198,53 @@
#%end
#%option G_OPT_F_INPUT
#% key: demand
-#% required: yes
+#% required: no
#% description: Control file with number of cells to convert
#% guisection: PGA
#%end
+#%flag
+#% key: l
+#% description: Only create patch size distribution file
+#% guisection: Calibration
+#%end
+#%rules
+#% collective: demand,scaling_factor,gamma,development_pressure_approach,seed_search,num_neighbors,incentive_table,devpot_params,n_dev_neighbourhood,predictors,development_pressure,calibration_results,discount_factor,compactness_range,compactness_mean,repeat
+#% exclusive: -l,demand
+#% exclusive: -l,num_steps
+#% exclusive: -l,scaling_factor
+#% exclusive: -l,gamma
+#% exclusive: -l,development_pressure_approach
+#% exclusive: -l,seed_search
+#% exclusive: -l,num_neighbors
+#% exclusive: -l,incentive_table
+#% exclusive: -l,devpot_params
+#% exclusive: -l,n_dev_neighbourhood
+#% exclusive: -l,predictors
+#% exclusive: -l,constrain_weight
+#% exclusive: -l,development_pressure
+#% exclusive: -l,calibration_results
+#% exclusive: -l,discount_factor
+#% exclusive: -l,compactness_range
+#% exclusive: -l,compactness_mean
+#% exclusive: -l,repeat
+#% required: -l,demand
+#% required: -l,scaling_factor
+#% required: -l,gamma
+#% required: -l,development_pressure_approach
+#% required: -l,seed_search
+#% required: -l,num_neighbors
+#% required: -l,incentive_table
+#% required: -l,devpot_params
+#% required: -l,n_dev_neighbourhood
+#% required: -l,predictors
+#% required: -l,development_pressure
+#% required: -l,calibration_results
+#% required: -l,discount_factor
+#% required: -l,compactness_range
+#% required: -l,compactness_mean
+#% required: -l,repeat
+#%end
-
import sys
import os
import atexit
@@ -366,10 +407,12 @@
def main():
dev_start = options['development_start']
dev_end = options['development_end']
- repeat = int(options['repeat'])
- compactness_means = [float(each) for each in options['compactness_mean'].split(',')]
- compactness_ranges = [float(each) for each in options['compactness_range'].split(',')]
- discount_factors = [float(each) for each in options['discount_factor'].split(',')]
+ only_file = flags['l']
+ if not only_file:
+ repeat = int(options['repeat'])
+ compactness_means = [float(each) for each in options['compactness_mean'].split(',')]
+ compactness_ranges = [float(each) for each in options['compactness_range'].split(',')]
+ discount_factors = [float(each) for each in options['discount_factor'].split(',')]
patches_file = options['patch_sizes']
threshold = float(options['patch_threshold'])
# v.clean removes size <= threshold, we want to keep size == threshold
@@ -397,9 +440,12 @@
gcore.message(_("Analyzing original patches..."))
diff_development(dev_start, dev_end, options['subregions'], orig_patch_diff)
patch_analysis(orig_patch_diff, threshold, tmp_patch_vect, tmp_patch_vect2, temp_file.name)
+ if only_file:
+ write_patches_file(tmp_patch_vect, cell_size, patches_file)
+ return
+
area, perimeter = np.loadtxt(fname=temp_file.name, unpack=True)
compact = compactness(area, perimeter)
- write_patches_file(tmp_patch_vect, cell_size, patches_file)
# area histogram
area = area / cell_size
Modified: grass-addons/grass7/raster/r.futures/r.futures.pga/main.c
===================================================================
--- grass-addons/grass7/raster/r.futures/r.futures.pga/main.c 2016-03-01 02:45:32 UTC (rev 67981)
+++ grass-addons/grass7/raster/r.futures/r.futures.pga/main.c 2016-03-01 04:19:54 UTC (rev 67982)
@@ -1453,6 +1453,34 @@
_("Raster map of developed areas (=1), undeveloped (=0) and excluded (no data)");
opt.developedFile->guisection = _("Basic input");
+ opt.indexFile = G_define_standard_option(G_OPT_R_INPUT);
+ opt.indexFile->key = "subregions";
+ opt.indexFile->required = YES;
+ opt.indexFile->description = _("Raster map of subregions");
+ opt.indexFile->guisection = _("Basic input");
+
+ opt.dumpFile = G_define_standard_option(G_OPT_R_OUTPUT);
+ opt.dumpFile->key = "output";
+ opt.dumpFile->required = YES;
+ opt.dumpFile->description =
+ _("State of the development at the end of simulation");
+ opt.dumpFile->guisection = _("Output");
+
+ opt.outputSeries = G_define_standard_option(G_OPT_R_BASENAME_OUTPUT);
+ opt.outputSeries->key = "output_series";
+ opt.outputSeries->required = NO;
+ opt.outputSeries->label =
+ _("Basename for raster maps of development generated after each step");
+ opt.outputSeries->guisection = _("Output");
+
+ opt.numSteps = G_define_option();
+ opt.numSteps->key = "num_steps";
+ opt.numSteps->type = TYPE_INTEGER;
+ opt.numSteps->required = NO;
+ opt.numSteps->description =
+ _("Number of steps to be simulated");
+ opt.numSteps->guisection = _("Basic input");
+
opt.addVariableFiles = G_define_standard_option(G_OPT_R_INPUTS);
opt.addVariableFiles->key = "predictors";
opt.addVariableFiles->required = YES;
@@ -1461,14 +1489,6 @@
opt.addVariableFiles->description = _("Listed in the same order as in the development potential table");
opt.addVariableFiles->guisection = _("Potential");
- opt.controlFileAll = G_define_standard_option(G_OPT_F_INPUT);
- opt.controlFileAll->key = "demand";
- opt.controlFileAll->required = YES;
- opt.controlFileAll->description =
- _("Control file with number of cells to convert");
- opt.controlFileAll->guisection = _("Demand");
-
-
opt.devpotParamsFile = G_define_standard_option(G_OPT_F_INPUT);
opt.devpotParamsFile->key = "devpot_params";
opt.devpotParamsFile->required = YES;
@@ -1477,10 +1497,58 @@
opt.devpotParamsFile->description =
_("Each line should contain region ID followed"
" by parameters (intercepts, development pressure, other predictors)."
- " Values are separated by whitespace (spaces or tabs)."
+ " Values are separated by tabs."
" First line is ignored, so it can be used for header");
opt.devpotParamsFile->guisection = _("Potential");
+ opt.devPressureFile = G_define_standard_option(G_OPT_R_INPUT);
+ opt.devPressureFile->key = "development_pressure";
+ opt.devPressureFile->required = YES;
+ opt.devPressureFile->description =
+ _("Raster map of development pressure");
+ opt.devPressureFile->guisection = _("Development pressure");
+
+ opt.nDevNeighbourhood = G_define_option();
+ opt.nDevNeighbourhood->key = "n_dev_neighbourhood";
+ opt.nDevNeighbourhood->type = TYPE_INTEGER;
+ opt.nDevNeighbourhood->required = YES;
+ opt.nDevNeighbourhood->description =
+ _("Size of square used to recalculate development pressure");
+ opt.nDevNeighbourhood->guisection = _("Development pressure");
+
+ opt.devPressureApproach = G_define_option();
+ opt.devPressureApproach->key = "development_pressure_approach";
+ opt.devPressureApproach->type = TYPE_STRING;
+ opt.devPressureApproach->required = YES;
+ opt.devPressureApproach->options = "occurrence,gravity,kernel";
+ opt.devPressureApproach->description =
+ _("Approaches to derive development pressure");
+ opt.devPressureApproach->answer = "gravity";
+ opt.devPressureApproach->guisection = _("Development pressure");
+
+ opt.alpha = G_define_option();
+ opt.alpha->key = "gamma";
+ opt.alpha->type = TYPE_DOUBLE;
+ opt.alpha->required = YES;
+ opt.alpha->description =
+ _("Influence of distance between neighboring cells");
+ opt.alpha->guisection = _("Development pressure");
+
+ opt.scalingFactor = G_define_option();
+ opt.scalingFactor->key = "scaling_factor";
+ opt.scalingFactor->type = TYPE_DOUBLE;
+ opt.scalingFactor->required = YES;
+ opt.scalingFactor->description =
+ _("Scaling factor of development pressure");
+ opt.scalingFactor->guisection = _("Development pressure");
+
+ opt.controlFileAll = G_define_standard_option(G_OPT_F_INPUT);
+ opt.controlFileAll->key = "demand";
+ opt.controlFileAll->required = YES;
+ opt.controlFileAll->description =
+ _("Control file with number of cells to convert");
+ opt.controlFileAll->guisection = _("Demand");
+
opt.discountFactor = G_define_option();
opt.discountFactor->key = "discount_factor";
opt.discountFactor->type = TYPE_DOUBLE;
@@ -1531,61 +1599,7 @@
_("File containing list of patch sizes to use");
opt.parcelSizeFile->guisection = _("PGA");
- opt.devPressureFile = G_define_standard_option(G_OPT_R_INPUT);
- opt.devPressureFile->key = "development_pressure";
- opt.devPressureFile->required = YES;
- opt.devPressureFile->description =
- _("Raster map of development pressure");
- opt.devPressureFile->guisection = _("Development pressure");
- opt.nDevNeighbourhood = G_define_option();
- opt.nDevNeighbourhood->key = "n_dev_neighbourhood";
- opt.nDevNeighbourhood->type = TYPE_INTEGER;
- opt.nDevNeighbourhood->required = YES;
- opt.nDevNeighbourhood->description =
- _("Size of square used to recalculate development pressure");
- opt.nDevNeighbourhood->guisection = _("Development pressure");
-
- opt.devPressureApproach = G_define_option();
- opt.devPressureApproach->key = "development_pressure_approach";
- opt.devPressureApproach->type = TYPE_STRING;
- opt.devPressureApproach->required = YES;
- opt.devPressureApproach->options = "occurrence,gravity,kernel";
- opt.devPressureApproach->description =
- _("Approaches to derive development pressure");
- opt.devPressureApproach->answer = "gravity";
- opt.devPressureApproach->guisection = _("Development pressure");
-
- opt.alpha = G_define_option();
- opt.alpha->key = "gamma";
- opt.alpha->type = TYPE_DOUBLE;
- opt.alpha->required = YES;
- opt.alpha->description =
- _("Influence of distance between neighboring cells");
- opt.alpha->guisection = _("Development pressure");
-
- opt.scalingFactor = G_define_option();
- opt.scalingFactor->key = "scaling_factor";
- opt.scalingFactor->type = TYPE_DOUBLE;
- opt.scalingFactor->required = YES;
- opt.scalingFactor->description =
- _("Scaling factor");
- opt.scalingFactor->guisection = _("Development pressure");
-
- opt.indexFile = G_define_standard_option(G_OPT_R_INPUT);
- opt.indexFile->key = "subregions";
- opt.indexFile->required = YES;
- opt.indexFile->description = _("Raster map of subregions with categories starting with 1");
- opt.indexFile->guisection = _("Basic input");
-
- opt.numSteps = G_define_option();
- opt.numSteps->key = "num_steps";
- opt.numSteps->type = TYPE_INTEGER;
- opt.numSteps->required = NO;
- opt.numSteps->description =
- _("Number of steps to be simulated");
- opt.numSteps->guisection = _("Basic input");
-
opt.probLookupFile = G_define_standard_option(G_OPT_F_INPUT);
opt.probLookupFile->key = "incentive_table";
opt.probLookupFile->required = YES;
@@ -1623,19 +1637,6 @@
" generator (use when you don't want to provide the seed option)");
flg.generateSeed->guisection = _("Random numbers");
- opt.dumpFile = G_define_standard_option(G_OPT_R_OUTPUT);
- opt.dumpFile->key = "output";
- opt.dumpFile->required = YES;
- opt.dumpFile->description =
- _("State of the development at the end of simulation");
- opt.dumpFile->guisection = _("Output");
-
- opt.outputSeries = G_define_standard_option(G_OPT_R_BASENAME_OUTPUT);
- opt.outputSeries->key = "output_series";
- opt.outputSeries->required = NO;
- opt.outputSeries->label =
- _("Basename for raster maps of development generated after each step");
- opt.outputSeries->guisection = _("Output");
// TODO: add mutually exclusive?
// TODO: add flags or options to control values in series and final rasters
Modified: grass-addons/grass7/raster/r.futures/r.futures.potential/r.futures.potential.py
===================================================================
--- grass-addons/grass7/raster/r.futures/r.futures.potential/r.futures.potential.py 2016-03-01 02:45:32 UTC (rev 67981)
+++ grass-addons/grass7/raster/r.futures/r.futures.potential/r.futures.potential.py 2016-03-01 04:19:54 UTC (rev 67982)
@@ -97,7 +97,7 @@
interc <- paste("(1|", opt$level, ")")
fmla <- as.formula(paste(opt$response, " ~ ", paste(c(predictors, interc), collapse= "+")))
-model = glmer(formula=fmla, family = binomial, data=input_data, na.action = "na.omit")
+model = glmer(formula=fmla, family = binomial, data=input_data, na.action = "na.fail")
if(opt$usedredge) {
#create all possible models, always include county as the level
@@ -145,7 +145,10 @@
TMP_POT = gscript.tempfile(create=False) + '_potential.csv'
columns += [binary, level]
- gscript.run_command('v.db.select', map=vinput, columns=columns, separator='comma', file=TMP_CSV)
+ where = "{c} IS NOT NULL".format(c=columns[0])
+ for c in columns[1:]:
+ where += " AND {c} IS NOT NULL".format(c=c)
+ gscript.run_command('v.db.select', map=vinput, columns=columns, separator='comma', where=where, file=TMP_CSV)
if dredge:
gscript.info(_("Running automatic model selection ..."))
More information about the grass-commit
mailing list