Skip to content

Commit

Permalink
removed redundant setUp method
Browse files Browse the repository at this point in the history
  • Loading branch information
jayneel-shah18 committed Feb 9, 2025
1 parent ad963ac commit 2d1e007
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions imagery/i.biomass/testsuite/test_i_biomass.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ def setUpClass(cls):
cls.use_temp_region()
cls.runModule("g.region", n=10, s=0, e=10, w=0, rows=10, cols=10)

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)

@classmethod
def _create_input_rasters(cls, expressions):
"""Helper method to create input rasters with specified expressions."""
Expand Down Expand Up @@ -95,11 +83,16 @@ def test_biomass_against_reference(self):

def test_biomass_linearity(self):
"""Test linearity of i.biomass by scaling inputs."""
self.runModule(
"r.mapcalc",
expression=f"{self.input_rasters['fpar']} = col() * 0.5",
overwrite=True,
)
input_expressions = {
"fpar": "col() * 0.5",
"lightuse_eff": "row() * 0.1",
"latitude": "45.0",
"dayofyear": "150",
"transmissivity": "0.75",
"water": "0.8",
}
self._create_input_rasters(input_expressions)

self.assertModule(
"i.biomass",
fpar=self.input_rasters["fpar"],
Expand Down Expand Up @@ -204,12 +197,16 @@ def test_biomass_with_extreme_values(self):

def test_biomass_latitude_dependency(self):
"""Test that biomass values vary reasonably with latitude."""
input_expressions = {
"fpar": "col() * 0.1",
"lightuse_eff": "row() * 0.1",
"latitude": "0",
"dayofyear": "150",
"transmissivity": "0.75",
"water": "0.8",
}
self._create_input_rasters(input_expressions)

self.runModule(
"r.mapcalc",
expression=f"{self.input_rasters['latitude']} = 0",
overwrite=True,
)
self.assertModule(
"i.biomass",
fpar=self.input_rasters["fpar"],
Expand Down Expand Up @@ -243,22 +240,20 @@ def test_biomass_latitude_dependency(self):

self.assertTrue(
np.mean(equatorial_output) > np.mean(polar_output),
"Biomass at equatorial regions should generally exceed"
"biomass at polar regions.",
"Biomass at equatorial regions should generally exceed biomass at polar regions.",
)

def test_biomass_ecological_range(self):
"""Test that biomass values fall within an expected ecological range."""

test_expressions = {
input_expressions = {
"fpar": "col() * 0.5",
"lightuse_eff": "row() * 0.1",
"latitude": "45.0",
"dayofyear": "150",
"transmissivity": "0.75",
"water": "0.8",
}
self._create_input_rasters(test_expressions)
self._create_input_rasters(input_expressions)

self.assertModule(
"i.biomass",
Expand Down

0 comments on commit 2d1e007

Please sign in to comment.