https://github.com/mwort/snakemake_grass
Snakemake - GRASS interface
https://github.com/mwort/snakemake_grass
grass-gis reproducible-research snakemake-workflows
Last synced: 5 months ago
JSON representation
Snakemake - GRASS interface
- Host: GitHub
- URL: https://github.com/mwort/snakemake_grass
- Owner: mwort
- Created: 2019-12-17T23:56:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-18T16:12:22.000Z (over 6 years ago)
- Last Synced: 2024-12-06T21:10:22.092Z (over 1 year ago)
- Topics: grass-gis, reproducible-research, snakemake-workflows
- Language: Python
- Size: 45.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
Snakemake - GRASS GIS interface
===============================
*Create reproducible and scaleable GRASS workflows*
:Author: Michel Wortmannn wortmann@pik-potsdam.de
:Version: **v0.1**
Requirements
------------
- `GRASS >= 7.8 `_
- `Snakemake `_
- Python >= 3.5 (Snakemake requirement)
- tested with Bash
Installation
------------
Latest release::
$ pip install snakemake_grass
Latest development version::
$ git clone git@github.com:mwort/snakemake_grass.git
$ pip install -e ./snakemake_grass/
Rationale
---------
`Snakemake `_ is a great way to create
**reproducible, scaleable and portable** computational workflows based on input
and output file tracking (`Perkel 2019 `_).
This presents a challenge for the database approach of `GRASS `_.
This Python module provides an interface between the two.
Docs and examples
-----------------
`API documentation `_
Here is a quick example Snakefile with one wildcard/template rule and two
target rules::
from snakemake_grass import GrassLocation, input_to_map, output_to_map
grass_ll = GrassLocation('grassdb', 'lonlat', epsg=4326)
rule new_raster:
output: grass_ll.raster('new_raster')
shell: grass_ll('r.mapcalc', exp='new_raster=1')
rule raster_template:
input: rules.new_raster.output
output: grass_ll.raster('raster{i}@raster{i}')
shell:
grass_ll('r.mapcalc', mapset=output_to_map(),
exp='raster{wildcards.i}={wildcards.i}')
rule merged_raster:
input: grass_ll.rasters('raster{i}@raster{i}', i=range(6))
output: grass_ll.raster('merged_raster')
shell:
grass_ll('r.series', input=[input_to_map(i) for i in range(6)],
method='count', output=output_to_map())
Run the last rule on 3 CPUs and create a graph of the workflow::
$ snakemake -j 3 merged_raster
$ snakemake --dag merged_raster | dot -T png -o dag.png
.. image:: docs/dag-merged_raster.png
Instead of running ``r.mapcalc``/``r.series``, it may be more common to actually run
entire Bash/Python script but any one command will work. For more examples, see
``_.
Tests
-----
Tests are provided in a ``_ and are run in the
``tests/`` directory like this, e.g. on 3 CPUs::
$ snakemake -j 3 all
$ snakemake clean