<div dir="ltr">Hi I'm writing a code in python able to perform several mapcalc operation on various rasters. I'm using GRASS 7.0.1 and Python 2.7. I'have my files stored in /home/myuser/rasters/ and they are linked to GRASS with r.external. The out put of the operation are going out of GRASS in /home/myuser/tmp/ with r.external.out.<div><br></div><div>I have written this code from the example provided in (<a href="https://grass.osgeo.org/grass70/manuals/libpython/pygrass.modules.interface.html?highlight=parallelmodulequeue#pygrass.modules.interface.module.ParallelModuleQueue">https://grass.osgeo.org/grass70/manuals/libpython/pygrass.modules.interface.html?highlight=parallelmodulequeue#pygrass.modules.interface.module.ParallelModuleQueue</a>)  but there is no difference in terms of time between setting nproces=1 or nproces=8. How is possible? How can I achieve improvements?</div><div><br></div><div>The task that the code need to do is to read data from a file containing datetime and 2 coefficients k1 and k2. Than need to multiply and sum the input raster as out = input1 * k1 + input2 * k2.</div><div><br></div><div>The code that i have written is:</div><div><br></div><div><div><br></div><div>import pandas as pd</div><div>import os<br></div><div>import grass.script.setup as gsetup</div><div>import grass.script as g</div><div>import time</div><div>import copy</div><div>from grass.pygrass.modules import Module, ParallelModuleQueue</div><div><br></div><div>def main():</div><div><br></div><div>   #set GRASS LOCATION AND MAPSET</div><div>    gisbase = os.environ['GISBASE']   # Grass 7.0svn</div><div>    gisdbase = os.path.abspath("/home/myuser/grassData") </div><div>    location = 'mylocation'             # Grass Location.  </div><div>    mapset = 'mymapset' </div><div>    gsetup.init(gisbase, gisdbase, location, mapset)</div><div>   </div><div>   #READ INPUT DATA FOR RASTER CALC</div><div>    df = pd.read_csv('input.csv', sep=";", index_col='Date Time', decimal=',')</div><div>    df.index = pd.to_datetime(df.index, unit='s')</div><div><br></div><div>    month={1:'17',2:'47',3:'75',4:'105',5:'135',6:'162',7:'198',8:'228',9:'258',10:'288',11:'318',12:'344'}</div><div>    hour={4:'04',5:'05',6:'06',7:'07',8:'08',9:'09',10:'10',11:'11',12:'12',13:'13',14:'14',15:'15',16:'16',17:'17',18:'18',19:'19',20:'20',21:'21',22:'22'}</div><div>    minute={0:'00',15:'15',30:'30',45:'45'}</div><div>    directory='/home/myuser/raster/'<br></div><div>    tmp='/home/myuser/tmp/'</div><div>    g.run_command('r.external.out', directory=tmp, format="GTiff")</div><div> #MAPCALC<br></div><div>    start_time = time.time()</div><div>    mapcalc_list = []</div><div>    mapcalc = Module("r.mapcalc", overwrite=True, run_=False)</div><div>    queue = ParallelModuleQueue(nprocs=8)</div><div>    for dfix in df.index:</div><div>        if 5<=dfix.hour<20:</div><div>            input1 = 'input1_' + month[dfix.month] + '_' + hour[dfix.hour] + minute[dfix.minute]</div><div>            input2 = 'input2_' + month[dfix.month] + '_' + hour[dfix.hour] + minute[dfix.minute]</div><div>            out = ' " ' + str(dfix.date()) + '_' + str(dfix.time()) + ' " '</div><div>            new_mapcalc = copy.deepcopy(mapcalc)</div><div>            mapcalc_list.append(new_mapcalc)</div><div>            m = new_mapcalc(expression="%s = %s*%i+%s*%i"%(out,input1,df.ix[dfix,'k1'],input2,df.ix[dfix,'k2']))</div><div>            queue.put(m)</div><div>    queue.wait()</div><div><br></div><div><br></div><div>    print("--- %s seconds ---" % (time.time() - start_time))</div></div><div><br></div><div><br></div><div><br></div><div>Best,</div><div><br></div><div>Lorenzo</div></div>