Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert per-pixel values to per-hectare values in raster outputs of multiple models #1717

Open
wants to merge 17 commits into
base: release/3.15.0
Choose a base branch
from

Conversation

emilyanndavis
Copy link
Member

@emilyanndavis emilyanndavis commented Dec 18, 2024

Description

Fixes #1270. Specifically, the following models (and their tests) have been updated:

  • Carbon
  • SDR
  • NDR
  • Forest Carbon
  • Crop Production: Percentile
  • Crop Production: Regression

Where these models previously produced raster outputs whose pixel values were in per-pixel units (e.g., Mg C/px, or kg N/(px•yr), etc.), they now produce raster outputs whose pixel values are in per-hectare units (e.g., Mg C/ha, or kg N/(ha•yr), etc.).

Regression tests now check raster outputs to make sure their values are in the appropriate units, and they also check any summary tables to make sure reported totals (e.g., total Mg C, or total kg N/yr, etc.) remain unchanged.

(Also includes some cleanup of miscellaneous items, such as unused variables, PEP8 issues picked up by my linter, and typos I noticed while reading the code and/or the user guide.)

Checklist

  • Requested feedback from internal (NatCap) users
  • Updated HISTORY.rst and link to any relevant issue
  • Updated the user's guide (in progress)
  • [ ] Tested the Workbench UI (if relevant)

@emilyanndavis emilyanndavis changed the base branch from main to release/3.15.0 February 6, 2025 20:59
@emilyanndavis emilyanndavis marked this pull request as ready for review February 6, 2025 21:44
Copy link
Contributor

@davemfish davemfish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, @emilyanndavis. I appreciate the comments about unit conversions and using the same regression values when possible to confirm that the results are correct. I have just a few minor comments.

@@ -548,10 +548,8 @@ def _generate_carbon_map(
Returns:
None.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't comment on the line, but the out_carbon_stock_path docstring might need updating for the new units.

@@ -835,9 +832,8 @@ def execute(args):
args=(args['aggregate_polygon_path'],
target_aggregate_vector_path,
landcover_raster_info['projection_wkt'],
crop_names, nutrient_df,
output_dir, file_suffix,
aggregate_results_table_path),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see aggregate_results_table_path was also being defined within the function, so it appears redundant to pass it in here. But for the sake of taskgraph and knowing the complete target_path_list, should we continue passing this filepath as an arg?

@@ -188,7 +188,7 @@
"about": "Total potential soil loss per pixel in the original land cover calculated from the USLE equation. (Eq. (68))",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to "per hectare"

@@ -247,6 +251,27 @@ def test_base_regression(self):
args['workspace_dir'], 'intermediate_outputs',
'what_drains_to_stream.tif')))

# Check raster outputs to make sure values are in kg/ha/yr.
# Pixel size in test data is 30m x 30m = 900 m^2.
pixels_per_hectare = 10000 / 900
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to get the pixel size directly from the test data instead of hardcoding it? It might make this a bit more resilient to future changes.

@@ -175,6 +177,28 @@ def test_base_regression(self):
self.assertEqual(
numpy.count_nonzero(sed_dep_array[negative_non_nodata_mask]), 0)

# Check raster outputs to make sure values are in tons/ha/yr.
# Pixel size in test data is 50m x 50m = 2500 m^2.
pixels_per_hectare = 10000 / 2500
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here - should we get the pixel size directly from the raster?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add value per hectare output values to relevant models
3 participants