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 10 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
imagery/i.biomass/testsuite/test_i_biomass.py Outdated Show resolved Hide resolved
imagery/i.biomass/testsuite/test_i_biomass.py Outdated Show resolved Hide resolved
)

self.assertRasterFitsUnivar(
raster=self.output_raster, reference=expected_stats, precision=1e-8
Copy link
Contributor

Choose a reason for hiding this comment

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

In other tests we use slightly lower precision which is sufficient. Also you can reduce the number of decimal places in the stats.

Suggested change
raster=self.output_raster, reference=expected_stats, precision=1e-8
raster=self.output_raster, reference=expected_stats, precision=1e-6

Copy link
Contributor Author

@jayneel-shah18 jayneel-shah18 Feb 6, 2025

Choose a reason for hiding this comment

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

I have changed it to check upto six decimal places and also reduced the number of decimal places in the stats.

Copy link
Contributor

@petrasovaa petrasovaa left a comment

Choose a reason for hiding this comment

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

The test functions can be executed in undefined order, so in the setUpClass you create the initial inputs, but the individual test functions modify them, so make sure that's not going to be a problem.

Comment on lines 26 to 37
def setUp(self):
"""Reset input rasters to default state before each test."""
input_expressions = {
"fpar": "col() * 0.1",
"lightuse_eff": "row() * 0.1",
"latitude": "45.0",
"dayofyear": "150",
"transmissivity": "0.75",
"water": "0.8",
}
self._create_input_rasters(input_expressions)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this setUp is not a bad idea but given many tests are anyway creating their own layers, this is being run wastefully, so I would compute the data at the beginning of each test. We are trying to make the tests run fast.

Copy link
Member

Choose a reason for hiding this comment

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

It's 5 seconds for now, some others in imagery take 1 second, some others take more.

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 feedback! I have restructured the tests to address the feedback about efficiency. The setUp method has been removed, and input rasters are now created directly within each test as needed avoiding redundant computations and ensuring faster test execution.

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.

3 participants