* Moritz Lennert <[email protected]> [2018-08-23 13:02:03 +0200]:

On 23/08/18 11:52, Nikos Alexandris wrote:
* Stefan Blumentrath <[email protected]> [2018-08-23 07:23:12 +0000]:

Dear Nikos,

Can you give us a bit more context?  What is it you want to achieve?
How are you using r.stats and what is it you want to do with the
output?

Personally, I am not too familiar with performance implications of
NumPy vs. plain Python, but rather use NumPy for convenience in
matrix/table operations (avoiding pandas)...

```
for category in categories:
    statistics_filename = prefix + '_' + category
    r.stats(input=(base,reclassified),
            output=statistics_filename,
            flags='ncapl',
            separator=',',
            quiet=True)
```

Instead, I want to (modify the above so as to) collect/direct all
iterations in one output file.

You can check the r.neighborhoodmatrix addon for one solution which I shamelessly took from a SE answer:

https://trac.osgeo.org/grass/browser/grass-addons/grass7/raster/r.neighborhoodmatrix/r.neighborhoodmatrix.py#L152

The code takes a list of filenames and the merges these files.

I've been confronted with a similar problem using v.db.select these days and I've been thinking about adding a flag / parameter to relevant modules allowing to append an existing file, instead of overwriting it. Should just be a case of using mode "a" instead of "w", so shouldn't be too complicated.

If you want to, try it with r.stats, by applying this change:

Index: raster/r.stats/main.c
===================================================================
--- raster/r.stats/main.c       (révision 72717)
+++ raster/r.stats/main.c       (copie de travail)
@@ -223,7 +223,7 @@

    name = option.output->answer;
    if (name != NULL && strcmp(name, "-") != 0) {
-       if (NULL == freopen(name, "w", stdout)) {
+       if (NULL == freopen(name, "a", stdout)) {
            G_fatal_error(_("Unable to open file <%s> for writing"), name);
        }
    }

and report back if it works as expected...

Moritz

I am sneaking in your scripts a lot lately. Just didn't see this, nor
did my greps/ags hit it.

The modification to r.stats works fine. So, it's a matter of an extra
flag then. Yet, I guess, this is to be explained with a proper warning (?).

Thank you Moritz, Nikos

ps- Some of my e-mails fail to deliver to your mailbox.

Attachment: signature.asc
Description: PGP signature

_______________________________________________
grass-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to