The code below works but as this involves averaging thousands of files, grass shows an error message:

Too many open files

The code:

raster_list = create_qgis_raster(files)
general.runalg('grass7:r.series', raster_list, False, 0,
   '%f,%f,%f,%f' % (xmin, xmax, ymin, ymax),
   0, output_path

The error happens because grass don't close these raster layers. The documentation of grass r.series algorithm has a flag called -z that means Do not keep files open. However, there is no place to put this option in runlang method of processing.

When I add the parameter -z, I get the error

Error: Wrong number of parameters
ALGORITHM: r.series - Makes each output cell value a function of the 
values assigned to the corresponding cells in the input raster layers.
   input <ParameterMultipleInput>
   -n <ParameterBoolean>
   method <ParameterSelection>
   range <ParameterString>
   output <OutputRaster>

QGIS version 2.18

Is there any way of adding those additional flags of r.series in processing runlang method?

Edit: Joseph's answer helped in adding the extra parameter but the added parameter has not closed open files after processing.

  • Which version of QGIS?
    – ndawson
    Jan 24, 2019 at 23:14
  • @ndawson Sorry not to mention that. It is 2.18. I will update the question.
    – wondim
    Jan 25, 2019 at 3:03

1 Answer 1


Inside your QGIS directory, find the r.series.txt file. For example in Windows:

C:/Program Files/QGIS 2.18/apps/qgis-ltr/python/plugins/processing/algs/grass7/description/r.series.txt

And in Linux:


It will look something like this:

Makes each output cell value a function of the values assigned to the corresponding cells in the input raster layers.
Raster (r.*)
ParameterMultipleInput|input|Input raster layer(s)|3.0|False
ParameterBoolean|-n|Propagate NULLs|False
ParameterSelection|method|Aggregate operation|average;count;median;mode;minimum;min_raster;maximum;max_raster;stddev;range;sum;variance;diversity;slope;offset;detcoeff;quart1;quart3;perc90;skewness;kurtosis
*ParameterString|range|Ignore values outside this range (lo,hi)|-10000000000,10000000000

The following line shows how the -n flag is set:

ParameterBoolean|-n|Propagate NULLs|False

Let's copy this but set it for the -z flag instead and insert it immediately after. If you're feeling whimsy, make it checked as default:

ParameterBoolean|-n|Propagate NULLs|False
ParameterBoolean|-z|Do not keep files open|True

Now save the file. If you cannot due to permission reasons, save the file in another location (i.e. desktop). Delete the original file then move the newly saved one from the desktop in its place. Restart QGIS and when you run the same tool, you should see the new parameter:

r.series tool

The python code should change to the following. True is added for the added as a third parameter for Don't keep files open paramerter:

general.runalg('grass7:r.series', raster_list, False, True, 0, 
   '%f,%f,%f,%f' % (xmin, xmax, ymin, ymax),
   0, output_path

Unfortunately I do not have many rasters to test this on so good luck!

  • Unfortunately, following your instruction helped in addition the parameter. However, I am still Getting too many files.
    – wondim
    Jan 25, 2019 at 17:01
  • It looks like this question is answered but shall I ask another question for grass issue?
    – wondim
    Jan 25, 2019 at 17:18
  • @wondim - Perhaps edit your question to mention that you tried the solution I posted but the problem persists. Then hopefully another could offer a working solution or advice :)
    – Joseph
    Jan 31, 2019 at 11:04
  • I have edited the question.
    – wondim
    Jan 31, 2019 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.