diff --git a/.travis.yml b/.travis.yml index 8590d763..aead48db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,6 @@ matrix: env: CONDA_ENV=py27-xarray0.10.9 - python: 2.7 env: CONDA_ENV=py27-xarray0.11.3 - - python: 2.7 - env: CONDA_ENV=py27-numpy1.11.1 - python: 3.5 env: CONDA_ENV=py35 - python: 3.6 diff --git a/ci/environment-py27-numpy1.11.1.yml b/ci/environment-py27-numpy1.11.1.yml deleted file mode 100644 index 2d91445e..00000000 --- a/ci/environment-py27-numpy1.11.1.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: test_env -dependencies: - - python=2.7 - - xarray>=0.8.2 - - dask>=0.11.1 - - numpy=1.11.1 - - pytest - - future - - pip: - - codecov - - pytest-cov diff --git a/xmitgcm/mds_store.py b/xmitgcm/mds_store.py index fcf20301..7534ad32 100644 --- a/xmitgcm/mds_store.py +++ b/xmitgcm/mds_store.py @@ -660,11 +660,14 @@ def load_from_prefix(self, prefix, iternum=None, extra_metadata=None): # How should we handle this? Can either eliminate one of the dims # or add an extra axis to the data. Let's try the former, on the # grounds that it is simpler for the user. - if len(dims) == 3 and data.ndim == 2: + if ((len(dims) == 3 and data.ndim == 2) or + (self.llc and (len(dims) == 3 and data.ndim == 3))): # Deleting the first dimension (z) assumes that 2D data always # corresponds to x,y horizontal data. Is this really true? # The answer appears to be yes: 2D (x|y,z) data retains the # missing dimension as an axis of length 1. + # Also handles https://github.com/xgcm/xmitgcm/issues/140 + # (special case for 2d llc diags) dims = dims[1:] elif len(dims) == 1 and data.ndim > 1: # this is for certain profile data like RC, PHrefC, etc. @@ -928,5 +931,5 @@ def _reshape_for_llc(dims, data): # add face dimension to dims jdim = dims.index(dim) dims.insert(jdim, LLC_FACE_DIMNAME) - assert data.ndim==len(dims) + assert data.ndim==len(dims), '%r %r' % (data.shape, dims) return dims, data diff --git a/xmitgcm/test/test_mds_store.py b/xmitgcm/test/test_mds_store.py index 9cca0c84..1bcfdfca 100644 --- a/xmitgcm/test/test_mds_store.py +++ b/xmitgcm/test/test_mds_store.py @@ -3,6 +3,7 @@ import xarray as xr from glob import glob from shutil import copyfile +import py _TESTDATA_FILENAME = 'testdata.tar.gz' _TESTDATA_ITERS = [39600, ] @@ -194,6 +195,39 @@ def test_open_dataset_no_meta(all_mds_datadirs): ds = xmitgcm.open_mdsdataset(dirname, prefix=['T', 'Eta'], nz=nz, **kwargs) +def test_open_dataset_2D_diags(all_mds_datadirs): + # convert 3D fields with only 2D diagnostic output + # https://github.com/xgcm/xmitgcm/issues/140 + dirname, expected = all_mds_datadirs + + shape = expected['shape'] + + nz = shape[0] + ny, nx = shape[-2:] + shape_2d = shape[1:] + dims_2d = ('j', 'i') + if expected['geometry']=='llc': + dims_2d = ('face',) + dims_2d + ny = nx*shape[-3] + dims_3d = dims_2d if nz==1 else ('k',) + dims_2d + dims_2d = ('time',) + dims_2d + dims_3d = ('time',) + dims_3d + + it = expected['test_iternum'] + kwargs = dict(iters=it, geometry=expected['geometry'], read_grid=False, + swap_dims=False) + + to_hide = ['T.%010d.meta' % it, 'T.%010d.data' % it] + with hide_file(dirname, *to_hide): + + ldir = py.path.local(dirname) + old_prefix = 'Eta.%010d' % it + new_prefix = 'T.%010d' % it + for suffix in ['.data', '.meta']: + lp = ldir.join(old_prefix + suffix) + lp.copy(ldir.join(new_prefix + suffix)) + + ds = xmitgcm.open_mdsdataset(dirname, prefix=['T'], **kwargs) def test_swap_dims(all_mds_datadirs): """See if we can swap dimensions."""