INNER CODE UNIT · Python
_validate_dimensions
QianyeSu/Skyborn · src/skyborn/calc/GPI/core.py:254
def _validate_dimensions(sst, psl, pressure_levels, temp, mixing_ratio, data_type="3D"):
"""Validate that input arrays have compatible dimensions based on temperature array."""
expected_levels = len(pressure_levels)
if data_type == "profile":
if temp.shape != (expected_levels,):
raise ValueError(
f"Temperature shape {temp.shape} doesn't match expected profile shape ({expected_levels},)"
)
if not (np.isscalar(sst) or sst.ndim == 0) or not (
np.isscalar(psl) or psl.ndim == 0
):
raise ValueError("SST and PSL must be scalars for profile data")
elif data_type == "3D":
if temp.ndim != 3 or temp.shape[0] != expected_levels:
raise ValueError(
f"Temperature shape {temp.shape} doesn't match expected 3D shape ({expected_levels}, nlat, nlon)"