The repetition between this and the preceding error is a bit of a red flag for me. You could combine the last two tests into:
```python
elif len(data.shape) == 3 and data.shape[2] in (3, 4):
    ...
```
and remove the repetition.