Skip to content

cutmaps

Jesús Casado Rodríguez edited this page Sep 12, 2024 · 3 revisions

This tool cuts NetCDF files using either a mask, a bounding box, or a list of stations along with an LDD (local drainage direction) map.

Output

Apart from the cut files in the output folder specified in the command prompt, cutmaps produces other outputs in the folder where the LDD map is stored:

  • mask.map and mask.nc for your area of interest, which may be needed in subsequent LISFLOOD/LISVAP executions.
  • outlets.map and outlets.nc based on stations.txt, which will let you produce gauges TSS if configured in LISFLOOD.

Usage

In the command prompt

The tool requires a series of arguments:

  • The area to be extracted can be defined in one of the following ways:
    • -m, --mask: a mask map (either PCRaster or NetCDF format).
    • -i, --cuts_indices: a bounding box defined by matrix indices in the form -i imin imax jmin jmax (the indices must be integers).
    • -c, --cuts: a bounding box defined by coordinates in the form -c xmin xmax ymin ymax (the coordinates can be integer or floating point numbers; x = longitude, y = latitude).
    • -N, -stations: a list of stations included in a tab separated text file. This approach requires a LDD (local drain direction) map as an extra input, defined with the argument -l (-ldd).
  • The files to be cut may be defined in one of the following ways:
    • -f, --folder: a folder containing NetCDF files.
    • -F, --file: a single netCDF file to be cut.
    • -S, --subdir: a directory containing a number of folders
  • The resulting files will be saved in the folder defined by the argument -o ( --outpath).

There are additional, optional arguments

  • -W, --overwrite: it allows to overwrite results.
  • -C, --clonemap: it can be used to define a clone map when the LDD input map (argument -l) is in NetCDF format.

Examples

Using a mask

The following command will cut all NetCDF files inside a specific folder (argument -f) using a mask (argument -m). The mask is a boolean map (1 only in the area of interes) that cutmaps uses to create a bounding box. The resulting files will be written in the current folder (argument -o).

cutmaps -m /workarea/Madeira/maps/MaskMap/Bacia_madeira.nc -f /workarea/Madeira/lai/ -o ./
Using indices

The following command cuts all the maps in an input folder (argument -f) using a bounding box defined by matrix indices (argument -i). Knowing your area of interest from your NetCDF files, you can determine indices of the array and pass them in the form -i imin imax jmin jmax (integer numbers).

cutmaps -i "150 350 80 180" -f /workarea/Madeira/lai/ -o ./
Using coordinates

The following command cuts all the maps in an input directory containing several folders (argument -S) using a bounding box defined by coordinates (argument -c). The argument -W allows to overwrite pre-existing files in the output directory (argument -o):

cutmaps -S /home/projects/lisflood-eu -c "4078546.12 4463723.85 811206.57 1587655.50" -o /Work/Tunisia/cutmaps -W
Using station coordinates and a local drain direction map

The TXT file with stations must have a specific format as in the example below. Each row represents a station, and it contains three columns separated by tabs that indicate the X and Y coordinates (or longitude and latitude) and the ID of the station.

4297500	1572500	1
4292500	1557500	2
4237500	1537500	3
4312500	1482500	4
4187500	1492500	5

The following command will cut all the maps in a specific folder (-f argument) given a LDD map (-l argument) and the previous text file (-N argument), and save the results in a folder defined by the argument -o.

cutmaps -f /home/projects/lisflood-eu -l ldd.map -N stations.txt -o /Work/Tunisia/cutmaps

If the LDD is in NetCDF format, it will be first converted into PCRaster format.

cutmaps -f /home/projects/lisflood-eu -l ldd.nc -N stations.txt -o /Work/Tunisia/cutmaps

If you experience problems, you can try to pass a path to a PCRaster clone map using the -C argument.

cutmaps -f /home/projects/lisflood-eu -l ldd.nc -C area.map -N stations.txt -o /Work/Tunisia/cutmaps

In a Python script

You can use the cutmaps tool programmatically from a Python code. You just need to import the tool and then run the following command:

from lisfloodutilities.cutmaps.cutlib import cutmap

cutmap(file_to_cut, file_out, x_min, x_max, y_min, y_max, use_coords=True)

Where use_coords=True means that it will cut the map using coordinates, while use_coords=False will use indices.

Clone this wiki locally