Skip to content

Commit

Permalink
Remove __repr__ methods from all neighbourhood plugins (metoppv#1648)
Browse files Browse the repository at this point in the history
  • Loading branch information
fionaRust authored Jan 17, 2022
1 parent 671b39c commit 7189962
Show file tree
Hide file tree
Showing 13 changed files with 2 additions and 211 deletions.
10 changes: 0 additions & 10 deletions improver/nbhood/circular_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ def __init__(
self.re_mask = re_mask
self.kernel = None

def __repr__(self) -> str:
"""Represent the configured plugin instance as a string."""
result = "<CircularNeighbourhood: weighted_mode: {}, " "sum_or_fraction: {}>"
return result.format(self.weighted_mode, self.sum_or_fraction)

def apply_circular_kernel(self, cube: Cube, ranges: int) -> Cube:
"""
Method to apply a circular kernel to the data within the input cube in
Expand Down Expand Up @@ -263,11 +258,6 @@ def __init__(
except TypeError:
self.percentiles = (percentiles,)

def __repr__(self) -> str:
"""Represent the configured class instance as a string."""
result = "<GeneratePercentilesFromACircularNeighbourhood: " "percentiles: {}>"
return result.format(self.percentiles)

def pad_and_unpad_cube(self, slice_2d: Cube, kernel: ndarray) -> Cube:
"""
Method to pad and unpad a two dimensional cube. The input array is
Expand Down
12 changes: 0 additions & 12 deletions improver/nbhood/nbhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,6 @@ def _find_radii(
radii = np.interp(cube_lead_times, self.lead_times, self.radii)
return radii

def __repr__(self) -> str:
"""Represent the configured plugin instance as a string."""
if callable(self.neighbourhood_method):
neighbourhood_method = self.neighbourhood_method()
else:
neighbourhood_method = self.neighbourhood_method
result = (
"<BaseNeighbourhoodProcessing: neighbourhood_method: {}; "
"radii: {}; lead_times: {}>"
)
return result.format(neighbourhood_method, self.radii, self.lead_times)

def process(self, cube: Cube, mask_cube: Optional[Cube] = None) -> Cube:
"""
Supply neighbourhood processing method, in order to smooth the
Expand Down
5 changes: 0 additions & 5 deletions improver/nbhood/recursive_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ def __init__(self, iterations: Optional[int] = None, edge_width: int = 15) -> No
self.edge_width = edge_width
self.smoothing_coefficient_name_format = "smoothing_coefficient_{}"

def __repr__(self) -> str:
"""Represent the configured plugin instance as a string."""
result = "<RecursiveFilter: iterations: {}, edge_width: {}"
return result.format(self.iterations, self.edge_width)

@staticmethod
def _recurse_forward(
grid: ndarray, smoothing_coefficients: ndarray, axis: int
Expand Down
8 changes: 0 additions & 8 deletions improver/nbhood/square_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ def __init__(
self.sum_or_fraction = sum_or_fraction
self.re_mask = re_mask

def __repr__(self) -> str:
"""Represent the configured plugin instance as a string."""
result = (
"<SquareNeighbourhood: weighted_mode: {}, "
"sum_or_fraction: {}, re_mask: {}>"
)
return result.format(self.weighted_mode, self.sum_or_fraction, self.re_mask)

@staticmethod
def _calculate_neighbourhood(
data: ndarray, mask: ndarray, nb_size: int, sum_only: bool, re_mask: bool
Expand Down
19 changes: 0 additions & 19 deletions improver/nbhood/use_nbhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,6 @@ def __init__(
message = "re_mask should be set to False when using collapse_weights"
raise ValueError(message)

def __repr__(self) -> str:
"""Represent the configured plugin instance as a string."""
result = (
"<ApplyNeighbourhoodProcessingWithAMask: "
"coord_for_masking: {}, neighbourhood_method: {}, "
"radii: {}, lead_times: {}, collapse_weights: {}, "
"weighted_mode: {}, sum_or_fraction: {}, re_mask: {}>"
)
return result.format(
self.coord_for_masking,
self.neighbourhood_method,
self.radii,
self.lead_times,
self.collapse_weights,
self.weighted_mode,
self.sum_or_fraction,
self.re_mask,
)

def collapse_mask_coord(self, cube: Cube) -> Cube:
"""
Collapse the chosen coordinate with the available weights. The result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,6 @@ def test_sum_or_fraction(self):
CircularNeighbourhood(sum_or_fraction=sum_or_fraction)


class Test__repr__(IrisTest):

"""Test the repr method."""

def test_basic(self):
"""Test that the __repr__ returns the expected string."""

result = str(CircularNeighbourhood())
msg = (
"<CircularNeighbourhood: weighted_mode: True, " "sum_or_fraction: fraction>"
)
self.assertEqual(str(result), msg)


class Test_apply_circular_kernel(IrisTest):

"""Test neighbourhood circular probabilities plugin."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@
)


class Test__repr__(IrisTest):

"""Test the repr method."""

def test_basic(self):
"""Test that the __repr__ returns the expected string."""

result = str(GeneratePercentilesFromACircularNeighbourhood())
msg = (
"<GeneratePercentilesFromACircularNeighbourhood: "
"percentiles: {}>".format(DEFAULT_PERCENTILES)
)
self.assertEqual(str(result), msg)


class Test_make_percentile_cube(IrisTest):

"""Test the make_percentile_cube method from
Expand Down
25 changes: 0 additions & 25 deletions improver_tests/nbhood/nbhood/test_BaseNeighbourhoodProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,31 +189,6 @@ def test_radii_varying_with_lead_time_mismatch(self):
NBHood(neighbourhood_method, radii, lead_times=lead_times)


class Test__repr__(IrisTest):

"""Test the repr method."""

def test_callable(self):
"""Test that the __repr__ returns the expected string."""
result = str(NBHood(CircularNeighbourhood(), 10000))
msg = (
"<BaseNeighbourhoodProcessing: neighbourhood_method: "
"<CircularNeighbourhood: weighted_mode: True, "
"sum_or_fraction: fraction>; "
"radii: 10000.0; lead_times: None>"
)
self.assertEqual(result, msg)

def test_not_callable(self):
"""Test that the __repr__ returns the expected string."""
result = str(NBHood("circular", 10000))
msg = (
"<BaseNeighbourhoodProcessing: neighbourhood_method: "
"circular; radii: 10000.0; lead_times: None>"
)
self.assertEqual(result, msg)


class Test__find_radii(IrisTest):

"""Test the internal _find_radii function is working correctly."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ def test_neighbourhood_method_exists(self):
"""
neighbourhood_method = "circular"
radii = 10000
result = NBHood(neighbourhood_method, radii)
msg = (
"<GeneratePercentilesFromACircularNeighbourhood: percentiles: "
"(0, 5, 10, 20, 25, 30, 40, 50, 60, 70, 75, 80, 90, 95, 100)>"
)
self.assertEqual(str(result.neighbourhood_method), msg)
NBHood(neighbourhood_method, radii)

def test_neighbourhood_method_does_not_exist(self):
"""
Expand All @@ -71,22 +66,6 @@ def test_neighbourhood_method_does_not_exist(self):
NBHood(neighbourhood_method, radii)


class Test__repr__(IrisTest):

"""Test the repr method."""

def test_basic(self):
"""Test that the __repr__ returns the expected string."""
result = str(NBHood("circular", 10000))
msg = (
"<BaseNeighbourhoodProcessing: neighbourhood_method: "
"<GeneratePercentilesFromACircularNeighbourhood: percentiles: "
"(0, 5, 10, 20, 25, 30, 40, 50, 60, 70, 75, 80, 90, 95, 100)>; "
"radii: 10000.0; lead_times: None>"
)
self.assertEqual(result, msg)


class Test_process(IrisTest):

"""Test the process method."""
Expand Down
22 changes: 1 addition & 21 deletions improver_tests/nbhood/nbhood/test_NeighbourhoodProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ def test_neighbourhood_method_exists(self):
method exists."""
neighbourhood_method = "circular"
radii = 10000
result = NBHood(neighbourhood_method, radii)
msg = (
"<CircularNeighbourhood: weighted_mode: True, " "sum_or_fraction: fraction>"
)
self.assertEqual(str(result.neighbourhood_method), msg)
NBHood(neighbourhood_method, radii)

def test_neighbourhood_method_does_not_exist(self):
"""Test that desired error message is raised, if the neighbourhood
Expand All @@ -66,22 +62,6 @@ def test_neighbourhood_method_does_not_exist(self):
NBHood(neighbourhood_method, radii)


class Test__repr__(IrisTest):

"""Test the repr method."""

def test_basic(self):
"""Test that the __repr__ returns the expected string."""
result = str(NBHood("circular", 10000))
msg = (
"<BaseNeighbourhoodProcessing: neighbourhood_method: "
"<CircularNeighbourhood: weighted_mode: True, "
"sum_or_fraction: fraction>; "
"radii: 10000.0; lead_times: None>"
)
self.assertEqual(result, msg)


class Test_process(IrisTest):

"""Test the process method."""
Expand Down
15 changes: 0 additions & 15 deletions improver_tests/nbhood/recursive_filter/test_RecursiveFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,6 @@ def _mean_points(points):
return np.array((points[:-1] + points[1:]) / 2, dtype=np.float32)


class Test__repr__(IrisTest):

"""Test the repr method."""

def test_basic(self):
"""Test that the __repr__ returns the expected string."""
iterations = None
edge_width = 1
result = str(RecursiveFilter(iterations, edge_width))
msg = "<RecursiveFilter: iterations: {}, edge_width: {}".format(
iterations, edge_width
)
self.assertEqual(result, msg)


class Test_RecursiveFilter(IrisTest):

"""Test class for the RecursiveFilter tests, setting up cubes."""
Expand Down
14 changes: 0 additions & 14 deletions improver_tests/nbhood/square_kernel/test_SquareNeighbourhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ def test_sum_or_fraction(self):
SquareNeighbourhood(sum_or_fraction=sum_or_fraction)


class Test__repr__(IrisTest):

"""Test the repr method."""

def test_basic(self):
"""Test that the __repr__ returns the expected string."""
result = str(SquareNeighbourhood())
msg = (
"<SquareNeighbourhood: weighted_mode: {}, "
"sum_or_fraction: {}, re_mask: {}>".format(True, "fraction", True)
)
self.assertEqual(result, msg)


class Test_run(IrisTest):

"""Test the run method on the SquareNeighbourhood class."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ class Test__init__(unittest.TestCase):

"""Test the __init__ method of ApplyNeighbourhoodProcessingWithAMask."""

def test_basic(self):
"""Test that the __init__ method returns the expected string."""
coord_for_masking = "topographic_zone"
radii = 2000
result = ApplyNeighbourhoodProcessingWithAMask(coord_for_masking, radii)
msg = (
"<ApplyNeighbourhoodProcessingWithAMask: coord_for_masking: "
"topographic_zone, neighbourhood_method: square, radii: 2000, "
"lead_times: None, collapse_weights: None, weighted_mode: True, "
"sum_or_fraction: fraction, re_mask: False>"
)
self.assertEqual(str(result), msg)

def test_raises_error(self):
"""Test raises an error if re_mask=True when using collapse_weights"""
message = "re_mask should be set to False when using collapse_weights"
Expand All @@ -73,24 +60,6 @@ def test_raises_error(self):
)


class Test__repr__(unittest.TestCase):

"""Test the __repr__ method of ApplyNeighbourhoodProcessingWithAMask."""

def test_basic(self):
"""Test that the __repr__ method returns the expected string."""
coord_for_masking = "topographic_zone"
radii = 2000
result = str(ApplyNeighbourhoodProcessingWithAMask(coord_for_masking, radii))
msg = (
"<ApplyNeighbourhoodProcessingWithAMask: coord_for_masking: "
"topographic_zone, neighbourhood_method: square, radii: 2000, "
"lead_times: None, collapse_weights: None, weighted_mode: True, "
"sum_or_fraction: fraction, re_mask: False>"
)
self.assertEqual(result, msg)


class Test_collapse_mask_coord(unittest.TestCase):
"""
Test the collapse_mask_coord method.
Expand Down

0 comments on commit 7189962

Please sign in to comment.