Repository: spacetx/starfish

Issue:
Add sanity checks to data formatting tools
## Objective

*As a user of spacetx format, I want starfish to catch common errors so that it's easier to debug simple problems in data formatting*

### Acceptance Criteria
* a warning is emitted if the shape of x & y aren't >= the shape of r, c, and z

### Notes
See: #1502 for rationale

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/spacetx/starfish/pull/1525?src=pr&el=h1) Report
> Merging [#1525](https://codecov.io/gh/spacetx/starfish/pull/1525?src=pr&el=desc) into [master](https://codecov.io/gh/spacetx/starfish/commit/a5b405b37e7c2ad377bccfbde1c429bf2a1ad333?src=pr&el=desc) will **decrease** coverage by `32.14%`.
> The diff coverage is `25%`.

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

```diff
@@             Coverage Diff             @@
##           master    #1525       +/-   ##
===========================================
- Coverage    87.1%   54.96%   -32.15%     
===========================================
  Files         139      139               
  Lines        4988     4992        +4     
===========================================
- Hits         4345     2744     -1601     
- Misses        643     2248     +1605
```


| [Impacted Files](https://codecov.io/gh/spacetx/starfish/pull/1525?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [starfish/core/experiment/builder/\_\_init\_\_.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS9leHBlcmltZW50L2J1aWxkZXIvX19pbml0X18ucHk=) | `29.21% <25%> (-67.26%)` | :arrow_down: |
| [...tructured\_formatter/structured\_formatter\_script.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS9leHBlcmltZW50L2J1aWxkZXIvdGVzdC9zdHJ1Y3R1cmVkX2Zvcm1hdHRlci9zdHJ1Y3R1cmVkX2Zvcm1hdHRlcl9zY3JpcHQucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [starfish/test/full\_pipelines/api/test\_dartfish.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvdGVzdC9mdWxsX3BpcGVsaW5lcy9hcGkvdGVzdF9kYXJ0ZmlzaC5weQ==) | `20% <0%> (-80%)` | :arrow_down: |
| [...e/experiment/builder/test/factories/all\_purpose.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS9leHBlcmltZW50L2J1aWxkZXIvdGVzdC9mYWN0b3JpZXMvYWxsX3B1cnBvc2UucHk=) | `21.27% <0%> (-78.73%)` | :arrow_down: |
| [...ilder/test/structured\_formatter/test\_single\_fov.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS9leHBlcmltZW50L2J1aWxkZXIvdGVzdC9zdHJ1Y3R1cmVkX2Zvcm1hdHRlci90ZXN0X3NpbmdsZV9mb3YucHk=) | `23.52% <0%> (-76.48%)` | :arrow_down: |
| [starfish/test/full\_pipelines/api/test\_iss\_api.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvdGVzdC9mdWxsX3BpcGVsaW5lcy9hcGkvdGVzdF9pc3NfYXBpLnB5) | `23.52% <0%> (-76.48%)` | :arrow_down: |
| [starfish/test/full\_pipelines/api/test\_merfish.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvdGVzdC9mdWxsX3BpcGVsaW5lcy9hcGkvdGVzdF9tZXJmaXNoLnB5) | `24.39% <0%> (-75.61%)` | :arrow_down: |
| [...re/spots/DetectSpots/local\_search\_blob\_detector.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS9zcG90cy9EZXRlY3RTcG90cy9sb2NhbF9zZWFyY2hfYmxvYl9kZXRlY3Rvci5weQ==) | `25% <0%> (-70.2%)` | :arrow_down: |
| [starfish/core/spacetx\_format/test\_fuzz.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS9zcGFjZXR4X2Zvcm1hdC90ZXN0X2Z1enoucHk=) | `31.03% <0%> (-68.97%)` | :arrow_down: |
| [starfish/core/util/click/\_\_init\_\_.py](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree#diff-c3RhcmZpc2gvY29yZS91dGlsL2NsaWNrL19faW5pdF9fLnB5) | `25.92% <0%> (-66.67%)` | :arrow_down: |
| ... and [77 more](https://codecov.io/gh/spacetx/starfish/pull/1525/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/spacetx/starfish/pull/1525?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/1525?src=pr&el=footer). Last update [a5b405b...1e8f692](https://codecov.io/gh/spacetx/starfish/pull/1525?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.rst b/README.rst
index 8e52f3e6..e95ed095 100644
--- a/README.rst
+++ b/README.rst
@@ -1,17 +1,29 @@
 Starfish
 ========
 
-.. image:: https://travis-ci.com/spacetx/starfish.svg?branch=master
-    :target: https://travis-ci.com/spacetx/starfish
-    :width: 20%
-.. image:: https://codecov.io/gh/spacetx/starfish/branch/master/graph/badge.svg
-    :target: https://codecov.io/gh/spacetx/starfish
+
+.. image:: https://img.shields.io/pypi/v/starfish   
+    :target: https://pypi.org/project/starfish/
+    :alt: PyPI
+    
+.. image:: https://img.shields.io/pypi/dm/starfish   
+   :target: https://pypistats.org/packages/starfish
+   :alt: PyPI - Downloads
+
 .. image:: https://readthedocs.org/projects/spacetx-starfish/badge/?version=latest
     :target: https://spacetx-starfish.readthedocs.io/en/latest/?badge=latest
     :alt: Documentation Status
+    
 .. image:: https://join-cziscience-slack.herokuapp.com/badge.svg
     :target: https://join-cziscience-slack.herokuapp.com/
     :alt: Join the CZI Science slack
+    
+.. image:: https://travis-ci.com/spacetx/starfish.svg?branch=master
+    :target: https://travis-ci.com/spacetx/starfish
+    
+.. image:: https://codecov.io/gh/spacetx/starfish/branch/master/graph/badge.svg
+    :target: https://codecov.io/gh/spacetx/starfish
+    
 
 .. ideally we could use the ..include directive here instead of copy and pasting the following
    information
diff --git a/starfish/core/experiment/builder/__init__.py b/starfish/core/experiment/builder/__init__.py
index 738714d1..99e9b55c 100644
--- a/starfish/core/experiment/builder/__init__.py
+++ b/starfish/core/experiment/builder/__init__.py
@@ -30,6 +30,7 @@ from slicedimage import (
 
 from starfish import FieldOfView
 from starfish.core.codebook.codebook import Codebook
+from starfish.core.errors import DataFormatWarning
 from starfish.core.experiment.builder.orderediterator import join_axes_labels, ordered_iterator
 from starfish.core.experiment.version import CURRENT_VERSION
 from starfish.core.types import Axes, Coordinates
@@ -116,6 +117,14 @@ def build_irregular_image(
                 current_ch,
                 current_zplane
             )
+            for axis in (Axes.X, Axes.Y):
+                if image.shape[axis] < max(len(rounds), len(chs), len(zplanes)):
+                    warnings.warn(
+                        f"{axis} axis appears to be smaller than rounds/chs/zplanes, which is "
+                        "unusual",
+                        DataFormatWarning
+                    )
+
             tile = Tile(
                 image.coordinates,
                 {


Test patch:
diff --git a/starfish/core/experiment/builder/test/test_small_axis.py b/starfish/core/experiment/builder/test/test_small_axis.py
new file mode 100644
index 00000000..0cc39e84
--- /dev/null
+++ b/starfish/core/experiment/builder/test/test_small_axis.py
@@ -0,0 +1,66 @@
+import warnings
+from typing import Callable, Collection, Mapping, Sequence
+
+import pytest
+
+from starfish.core.errors import DataFormatWarning
+from starfish.core.types import Coordinates, CoordinateValue
+from .factories.all_purpose import collection_factory
+from .factories.unique_tiles import UniqueTiles
+from .. import TileIdentifier
+
+
+@pytest.mark.parametrize(
+    "num_round_labels, num_ch_labels, num_zplane_labels, tile_height, tile_width, has_warnings",
+    (
+        (1, 1, 1, 100, 100, False),
+        (1, 1, 1000, 100, 100, True),
+        (1, 1000, 1, 100, 100, True),
+        (1000, 1, 1, 100, 100, True),
+        (1000, 1, 1, 10000, 100, True),
+        (1000, 1, 1, 100, 10000, True),
+    )
+)
+def test_small_axis(
+        num_round_labels,
+        num_ch_labels,
+        num_zplane_labels,
+        tile_height,
+        tile_width,
+        has_warnings,
+):
+    tile_identifiers: Collection[TileIdentifier] = [
+        TileIdentifier(0, round_label, ch_label, zplane_label)
+        for round_label in range(num_round_labels)
+        for ch_label in range(num_ch_labels)
+        for zplane_label in range(num_zplane_labels)
+    ]
+
+    def make_tile_coordinate_callback(
+            all_zplane_labels: Sequence[int]
+    ) -> Callable[[TileIdentifier], Mapping[Coordinates, CoordinateValue]]:
+        def tile_coordinate_callback(
+                tile_identifier: TileIdentifier
+        ) -> Mapping[Coordinates, CoordinateValue]:
+            zplane_offset = all_zplane_labels.index(tile_identifier.zplane_label)
+            return {
+                Coordinates.X: (0.0, 0.1),
+                Coordinates.Y: (0.0, 0.1),
+                Coordinates.Z: zplane_offset * 0.1,
+            }
+
+        return tile_coordinate_callback
+
+    with warnings.catch_warnings(record=True) as warnings_:
+        collection_factory(
+            UniqueTiles,
+            tile_identifiers,
+            make_tile_coordinate_callback(
+                sorted(set(tile_identifier.zplane_label for tile_identifier in tile_identifiers))),
+            tile_height,
+            tile_width,
+        )
+        assert has_warnings == (
+            0 != len(
+                [warning for warning in warnings_
+                 if issubclass(warning.category, DataFormatWarning)]))