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

Issu#136 region #22

Merged
merged 18 commits into from Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions .travis.yml
@@ -1,6 +1,13 @@
os:
- linux
- linux

language: python

python:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnadeau4 why do we need this? Does it run the test twice now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it from UV-CDAT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed python 3.6 since we already do both version in the conda env.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@doutriaux1 Can you merge it?

- "2.7"

sudo: false

before_install:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then wget https://repo.continuum.io/miniconda/Miniconda2-4.3.21-Linux-x86_64.sh -O miniconda.sh; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then wget https://repo.continuum.io/miniconda/Miniconda2-latest-MacOSX-x86_64.sh -O miniconda.sh; fi
Expand All @@ -10,7 +17,8 @@ before_install:
- conda update -y -q conda
#- conda install gcc
script:
- conda create -n py2 -c uvcdat/label/nightly -c conda-forge genutil nose flake8 "numpy=1.13" netcdf-fortran=4.4.4=3
# =======
- conda create -n py2 -c uvcdat/label/nightly -c conda-forge genutil nose flake8 "numpy=1.13"
- export UVCDAT_ANONYMOUS_LOG=False
- echo $TRAVIS_BRANCH
- export TRAVIS_PR_BRANCH=$TRAVIS_BRANCH
Expand All @@ -20,7 +28,8 @@ script:
- python setup.py install
- python run_tests.py -v2
- rm -rf build
- conda create -n py3 -c uvcdat/label/nightly -c conda-forge -c nesii/channel/dev-esmf genutil nose flake8 "python>3" "numpy=1.13" netcdf-fortran=4.4.4=3
# netcdf-fortran 4.4.4=6 (3 is no longer avail)
- conda create -n py3 -c uvcdat/label/nightly -c conda-forge -c nesii/channel/dev-esmf genutil nose flake8 "python>3" "numpy=1.13"
- source activate py3
- python setup.py install
- python run_tests.py -v2
Expand Down
7 changes: 7 additions & 0 deletions Lib/region.py
@@ -1,6 +1,7 @@
# Adapted for numpy/ma/cdms2 by convertcdms.py
from cdms2.selectors import SelectorComponent
import cdat_info
import warnings


class DomainComponent(SelectorComponent):
Expand Down Expand Up @@ -61,6 +62,9 @@ def specify(self, slab, axes, specification, confined_by, aux):
confined_by[i] = self
# How do we want to confine this dim ?
self.aux[i] = specs = list(self.args[i])
if len(specs) > 2:
warnings.warn(
"Only axis bounds (min, max) can be specified for axis, other arguments are ignored.")
if isinstance(specs, type(slice(0))):
specification[i] = specs # If it's a slicing nothing to do
else: # But if it's not...
Expand Down Expand Up @@ -133,6 +137,9 @@ def specify(self, slab, axes, specification, confined_by, aux):
confined_by[axis] = self
myconfined[axis] = 1
self.aux[axis] = specs = list(self.kargs[kw])
if len(specs) > 2:
warnings.warn(
"Only axis bounds (min, max) can be specified for axis, other arguments are ignored.")
if not isinstance(specs, type(slice(0))):
if specs[0] is None:
tmp = axes[axis].getBounds()
Expand Down
12 changes: 6 additions & 6 deletions Lib/times.py
Expand Up @@ -1024,9 +1024,9 @@ def dayBasedSlicer(tim, arg=None):

def weekday(a, calendar=None):
if calendar is None:
b = a.torel('days since 0')
b = a.torel('days since 1')
else:
b = a.torel('days since 0', calendar)
b = a.torel('days since 1', calendar)
d = (b.value - 3) % 7
if d == 1:
return 'monday'
Expand Down Expand Up @@ -1565,11 +1565,11 @@ def climatology(self, slab, criteriaarg=None,
months[0] = months[0] - 12
v1 = cdtime.reltime(
months[0] - 1,
'months since 0').torel(
'days since 0',
'months since 1').torel(
'days since 1',
timecalendar)
v2 = cdtime.reltime(months[-1],
'months since 0').torel('days since 0',
'months since 1').torel('days since 1',
timecalendar)
vals[i] = float(v1.value + v2.value) / 2.
bnds[i] = [v1.value, v2.value]
Expand Down Expand Up @@ -1608,7 +1608,7 @@ def climatology(self, slab, criteriaarg=None,
statusbar.pop(0)
t = cdms2.createAxis(vals, bounds=bnds)
t.id = 'time'
t.units = 'days since 0'
t.units = 'days since 1'
t.designateTime()
t.setCalendar(tim.getCalendar())
ax = slab.getAxisList()
Expand Down
4 changes: 2 additions & 2 deletions ci-support/circleci_mac_dep.sh
Expand Up @@ -2,8 +2,8 @@
ls
pwd
export PATH=${HOME}/miniconda/bin:${PATH}
conda create -n py3 -c uvcdat/label/nightly -c conda-forge -c nadeau1 genutil nose flake8 "python>3" "numpy=1.13" netcdf-fortran=4.4.4=3
conda create -n py2 -c uvcdat/label/nightly -c conda-forge genutil nose flake8 "numpy=1.13" netcdf-fortran=4.4.4=3
conda create -n py3 -c nesii/label/dev-esmf -c uvcdat/label/nightly -c conda-forge genutil nose flake8 "python>3" "numpy=1.13"
conda create -n py2 -c nesii/label/dev-esmf -c uvcdat/label/nightly -c conda-forge genutil nose flake8 "numpy=1.13"
export UVCDAT_ANONYMOUS_LOG=False
source activate py3
python setup.py install
Expand Down
3 changes: 1 addition & 2 deletions ci-support/conda_upload.sh
Expand Up @@ -4,15 +4,14 @@ USER=uvcdat
VERSION="2.12"
export PATH="$HOME/miniconda/bin:$PATH"
echo "Trying to upload conda"
ESMF_CHANNEL="nesii/label/dev-esmf"
if [ $(uname) == "Linux" ]; then
OS=linux-64
echo "Linux OS"
conda update -y -q conda
ESMF_CHANNEL="nesii/label/dev-esmf"
else
echo "Mac OS"
OS=osx-64
ESMF_CHANNEL="nadeau1"
fi

mkdir ~/conda-bld
Expand Down
27 changes: 27 additions & 0 deletions tests/test_cdutil_selectRegion.py
@@ -0,0 +1,27 @@
import cdutil
import cdat_info
import cdms2
import cdms2,cdutil,sys,MV2,numpy,os,cdat_info
import unittest
import numpy
import tempfile

class CDUTIL(unittest.TestCase):

def testRegions(self):

regionNA = cdutil.region.domain(latitude=(-50.,50.,'ccb'))
f=cdms2.open(cdat_info.get_sampledata_path()+'/clt.nc')
d=f('u', regionNA)

# --------------------------------------------------------
# makesure the warning has been displayed for the 3rd args
# --------------------------------------------------------

bounds = d.getLatitude().getBounds()
self.assertTrue(numpy.allclose(bounds[0], numpy.array([-50., -49.19124603])))
self.assertTrue(numpy.allclose(bounds[-1], numpy.array([49.19124603, 50.])))

if __name__ == "__main__":
unittest.main()