grid.py 23 KB

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