Repository: RadioAstronomySoftwareGroup/pyradiosky

Issue:
Error message with SkyModel input lengths
When a SkyModel is passed multiple inputs and one is of different length, the error message reads:

`ValueError: UVParameter <pyuvdata.parameter.UVParameter object at 0x7fe0a97efe80> is not expected shape. Parameter shape is (699,), expected shape is (26734,).`

This could be more intuitive to solve if the error indicated which input is of an incorrect length. 

Comments:

Patch:
diff --git a/pyradiosky/skymodel.py b/pyradiosky/skymodel.py
index 8b03268..882b2ed 100644
--- a/pyradiosky/skymodel.py
+++ b/pyradiosky/skymodel.py
@@ -4,8 +4,8 @@
 """Define SkyModel class and helper functions."""
 
 import warnings
-
 import os
+
 import h5py
 import numpy as np
 from scipy.linalg import orthogonal_procrustes as ortho_procr
@@ -15,15 +15,11 @@ from astropy.time import Time
 import astropy.units as units
 from astropy.units import Quantity
 from astropy.io import votable
+
 from pyuvdata.uvbase import UVBase
 from pyuvdata.parameter import UVParameter
 import pyuvdata.utils as uvutils
-
-try:
-    from pyuvdata.uvbeam.cst_beam import CSTBeam
-except ImportError:  # pragma: no cover
-    # backwards compatility for older pyuvdata versions
-    from pyuvdata.cst_beam import CSTBeam
+from pyuvdata.uvbeam.cst_beam import CSTBeam
 
 from . import utils as skyutils
 from . import spherical_coords_transforms as sct
@@ -446,7 +442,7 @@ class SkyModel(UVBase):
         # initialize the underlying UVBase properties
         super(SkyModel, self).__init__()
 
-        # String to add to history of any files written with this version of pyuvdata
+        # String to add to history of any files written with this version of pyradiosky
         self.pyradiosky_version_str = (
             "  Read/written with pyradiosky version: " + __version__ + "."
         )
@@ -713,6 +709,15 @@ class SkyModel(UVBase):
             if self.Ncomponents == 1:
                 self.stokes = self.stokes.reshape(4, self.Nfreqs, 1)
 
+            stokes_eshape = self._stokes.expected_shape(self)
+            if self.stokes.shape != stokes_eshape:
+                # Check this here to give a clear error. Otherwise this shape
+                # propagates to coherency_radec and gives a confusing error message.
+                raise ValueError(
+                    "stokes is not the correct shape. stokes shape is "
+                    f"{self.stokes.shape}, expected shape is {stokes_eshape}."
+                )
+
             if stokes_error is not None:
                 self.stokes_error = stokes_error
                 if self.Ncomponents == 1:


Test patch:
diff --git a/.github/workflows/testsuite.yaml b/.github/workflows/testsuite.yaml
index 2da4e94..e5ebf6f 100644
--- a/.github/workflows/testsuite.yaml
+++ b/.github/workflows/testsuite.yaml
@@ -91,7 +91,7 @@ jobs:
           # pytest --pyargs pyradiosky --cov=pyradiosky --cov-config=../.coveragerc --cov-report xml:../coverage.xml --junitxml=../test-reports/xunit.xml
           # cd ..
 
-      - uses: codecov/codecov-action@v1.5.2
+      - uses: codecov/codecov-action@v2.0.2
         if: success()
         with:
           token: ${{secrets.CODECOV_TOKEN}} #required
@@ -139,7 +139,7 @@ jobs:
         run: |
           python -m pytest -v --cov=pyradiosky --cov-config=.coveragerc --cov-report xml:./coverage.xml --junitxml=test-reports/xunit.xml
 
-      - uses: codecov/codecov-action@v1.5.2
+      - uses: codecov/codecov-action@v2.0.2
         if: success()
         with:
           token: ${{secrets.CODECOV_TOKEN}} #required
diff --git a/pyradiosky/tests/test_skymodel.py b/pyradiosky/tests/test_skymodel.py
index 3aef7e8..014563b 100644
--- a/pyradiosky/tests/test_skymodel.py
+++ b/pyradiosky/tests/test_skymodel.py
@@ -646,6 +646,16 @@ def test_skymodel_init_errors(zenith_skycoord):
             freq_array=[1e8] * units.Hz,
         )
 
+    with pytest.raises(ValueError, match=("stokes is not the correct shape.")):
+        SkyModel(
+            name=["icrs_zen0", "icrs_zen0", "icrs_zen0"],
+            ra=[ra] * 3,
+            dec=[dec] * 3,
+            stokes=[1.0, 0, 0, 0] * units.Jy,
+            spectral_type="flat",
+            freq_array=[1e8] * units.Hz,
+        )
+
     with pytest.raises(
         ValueError, match=("For point component types, the coherency_radec")
     ):