grid.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Mar 28 11:06:00 2013
  4. @author: pietro
  5. """
  6. from __future__ import (nested_scopes, generators, division, absolute_import,
  7. with_statement, print_function, unicode_literals)
  8. import os
  9. import multiprocessing as mltp
  10. import subprocess as sub
  11. import shutil as sht
  12. from grass.script.setup import write_gisrc
  13. from grass.pygrass.gis import Mapset, Location
  14. from grass.pygrass.gis.region import Region
  15. from grass.pygrass.modules import Module
  16. from grass.pygrass.functions import get_mapset_raster, findmaps
  17. from grass.pygrass.modules.grid.split import split_region_tiles
  18. from grass.pygrass.modules.grid.patch import rpatch_map
  19. def select(parms, ptype):
  20. """Select only a certain type of parameters.
  21. :param parms: a DictType parameter with inputs or outputs of a Module class
  22. :type parms: DictType parameters
  23. :param ptype: String define the type of parameter that we want to select,
  24. valid ptype are: 'raster', 'vector', 'group'
  25. :type ptype: str
  26. :returns: An iterator with the value of the parameter.
  27. >>> slp = Module('r.slope.aspect',
  28. ... elevation='ele', slope='slp', aspect='asp',
  29. ... run_=False)
  30. >>> for rast in select(slp.outputs, 'raster'):
  31. ... print(rast)
  32. ...
  33. slp
  34. asp
  35. """
  36. for k in parms:
  37. par = parms[k]
  38. if par.type == ptype or par.typedesc == ptype and par.value:
  39. if par.multiple:
  40. for val in par.value:
  41. yield val
  42. else:
  43. yield par.value
  44. def copy_special_mapset_files(path_src, path_dst):
  45. """Copy all the special GRASS files that are contained in
  46. a mapset to another mapset
  47. :param path_src: the path to the original mapset
  48. :type path_src: str
  49. :param path_dst: the path to the new mapset
  50. :type path_dst: str
  51. """
  52. for fil in (fi for fi in os.listdir(path_src) if fi.isupper()):
  53. sht.copy(os.path.join(path_src, fil), path_dst)
  54. def copy_mapset(mapset, path):
  55. """Copy mapset to another place without copying raster and vector data.
  56. :param mapset: a Mapset instance to copy
  57. :type mapset: Mapset object
  58. :param path: path where the new mapset must be copied
  59. :type path: str
  60. :returns: the instance of the new Mapset.
  61. >>> mset = Mapset()
  62. >>> mset.name
  63. 'user1'
  64. >>> import tempfile as tmp
  65. >>> import os
  66. >>> path = os.path.join(tmp.gettempdir(), 'my_loc', 'my_mset')
  67. >>> copy_mapset(mset, path)
  68. Mapset('user1')
  69. >>> sorted(os.listdir(path))
  70. [u'PERMANENT', u'user1']
  71. >>> sorted(os.listdir(os.path.join(path, 'PERMANENT')))
  72. [u'DEFAULT_WIND', u'PROJ_INFO', u'PROJ_UNITS', u'VAR', u'WIND']
  73. >>> sorted(os.listdir(os.path.join(path, 'user1'))) # doctest: +ELLIPSIS
  74. [...u'SEARCH_PATH', u'VAR', u'WIND']
  75. >>> import shutil
  76. >>> shutil.rmtree(path)
  77. """
  78. per_old = os.path.join(mapset.gisdbase, mapset.location, 'PERMANENT')
  79. per_new = os.path.join(path, 'PERMANENT')
  80. map_old = mapset.path()
  81. map_new = os.path.join(path, mapset.name)
  82. if not os.path.isdir(per_new):
  83. os.makedirs(per_new)
  84. if not os.path.isdir(map_new):
  85. os.mkdir(map_new)
  86. copy_special_mapset_files(per_old, per_new)
  87. copy_special_mapset_files(map_old, map_new)
  88. gisdbase, location = os.path.split(path)
  89. return Mapset(mapset.name, location, gisdbase)
  90. def read_gisrc(gisrc):
  91. """Read a GISRC file and return a tuple with the mapset, location
  92. and gisdbase.
  93. :param gisrc: the path to GISRC file
  94. :type gisrc: str
  95. :returns: a tuple with the mapset, location and gisdbase
  96. >>> import os
  97. >>> read_gisrc(os.environ['GISRC']) # doctest: +ELLIPSIS
  98. (u'user1', ...)
  99. """
  100. with open(gisrc, 'r') as gfile:
  101. gis = dict([(k.strip(), v.strip())
  102. for k, v in [row.split(':') for row in gfile]])
  103. return gis['MAPSET'], gis['LOCATION_NAME'], gis['GISDBASE']
  104. def get_mapset(gisrc_src, gisrc_dst):
  105. """Get mapset from a GISRC source to a GISRC destination.
  106. :param gisrc_src: path to the GISRC source
  107. :type gisrc_src: str
  108. :param gisrc_dst: path to the GISRC destination
  109. :type gisrc_dst: str
  110. :returns: a tuple with Mapset(src), Mapset(dst)
  111. """
  112. msrc, lsrc, gsrc = read_gisrc(gisrc_src)
  113. mdst, ldst, gdst = read_gisrc(gisrc_dst)
  114. path_src = os.path.join(gsrc, lsrc, msrc)
  115. path_dst = os.path.join(gdst, ldst, mdst)
  116. if not os.path.isdir(path_dst):
  117. os.makedirs(path_dst)
  118. copy_special_mapset_files(path_src, path_dst)
  119. src = Mapset(msrc, lsrc, gsrc)
  120. dst = Mapset(mdst, ldst, gdst)
  121. visible = [m for m in src.visible]
  122. visible.append(src.name)
  123. dst.visible.extend(visible)
  124. return src, dst
  125. def copy_groups(groups, gisrc_src, gisrc_dst, region=None):
  126. """Copy group from one mapset to another, crop the raster to the region
  127. :param groups: a list of strings with the group that must be copied
  128. from a master to another.
  129. :type groups: list of strings
  130. :param gisrc_src: path of the GISRC file from where we want to copy the groups
  131. :type gisrc_src: str
  132. :param gisrc_dst: path of the GISRC file where the groups will be created
  133. :type gisrc_dst: str
  134. :param region: a region like object or a dictionary with the region
  135. parameters that will be used to crop the rasters of the
  136. groups
  137. :type region: Region object or dictionary
  138. :returns: None
  139. """
  140. env = os.environ.copy()
  141. # instantiate modules
  142. get_grp = Module('i.group', flags='lg', stdout_=sub.PIPE, run_=False)
  143. set_grp = Module('i.group')
  144. get_grp.run_ = True
  145. rmloc = lambda r: r.split('@')[0] if '@' in r else r
  146. src = read_gisrc(gisrc_src)
  147. dst = read_gisrc(gisrc_dst)
  148. rm = True if src[2] != dst[2] else False
  149. all_rasts = [r[0]
  150. for r in findmaps('rast', location=dst[1], gisdbase=dst[2])]
  151. for grp in groups:
  152. # change gisdbase to src
  153. env['GISRC'] = gisrc_src
  154. get_grp(group=grp, env_=env)
  155. rasts = [r for r in get_grp.outputs.stdout.split()]
  156. # change gisdbase to dst
  157. env['GISRC'] = gisrc_dst
  158. rast2cp = [r for r in rasts if rmloc(r) not in all_rasts]
  159. if rast2cp:
  160. copy_rasters(rast2cp, gisrc_src, gisrc_dst, region=region)
  161. set_grp(group=grp,
  162. input=[rmloc(r) for r in rasts] if rast2cp or rm else rasts,
  163. env_=env)
  164. def set_region(region, gisrc_src, gisrc_dst, env):
  165. """Set a region into two different mapsets.
  166. :param region: a region like object or a dictionary with the region
  167. parameters that will be used to crop the rasters of the
  168. groups
  169. :type region: Region object or dictionary
  170. :param gisrc_src: path of the GISRC file from where we want to copy the groups
  171. :type gisrc_src: str
  172. :param gisrc_dst: path of the GISRC file where the groups will be created
  173. :type gisrc_dst: str
  174. :param env:
  175. :type env:
  176. :returns: None
  177. """
  178. reg_str = "g.region n=%(north)r s=%(south)r " \
  179. "e=%(east)r w=%(west)r " \
  180. "nsres=%(nsres)r ewres=%(ewres)r"
  181. reg_cmd = reg_str % dict(region.items())
  182. env['GISRC'] = gisrc_src
  183. sub.Popen(reg_cmd, shell=True, env=env)
  184. env['GISRC'] = gisrc_dst
  185. sub.Popen(reg_cmd, shell=True, env=env)
  186. def copy_rasters(rasters, gisrc_src, gisrc_dst, region=None):
  187. """Copy rasters from one mapset to another, crop the raster to the region.
  188. :param rasters: a list of strings with the raster map that must be copied
  189. from a master to another.
  190. :type rasters: list
  191. :param gisrc_src: path of the GISRC file from where we want to copy the groups
  192. :type gisrc_src: str
  193. :param gisrc_dst: path of the GISRC file where the groups will be created
  194. :type gisrc_dst: str
  195. :param region: a region like object or a dictionary with the region
  196. parameters that will be used to crop the rasters of the
  197. groups
  198. :type region: Region object or dictionary
  199. :returns: None
  200. """
  201. env = os.environ.copy()
  202. if region:
  203. set_region(region, gisrc_src, gisrc_dst, env)
  204. path_dst = os.path.join(*read_gisrc(gisrc_dst)[::-1])
  205. nam = "copy%d__%s" % (id(gisrc_dst), '%s')
  206. # instantiate modules
  207. mpclc = Module('r.mapcalc')
  208. rpck = Module('r.pack')
  209. rupck = Module('r.unpack')
  210. remove = Module('g.remove')
  211. for rast in rasters:
  212. rast_clean = rast.split('@')[0] if '@' in rast else rast
  213. # change gisdbase to src
  214. env['GISRC'] = gisrc_src
  215. name = nam % rast_clean
  216. mpclc(expression="%s=%s" % (name, rast), overwrite=True, env_=env)
  217. file_dst = "%s.pack" % os.path.join(path_dst, name)
  218. rpck(input=name, output=file_dst, overwrite=True, env_=env)
  219. remove(rast=name, env_=env)
  220. # change gisdbase to dst
  221. env['GISRC'] = gisrc_dst
  222. rupck(input=file_dst, output=rast_clean, overwrite=True, env_=env)
  223. os.remove(file_dst)
  224. def copy_vectors(vectors, gisrc_src, gisrc_dst):
  225. """Copy vectors from one mapset to another, crop the raster to the region.
  226. :param vectors: a list of strings with the vector map that must be copied
  227. from a master to another.
  228. :type vectors: list
  229. :param gisrc_src: path of the GISRC file from where we want to copy the groups
  230. :type gisrc_src: str
  231. :param gisrc_dst: path of the GISRC file where the groups will be created
  232. :type gisrc_dst: str
  233. :returns: None
  234. """
  235. env = os.environ.copy()
  236. path_dst = os.path.join(*read_gisrc(gisrc_dst))
  237. nam = "copy%d__%s" % (id(gisrc_dst), '%s')
  238. # instantiate modules
  239. vpck = Module('v.pack')
  240. vupck = Module('v.unpack')
  241. remove = Module('g.remove')
  242. for vect in vectors:
  243. # change gisdbase to src
  244. env['GISRC'] = gisrc_src
  245. name = nam % vect
  246. file_dst = "%s.pack" % os.path.join(path_dst, name)
  247. vpck(input=name, output=file_dst, overwrite=True, env_=env)
  248. remove(vect=name, env_=env)
  249. # change gisdbase to dst
  250. env['GISRC'] = gisrc_dst
  251. vupck(input=file_dst, output=vect, overwrite=True, env_=env)
  252. os.remove(file_dst)
  253. def get_cmd(cmdd):
  254. """Transform a cmd dictionary to a list of parameters. It is useful to
  255. pickle a Module class and cnvert into a string that can be used with
  256. `Popen(get_cmd(cmdd), shell=True)`.
  257. :param cmdd: a module dictionary with all the parameters
  258. :type cmdd: dict
  259. >>> slp = Module('r.slope.aspect',
  260. ... elevation='ele', slope='slp', aspect='asp',
  261. ... overwrite=True, run_=False)
  262. >>> get_cmd(slp.get_dict()) # doctest: +ELLIPSIS
  263. ['r.slope.aspect', u'elevation=ele', u'format=degrees', ..., u'--o']
  264. """
  265. cmd = [cmdd['name'], ]
  266. cmd.extend(("%s=%s" % (k, v) for k, v in cmdd['inputs']
  267. if not isinstance(v, list)))
  268. cmd.extend(("%s=%s" % (k, ','.join(vals if isinstance(vals[0], str)
  269. else [repr(v) for v in vals]))
  270. for k, vals in cmdd['inputs']
  271. if isinstance(vals, list)))
  272. cmd.extend(("%s=%s" % (k, v) for k, v in cmdd['outputs']
  273. if not isinstance(v, list)))
  274. cmd.extend(("%s=%s" % (k, ','.join([repr(v) for v in vals]))
  275. for k, vals in cmdd['outputs'] if isinstance(vals, list)))
  276. cmd.extend(("%s" % (flg) for flg in cmdd['flags'] if len(flg) == 1))
  277. cmd.extend(("--%s" % (flg[0]) for flg in cmdd['flags'] if len(flg) > 1))
  278. return cmd
  279. def cmd_exe(args):
  280. """Create a mapset, and execute a cmd inside.
  281. :param args: is a tuple that contains several information see below
  282. :type args: tuple
  283. :returns: None
  284. The puple has to contain:
  285. - bbox (dict): a dict with the region parameters (n, s, e, w, etc.)
  286. that we want to set before to apply the command.
  287. - mapnames (dict): a dictionary to substitute the input if the domain has
  288. been splitted in several tiles.
  289. - gisrc_src (str): path of the GISRC file from where we want to copy the
  290. groups.
  291. - gisrc_dst (str): path of the GISRC file where the groups will be created.
  292. - cmd (dict): a dictionary with all the parameter of a GRASS module.
  293. - groups (list): a list of strings with the groups that we want to copy in
  294. the mapset.
  295. """
  296. bbox, mapnames, gisrc_src, gisrc_dst, cmd, groups = args
  297. src, dst = get_mapset(gisrc_src, gisrc_dst)
  298. env = os.environ.copy()
  299. env['GISRC'] = gisrc_dst
  300. if mapnames:
  301. inputs = dict(cmd['inputs'])
  302. # reset the inputs to
  303. for key in mapnames:
  304. inputs[key] = mapnames[key]
  305. cmd['inputs'] = inputs.items()
  306. # set the region to the tile
  307. sub.Popen(['g,region', 'rast=%s' % key], env=env).wait()
  308. else:
  309. # set the computational region
  310. lcmd = ['g.region', ]
  311. lcmd.extend(["%s=%s" % (k, v) for k, v in bbox.items()])
  312. sub.Popen(lcmd, env=env).wait()
  313. if groups:
  314. copy_groups(groups, gisrc_src, gisrc_dst)
  315. # run the grass command
  316. sub.Popen(get_cmd(cmd), env=env).wait()
  317. # remove temp GISRC
  318. os.remove(gisrc_dst)
  319. class GridModule(object):
  320. # TODO maybe also i.* could be supported easily
  321. """Run GRASS raster commands in a multiprocessing mode.
  322. :param cmd: raster GRASS command, only command staring with r.* are valid.
  323. :type cmd: str
  324. :param width: width of the tile, in pixel
  325. :type width: int
  326. :param height: height of the tile, in pixel.
  327. :type height: int
  328. :param overlap: overlap between tiles, in pixel.
  329. :type overlap: int
  330. :param processes: number of threads, default value is equal to the number
  331. of processor available.
  332. :param split: if True use r.tile to split all the inputs.
  333. :type split: bool
  334. :param run_: if False only instantiate the object
  335. :type run_: bool
  336. :param args: give all the parameters to the command
  337. :param kargs: give all the parameters to the command
  338. >>> grd = GridModule('r.slope.aspect',
  339. ... width=500, height=500, overlap=2,
  340. ... processes=None, split=False,
  341. ... elevation='elevation',
  342. ... slope='slope', aspect='aspect', overwrite=True)
  343. >>> grd.run()
  344. """
  345. def __init__(self, cmd, width=None, height=None, overlap=0, processes=None,
  346. split=False, debug=False, region=None, move=None, log=False,
  347. start_row=0, start_col=0, out_prefix='',
  348. *args, **kargs):
  349. kargs['run_'] = False
  350. self.mset = Mapset()
  351. self.module = Module(cmd, *args, **kargs)
  352. self.width = width
  353. self.height = height
  354. self.overlap = overlap
  355. self.processes = processes
  356. self.region = region if region else Region()
  357. self.start_row = start_row
  358. self.start_col = start_col
  359. self.out_prefix = out_prefix
  360. self.log = log
  361. self.move = move
  362. self.gisrc_src = os.environ['GISRC']
  363. self.n_mset, self.gisrc_dst = None, None
  364. if self.move:
  365. self.n_mset = copy_mapset(self.mset, self.move)
  366. self.gisrc_dst = write_gisrc(self.n_mset.gisdbase,
  367. self.n_mset.location,
  368. self.n_mset.name)
  369. rasters = [r for r in select(self.module.inputs, 'raster')]
  370. if rasters:
  371. copy_rasters(rasters, self.gisrc_src, self.gisrc_dst,
  372. region=self.region)
  373. vectors = [v for v in select(self.module.inputs, 'vector')]
  374. if vectors:
  375. copy_vectors(vectors, self.gisrc_src, self.gisrc_dst)
  376. groups = [g for g in select(self.module.inputs, 'group')]
  377. if groups:
  378. copy_groups(groups, self.gisrc_src, self.gisrc_dst,
  379. region=self.region)
  380. self.bboxes = split_region_tiles(region=region,
  381. width=width, height=height,
  382. overlap=overlap)
  383. self.msetstr = cmd.replace('.', '') + "_%03d_%03d"
  384. self.inlist = None
  385. if split:
  386. self.split()
  387. self.debug = debug
  388. def __del__(self):
  389. if self.gisrc_dst:
  390. # remove GISRC file
  391. os.remove(self.gisrc_dst)
  392. def clean_location(self, location=None):
  393. """Remove all created mapsets.
  394. :param location: a Location instance where we are running the analysis
  395. :type location: Location object
  396. """
  397. if location is None:
  398. if self.n_mset:
  399. self.n_mset.current()
  400. location = Location()
  401. mapsets = location.mapsets(self.msetstr.split('_')[0] + '_*')
  402. for mset in mapsets:
  403. Mapset(mset).delete()
  404. if self.n_mset and self.n_mset.is_current():
  405. self.mset.current()
  406. def split(self):
  407. """Split all the raster inputs using r.tile"""
  408. rtile = Module('r.tile')
  409. inlist = {}
  410. for inm in select(self.module.inputs, 'raster'):
  411. rtile(input=inm.value, output=inm.value,
  412. width=self.width, height=self.height,
  413. overlap=self.overlap)
  414. patt = '%s-*' % inm.value
  415. inlist[inm.value] = sorted(self.mset.glist(type='rast',
  416. pattern=patt))
  417. self.inlist = inlist
  418. def get_works(self):
  419. """Return a list of tuble with the parameters for cmd_exe function"""
  420. works = []
  421. reg = Region()
  422. if self.move:
  423. mdst, ldst, gdst = read_gisrc(self.gisrc_dst)
  424. else:
  425. ldst, gdst = self.mset.location, self.mset.gisdbase
  426. cmd = self.module.get_dict()
  427. groups = [g for g in select(self.module.inputs, 'group')]
  428. for row, box_row in enumerate(self.bboxes):
  429. for col, box in enumerate(box_row):
  430. inms = None
  431. if self.inlist:
  432. inms = {}
  433. cols = len(box_row)
  434. for key in self.inlist:
  435. indx = row * cols + col
  436. inms[key] = "%s@%s" % (self.inlist[key][indx],
  437. self.mset.name)
  438. # set the computational region, prepare the region parameters
  439. bbox = dict([(k[0], str(v)) for k, v in box.items()[:-2]])
  440. bbox['nsres'] = '%f' % reg.nsres
  441. bbox['ewres'] = '%f' % reg.ewres
  442. new_mset = self.msetstr % (self.start_row + row,
  443. self.start_col + col),
  444. works.append((bbox, inms,
  445. self.gisrc_src,
  446. write_gisrc(gdst, ldst, new_mset),
  447. cmd, groups))
  448. return works
  449. def define_mapset_inputs(self):
  450. """Add the mapset information to the input maps
  451. """
  452. for inmap in self.module.inputs:
  453. inm = self.module.inputs[inmap]
  454. if inm.type in ('raster', 'vector') and inm.value:
  455. if '@' not in inm.value:
  456. mset = get_mapset_raster(inm.value)
  457. inm.value = inm.value + '@%s' % mset
  458. def run(self, patch=True, clean=True):
  459. """Run the GRASS command
  460. :param patch: set False if you does not want to patch the results
  461. :type patch: bool
  462. :param clean: set False if you does not want to remove all the stuff
  463. created by GridModule
  464. :type clean: bool
  465. """
  466. self.module.flags.overwrite = True
  467. self.define_mapset_inputs()
  468. if self.debug:
  469. for wrk in self.get_works():
  470. cmd_exe(wrk)
  471. else:
  472. pool = mltp.Pool(processes=self.processes)
  473. result = pool.map_async(cmd_exe, self.get_works())
  474. result.wait()
  475. if not result.successful():
  476. raise RuntimeError
  477. if patch:
  478. if self.move:
  479. os.environ['GISRC'] = self.gisrc_dst
  480. self.n_mset.current()
  481. self.patch()
  482. os.environ['GISRC'] = self.gisrc_src
  483. self.mset.current()
  484. # copy the outputs from dst => src
  485. routputs = [self.out_prefix + o
  486. for o in select(self.module.outputs, 'raster')]
  487. copy_rasters(routputs, self.gisrc_dst, self.gisrc_src)
  488. else:
  489. self.patch()
  490. if self.log:
  491. # record in the temp directory
  492. from grass.lib.gis import G_tempfile
  493. tmp, dummy = os.path.split(G_tempfile())
  494. tmpdir = os.path.join(tmp, self.module.name)
  495. for k in self.module.outputs:
  496. par = self.module.outputs[k]
  497. if par.typedesc == 'raster' and par.value:
  498. dirpath = os.path.join(tmpdir, par.name)
  499. if not os.path.isdir(dirpath):
  500. os.makedirs(dirpath)
  501. fil = open(os.path.join(dirpath,
  502. self.out_prefix + par.value), 'w+')
  503. fil.close()
  504. if clean:
  505. self.clean_location()
  506. self.rm_tiles()
  507. if self.n_mset:
  508. gisdbase, location = os.path.split(self.move)
  509. self.clean_location(Location(location, gisdbase))
  510. # rm temporary gis_rc
  511. os.remove(self.gisrc_dst)
  512. self.gisrc_dst = None
  513. sht.rmtree(os.path.join(self.move, 'PERMANENT'))
  514. sht.rmtree(os.path.join(self.move, self.mset.name))
  515. def patch(self):
  516. """Patch the final results."""
  517. bboxes = split_region_tiles(width=self.width, height=self.height)
  518. loc = Location()
  519. mset = loc[self.mset.name]
  520. mset.visible.extend(loc.mapsets())
  521. for otmap in self.module.outputs:
  522. otm = self.module.outputs[otmap]
  523. if otm.typedesc == 'raster' and otm.value:
  524. rpatch_map(otm.value,
  525. self.mset.name, self.msetstr, bboxes,
  526. self.module.flags.overwrite,
  527. self.start_row, self.start_col, self.out_prefix)
  528. def rm_tiles(self):
  529. """Remove all the tiles."""
  530. # if split, remove tiles
  531. if self.inlist:
  532. grm = Module('g.remove')
  533. for key in self.inlist:
  534. grm(rast=self.inlist[key])