natcap.invest.crop_production_regression.crop_production_regression
InVEST Crop Production Regression Model.
- class natcap.invest.crop_production_regression.crop_production_regression.CropNameColumnInput(*, id: str, name: str | None = None, about: str | None = None, required: bool | str = True, allowed: bool | str = True, hidden: bool = False, options: list[Option], include_placeholder: bool = False, dropdown_function: Callable | None = None)
Bases:
OptionStringInputRepresents the ‘crop_name’ column in the crop nutrient table.
- model_config = {'arbitrary_types_allowed': True, 'frozen': True}
Allow fields to have arbitrary types that don’t inherit from BaseModel (needed for pint.Unit).
- validate(value)
Validate a value against the requirements for this input.
- Parameters:
value – The value to validate.
- Returns:
A string error message if an error was found.
Noneotherwise.
- class natcap.invest.crop_production_regression.crop_production_regression.CropToPathTables(climate_bin, observed_yield, percentile_yield, regression_yield)
Bases:
tuple- climate_bin
Alias for field number 0
- observed_yield
Alias for field number 1
- percentile_yield
Alias for field number 2
- regression_yield
Alias for field number 3
- natcap.invest.crop_production_regression.crop_production_regression.aggregate_regression_results_to_polygons(base_aggregate_vector_path, target_aggregate_vector_path, aggregate_results_table_path, landcover_raster_projection, crop_names, nutrient_df, pixel_area_ha, file_registry)
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
aggregate_results_table_path (string) – path to CSV file where aggregate results will be reported.
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
pixel_area_ha (float) – area of lulc raster cells (hectares)
file_registry (FileRegistry) – used to look up target file paths
- Returns:
None
- natcap.invest.crop_production_regression.crop_production_regression.execute(args)
Crop Production Regression.
This model will take a landcover (crop cover?), N, P, and K map and produce modeled yields, and a nutrient table.
- 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['fertilization_rate_table_path'] (string) – path to CSV table that contains fertilization rates for the crops in the simulation, though it can contain additional crops not used in the simulation. The headers must be ‘crop_name’, ‘nitrogen_rate’, ‘phosphorus_rate’, and ‘potassium_rate’, where ‘crop_name’ is the name string used to identify crops in the ‘landcover_to_crop_table_path’, and rates are in units kg/Ha.
args['aggregate_polygon_path'] (string) – path to polygon vector that will be used to aggregate crop yields and total nutrient value. (optional, if value is None, then skipped)
args['regression_yield_csv_table'] (string) – path to a table that maps each crop name to a path to its corresponding regression 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.
- Returns:
File registry dictionary mapping MODEL_SPEC output ids to absolute paths
- natcap.invest.crop_production_regression.crop_production_regression.tabulate_regression_results(nutrient_df, 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
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 target file paths
target_table_path (string) – path to ‘result_table.csv’ in the output workspace
- Returns:
None