Running basic analysis with GRASS GIS on Hazel
The goal of this section is to become familiar with running basic GRASS GIS commands on HPC, including creating a Location, importing data, running a simple analysis and exporting data.
First, we will copy our prepared data from mass storage (/gpfs_archive/gis714s23
)
to our scratch space and unzip.
Why do we need to copy it there?
mkdir /share/gis714s23/$USER/input_data
cd /share/gis714s23/$USER/input_data
cp /gpfs_archive/gis714s23/nlcd_2019_land_cover_l48_20210604.zip .
unzip nlcd_2019_land_cover_l48_20210604.zip
Note: unzipping can take some time, if we would be unzipping multiple files like these,
we would need to do that on a compute node rather than on a login node.
Why?
Loading GRASS GIS
On HPC you need to first load GRASS GIS to be able to use it. First, append geospatial modules to list of available modules:module use --append /usr/local/usrapps/geospatial/modulefiles
You can see what is currently the default version and what are the other versions and software available.
See also the installed versions here.
module avail
At the bottom you will see several available versions of GRASS GIS,
we will use the default one:
module load grass
You will need to execute these 2 lines every time you open a new terminal or include them in your job submission:
module use --append /usr/local/usrapps/geospatial/modulefiles
module load grass
Creating a new Location
In your scratch space (/share/gis714s23/$USER
) create a new Location
with CRS matching NLCD data located in the class' mass storage (/gpfs_archive/gis714s23
):
mkdir /share/gis714s23/$USER/grassdata
grass -c /share/gis714s23/$USER/input_data/nlcd_2019_land_cover_l48_20210604.img /share/gis714s23/$USER/grassdata/intro --text
This will automatically start in a new mapset PERMANENT and set the default computational region to match the NLCD raster.
Now, review projection and computational region info and exit:
g.proj -p
g.region -p
exit
Which projection is NLCD data in? How many cells?
Importing NLCD
We will import 2019 NLCD land cover into our newly created location. We will import data in an interactive session on a compute node We request a single core and 2GB of memory for 30 minutes:bsub -Is -n 1 -R "rusage[mem=2GB]" -W 30 bash
Load GRASS GIS:
module use --append /usr/local/usrapps/geospatial/modulefiles
module load grass
Start GRASS GIS in the newly created Location:
grass /share/gis714s23/$USER/grassdata/intro/PERMANENT
Set region to smaller area so that we don't have to wait too much:
g.region n=1690185 s=252165 e=1838925 w=514635 res=30 -p
Import NLCD land cover data (will take couple minutes):
r.in.gdal input=/share/gis714s23/$USER/input_data/nlcd_2019_land_cover_l48_20210604.img output=nlcd_2019 memory=2000 -r
Once you are done, you can launch GUI with g.gui
add the new raster.
Alternatively, launch a GRASS monitor and add the raster like this:
d.mon wx0
Once the display opens, run:
d.rast nlcd_2019
Take a screenshot for the report.
Then close the window and exit GRASS GIS and the compute node.
exit
exit
Running an analysis and export
Next we will compute a simple analysis withr.neighbors
(number of different values within a 3x3 neighborhood)
and export the result into tif. We use compression option when exporting to minimize file size
(consult GDAL documentation for further explanation).
For that we submit a job, we request 1 core, 2GB of memory for 5 hours. GRASS tool is executed
using the --exec
interface which starts a GRASS session in specified Location, executed the command and ends the session.
We will create a text file in your home folder using nano editor:
nano /home/$USER/bsub_neighbors.sh
Copy and paste the following content and exit (Ctrl+X) and save (Shift+Y):
#!/bin/bash
#BSUB -n 1
#BSUB -W 3:00
#BSUB -R "rusage[mem=2GB]"
#BSUB -oo neighbors_out
#BSUB -eo neighbors_err
#BSUB -J neighbors
module use --append /usr/local/usrapps/geospatial/modulefiles
module load grass
grass /share/gis714s23/$USER/grassdata/intro/PERMANENT --exec r.neighbors input=nlcd_2019 output=diversity_2019 size=3 method=diversity
grass /share/gis714s23/$USER/grassdata/intro/PERMANENT --exec r.out.gdal input=diversity_2019 output=/share/gis714s23/$USER/diversity_2019.tif type=Byte createopt=COMPRESS=LZW,PREDICTOR=2,BIGTIFF=YES
Submit the job from scratch space:
cd /share/gis714s23/$USER/
bsub < /home/$USER/bsub_neighbors.sh
Now check that job is submitted.
bjobs
Once it runs, check the error output for progress messages from GRASS GIS.
less neighbors_err
Once the job is finished, inspect the summary output and see how long it took:
less neighbors_out
Check the tif file is created and copy it on your local machine and open it in a GIS.
Take a screenshot for the report.