Repository: spacetx/starfish

Issue:
MinDistanceLabel needs kwargs and sanity checking
#### Description
<!-- Example: Joblib Error thrown when calling fit on LatentDirichletAllocation with evaluate_every > 0-->

#### Steps/Code to Reproduce
<!--
If the code is too long, feel free to put it in a public gist and link
it in the issue: https://gist.github.com
-->

#### Expected Results
<!-- Example: No error is thrown. Please paste or describe the expected results.-->

#### Actual Results
<!-- Please paste or specifically describe the actual output or traceback. -->

#### Versions
<!--
import platform; print(platform.platform())
import sys; print("Python", sys.version)
import numpy; print("NumPy", numpy.__version__)
import scipy; print("SciPy", scipy.__version__)
import skimage; print("scikit-image", skimage.__version__)
import pandas; print("pandas", pandas.__version__)
import sklearn; print("sklearn", sklearn.__version__)
import xarray; print("xarray", xarray.__version__)
import sympy; print("sympy", sympy.__version__)
import starfish; print("starfish", starfish.__version__)
-->


<!-- Thanks for contributing! -->


Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/spacetx/starfish/pull/1718?src=pr&el=h1) Report
> Merging [#1718](https://codecov.io/gh/spacetx/starfish/pull/1718?src=pr&el=desc) into [master](https://codecov.io/gh/spacetx/starfish/commit/0f1420e521e7fae0561af6dff8b7894961641332?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `90.9%`.

[![Impacted file tree graph](https://codecov.io/gh/spacetx/starfish/pull/1718/graphs/tree.svg?width=650&token=kliQHejt6T&height=150&src=pr)](https://codecov.io/gh/spacetx/starfish/pull/1718?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1718      +/-   ##
==========================================
+ Coverage   89.96%   89.97%   +<.01%     
==========================================
  Files         246      246              
  Lines        9170     9176       +6     
==========================================
+ Hits         8250     8256       +6     
  Misses        920      920
```


| [Impacted Files](https://codecov.io/gh/spacetx/starfish/pull/1718?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [starfish/core/test/test\_display.py](https://codecov.io/gh/spacetx/starfish/pull/1718/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS90ZXN0L3Rlc3RfZGlzcGxheS5weQ==) | `60.86% <0%> (ø)` | :arrow_up: |
| [starfish/core/morphology/Filter/areafilter.py](https://codecov.io/gh/spacetx/starfish/pull/1718/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS9tb3JwaG9sb2d5L0ZpbHRlci9hcmVhZmlsdGVyLnB5) | `100% <100%> (ø)` | :arrow_up: |
| [...ish/core/morphology/Filter/test/test\_areafilter.py](https://codecov.io/gh/spacetx/starfish/pull/1718/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS9tb3JwaG9sb2d5L0ZpbHRlci90ZXN0L3Rlc3RfYXJlYWZpbHRlci5weQ==) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/spacetx/starfish/pull/1718?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/spacetx/starfish/pull/1718?src=pr&el=footer). Last update [0f1420e...f9f1dd0](https://codecov.io/gh/spacetx/starfish/pull/1718?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/starfish/core/morphology/Filter/areafilter.py b/starfish/core/morphology/Filter/areafilter.py
index 963f18f5..f3f9c399 100644
--- a/starfish/core/morphology/Filter/areafilter.py
+++ b/starfish/core/morphology/Filter/areafilter.py
@@ -19,10 +19,15 @@ class AreaFilter(FilterAlgorithm):
         collection.
     """
 
-    def __init__(self, min_area: Optional[int], max_area: Optional[int]):
+    def __init__(self, *, min_area: Optional[int] = None, max_area: Optional[int] = None):
         self._min_area = min_area
         self._max_area = max_area
 
+        if (self._min_area is not None
+                and self._max_area is not None
+                and self._min_area > self._max_area):
+            raise ValueError(f"min_area ({min_area}) should be smaller than max_area ({max_area})")
+
     def run(
             self,
             binary_mask_collection: BinaryMaskCollection,


Test patch:
diff --git a/starfish/core/morphology/Filter/test/test_areafilter.py b/starfish/core/morphology/Filter/test/test_areafilter.py
index 32d85b1d..1a52c0e1 100644
--- a/starfish/core/morphology/Filter/test/test_areafilter.py
+++ b/starfish/core/morphology/Filter/test/test_areafilter.py
@@ -1,10 +1,12 @@
+import pytest
+
 from starfish.core.morphology.binary_mask.test.factories import binary_mask_collection_2d
 from ..areafilter import AreaFilter
 
 
 def test_empty_filter():
     input_mask_collection = binary_mask_collection_2d()
-    output_mask_collection = AreaFilter(None, None).run(input_mask_collection)
+    output_mask_collection = AreaFilter().run(input_mask_collection)
     assert len(output_mask_collection) == len(input_mask_collection)
 
     for mask_num in range(len(input_mask_collection)):
@@ -15,11 +17,16 @@ def test_empty_filter():
 
 def test_min_area():
     input_mask_collection = binary_mask_collection_2d()
-    output_mask_collection = AreaFilter(6, None).run(input_mask_collection)
+    output_mask_collection = AreaFilter(min_area=6).run(input_mask_collection)
     assert len(output_mask_collection) == 1
 
 
 def test_max_area():
     input_mask_collection = binary_mask_collection_2d()
-    output_mask_collection = AreaFilter(None, 5).run(input_mask_collection)
+    output_mask_collection = AreaFilter(max_area=5).run(input_mask_collection)
     assert len(output_mask_collection) == 1
+
+
+def test_illegal_areas():
+    with pytest.raises(ValueError):
+        AreaFilter(min_area=7, max_area=1)