Skip to content

Commit

Permalink
Merge pull request #25 from ocefpaf/extract_track
Browse files Browse the repository at this point in the history
Minor bug fixes
  • Loading branch information
ocefpaf authored Jul 18, 2016
2 parents dae2691 + a29bc39 commit 68f2dcc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ language: python

env:
- CONDA="python=2.7"
- CONDA="python=3.4"
- CONDA="python=3.5"

before_install:
- wget http://bit.ly/miniconda -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- conda update --yes conda
- conda config --add channels ioos -f
- travis_retry conda create --yes -n test $CONDA --file requirements.txt
- source activate test
- conda install --yes --file requirements-dev.txt
- conda config --add channels conda-forge -f
- conda create --yes -n TEST $CONDA --file requirements.txt
- conda install --yes -n TEST --file requirements-dev.txt
- source activate TEST

script:
- py.test --verbose --doctest-modules --ignore setup.py
- python setup.py test
- find . -type f -name "*.py" | xargs flake8 --max-line-length=100
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ oceans
netcdf4
pyugrid
pysgrid
gridgeo
2 changes: 1 addition & 1 deletion tardis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
'slices',
'utils']

__version__ = '0.3.0'
__version__ = '0.3.1'
8 changes: 4 additions & 4 deletions tardis/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def t_coord(cube):
>>> url = ("http://omgsrv1.meas.ncsu.edu:8080/thredds/dodsC/fmrc/"
... "sabgom/SABGOM_Forecast_Model_Run_Collection_best.ncd")
>>> cube = iris.load_cube(url, 'sea_water_potential_temperature')
>>> t_coord(cube).name()
u'time'
>>> str(t_coord(cube).name())
'time'
"""
try:
Expand All @@ -50,8 +50,8 @@ def z_coord(cube):
>>> url = ("http://omgsrv1.meas.ncsu.edu:8080/thredds/dodsC/fmrc/"
... "sabgom/SABGOM_Forecast_Model_Run_Collection_best.ncd")
>>> cube = iris.load_cube(url, 'sea_water_potential_temperature')
>>> z_coord(cube).name()
u'ocean_s_coordinate_g1'
>>> str(z_coord(cube).name())
'ocean_s_coordinate_g1'
"""
non_dimensional = ['atmosphere_hybrid_height_coordinate',
Expand Down
21 changes: 15 additions & 6 deletions tardis/slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ def find_time(cube, datetime):
Examples
--------
>>> import iris
>>> import numpy as np
>>> from datetime import datetime
>>> url = ("http://omgsrv1.meas.ncsu.edu:8080/thredds/dodsC/fmrc/sabgom/"
... "SABGOM_Forecast_Model_Run_Collection_best.ncd")
>>> cube = iris.load_cube(url, 'sea_water_potential_temperature')
>>> isinstance(find_time(cube, datetime.utcnow()), int)
>>> isinstance(find_time(cube, datetime.utcnow()), np.integer)
True
"""
Expand All @@ -81,12 +82,13 @@ def find_bbox(cube, bbox):
Examples
--------
>>> import iris
>>> import numpy as np
>>> url = ("http://omgsrv1.meas.ncsu.edu:8080/thredds/dodsC/fmrc/sabgom/"
... "SABGOM_Forecast_Model_Run_Collection_best.ncd")
>>> cube = iris.load_cube(url, 'sea_water_potential_temperature')
>>> bbox = [-87.40, 24.25, -74.70, 36.70]
>>> bbox = [-87.40, -74.70, 24.25, 36.70]
>>> idxs = find_bbox(cube, bbox)
>>> [isinstance(idx, int) for idx in idxs]
>>> [isinstance(idx, np.integer) for idx in idxs]
[True, True, True, True]
"""
Expand All @@ -96,8 +98,8 @@ def find_bbox(cube, bbox):
lons = wrap_lon180(lons)

inregion = np.logical_and(np.logical_and(lons > bbox[0],
lons < bbox[2]),
np.logical_and(lats > bbox[1],
lons < bbox[1]),
np.logical_and(lats > bbox[2],
lats < bbox[3]))
region_inds = np.where(inregion)
imin, imax = _minmax(region_inds[0])
Expand Down Expand Up @@ -189,7 +191,14 @@ def extract_bbox(cube, bbox, grid_type):
cube = cube.extract(lon & lat)
elif grid_type == 'sgrid' or grid_type == '2D_curvilinear':
imin, imax, jmin, jmax = find_bbox(cube, bbox)
cube = cube[..., imin:imax, jmin:jmax]
if cube.ndim > 2:
cube = cube[..., imin:imax, jmin:jmax]
elif cube.ndim == 2:
cube = cube[imin:imax, jmin:jmax]
else:
msg = 'Cannot subset {!r} with bbox {}'.format
raise ValueError(msg(cube, bbox))

# NOTE: `rgrid` and `unknown` are passed to iris`.intersection()`
# intersection should deal 0-360 properly.
else:
Expand Down

0 comments on commit 68f2dcc

Please sign in to comment.