<div dir="auto"><div data-smartmail="gmail_signature" dir="auto"><br></div><br><div class="gmail_quote" dir="auto"><div dir="ltr">On Fri, Feb 15, 2019, 06:01 Micha Silver <<a href="mailto:tsvibar@gmail.com">tsvibar@gmail.com</a> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
    
  
  <div style="direction:ltr" text="#000000" bgcolor="#FFFFFF">
    <br>
    <div class="m_-3585180151021423630moz-cite-prefix">On 2/14/19 4:49 PM, César Augusto
      Ramírez Franco wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div dir="ltr">
          <div class="gmail_default" style="color:rgb(39,78,19)">Greetings,<br>
            <br>
            I have a municipality polygon layer with a poverty index
            (percent) and a population count, I'm multiplying them to
            visualize the vulnerability for each municipality, due to
            the distribution of that new variable I want to compute the
            logarithm, which is not possible in sqlite, so I tried
            reading the column with numpy and issuing a np.log10(). I'm
            happy with the result, but how can I get this new numpy
            array to a new column in the vector map in a simple way?<br>
            <br>
            This is what I already have:<br>
            <br>
            <span style="font-family:monospace,monospace">#!/usr/bin/env
              python<br>
              <br>
              import grass.script as gs<br>
              import numpy as np<br>
              import matplotlib.pyplot as plt<br>
              <br>
              nbi_pob = np.array(gs.vector_db_select("muniant", columns
              = "nbi_pob")["values"].values()).astype(float).squeeze()<br>
              <br>
              plt.hist(nbi_pob)<br>
              plt.show()<br>
              <br>
              log_nbi_pob = np.log10(nbi_pob)<br>
              <br>
              plt.hist(log_nbi_pob)<br>
              plt.show()</span><br>
            <br>
            I'm trying to introduce this kind of analysis to students
            who are not familiar nor proficient with programming (this
            is an GIS introductory course) so the numpy bit is already
            complex enough to them, and I'd like to avoid using for
            loops with cursors to achieve this.<br>
          </div>
        </div>
      </div>
    </blockquote>
    <p><br>
    </p>
    <p>I also can't think of any simple way to do this. However
      PostgreSQL does have a log() function. So if you migrate your
      backend DB to PostgreSQL you should be able to do (not tested):</p>
    <p><br>
    </p>
    <p>gs.run_command('v.db.addcolumn', map_="muniant",
      column="log_nbi_pob DOUBLE")</p>
    <p>gs.run_command('v.to.db', map_="muniant", column="log_nbi_pob",
      query="log(nbi_pob)")</p>
    <p><br>
    </p>
    <p>But I must say that it seems strange that you are introducing
      numpy, matplotlib and the GRASS python interface to students who
      don't yet have the basic tools of programming, such as 'for'
      loops. Isn't this is a case of "putting the wagon in front of the
      horse"?? <span class="m_-3585180151021423630moz-smiley-s1"><span>:-)</span></span></p></div></blockquote></div><div dir="auto"><br></div><div dir="auto">That script hasn't been introduced to students, I was just fiddling with the data after a class when the question arose, trying to figure out how to do that. I do most of the Lab research analysis with R, and lately I've been studying the scipy ecosystem to try and do them within R, but maybe Markus' suggestion would do to get students going with their course's projects.</div><div dir="auto"><br></div><div dir="auto">Thanks!</div><div dir="auto"><br></div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="direction:ltr" text="#000000" bgcolor="#FFFFFF"><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="color:rgb(39,78,19)">
            Is there a simple solution to this?<br clear="all">
          </div>
          <br>
          -- <br>
          <div dir="ltr" class="m_-3585180151021423630gmail_signature">
            <div dir="ltr">
              <div>
                <div dir="ltr">
                  <div dir="ltr">
                    <div dir="ltr">
                      <div dir="ltr">
                        <div dir="ltr">
                          <div><b>César Augusto Ramírez Franco</b></div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="m_-3585180151021423630mimeAttachmentHeader"></fieldset>
      <pre class="m_-3585180151021423630moz-quote-pre">_______________________________________________
grass-user mailing list
<a class="m_-3585180151021423630moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org" target="_blank" rel="noreferrer">grass-user@lists.osgeo.org</a>
<a class="m_-3585180151021423630moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/grass-user" target="_blank" rel="noreferrer">https://lists.osgeo.org/mailman/listinfo/grass-user</a></pre>
    </blockquote>
    <pre class="m_-3585180151021423630moz-signature" cols="72">-- 
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918</pre>
  </div>

</blockquote></div></div>