natcap.invest.crop_production_percentile.crop_production_percentile
InVEST Crop Production Percentile Model.
- natcap.invest.crop_production_percentile.crop_production_percentile.aggregate_to_polygons(base_aggregate_vector_path, target_aggregate_vector_path, landcover_raster_projection, crop_names, nutrient_df, yield_percentile_headers, pixel_area_ha, file_registry, 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.
pixel_area_ha (float) – area of lulc raster cells (hectares)
file_registry (FileRegistry) – used to look up output file paths
target_aggregate_table_path (string) – path to ‘aggregate_results.csv’ in the output workspace
- Returns:
None
- natcap.invest.crop_production_percentile.crop_production_percentile.calculate_crop_production(lulc_path, yield_path, crop_lucode, 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 (in Mg/ha), 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_pathraster.target_path (str) – Path to write the output crop production raster
- Returns:
None
- natcap.invest.crop_production_percentile.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
CROP_OPTIONS. A ValueError is raised if no corresponding climate bin raster path is found in the Climate Bin Raster Table.
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['percentile_yield_csv_table'] (string) – path to a table that maps each crop name to a path to its corresponding percentile yield table.
args['climate_bin_raster_table'] (string) – path to a table that maps each crop name to a path to its corresponding climate bin raster.
args['observed_yield_raster_table'] (string) – path to a table that maps each crop name to a path to its corresponding observed yield raster.
args['crop_nutrient_table'] (string) – path to a table that lists amounts of nutrients in each crop.
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:
File registry dictionary mapping MODEL_SPEC output ids to absolute paths
- natcap.invest.crop_production_percentile.crop_production_percentile.tabulate_results(nutrient_df, yield_percentile_headers, crop_names, pixel_area_ha, landcover_raster_path, landcover_nodata, file_registry, 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
file_registry (FileRegistry) – used to look up output file paths
target_table_path (string) – path to ‘result_table.csv’ in the output workspace
- Returns:
None