<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";
        mso-fareast-language:EN-ZA;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-ZA link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Dear Vaclav,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I did a quick manual test to see if the results were correct for a few 5x5 windows and yes, everything appears 100%:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'># Example data from one 5x5 window<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>test1 = c(572,617,661,638,616,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>          662,617,593,638,616,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>          662,639,572,661,616,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>          662,662,639,662,616,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>          594,572,594,639,593)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'># Calculate info needed for diversity indices<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>freq1 = as.data.frame(table(test1)) # Calculate frequency table<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>S = length(unique(test1)) # Total number of species (S) <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>N = length(test1) # Total number of individuals (N)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>ln.S = log(S) #Natural log of species (ln S)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>ln.N = log(N) # Natural log of individuals (ln N)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Pi = freq1$Freq/N # Proportion of individuals that belong to each species<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Pi2 = (Pi ^ 2)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>ln.pi = log(Pi)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>pi.ln.pi = Pi * ln.pi<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>pi.ln.pi2 = (ln.pi^2)*Pi<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'># Calculate different diversity indices<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>(M = (S-1)/ln.N) # Margalef's index (M) <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>(i.Di = 1/sum(Pi2)) # Simpson's index [Inverse] (i.Di)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>(i.Dc = 1 - (sum(Pi2))) # Simpson's index [Complement] (i.Dc) * This one calculated with r.diversity<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>(H = sum(pi.ln.pi)*-1) # Shannon-Wiener index (H') <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>(J = H/ln.S) # Pielou's index (J) <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks again<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Cheers<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Sandra<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Vaclav Petras [<a href="mailto:wenzeslaus@gmail.com">mailto:wenzeslaus@gmail.com</a>] <br><b>Sent:</b> 18 September 2014 02:46 AM<br><b>To:</b> Sandra MacFadyen<br><b>Cc:</b> Markus Neteler; GRASS user list; Duccio Rocchini; Luca Delucchi<br><b>Subject:</b> Re: [GRASS-user] Solved: execGRASS("r.diversity") Done. No rasters created (Large rasters)<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Wed, Sep 17, 2014 at 7:40 PM, Sandra MacFadyen <<a href="mailto:sandramf@live.co.za" target="_blank">sandramf@live.co.za</a>> wrote:<o:p></o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>Dear Markus,<br><br>Excellent! Thanks to everyone for their help.<br>I tested r.diversity in the new revision (61840) on a raster with 12933032 cells and it took under 3 minutes to complete r.li.simpson, r.li.shannon, r.li.pielou and r.li.renyi outputs.<br>Amazing :)<br><br>> execGRASS("r.diversity",flags="overwrite", parameters=list(input="flow", prefix="flow_div", alpha=0.5, size=3))<br>> r.li.simpson complete. Raster map <flow_div_simpson_size_3.0> created.<br>> r.li.shannon complete. Raster map <flow_div_shannon_size_3.0> created.<br>> r.li.pielou complete. Raster map <flow_div_pielou_size_3.0> created.<br>> r.li.renyi complete. Raster map <flow_div_renyi_size_3.0_alpha_0.5><br>> created.<br>> Done.<br><br>Thanks again and keep well.<o:p></o:p></p><div><p class=MsoNormal>Good to hear that. Can you say if the results are correct? I computed difference of one map before and after and it was OK. But it would be great to have more tests. Let's start with: does the result make sense?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Vaclav<br> <o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><p class=MsoNormal>Cheers<br>Sandra<br><br>-----Original Message-----<br>From: <a href="mailto:neteler.osgeo@gmail.com">neteler.osgeo@gmail.com</a> [mailto:<a href="mailto:neteler.osgeo@gmail.com">neteler.osgeo@gmail.com</a>] On Behalf Of Markus Neteler<br>Sent: 06 September 2014 05:15 AM<br>To: Sandra MacFadyen<br>Cc: GRASS user list; Duccio Rocchini; Luca Delucchi<br>Subject: Re: [GRASS-user] execGRASS("r.diversity") Done. No rasters created (Large rasters)<br><br>Dear Sandra,<br><br>On Fri, Jun 20, 2014 at 7:49 AM, Markus Neteler <<a href="mailto:neteler@osgeo.org">neteler@osgeo.org</a>> wrote:<br>> On Sat, Jun 14, 2014 at 9:21 AM, Sandra MacFadyen <<a href="mailto:sandramf@live.co.za">sandramf@live.co.za</a>> wrote:<br>>> I am using r.diversity (GRASS GIS 7.0.0svn build 60785 win32) through<br>>> R (R version 3.0.2 win32) on Windows 7 64bit.<br>...<br>>> However, when running the same code on a larger image (cells=6746328)<br>>> from my own location, although it reports Done, no rasters are<br>>> created. If I subset the image<br>>> (cells=1632830) and run it again its works (see # sub2Kruger # code and results below).<br>>> So I'm guessing it is a memory issue?<br>...<br>> ... it consumes a lot of memory... will check on a bigger machine,<br>> perhaps a memory leak.<br><br>The assumption turned out to be right and I think we got it today!<br><br>Vaclav Petras checked it and discovered an "unfortunate" memory allocation which he fixed in r.li.* in revision <a href="http://trac.osgeo.org/grass/changeset/61812" target="_blank">http://trac.osgeo.org/grass/changeset/61812</a> ("<a href="http://r.li" target="_blank">r.li</a>: fix memory handling (memory leak in avl_to_array function))".<br><br>Now <a href="http://r.li" target="_blank">r.li</a> has become very fast, on my laptop:<br><br>GRASS 7.1.svn (nc_spm_08_grass7):~ >  g.region -p rast=lsat5_1987_10 res=10 -a ...<br>rows:       1355<br>cols:       1503<br>cells:      2036565<br><br>GRASS 7.1.svn (nc_spm_08_grass7):~ > time -p r.li.simpson --o input=lsat5_1987_10@landsat conf=conf_diversity_5.0<br>output=lsat5_1987_div__simpson_size_5.0<br>r.li.simpson complete. Raster map <lsat5_1987_div__simpson_size_5.0><br>created.<br>--> 29.32 seconds<br><br>or with a simulated higher resolution:<br><br>GRASS 7.1.svn (nc_spm_08_grass7):~ >  g.region -p rast=lsat5_1987_10<br>res=5 -aprojection: 99 (Lambert Conformal Conic) ...<br>rows:       2708<br>cols:       3005<br>cells:      8137540<br><br>GRASS 7.1.svn (nc_spm_08_grass7):~ > time -p r.li.simpson --o input=lsat5_1987_10@landsat conf=conf_diversity_5.0<br>output=lsat5_1987_div__simpson_size_5.0<br>r.li.simpson complete. Raster map <lsat5_1987_div__simpson_size_5.0><br>created.<br>--> 227.37 seconds (used to be > 2 hours)<br><br>So, to grab this improvement for Windows, grab the version from here:<br><a href="http://wingrass.fsv.cvut.cz/grass71/" target="_blank">http://wingrass.fsv.cvut.cz/grass71/</a><br><br>(or via OSGeo4W installer). Be sure that the revision is at least<br>r61812 which is indicated in the file name.<br><br>Please let us know if all works to avoid that the change has any negative impact.<br>Tests here did not show any changes in the output except for the speed improvement and solved memory leak.<br><br>Subsequently also r.diversity should behave now.<br><br>I'll backport it to GRASS 7.0 release branch after some testing.<br><br>Markus<br><br>_______________________________________________<br>grass-user mailing list<br><a href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a><br><a href="http://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/grass-user</a><o:p></o:p></p></blockquote></div><p class=MsoNormal><o:p> </o:p></p></div></div></div></body></html>