natcap.invest.crop_production_percentile
InVEST Crop Production Percentile Model.
- natcap.invest.crop_production_percentile.aggregate_to_polygons(base_aggregate_vector_path, target_aggregate_vector_path, landcover_raster_projection, crop_names, nutrient_df, yield_percentile_headers, output_dir, file_suffix, target_aggregate_table_path)
Write table with aggregate results of yield and nutrient values.
Use zonal statistics to summarize total observed and interpolated production and nutrient information for each polygon in base_aggregate_vector_path.
- Parameters:
base_aggregate_vector_path (string) – path to polygon vector
target_aggregate_vector_path (string) – path to re-projected copy of polygon vector
landcover_raster_projection (string) – a WKT projection string
crop_names (list) – list of crop names
nutrient_df (pandas.DataFrame) – a table of nutrient values by crop
yield_percentile_headers (list) – list of strings indicating percentiles at which yield was calculated.
output_dir (string) – the file path to the output workspace.
file_suffix (string) – string to appened to any output filenames.
target_aggregate_table_path (string) – path to ‘aggregate_results.csv’ in the output workspace
- Returns:
None
- natcap.invest.crop_production_percentile.calculate_crop_production(lulc_path, yield_path, crop_lucode, pixel_area_ha, target_path)
Calculate crop production for a particular crop.
The resulting production value is:
nodata, where either the LULC or yield input has nodata
0, where the LULC does not match the given LULC code
yield * pixel area, where the given LULC code exists
- Parameters:
lulc_path (str) – path to a raster of LULC codes
yield_path (str) – path of a raster of yields for the crop identified by
crop_lucode
, in units per hectarecrop_lucode (int) – LULC code that identifies the crop of interest in the
lulc_path
raster.pixel_area_ha (number) – Pixel area in hectares for both input rasters
target_path (str) – Path to write the output crop production raster
- Returns:
None
- natcap.invest.crop_production_percentile.execute(args)
Crop Production Percentile.
This model will take a landcover (crop cover?) map and produce yields, production, and observed crop yields, a nutrient table, and a clipped observed map.
- Parameters:
args['workspace_dir'] (string) – output directory for intermediate, temporary, and final files
args['results_suffix'] (string) – (optional) string to append to any output file names
args['landcover_raster_path'] (string) – path to landcover raster
args['landcover_to_crop_table_path'] (string) –
path to a table that converts landcover types to crop names that has two headers:
lucode: integer value corresponding to a landcover code in args[‘landcover_raster_path’].
crop_name: a string that must match one of the crops in args[‘model_data_path’]/climate_bin_maps/[cropname]_* A ValueError is raised if strings don’t match.
args['aggregate_polygon_path'] (string) – path to polygon shapefile that will be used to aggregate crop yields and total nutrient value. (optional, if value is None, then skipped)
args['model_data_path'] (string) –
path to the InVEST Crop Production global data directory. This model expects that the following directories are subdirectories of this path:
climate_bin_maps (contains [cropname]_climate_bin.tif files)
climate_percentile_yield (contains [cropname]_percentile_yield_table.csv files)
Please see the InVEST user’s guide chapter on crop production for details about how to download these data.
args['n_workers'] (int) – (optional) The number of worker processes to use for processing this model. If omitted, computation will take place in the current process.
- Returns:
None.
- natcap.invest.crop_production_percentile.tabulate_results(nutrient_df, yield_percentile_headers, crop_names, pixel_area_ha, landcover_raster_path, landcover_nodata, output_dir, file_suffix, target_table_path)
Write table with total yield and nutrient results by crop.
This function includes all the operations that write to results_table.csv.
- Parameters:
nutrient_df (pandas.DataFrame) – a table of nutrient values by crop
yield_percentile_headers (list) – list of strings indicating percentiles at which yield was calculated.
crop_names (list) – list of crop names
pixel_area_ha (float) – area of lulc raster cells (hectares)
landcover_raster_path (string) – path to landcover raster
landcover_nodata (float) – landcover raster nodata value
output_dir (string) – the file path to the output workspace.
file_suffix (string) – string to appened to any output filenames.
target_table_path (string) – path to ‘result_table.csv’ in the output workspace
- Returns:
None