Repository: NeurodataWithoutBorders/nwbinspector (language: python)

Issue:
[Bug]: `check_timestamps_match_first_dimension` is triggered for `ImageSeries` when external format and timestamps
### What happened?

I created an ImageSeries with external file format and timestamps (data is not specified), after writing such an ImageSeries to NWB and running `nwbinspector` I get the following message:

0.8 stub_functional_scan_17797_4_10_v2.nwb: check_timestamps_match_first_dimension - 'ImageSeries' object at location '/acquisition/Video: stimulus_17797_4_10_v4'
       Message: The length of the first dimension of data (0) does not match the length of timestamps (381078).



### Steps to Reproduce

```shell
from pynwb.testing.mock.file import mock_NWBFile
from pynwb.image import ImageSeries
from pynwb import NWBHDF5IO
from nwbinspector import inspect_nwb

image = ImageSeries(
    name="test_image_series",
    description="no description",
    format="external",
    external_file=["something"],
    timestamps=[0,1,2,3],
)

nwb = mock_NWBFile()
nwb.add_acquisition(image)

with NWBHDF5IO("test_image_series.nwb", "w") as io:
    io.write(nwb)
    
results = list(inspect_nwb(nwbfile_path="test_image_series.nwb"))

from nwbinspector.inspector_tools import format_messages

print("\n".join(format_messages(results, levels=["importance", "file_path"])))
```


### Traceback

_No response_

### Operating System

Linux

### Python Executable

Python

### Python Version

3.10

### Usage

Library (Python code)

### Were you streaming with ROS3?

No

### Package Versions

_No response_

### 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 bug was not already [reported](https://github.com/neurodatawithoutborders/nwbinspector/issues)?
- [X] To the best of your ability, have you ensured this is a bug within the code that checks the NWBFile, rather than a bug in the NWBFile reader (e.g., [PyNWB](https://github.com/NeurodataWithoutBorders/pynwb) or [MatNWB](https://github.com/NeurodataWithoutBorders/matnwb))?


Discussion / hints:
Thanks for reporting this, @weiglszonja. Do you think you can fix it?
thanks, yes, I'll try to open a PR by tomorrow. 
Interestingly, we have tests that this is intended behavior for `TimeSeries` whose data is explicitly set:

https://github.com/NeurodataWithoutBorders/nwbinspector/blob/dev/tests/unit_tests/test_time_series.py#L176-L193

and I know we must have previously considered the special case of `ImageSeries` with external mode, but alas no actual tests for that skip...
Yeah I noticed, so the correct fix is to check when external mode is on, and data is empty, skip it. 

Fix patch:
diff --git a/src/nwbinspector/checks/time_series.py b/src/nwbinspector/checks/time_series.py
index c48441ed6..f1ef94170 100644
--- a/src/nwbinspector/checks/time_series.py
+++ b/src/nwbinspector/checks/time_series.py
@@ -59,6 +59,9 @@ def check_timestamps_match_first_dimension(time_series: TimeSeries):
     if time_series.data is None or time_series.timestamps is None:
         return
 
+    if getattr(time_series, "external_file", None) is not None and get_data_shape(time_series.data)[0] == 0:
+        return
+
     # A very specific edge case where this has been allowed, though much more preferable
     # to use a stack of Images rather than an ImageSeries
     if (


Test patch:
diff --git a/tests/unit_tests/test_image_series.py b/tests/unit_tests/test_image_series.py
index a6c1d4302..d144172fa 100644
--- a/tests/unit_tests/test_image_series.py
+++ b/tests/unit_tests/test_image_series.py
@@ -13,6 +13,7 @@
     check_image_series_external_file_valid,
     check_image_series_external_file_relative,
     check_image_series_data_size,
+    check_timestamps_match_first_dimension,
 )
 from nwbinspector.tools import make_minimal_nwbfile
 from nwbinspector.testing import load_testing_config
@@ -123,6 +124,17 @@ def test_check_small_image_series_stored_internally():
     assert check_image_series_data_size(image_series=image_series) is None
 
 
+def test_check_image_series_external_file_no_data_valid_pass():
+    image_series = ImageSeries(
+        name="ImageSeriesLarge",
+        external_file=["Test"],
+        format="external",
+        timestamps=[0, 1, 2, 3],
+        unit="TestUnit",
+    )
+    assert check_timestamps_match_first_dimension(time_series=image_series) is None
+
+
 def test_check_large_image_series_stored_internally():
     gb_size = 0.010  # 10 MB
     frame_length = 10