Repository: NeurodataWithoutBorders/nwbinspector (language: python)

Issue:
[Add Check]: IndexSeries should reference Images, not TimeSeries (which is deprecated)
### What would you like to see added to the NWBInspector?

See title.

### Pseudocode or other logic of the check

_No response_

### Do you have any interest in helping implement the check function?

Maybe.

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/NeurodataWithoutBorders/nwbinspector/blob/dev/.github/CODE_OF_CONDUCT.rst)
- [X] Have you ensured this check was not already [requested](https://github.com/neurodatawithoutborders/nwbinspector/issues)?


Discussion / hints:

Fix patch:
diff --git a/src/nwbinspector/checks/images.py b/src/nwbinspector/checks/images.py
index c611c262c..cb1ff4827 100644
--- a/src/nwbinspector/checks/images.py
+++ b/src/nwbinspector/checks/images.py
@@ -8,6 +8,7 @@
 except ImportError:
     HAVE_IMAGES = False
 
+from pynwb.image import IndexSeries
 
 if HAVE_IMAGES:
 
@@ -29,3 +30,11 @@ def check_order_of_images_len(images: Images):
                 message=f"Length of order_of_images ({len(images.order_of_images)}) does not match the number of "
                 f"images ({len(images.images)})."
             )
+
+    @register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=IndexSeries)
+    def check_index_series_points_to_image(index_series: IndexSeries):
+        if index_series.indexed_timeseries is not None:
+            return InspectorMessage(
+                message="Pointing an IndexSeries to a TimeSeries will be deprecated. Please point to an Images "
+                "container instead."
+            )


Test patch:
diff --git a/tests/unit_tests/test_images.py b/tests/unit_tests/test_images.py
index 88dcfe312..936d39f49 100644
--- a/tests/unit_tests/test_images.py
+++ b/tests/unit_tests/test_images.py
@@ -1,10 +1,15 @@
 import pytest
 
 import numpy as np
-from pynwb.image import GrayscaleImage
+from pynwb import TimeSeries
+from pynwb.image import GrayscaleImage, IndexSeries
 
 from nwbinspector import InspectorMessage, Importance
-from nwbinspector.checks.images import check_order_of_images_unique, check_order_of_images_len
+from nwbinspector.checks.images import (
+    check_order_of_images_unique,
+    check_order_of_images_len,
+    check_index_series_points_to_image,
+)
 
 try:
     from pynwb.base import Images, ImageReferences
@@ -67,3 +72,61 @@ def test_pass_check_order_of_images_len():
     images = Images(name="my_images", images=imgs, order_of_images=img_refs)
 
     assert check_order_of_images_len(images) is None
+
+
+@pytest.mark.skipif(not HAVE_IMAGES, reason=skip_reason)
+def test_pass_check_index_series_points_to_image():
+
+    gs_img = GrayscaleImage(
+        name="random grayscale",
+        data=np.empty(shape=(40, 50), dtype=np.uint8),
+        resolution=70.0,
+        description="Grayscale version of a raccoon.",
+    )
+
+    images = Images(
+        name="images",
+        images=[gs_img],
+        description="An example collection.",
+        order_of_images=ImageReferences("order_of_images", [gs_img]),
+    )
+
+    idx_series = IndexSeries(
+        name="stimuli",
+        data=[0, 1, 0, 1],
+        indexed_images=images,
+        unit="N/A",
+        timestamps=[0.1, 0.2, 0.3, 0.4],
+    )
+
+    assert check_index_series_points_to_image(idx_series) is None
+
+
+@pytest.mark.skipif(not HAVE_IMAGES, reason=skip_reason)
+def test_fail_check_index_series_points_to_image():
+
+    time_series = TimeSeries(
+        name="TimeSeries",
+        data=np.empty(shape=(2, 50, 40)),
+        rate=400.0,
+        description="description",
+        unit="n.a.",
+    )
+
+    idx_series = IndexSeries(
+        name="stimuli",
+        data=[0, 1, 0, 1],
+        indexed_timeseries=time_series,
+        unit="N/A",
+        timestamps=[0.1, 0.2, 0.3, 0.4],
+    )
+
+    assert check_index_series_points_to_image(idx_series) == InspectorMessage(
+        object_name="stimuli",
+        importance=Importance.BEST_PRACTICE_VIOLATION,
+        object_type="IndexSeries",
+        message="Pointing an IndexSeries to a TimeSeries will be deprecated. Please point to an Images container "
+        "instead.",
+        location="/",
+        check_function_name="check_index_series_points_to_image",
+    )