InVEST Recreation ad Tourism model Regression

What is the issue or question you have?

I used an AOI at the ADM1 level with the following code, but I couldn’t get the correct proportion of photo user days (pr_PUD[i]).

I want to calculate the proportion for each province as

# The proportion in each cell i
pr_PUD[i] = PUD_YR_AVG[i] / PUD_YR_AVG.sum()
pr_TUD[i] = TUD_YR_AVG[i] / TUD_YR_AVG.sum()
avg_pr_UD[i] = (pr_PUD[i] + pr_TUD[i]) / 2
*This equation is from "User Days" of Visitation: Recreation and Tourism on your InVEST guideline.

where the sum is taken at the ADM1 level. However, I’m not getting the correct PUD proportion because it seems that all avg_pr_UD[i] of each province equals 1 when I run the code for each province individually. How can I correctly compute the PUD proportion for each province at the ADM1 level?

Should I calculate it manually? or Should I change the AOI to cell level? or Is there other ways?

Thank you for your cooperation.

-----------------------

RUN InVEST Recreation

-----------------------

for idx, row in tqdm(admin_gdf.iterrows(), total=len(admin_gdf)):province_name_safe = row[“NAME_1”].strip().replace(" ", “_”)workspace = workspace_root / “ADM1” / province_name_safeworkspace.mkdir(parents=True, exist_ok=True)

args = {
"workspace_dir": str(workspace),
"aoi_path": str(split_admin_dir / f"{province_name_safe}.geojson"),
"start_year": START_YEAR,
"end_year": END_YEAR,
"grid_size": 5000,
"compute_regression": True,  
"predictor_table_path": str(predictor_table_path)
}

logging.info(f"Running InVEST Recreation for {province_name_safe}...")
try:
    rec.execute(args)
    logging.info(f"Completed successfully: {province_name_safe}")
except Exception as e:
    logging.error(f"Error in {province_name_safe}: {e}")
    logging.error(traceback.format_exc())

Hi @yf11

I think I understand your question, but please correct me if I’m misinterpreting.

it seems that all avg_pr_UD[i] of each province equals 1 when I run the code for each province individually

This is what’s expected when each province is its own AOI. The sum is over all cells/polygons in the AOI in the run. If your AOI is just 1 polygon (1 province, not gridded), then the sum will equal the average. If your AOI is gridded but you run the model province by province, then for each loop, PUD_YR_AVG.sum() is the sum over cells in that province only. So, within each province, the pr_PUD and therefore avg_pr_UD will sum to 1.

In addition, the args you’re passing to execute are not all correct. Specifically, grid_size is not a recognized argument. Instead, you may want to specify cell_size, grid_type, and grid_aoi. Here is the Python API reference: https://invest.readthedocs.io/en/latest/api/natcap.invest.recreation.recmodel_client.html#natcap.invest.recreation.recmodel_client.execute.

If I understand your goal correctly, you want each province’s pr_PUD to reflect its share of the whole study area, so that the sum across all province of pr_PUD = 1. To achieve this, you can build a single AOI vector that contains all provinces as their own features, and then don’t split by province in a loop (i.e., just run the model once and set grid_aoi=False so that the polygons in the AOI are the provinces). You will then see in the resulting regression data gpkg, a row per province that contains attribute pr_PUD which gives “the proportion of the sum of PUD_YR_AVG across all features” which is calculated as PUD_YR_AVG for the feature divided by the PUD sum of all features. Here is the User’s Guide section about how to interpret the results (including for regression_data.gpkg): Visitation: Recreation and Tourism — InVEST® documentation

Thank you for your reply and understandings!

I divided the AOI by province because I couldn’t successfully run the entire country AOI due to limitations on the number of points required for the recreation model.

Therefore, I think I cannot get the desired output when I put the single AOI vector that contains all provinces…