Skip to content

Commit

Permalink
Merge pull request #5 from snowman2/gdal_pin
Browse files Browse the repository at this point in the history
Pin GDAL 2.2.* to see if it fixes build
Remove mapkit
coords -> x_coords, y_coords
  • Loading branch information
snowman2 committed Jul 15, 2018
2 parents d133d82 + e2a8713 commit 39658a4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
@@ -1,2 +1,2 @@
[MESSAGES CONTROL]
disable=broad-except,invalid-unary-operand-type,too-many-arguments,too-many-locals,no-member,redefined-variable-type,too-many-branches,too-many-statements,logging-format-truncated,too-many-public-methods
disable=broad-except,invalid-unary-operand-type,too-many-arguments,too-many-locals,no-member,redefined-variable-type,too-many-branches,too-many-statements,logging-format-truncated,too-many-public-methods,useless-object-inheritance
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -25,7 +25,7 @@ install:
- activate gazar
- conda env update -n gazar -f conda_env.yml
# restart environment
- deactivate gazar
- deactivate
- activate gazar
#-------------------------------------------------------------------------------
# Install gazar
Expand Down
3 changes: 1 addition & 2 deletions conda_env.yml
Expand Up @@ -11,7 +11,6 @@ channels:
dependencies:
- affine
- appdirs
- gdal
- mapkit
- gdal=2.2.*
- pyproj
- utm
34 changes: 20 additions & 14 deletions gazar/grid.py
Expand Up @@ -19,7 +19,6 @@

# external modules
from affine import Affine
from mapkit import lookupSpatialReferenceID
import numpy as np
from osgeo import gdal, gdalconst, ogr, osr
from pyproj import Proj, transform
Expand Down Expand Up @@ -74,7 +73,7 @@ def utm_proj_from_latlon(latitude, longitude, as_wkt=False, as_osr=False):

sp_ref.AutoIdentifyEPSG()

if as_osr:
if as_osr: # pylint: disable=no-else-return
return sp_ref
elif as_wkt:
return sp_ref.ExportToWkt()
Expand Down Expand Up @@ -180,9 +179,7 @@ def epsg(self):
self.projection.AutoIdentifyEPSG()
except RuntimeError:
pass
epsg = self.projection.GetAuthorityCode(None)
# return or attempt online lookup if not found
return epsg or lookupSpatialReferenceID(self.wkt)
return self.projection.GetAuthorityCode(None)

def bounds(self, as_geographic=False, as_utm=False, as_projection=None):
"""Returns bounding coordinates for the dataset.
Expand Down Expand Up @@ -321,23 +318,32 @@ def lonlat2pixel(self, longitude, latitude):
return self.coord2pixel(x_coord, y_coord)

@property
def coords(self):
"""Returns x and y coordinate arrays representing the grid.
def x_coords(self):
"""Returns x coordinate array representing the grid.
Use method from: https://github.com/pydata/xarray/pull/1712
Returns
-------
y_coords: :func:`numpy.array`
The Y coordinate array.
x_coords: :func:`numpy.array`
The X coordinate array.
"""
x_coords, _ = (np.arange(self.x_size) + 0.5,
np.zeros(self.x_size) + 0.5) * self.affine
return x_coords

@property
def y_coords(self):
"""Returns y coordinate array representing the grid.
Use method from: https://github.com/pydata/xarray/pull/1712
Returns
-------
y_coords: :func:`numpy.array`
The Y coordinate array.
"""
_, y_coords = (np.zeros(self.y_size) + 0.5,
np.arange(self.y_size) + 0.5) * self.affine
x_2d_coords, y_2d_coords = np.meshgrid(x_coords, y_coords)
return y_2d_coords, x_2d_coords
return y_coords

@property
def latlon(self):
Expand All @@ -350,12 +356,12 @@ def latlon(self):
proj_lons: :func:`numpy.array`
The longitude array.
"""
y_coords, x_coords = self.coords
x_2d_coords, y_2d_coords = np.meshgrid(self.x_coords, self.y_coords)

proj_lons, proj_lats = transform(self.proj,
Proj(init='epsg:4326'),
x_coords,
y_coords)
x_2d_coords,
y_2d_coords)
return proj_lats, proj_lons

def np_array(self, band=1, masked=True):
Expand Down
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -12,7 +12,6 @@
'affine',
'appdirs',
'gdal',
'mapkit',
'pyproj',
'utm',
]
Expand Down
17 changes: 8 additions & 9 deletions tests/test_grid_tools.py
Expand Up @@ -106,15 +106,14 @@ def test_gdal_grid(prep, tgrid):
assert_almost_equal(longitude[20:22, 20:22],
[[121.17069444, 121.17902778],
[121.17069444, 121.17902778]])
y_coords, x_coords = ggrid.coords
assert y_coords.shape == (120, 120)
assert x_coords.shape == (120, 120)
assert_almost_equal(y_coords[20:22, 20:22],
[[15.83736111, 15.83736111],
[15.82902778, 15.82902778]])
assert_almost_equal(x_coords[20:22, 20:22],
[[121.17069444, 121.17902778],
[121.17069444, 121.17902778]])
y_coords = ggrid.y_coords
assert y_coords.shape == (120,)
assert_almost_equal(y_coords[20:22],
[15.83736111, 15.82902778])
x_coords = ggrid.x_coords
assert x_coords.shape == (120,)
assert_almost_equal(x_coords[20:22],
[121.17069444, 121.17902778])
# check functions
assert_almost_equal(ggrid.bounds(),
(120.99986111111112,
Expand Down

0 comments on commit 39658a4

Please sign in to comment.