Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1707 curvsetaxis #199

Merged
merged 13 commits into from
Nov 30, 2017
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ before_install:
script:
#- conda install -c uvcdat/label/nightly -c conda-forge -c uvcdat libcf distarray cdtime libcdms cdat_info numpy esmf esmpy libdrs_f pyopenssl nose requests flake8
- conda create -n py3 python=3.6
- conda install -n py3 -c conda-forge -c uvcdat libcf distarray cdtime libcdms cdat_info numpy libdrs_f pyopenssl nose requests flake8 myproxyclient netcdf-fortran=4.4.4=3
- conda install -n py3 -c conda-forge -c uvcdat libcf distarray cdtime libcdms cdat_info numpy libdrs_f pyopenssl nose requests flake8 myproxyclient netcdf-fortran=4.4.4=5
- source activate py3
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then conda install -n py3 -c nesii/channel/dev-esmf -c conda-forge esmpy=7.1.0.dev34 netcdf-fortran=4.4.4=3; fi
- export UVCDAT_ANONYMOUS_LOG=False
Expand Down
11 changes: 10 additions & 1 deletion Lib/MV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy
from numpy import character, float, float32, float64 # noqa
from numpy import int, int8, int16, int32, int64, byte # noqa
from numpy import ubyte, uint8, uint16, uint32, uint64, long # noqa
from numpy import ubyte, uint8, uint16, uint32, uint64, long # noqa
from numpy.ma import allclose, allequal, common_fill_value # noqa
from numpy.ma import make_mask_none, dot, filled # noqa
from numpy.ma import getmask, getmaskarray, identity # noqa
Expand Down Expand Up @@ -343,6 +343,15 @@ def _conv_axis_arg(axis):
return axis


def squeeze(x):
"call numpy.squeeze on ndarray and rebuild tvariable."
# ta = _makeMaskedArg(x)
maresult = numpy.squeeze(x._data)
axes, attributes, id, grid = _extractMetadata(x)
return TransientVariable(
maresult, axes=axes, attributes=attributes, grid=grid, id=id)


def is_masked(x):
"Is x a 0-D masked value?"
return isMaskedArray(x) and x.size == 1 and x.ndim == 0 and x.mask.item()
Expand Down
3 changes: 3 additions & 0 deletions Lib/avariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,9 @@ def getGridIndices(self):

# numpy.ma overrides

def squeeze(self):
return(MV.squeeze(self))

def __getitem__(self, key):
if isinstance(key, tuple):
speclist = self._process_specs(key, {})
Expand Down
21 changes: 12 additions & 9 deletions Lib/hgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,16 @@ def getGridSlices(self, domainlist, newaxislist, slicelist):
k = 0
i = j = -1
for d in domainlist:
if d is iaxis:
inewaxis = newaxislist[k]
islice = slicelist[k]
i = k
if d is jaxis:
jnewaxis = newaxislist[k]
jslice = slicelist[k]
j = k
if d.shape == iaxis.shape:
if numpy.allclose(d[:], iaxis[:]) is True:
inewaxis = newaxislist[k]
islice = slicelist[k]
i = k
if d.shape == jaxis.shape:
if numpy.allclose(d[:], jaxis[:]) is True:
jnewaxis = newaxislist[k]
jslice = slicelist[k]
j = k
k += 1

if i == -1 or j == -1:
Expand Down Expand Up @@ -677,7 +679,8 @@ def isClose(self, g):
def checkAxes(self, axes):
"""Return 1 iff every element of self.getAxisList() is in the list 'axes'."""
for item in self.getAxisList():
if item not in axes:
# if all [False, False, ....] result=0
if not any([allclose(item[:], axis[:]) for axis in axes]):
result = 0
break
else:
Expand Down
2 changes: 2 additions & 0 deletions Lib/tvariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def __array_finalize__(self, obj):
def __copy__(self):
return numpy.ma.MaskedArray.copy(self)

squeeze = AbstractVariable.squeeze

__mul__ = AbstractVariable.__mul__
__rmul__ = AbstractVariable.__rmul__
__imul__ = AbstractVariable.__imul__
Expand Down
6 changes: 3 additions & 3 deletions ci-support/circleci_mac_dep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ echo $cmd
$cmd

# Create Python 3 environment
cmd="conda create -n py3 -c uvcdat/label/nightly -c conda-forge -c uvcdat libcf distarray cdtime libcdms cdat_info numpy libdrs_f pyopenssl nose requests flake8 myproxyclient netcdf-fortran=4.4.4=3"
cmd="conda create -n py3 -c uvcdat/label/nightly -c conda-forge -c uvcdat libcf distarray cdtime libcdms cdat_info numpy libdrs_f pyopenssl nose requests flake8 myproxyclient netcdf-fortran=4.4.4=5"
echo $cmd
$cmd

cmd="conda install -n py3 -c nadeau1 -c conda-forge esmf esmpy netcdf-fortran=4.4.4=3"
cmd="conda install -n py3 -c nadeau1 -c conda-forge esmf esmpy netcdf-fortran=4.4.4=5"
echo $cmd
$cmd

Expand All @@ -30,7 +30,7 @@ cmd="source activate py2"
echo $cmd
$cmd

cmd="conda install -n py2 -c uvcdat/label/nightly -c conda-forge -c uvcdat libcf distarray cdtime libcdms cdat_info numpy esmf esmpy libdrs_f pyopenssl nose requests flake8 myproxyclient netcdf-fortran=4.4.4=3"
cmd="conda install -n py2 -c uvcdat/label/nightly -c conda-forge -c uvcdat libcf distarray cdtime libcdms cdat_info numpy esmf esmpy libdrs_f pyopenssl nose requests flake8 myproxyclient netcdf-fortran=4.4.4=5"
echo $cmd
$cmd

Expand Down
10 changes: 10 additions & 0 deletions tests/test_curvilinear_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
import os
import sys
import basetest
import copy


class TestCurvilinearGrids(basetest.CDMSBaseTest):

def testReadCurvGrid(self):
f = self.getDataFile('sampleCurveGrid4.nc')
data = f("sample")
attrs = copy.copy(data.attributes)
axes = list([x[0].clone() for x in data.getDomain()])
data2 = cdms2.createVariable(data, copy=0, attributes=attrs, axes=axes)
data3=data2(*(),squeeze=1)

def testCurvilinear(self):
datb = numpy.array(
[[697., 698., 699., 700., 701., 702., ],
Expand Down