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

i.biomass: added test file for i.biomass module #4962

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

jayneel-shah18
Copy link
Contributor

This PR introduces a suite of tests for the i.biomass GRASS GIS module, covering a range of scenarios, including functionality validation, property testing, edge cases, and performance evaluation.

Key updates in this PR include:

  • Functionality: Verify output raster existence and dimensions.
  • Properties: Test linearity and latitude dependency.
  • Edge Cases: Validate behavior with zero and extreme input values.
  • Performance: Test large-scale processing.

Test Case Additions:

  • Basic Functionality:

    • Validate the creation and existence of the biomass output raster.
  • Advanced Properties:

    • Linearity: Verify output scales proportionally with input.
    • Latitude Dependency: Ensure biomass values vary reasonably with latitude.
  • Edge Cases:

    • Handle all-zero input rasters.
    • Test extreme values for all parameters.
  • Performance:

    • Assess processing of large input rasters.

@github-actions github-actions bot added Python Related code is in Python module imagery tests Related to Test Suite labels Jan 18, 2025
@neteler neteler requested a review from YannChemin January 20, 2025 09:54
imagery/i.biomass/testsuite/test_i_biomass.py Outdated Show resolved Hide resolved
)
cls.del_temp_region()

def test_biomass_with_zero_inputs(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is particularly useful test. Instead, do a regression test to make sure the values stay the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion! I have replaced the test with a regression test to ensure the values remain consistent.

imagery/i.biomass/testsuite/test_i_biomass.py Show resolved Hide resolved
Comment on lines +72 to +97
def test_biomass_regression(self):
"""Regression test to ensure i.biomass output remains consistent."""
self._create_reference_raster()
reference_raster = "biomass_reference"

self.assertModule(
"i.biomass",
fpar=self.input_rasters["fpar"],
lightuse_efficiency=self.input_rasters["lightuse_eff"],
latitude=self.input_rasters["latitude"],
dayofyear=self.input_rasters["dayofyear"],
transmissivity_singleway=self.input_rasters["transmissivity"],
water_availability=self.input_rasters["water"],
output=self.output_raster,
overwrite=True,
)
self.assertRasterExists(self.output_raster)
self.assertRasterExists(reference_raster)

output_values = array.array(self.output_raster)
reference_values = array.array(reference_raster)

self.assertTrue(
np.allclose(output_values, reference_values, atol=2.0),
"Biomass raster values should match the reference values",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

That's not what I had in mind. You are computing the reference raster with each test run, but the idea is to compute the reference at the moment you are writing the test and then this reference is considered to be correct, the values are fixed in the test. So when somebody later changes the tool, resulting in different results, the test will fail and you will know that there is potentially a newly introduced bug. See for example r.viewshed test. It is often enough to compute univariate statistics with r.univar and then test those statistics, not cell-by-cell comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imagery module Python Related code is in Python tests Related to Test Suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants