Skip to content

Commit

Permalink
Merge pull request #6 from ecodiv/workinprogress
Browse files Browse the repository at this point in the history
Various small improvements / correction typo's en update email / url
  • Loading branch information
Paulo van Breugel committed Jun 8, 2019
2 parents f22297f + 2ab812c commit f5bedf0
Show file tree
Hide file tree
Showing 11 changed files with 869 additions and 131 deletions.
2 changes: 1 addition & 1 deletion grass7/display/d.vect.colbp/d.vect.colbp.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>DESCRIPTION</h2>
<h2>NOTE</h2>
<p>
This script, based on d.vect.colhist, is a quick and dirty solution
using basic matplotlib, and will need some further fine-tuning and
sing basic matplotlib, and will need some further fine-tuning and
testing.

<h2>EXAMPLE</h2>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions grass7/raster/r.meb/r.meb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# and median of MES values in B (MESb), divided by the median of
# the absolute deviations of MESb from the median of MESb (MAD)
#
# COPYRIGHT: (C) 2014-2016 by Paulo van Breugel and the GRASS Development Team
# COPYRIGHT: (C) 2014-2019 by Paulo van Breugel and the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
Expand Down Expand Up @@ -129,9 +129,9 @@
100% 50:136:189
"""

#----------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Functions
#----------------------------------------------------------------------------
# ---------------------------------------------------------------------------

# create set to store names of temporary maps to be deleted upon exit
CLEAN_RAST = []
Expand Down Expand Up @@ -258,9 +258,9 @@ def main(options, flags):
text_file.write(hist)
text_file.close()

#-------------------------------------------------------------------------
# ------------------------------------------------------------------------
# Compute MES
#-------------------------------------------------------------------------
# ------------------------------------------------------------------------

# Create temporary copy of ref layer
tmpref0 = tmpname("reb1")
Expand Down Expand Up @@ -321,9 +321,9 @@ def main(options, flags):
os.remove(tmprule)
ipi.append(tmpf3)

#-----------------------------------------------------------------------
# ----------------------------------------------------------------------
# Calculate EB statistics
#-----------------------------------------------------------------------
# ----------------------------------------------------------------------

# EB MES
if flag_m:
Expand Down Expand Up @@ -376,7 +376,7 @@ def main(options, flags):
if not out:
CLEAN_RAST.append(nmn)
else:
# Write layer metadata
# Write layer metadata
gs.run_command("r.support", map=nmn,
title="Multivariate environmental similarity (MES)",
units="0-100 (relative score",
Expand Down
2 changes: 1 addition & 1 deletion grass7/raster/r.mess/r.mess.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ <h2>REFERENCES</h2>

<h2>AUTHOR</h2>

Paulo van Breugel, paulo at ecodiv.org
Paulo van Breugel, paulo at ecodiv.earth


<p><i>Last changed: $Date$</i>
20 changes: 10 additions & 10 deletions grass7/raster/r.mess/r.mess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
########################################################################
#
# MODULE: r.mess
# AUTHOR(S): Paulo van Breugel <p.vanbreugel AT gmail.com>
# AUTHOR(S): Paulo van Breugel <paulo ecodiv earth>
# PURPOSE: Calculate the multivariate environmental similarity
# surface (MESS) as proposed by Elith et al., 2010,
# Methods in Ecology & Evolution, 1(330–342).
Expand Down Expand Up @@ -201,8 +201,8 @@ def main(options, flags):
reftype['max'] != 1):
gs.fatal(_("The ref_rast map must be a binary raster,"
" i.e. it should contain only values 0 and 1 or 1 only"
" (now the minimum is %d and maximum is %d)")
% (reftype['min'], reftype['max']))
" (now the minimum is {} and maximum is {})".
format(reftype['min'], reftype['max'])))

# old environmental layers & variable names
REF = options['env']
Expand All @@ -222,8 +222,8 @@ def main(options, flags):
raster_exists(PROJ)
if len(PROJ) != len(REF) and len(PROJ) != 0:
gs.fatal(_("The number of reference and predictor variables"
" should be the same. You provided %d reference and %d"
" projection variables") % (len(REF), len(PROJ)))
" should be the same. You provided {} reference and {}"
" projection variables".format(len(REF), len(PROJ))))

# output layers
opl = options['output']
Expand Down Expand Up @@ -368,7 +368,7 @@ def main(options, flags):
gs.run_command("r.mask", quiet=True, flags="r")

# Upload raster values and get value in python as frequency table
sql1 = "SELECT cat FROM %s" % tmpf0
sql1 = "SELECT cat FROM {}".format(str(tmpf0))
cn = len(np.hstack(db.db_select(sql=sql1)))
for m in xrange(len(REF)):

Expand All @@ -382,12 +382,12 @@ def main(options, flags):
mid = str(m)
laytype = gs.raster_info(REF[m])['datatype']
if laytype == 'CELL':
columns = "envvar_%s integer" % mid
columns = "envvar_{} integer".format(str(mid))
else:
columns = "envvar_%s double precision" % mid
gs.run_command("v.db.addcolumn", map=tmpf0, columns=columns,
quiet=True)
sql2 = "UPDATE %s SET envvar_%s = NULL" % (tmpf0, mid)
sql2 = "UPDATE {} SET envvar_{} = NULL".format(str(tmpf0), str(mid))
gs.run_command("db.execute", sql=sql2, quiet=True)
coln = "envvar_%s" % mid
gs.run_command("v.what.rast", quiet=True, map=tmpf0,
Expand All @@ -402,9 +402,9 @@ def main(options, flags):

# Check for point without values
if b < cn:
gs.info(_("Please note that there were %d points without "
gs.info(_("Please note that there were {} points without "
"value. This is probably because they are outside "
"the computational region or mask") % (cn - b))
"the computational region or mask".format((cn - b))))

# Set region to env_proj layers (if different from env) and remove
# mask (if set above)
Expand Down
115 changes: 115 additions & 0 deletions grass7/raster/r.mess/tests/r_mess_tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#-----------------------------------------------------------------------
# Test 1 - same area, without mask
#-----------------------------------------------------------------------
g.remove type=raster pattern=Ex_* -f
g.region raster=bio1
r.mess2 env=bio1,bio12,bio15 \
output=Ex_01
r.mess2 -c -k -m -n env=bio1,bio12,bio15 \
ref_rast=ppa \
output=Ex_02
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
env_proj=IPSL_bio1,IPSL_bio12,IPSL_bio15 \
output=Ex_03
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
ref_vect=sample_locations@mess \
output=Ex_04
r.mess2 -c -k -m -n env=bio1,bio12,bio15 \
env_proj=IPSL_bio1,IPSL_bio12,IPSL_bio15 \
ref_vect=sample_locations@mess \
output=Ex_05

#-----------------------------------------------------------------------
# Test 2 - same area, with mask
#-----------------------------------------------------------------------
g.remove type=raster pattern=Ex_* -f
g.region raster=bio1
r.mask raster=pnvmap
r.mess2 env=bio1,bio12,bio15 \
output=Ex_06
r.mask raster=pnvmap
r.mess2 -c -k -m -n env=bio1,bio12,bio15 \
ref_rast=ppa \
output=Ex_07
r.mask raster=pnvmap
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
env_proj=IPSL_bio1,IPSL_bio12,IPSL_bio15 \
output=Ex_08
r.mask raster=pnvmap
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
ref_vect=sample_locations@mess \
output=Ex_09
r.mask raster=pnvmap
r.mess2 -c -k -m -n env=bio1,bio12,bio15 \
env_proj=IPSL_bio1,IPSL_bio12,IPSL_bio15 \
ref_vect=sample_locations@mess \
output=Ex_10

#-----------------------------------------------------------------------
# Test 3 - different reference and projection area, without mask
#-----------------------------------------------------------------------
g.remove type=raster pattern=Ex_* -f
r.mask -r
g.region raster=bio1
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
env_proj=bio1_Eth,bio12_Eth,bio15_Eth \
output=Ex_11
g.region raster=bio1
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
env_proj=bio1_Eth,bio12_Eth,bio15_Eth \
ref_rast=ppa \
output=Ex_12
g.region raster=bio1
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
env_proj=bio1_Eth,bio12_Eth,bio15_Eth \
ref_vect=sample_locations@mess \
output=Ex_13

# Test 3 - different reference and projection area, with mask
#-----------------------------------------------------------------------
g.remove type=raster pattern=Ex_* -f
g.region raster=bio1
r.mask raster=pnvmap
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
env_proj=bio1_Eth,bio12_Eth,bio15_Eth \
output=Ex_14
g.region raster=bio1
r.mask raster=pnvmap
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
env_proj=bio1_Eth,bio12_Eth,bio15_Eth \
ref_rast=ppa \
output=Ex_15
g.region raster=bio1
r.mask raster=pnvmap
r.mess2 -c -k -m -n \
env=bio1,bio12,bio15 \
env_proj=bio1_Eth,bio12_Eth,bio15_Eth \
ref_vect=sample_locations@mess \
output=Ex_16

# Test 4 - Compare tests that should give the same results
#-----------------------------------------------------------------------
g.region raster=bio1
r.mask -r
r.mess2 -c -k -m -n env=bio1,bio12,bio15 \
ref_rast=ppa \
output=Ex_02

r.mask raster=ppa
r.mess2 -c -k -m -n env=bio1,bio12,bio15 output=Ex_17







7 changes: 3 additions & 4 deletions grass7/raster/r.niche.similarity/r.niche.similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
########################################################################
#
# MODULE: r.niche.similarity
# AUTHOR(S): Paulo van Breugel <p.vanbreugel AT gmail.com>
# AUTHOR(S): Paulo van Breugel <paulo ecodiv earth>
# PURPOSE: Compute degree of niche overlap using the statistics D
# and I (as proposed by Warren et al., 2008) based on
# Schoeners D (Schoener, 1968) and Hellinger Distances
# (van der Vaart, 1998)
#
# COPYRIGHT: (C) 2015 Paulo van Breugel
# http://ecodiv.org
# http://pvanb.wordpress.com/
# COPYRIGHT: (c) 2015-2019 Paulo van Breugel and GRASS Development Team
# http://ecodiv.earth
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
Expand Down
4 changes: 2 additions & 2 deletions grass7/raster/r.out.legend/r.out.legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ def main():
d_legend = Module("d.legend", flags=flag, raster=inmap, font=font,
at=at, fontsize=fz, labelnum=labelnum, run_=False)
if vr:
val_range = list(map(float, vr.split(',')))
val_range = map(float, vr.split(','))
d_legend.inputs.range = val_range
if labval:
label_values = list(map(float, labval.split(',')))
label_values = map(float, labval.split(','))
d_legend.inputs.label_values = label_values
if labstep:
label_step = float(labstep)
Expand Down

0 comments on commit f5bedf0

Please sign in to comment.