grid.py 22 KB

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