[GRASS-SVN] r64394 - grass-addons/grass7/raster/r.fidimo

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Feb 2 04:23:13 PST 2015


Author: jradinger
Date: 2015-02-02 04:23:13 -0800 (Mon, 02 Feb 2015)
New Revision: 64394

Modified:
   grass-addons/grass7/raster/r.fidimo/r.fidimo.py
Log:
Introduction of two seeds, one for selecting dispersal parameters (e.g. a random sigma_value within the CI range) and one for the multinomial realisation step

Modified: grass-addons/grass7/raster/r.fidimo/r.fidimo.py
===================================================================
--- grass-addons/grass7/raster/r.fidimo/r.fidimo.py	2015-02-02 08:13:59 UTC (rev 64393)
+++ grass-addons/grass7/raster/r.fidimo/r.fidimo.py	2015-02-02 12:23:13 UTC (rev 64394)
@@ -149,14 +149,22 @@
 #% guisection: Optional
 #%End
 #%Option
-#% key: seed
+#% key: seed1
 #% type: integer
 #% required: no
 #% multiple: no
-#% description: fixed seed for generating dispersal parameters and for multinomial realisation step
+#% description: fixed seed for generating dispersal parameters
 #% guisection: Optional
 #%End
 #%Option
+#% key: seed2
+#% type: integer
+#% required: no
+#% multiple: no
+#% description: fixed seed for multinomial realisation step
+#% guisection: Optional
+#%End
+#%Option
 #% key: output
 #% type: string
 #% gisprompt: new
@@ -175,7 +183,7 @@
 #% key_desc: name
 #% description: Statistical Intervals
 #% guisection: Output
-#% options:no,Confidence Interval,Prediction Interval
+#% options:no,Confidence Interval,Prediction Interval,Random Value within Confidence Interval
 #% answer:no
 #%end
 
@@ -188,6 +196,7 @@
 import sqlite3
 import math #for function sqrt()
 import csv
+import random
 
 # import required grass modules
 import grass.script as grass
@@ -326,8 +335,8 @@
 
 	##### Calculating 'fishmove' depending on species or L & AR
 	#Set fixed seed if specified
-	if options['seed']:
-		seed = ",seed="+str(options['seed'])
+	if options['seed1']:
+		seed = ",seed="+str(options['seed1'])
 	else:
 		seed = ""
 
@@ -648,7 +657,7 @@
 	
 	########### Looping over nrun, over segements, over source points ##########
 	
-	if str(options['statistical_interval']) == "no":
+	if str(options['statistical_interval']) == ("no" or "Random Value within Confidence Interval"):
 		nrun = ['fit']
 	else:
 		nrun = ['fit','lwr','upr']
@@ -711,9 +720,21 @@
 				SO = 'SO='+str(Strahler)
 				grass.debug(_("This is i:"+str(i)))
 				grass.debug(_("This is "+str(SO)))
-				sigma_stat = fishmove.rx(i,'sigma_stat',1,1,SO,1)
-				sigma_mob = fishmove.rx(i,'sigma_mob',1,1,SO,1)
+				
+				#if Random Value within Confidence Interval than select a sigma value that is within the CI assuming a normal distribution of sigma within the CI
+				if str(options['statistical_interval']) == "Random Value within Confidence Interval":
+					random.seed(seed=int(options['seed1']))
+					sigma_stat = random.gauss(mu=fishmove.rx("fit",'sigma_stat',1,1,SO,1)[0],
+							sigma=(fishmove.rx("upr",'sigma_stat',1,1,SO,1)[0]-fishmove.rx("lwr",'sigma_stat',1,1,SO,1)[0])/4)
+					random.seed(seed=int(options['seed1']))
+					sigma_mob = random.gauss(mu=fishmove.rx("fit",'sigma_mob',1,1,SO,1)[0],
+							sigma=(fishmove.rx("upr",'sigma_mob',1,1,SO,1)[0]-fishmove.rx("lwr",'sigma_mob',1,1,SO,1)[0])/4)
+				else:
+					sigma_stat = fishmove.rx(i,'sigma_stat',1,1,SO,1)
+					sigma_mob = fishmove.rx(i,'sigma_mob',1,1,SO,1)
 
+					
+
 				grass.debug(_("Dispersal parameters: prob_scalar="+str(prob_scalar)+", sigma_stat="+str(sigma_stat)+", sigma_mob="+str(sigma_mob)+", p="+str(p)))		
 
 				# Getting maximum distance (cutting distance) based on truncation criterion	  
@@ -980,8 +1001,8 @@
 
 
 					RealisedDensity = garray.array()
-					if options['seed']:
-						numpy.random.seed(seed=int(options['seed']))
+					if options['seed2']:
+						numpy.random.seed(seed=int(options['seed2']))
 					RealisedDensity[...] = numpy.random.multinomial(n_fish, (CorrectedDensity/numpy.sum(CorrectedDensity)).flat, size=1).reshape(CorrectedDensity.shape)
 										
 					RealisedDensity.write("realised_density_"+str(cat))



More information about the grass-commit mailing list