Repository: DKISTDC/dkist

Issue:
`TiledDataset.flat` breaks if not indexed
```
>>> import dkist
>>> from dkist.data.sample import VBI_AJQWW
>>> tds = dkist.load_dataset(VBI_AJQWW)
>>>tds.flat

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
File ~/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/IPython/core/formatters.py:711, in PlainTextFormatter.__call__(self, obj)
    704 stream = StringIO()
    705 printer = pretty.RepresentationPrinter(stream, self.verbose,
    706     self.max_width, self.newline,
    707     max_seq_length=self.max_seq_length,
    708     singleton_pprinters=self.singleton_printers,
    709     type_pprinters=self.type_printers,
    710     deferred_pprinters=self.deferred_printers)
--> 711 printer.pretty(obj)
    712 printer.flush()
    713 return stream.getvalue()

File ~/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/IPython/lib/pretty.py:419, in RepresentationPrinter.pretty(self, obj)
    408                         return meth(obj, self, cycle)
    409                 if (
    410                     cls is not object
    411                     # check if cls defines __repr__
   (...)
    417                     and callable(_safe_getattr(cls, "__repr__", None))
    418                 ):
--> 419                     return _repr_pprint(obj, self, cycle)
    421     return _default_pprint(obj, self, cycle)
    422 finally:

File ~/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/IPython/lib/pretty.py:794, in _repr_pprint(obj, p, cycle)
    792 """A pprint that just redirects to the normal repr function."""
    793 # Find newlines and replace them with p.break_()
--> 794 output = repr(obj)
    795 lines = output.splitlines()
    796 with p.group():

File ~/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/dkist/dataset/tiled_dataset.py:189, in TiledDataset.__repr__(self)
    185 """
    186 Overload the NDData repr because it does not play nice with the dask delayed io.
    187 """
    188 prefix = object.__repr__(self)
--> 189 return dedent(f"{prefix}\n{self.__str__()}")

File ~/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/dkist/dataset/tiled_dataset.py:192, in TiledDataset.__str__(self)
    191 def __str__(self):
--> 192     return dataset_info_str(self)

File ~/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/dkist/dataset/utils.py:21, in dataset_info_str(ds_in)
     19 if is_tiled:
     20     tile_shape = ds_in.shape
---> 21     ds = ds_in[0, 0]
     22 else:
     23     ds = ds_in

File ~/mambaforge/envs/dkist-workshop/lib/python3.13/site-packages/dkist/dataset/tiled_dataset.py:96, in TiledDataset.__getitem__(self, aslice)
     95 def __getitem__(self, aslice):
---> 96     new_data = self._data[aslice]
     97     if isinstance(new_data, Dataset):
     98         return new_data

IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
```

Discussion:

Patch:
diff --git a/changelog/475.trivial.rst b/changelog/475.trivial.rst
new file mode 100644
index 0000000..8aeee1f
--- /dev/null
+++ b/changelog/475.trivial.rst
@@ -0,0 +1,1 @@
+Fix small bug which caused `ds.flat` to break if not indexed.
diff --git a/dkist/dataset/utils.py b/dkist/dataset/utils.py
index bab3e33..2b690c1 100644
--- a/dkist/dataset/utils.py
+++ b/dkist/dataset/utils.py
@@ -18,7 +18,7 @@ def dataset_info_str(ds_in):
     dstype = type(ds_in).__name__
     if is_tiled:
         tile_shape = ds_in.shape
-        ds = ds_in[0, 0]
+        ds = ds_in.flat[0]
     else:
         ds = ds_in
     wcs = ds.wcs.low_level_wcs


Test patch:
diff --git a/dkist/dataset/tests/test_dataset.py b/dkist/dataset/tests/test_dataset.py
index 90b8c57..941cee7 100644
--- a/dkist/dataset/tests/test_dataset.py
+++ b/dkist/dataset/tests/test_dataset.py
@@ -51,6 +51,12 @@ def test_repr(dataset, dataset_3d):
     assert str(dataset_3d.data) in r
 
 
+@pytest.mark.accept_cli_dataset
+def test_flat_repr(large_tiled_dataset):
+    r = repr(large_tiled_dataset.flat)
+    assert f"is an array of ({np.prod(large_tiled_dataset.shape)},) Dataset objects" in r
+
+
 @pytest.mark.accept_cli_dataset
 def test_wcs_roundtrip(dataset):
     p = [1*u.pixel] * dataset.wcs.pixel_n_dim