Skip to content

Commit

Permalink
Merge pull request #24 from ocefpaf/dont_rename_xy_coord
Browse files Browse the repository at this point in the history
Do not rename coords
  • Loading branch information
ocefpaf committed Dec 31, 2015
2 parents 7b2b9bc + bf11043 commit dae2691
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 68 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ before_install:
- conda config --add channels ioos -f
- travis_retry conda create --yes -n test $CONDA --file requirements.txt
- source activate test
- travis_retry conda install --yes pytest
- conda info -a
- conda install --yes --file requirements-dev.txt

script:
- python setup.py test
- py.test --verbose --doctest-modules --ignore setup.py
- find . -type f -name "*.py" | xargs flake8 --max-line-length=100
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flake8
pytest
60 changes: 1 addition & 59 deletions tardis/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,10 @@
iris.FUTURE.cell_datetime_objects = True


__all__ = ['x_coord',
'y_coord',
't_coord',
__all__ = ['t_coord',
'z_coord']


def x_coord(cube):
"""
Return the canonical x-coordinate and rename it to `longitude`.
If more than one x-coordinate is present it will try to return only
the one names `longitude`.
Examples
--------
>>> import iris
>>> 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')
>>> x_coord(cube).name()
'longitude'
"""
try:
# FIXME: This might wrongly rename some grids.
cube.coord(axis='X').rename('longitude')
except CoordinateNotFoundError:
# This will fail if there more than 1 x-coordinate
# and none are named `longitude`.
coord = cube.coord('longitude')
else:
coord = cube.coord('longitude')
return coord


def y_coord(cube):
"""
Return the canonical y-coordinate and rename it to `latitude`.
If more than one y-coordinate is present it will try to return only
the one names `latitude`.
Examples
--------
>>> import iris
>>> 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')
>>> y_coord(cube).name()
'latitude'
"""
try:
# FIXME: This might wrongly rename some grids.
cube.coord(axis='Y').rename('latitude')
except CoordinateNotFoundError:
# This will fail if there more than 1 y-coordinate
# and none are named `latitude`.
coord = cube.coord('latitude')
else:
coord = cube.coord('latitude')
return coord


def t_coord(cube):
"""
Return the canonical time coordinate and rename it to `time`.
Expand Down
6 changes: 3 additions & 3 deletions tardis/slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import iris
from iris import Constraint

from .coords import x_coord, y_coord, z_coord, t_coord
from .coords import z_coord, t_coord

iris.FUTURE.netcdf_promote = True
iris.FUTURE.cell_datetime_objects = True
Expand Down Expand Up @@ -91,8 +91,8 @@ def find_bbox(cube, bbox):
"""
from oceans import wrap_lon180
lons = x_coord(cube).points
lats = y_coord(cube).points
lons = cube.coords(axis='X')[0].points
lats = cube.coords(axis='Y')[0].points
lons = wrap_lon180(lons)

inregion = np.logical_and(np.logical_and(lons > bbox[0],
Expand Down
9 changes: 6 additions & 3 deletions tardis/tardis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import pysgrid # NOTE: Really?! How many custom exceptions to say ValueError?
from pysgrid.custom_exceptions import SGridNonCompliantError

from .coords import x_coord, y_coord
from .utils import wrap_lon180, cf_name_list

__all__ = ['load_phenomena',
'OceanModelCube',
'cf_name_list']


def _get_grid(self):
grid = 'unknown'
Expand Down Expand Up @@ -110,8 +113,8 @@ def __init__(self, cube, filename=None):
self.grid = _get_grid(self)
self.grid_type = _get_grid_type(self)
# NOTE: I always wrap longitude between -180, 180.
self.lon = wrap_lon180(x_coord(cube).points)
self.lat = y_coord(cube).points
self.lon = wrap_lon180(cube.coords(axis='X')[0].points)
self.lat = cube.coords(axis='Y')[0].points

def __repr__(self):
msg = "<OceanModelCube of {}. Grid type: {}>".format
Expand Down

0 comments on commit dae2691

Please sign in to comment.