[GRASS-dev] pyGRASS find number of rows and columns

Yann Chemin ychemin at gmail.com
Mon Sep 16 04:47:56 PDT 2013


Hi Pietro,

for 3 maps, I am collecting one pixel at a time for thousands of maps,
create a temporal signature for all 3, then use python-pywt on it, then
return the single pixel to each map. To do that I need to open files and
close them before reaching the max file opened OS limit...

Very slow indeed, but python-pywt has a large library of wavelet
coefficients, and libgsl has none of that choice and is not made for fused
recomposition from different sources (I asked the maintainer of libgsl, and
he is not the author, and does not understand why we (RS/GIS guys) want to
recompose from different sources....

Thanks,
Yann




On 16 September 2013 16:05, Pietro <peter.zamb at gmail.com> wrote:

> Hi all!
>
> On Mon, Sep 16, 2013 at 10:43 AM, Sören Gebbert
> <soerengebbert at googlemail.com> wrote:
> > Hi Yann,
> > you can use the raster info-oject to access the raster specific region
> > information's:
> >
> > ras = raster.RasterRow("Bla")
> > ras.info.rows
> >
> > You don't need to open the map to gather the info.
>
> just some example to be more clear...
>
> I'm on North Carolina dataset, my region is:
>
> {{{
> projection: 99 (Lambert Conformal Conic)
> zone:       0
> datum:      nad83
> ellipsoid:  a=6378137 es=0.006694380022900787
> north:      220750
> south:      220000
> west:       638300
> east:       639000
> nsres:      0.2
> ewres:      0.2
> rows:       3750
> cols:       3500
> cells:      13125000
> }}}
>
> now with python:
>
> {{{
> >>> from grass.pygrass.raster import RasterRow
> >>> elev = RasterRow('elevation')
> >>> elev.info
> elevation at PERMANENT
> rows: 1350
> cols: 1500
> north: 228500.0 south: 215000.0 nsres:10.0
> east:  645000.0 west: 630000.0 ewres:10.0
> range: 56, 156
> proj: 99
> >>> elev.info.rows
> 1350
> }}}
>
> So the info return just the main data of the raster.
>
> If you open the raster map:
>
> {{{
> >>> elev.open('r')
> >>> elev.info.rows
> 1350
> >>> elev.info.cols
> 1500
> >>> elev._rows
> 3750
> >>> elev._cols
> 3500
> >>> len(elev)
> 3750
> >>> len(elev[0])
> 3500
> }}}
>
> I put the underscore in front of the rows and cols attribute because
> the number of rows and columns depend from the active region that you
> are using...
>
> and to discourage the user to work/use these data...
>
> Why do you need the number of rows and columns? If you want to do a
> cycle you can do something like:
>
> {{{
> >>> for row in elev:
> ...     dosomething(row)
> ...
> }}}
>
> if you need the row number you can just use enumerate
>
> {{{
> >>> for irow, row in enumerate(elev):
> ...     dosomething(irow, row)
> ...
> }}}
>
> of course you can nest two cycle, something like
>
> {{{
> >>> for irow, row in enumerate(elev):
> ...     for icol, col in enumerate(row):
> ...         dosomething(irow, icol, row, col)
> ...
> }}}
>
> But I discourage to cycle over the column of a row, because it is too
> slow, the row is a numpy array and you should use the numpy API to
> work with the row...
>
> Any way If you think that rows and cols are useful attributes I can
> rename them from _rows, _cols => row, cols :-)
>
> Best regards
>
> Pietro
>



-- 
----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20130916/725a0f7e/attachment-0001.html>


More information about the grass-dev mailing list