Skip to main content

A set of tools for clipping ParFlow models and their outputs

Project description

Build Status

Subsetter

The subsetter is a suite of tools for clipping ParFlow inputs and outputs. Included are command line scripts to:

  1. subset the inputs from CONUS1 or CONUS2 domains subset_conus
  2. generate a rasterized mask from a shapefile rasterize_shape
  3. clip data from any number of supported input files bulk_clip

Prerequisites

Packages

Building Solid Files

To build solid files (.pfsol), one of the following tools is required: pfmask-to-pfsol (included with ParFlow) or mask-to-pfsol

If using mask-to-pfsol, be sure to follow instructions for building the utilities.

Environment Variables

For the solidfile generator to work, it must be able to locate either mask-to-pfsol or pfmask-to-pfsol

The generator will search the following places, in this order.

  1. PFMASKUTILS environment variable
  2. mask-to-pfsol directory in PATH variable
  3. PARFLOW_DIR environment variable
  4. ParFlow bin directory in PATH variable

Setup

Create a clean environment using anaconda or miniconda:

git clone https://github.com/hydroframe/subsetting
cd subsetting
conda env create -f=environment.yml
conda activate pf_subsetter

Input Files

For CONUS1 and CONUS2 domains, local copies of model input files are required.

CONUS1 Files

required_files:
  DOMAIN_MASK: Domain_Blank_Mask.tif
  SUBSURFACE_DATA: grid3d.v3.pfb
  PME: PmE.flux.pfb
  SLOPE_X: slopex.pfb
  SLOPE_Y: slopey.pfb
optional_files:
  LAND_COVER: conus1_landcover.sa
  LAT_LON: conus1_Grid_Centers_Short_Deg.format.sa
  DEM: CONUS2.0_RawDEM_CONUS1clip.tif

CONUS2 Files

required_files:
  DOMAIN_MASK: conus_1km_PFmask2.tif
  SUBSURFACE_DATA: 3d-grid.v3.tif
  PME: PME.tif
  SLOPE_X: Str3Ep0_smth.rvth_1500.mx0.5.mn5.sec0.up_slopex.tif
  SLOPE_Y: Str3Ep0_smth.rvth_1500.mx0.5.mn5.sec0.up_slopey.tif
  SINKS: conus_1km_PFmask_manualsinks.tif
  RESERVOIRS: conus_1km_PFmask_reservoirs.tif
  LAKE_BORDER: conus_1km_PFmask_selectLakesborder.tif
  LAKE_MASK: conus_1km_PFmask_selectLakesmask.tif
  CHANNELS: 1km_upscaledNWM_ChannelOrder5_mod2.tif
  CELL_TYPES: 1km_PF_BorderCellType.tif
optional_files:
  LAND_COVER: 1km_CONUS2_landcover_IGBP.tif
  LAT_LON: latlonCONUS2.sa
  DEM: CONUS2.0_RawDEM.tif

Local Filenames

If your local filenames differ from this list, update the local filenames in:

parflow/subset/data/conus_manifest.yaml

Testing

Run these tests to do some basic checks to make sure the tools are working correctly after install or update.

chmod +x run_tests.sh
./run_tests.sh

Usage

Create subset from CONUS models from a shapefile

python -m parflow.subset.tools.subset_conus --input_path -i INPUT_PATH --shapefile -s
                                     SHAPEFILE --conus_files -f CONUS_FILES
                                     [--manifest -m MANIFEST_FILE]
                                     [--version -v {1,2}] [--out_dir -o OUT_DIR]
                                     [--out_name -n OUT_NAME] [--clip_clm -c]
                                     [--write_tcl -w]
                                     [--padding -p Top Right Bottom Left]
                                     [--attribute_ids -a ATTRIBUTE_IDS [ATTRIBUTE_IDS ...]]
                                     [--attribute_name -e ATTRIBUTE_NAME]
                                     [--tif_outs -t]

Example usage:

Create a subset of the CONUS1 domain with CLM inputs based on the shapefile at ~/downloads/shapfiles/WBDHU8.shp and write the .tcl file to run the model

python -m parflow.subset.tools.subset_conus -i ~/downloads/shapefiles -s WBDHU8 -f ~/downloads/conus1 -c 1 -w 1 -n watershedA_conus1_clip

Rasterize a shapefile for use as a mask

python -m parflow.subset.tools.rasterize_shape -i <path_to_shapefile_parts> -s <shapefile_name> -r <reference_dataset> 
                              -o [path_to_write_outputs=.] 
                              -n [output_filename=shapfile_name] 
                              -p [padding clockwise from top (top,right,bottom,left)=(0,0,0,0)]                              
                              -e [shapefile_attribute_name='OBJECTID'] 
                              -a [shapefile_attribute_ids=[1]]

Example usage:

Re-project the shapefile at ~/downloads/shapfiles/WBDHU8.shp to the CONUS1 projection and extent

python -m parflow.subset.tools.rasterize_shape -i ~/downloads/shapefiles -s WBDHU8

Use a mask to clip multiple files to PFB or TIF

assumes all files are identically gridded and same as the mask file, if write_tifs=1 then you must supply at least one tif with correct projection and transform information as either the mask file, as a reference dataset with the -r option, or in the list of datafiles to clip

python -m parflow.subset.tools.bulk_clipper (--maskfile -m MASK_FILE | --bboxfile -b BBOX_FILE | --inline-bbox -l X1 Y1 NX NY)
       (--datafiles -d DATA_FILES [DATA_FILES ...] | --glob -g GLOB_PATTERN)
       [--input_path -i INPUT_PATH] [--ref_file -r REF_FILE] [--out_dir -o OUT_DIR]
       [--pfb_outs -p] [--tif_outs -t]

Example usage with mask file:

Clip the domain outputs to the bounds of a mask generated from rasterize_shape or subset_conus

python -m parflow.subset.tools.bulk_clipper -m ~/outputs/WBDHU8.tif -d ~/outputs/runname.out.press.00001.pfb ~/outputs/runname.out.press.00002.pfb

Example usage with bounding box file:

Clip the domain outputs, starting at x, y, and extending for nx, ny

python -m parflow.subset.tools.bulk_clipper -b ~/outputs/bbox.txt -d ~/outputs/runname.out.press.00001.pfb ~/outputs/runname.out.press.00002.pfb

where bbox.txt is a tab-separated text file in the format:

x y nx ny
x_1 y_1 nx ny

Example bbox.txt clipping only the very first (lower left) cell in a domain:

x y nx ny
1 1 1 1

Example usage with bounding box declared in-line:

Clip the domain outputs, starting at x, y, and extending for nx, ny

python -m parflow.subset.tools.bulk_clipper -l 1 1 10 20 -d ~/outputs/runname.out.press.00001.pfb ~/outputs/runname.out.press.00002.pfb

clips a 10 x 20 grid anchored in the lower left from each of the inputs

Optional Arguments Explanation

Many optional arguments are available for subset_conus and rasterize_shape. Below is an explanation of the options.

-n [name for output files=shapfile_name] The name to give the output raster, defaults to shapefile name
-v [conus verson=1] The version of the ParFlow CONUS model to subset from (1 or 2), defaults to version 1
-o [path_to_write_outputs=.] The path to write the output files, defaults to current directory
-c [clip_clim] Whether or not to clip the CLM lat/lon and vegm data. Defaults to False.
-w [write_tcl] Whether or not to write the .tcl file to run the ParFlow model. Defaults to False
-p [padding for mask areas] specified clockwise from top (top, right, bottom, left). Default (0,0,0,0)
-e [shapefile_attribute_name='OBJECTID'] The name of the attribute table column to uniquely ID objects. 
-a [shapefile_attribute_ids=[1]] The list of objects in the shapefile to rasterize. Default [1]
-t [tif_outs] Whether or not to write outputs as .tif files. Defaults to False.

Supported File Types

  1. .pfb
  2. .tif
  3. .sa

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parflow_subsetter-0.99.3b0.tar.gz (44.1 kB view details)

Uploaded Source

Built Distribution

parflow_subsetter-0.99.3b0-py3-none-any.whl (52.6 kB view details)

Uploaded Python 3

File details

Details for the file parflow_subsetter-0.99.3b0.tar.gz.

File metadata

  • Download URL: parflow_subsetter-0.99.3b0.tar.gz
  • Upload date:
  • Size: 44.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.1 CPython/3.8.6

File hashes

Hashes for parflow_subsetter-0.99.3b0.tar.gz
Algorithm Hash digest
SHA256 6b97809a91051dc8dd25e611a9355598fd237908331e029a7349b67b01ff7d11
MD5 04d30fa06fb8cbb2ed74e525f3e43da0
BLAKE2b-256 722372ee52b77b2f70d27bfa0cffbf7944e0debffa5f8cbad5c9e1bc06fd8850

See more details on using hashes here.

File details

Details for the file parflow_subsetter-0.99.3b0-py3-none-any.whl.

File metadata

  • Download URL: parflow_subsetter-0.99.3b0-py3-none-any.whl
  • Upload date:
  • Size: 52.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.1 CPython/3.8.6

File hashes

Hashes for parflow_subsetter-0.99.3b0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a6a09438b229ca8ef424a9c5e0ac7da3b4f7cdf10874aa70bd86b54e9ff27c9
MD5 d0952958cb944f37d17e12470b987bfc
BLAKE2b-256 8461b6f3c3f26342250c96cb39e4328912c89efd42c6fe1495f4bfa3d01d1b7c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page