Grass can be used in text mode or GUI mode. This is useful for batch scripting, and running specific Grass commands in the Grass environment.
Similar to the GUI mode, you'll need to submit a request to use the compute node. This will allocate a specific node for you to use. To request access to a node, enter the following command:
> salloc --time=1:00:00 --partition=interactive --nodes=1
> squeue
(shows which node and jobID your request was assigned. In this case compute128 and 28628)
>ssh compute128
> module load Spatial/grass/7.4.0/batch/gcc-7.2.0
Once the module has been loaded, you can now start using Grass in text mode.
To start Grass in text mode, you have two methods of launching into the Grass environment. The first method of starting Grass is to load the mapset you are going to be working on. You can do this by entering the following command:
> grass74 /path/to/map/MAPSET
The second method of launching Grass is by creating a new mapset from scratch, you can create a new mapset by entering the following command:
> grass74 -c epsg:32632 /path/to/new/map
You can replace epsg:32632 with the map-settings of your choice. Please refer to the manual pages for more info.
Both commands will launch you into a Grass environment. This environment gives you access to all the regular Linux commands plus additional commands used in the Grass GIS program.
In Grass, you can output data to images by running this command:
d.mon cairo out=output.png
After entering this command, you can start drawing your data onto the image.
This section will go over basic scripting in Grass, how to submit a Grass batch job through the SLURM Scheduler, and how to split mapsets for multi-node processing.
The following example script generates patches of my mapset, then outputs the geological data points of my mapset.
> cat myScript.sh
#!/bin/bash
v.generalize input=geology output=patches_smoothed method=sliding_averaging look_ahead=7 slide=0.7 threshold=1 --overwrite
v.build map=patches_smoothed --overwrite
v.out.ogr --overwrite input=patches_smoothed type=auto dsn=test rm test
To run your batch script in the Grass environment, simply call your script within the Grass environment.
> grass74
./myScript.sh
To submit a task to the SLURM scheduler, you'll need to write a script to launch the program. This script tells the SLURM scheduler what the name of my job is, what partition I want to run in, and where to output my console output. The script then loads the module for Grass, then sets an environmental variable called GRASS_BATCH_JOB. This variable will let Grass know on startup that grass should load the script as soon as the program launches.
>cat mySbatch.sh
#!/bin/bash
#SBATCH --job-name grass_test
#SBATCH --partition medium
#SBATCH -o grass_test_%j.out
#SBATCH -e grass_test_%j.err
module load Spatial/grass/7.4.0/batch/gcc-7.2.0
export GRASS_BATCH_JOB=myScript.sh
srun grass74 -text /path/to/mapset/
unset GRASS_BATCH_JOB
To queue your job in the cluster, enter the following command:
>sbatch mySbatch.sh
Refer to SLURM Scheduler article for more information on how to use the SLURM Scheduler.
Grass has limited support for parallel jobs, so scaling to multiple nodes needs to be done manually. To accomplish this, the Grass community recommendations the following steps:
Split your mapset into smaller mapsets (or separate regions)
Submit an sbatch job for each mapset/region (the SLURM scheduler will assign each job to it's own node)
Once all jobs have finished, combine all mapsets into one mapset.
There are many ways to split a mapset. One common method is to split the mapset into tiles. You can accomplish this using r.tile
# generating 2 x 2 = 4 tiles (width=1500/2, height=rows/2)
r.tile input=elevation output=elev_tile width=750 height=675
The Grass Community Wiki has additional information on how to run Grass in parallel.
This is because the Grass environment needs a mapset to launch into before you enter the Grass environment. In fact, when you launch Grass for the first time in GUI mode, you're greeted to a splash page that ask you to either create a new mapset, or load an existing mapset before you enter the Grass environment.