Skip to content

Commit

Permalink
Merge pull request #35 from ocefpaf/cli
Browse files Browse the repository at this point in the history
command line saver
  • Loading branch information
ocefpaf authored Mar 31, 2018
2 parents eb86e5c + f0e93c5 commit f5a1628
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 40 deletions.
47 changes: 47 additions & 0 deletions gridgeo/gridio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

from docopt import docopt

from gridgeo import GridGeo

__doc__ = """
Save a GeoJSON or ESRI Shapefile representation of an ocean model grid.
Usage:
gridio URL VAR --output=OUTFILE
gridio (-h | --help -o | --output)
Examples:
gridio netcdf-file.nc sea_water_temperature --output=grid.shp
gridio remote-opendap-url sea_water_temperature --output=grid.geojson
Arguments:
directory Configuration directory.
Options:
-h --help Show this screen.
-o OUTFILE --output=OUTFILE Output file
"""


def parse_args():
args = docopt(__doc__)
return args


def cli(args):
url = args.get('URL')
standard_name = args.get('VAR')
filename = args.get('--output')

grid = GridGeo(url, standard_name=standard_name)
grid.save(filename, float_precision=4)


def main():
args = parse_args()
cli(args)


if __name__ == '__main__':
main()
53 changes: 29 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,32 @@ def read(*parts):
require = f.readlines()
install_requires = [r.strip() for r in require]

setup(name='gridgeo',
version=versioneer.get_version(),
license=LICENSE,
long_description=long_description,
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.6',
'Topic :: Scientific/Engineering',
],
description=('Convert UGRID, SGRID, and some non-compliant ocean model grids to geo-like objects'), # noqa
url='https://github.com/pyoceans/gridgeo',
platforms='any',
keywords=['geojson', 'ocean models', 'ugrid', 'sgrid'],
install_requires=install_requires,
packages=['gridgeo'],
tests_require=['pytest'],
cmdclass=versioneer.get_cmdclass(),
author=['Filipe Fernandes'],
author_email='ocefpaf@gmail.com',
)
setup(
name='gridgeo',
version=versioneer.get_version(),
license=LICENSE,
long_description=long_description,
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.6',
'Topic :: Scientific/Engineering',
],
description=('Convert UGRID, SGRID, and some non-compliant ocean model grids to geo-like objects'), # noqa
url='https://github.com/pyoceans/gridgeo',
platforms='any',
keywords=['geojson', 'shapefile', 'ocean models', 'ugrid', 'sgrid'],
install_requires=install_requires,
packages=['gridgeo'],
tests_require=['pytest'],
cmdclass=versioneer.get_cmdclass(),
author=['Filipe Fernandes'],
author_email='ocefpaf@gmail.com',
entry_points={'console_scripts': [
'gridio = gridgeo.gridio:main',
],
},
)
8 changes: 4 additions & 4 deletions tests/test_sgrid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

import gridgeo

import numpy as np

from shapely.geometry import MultiPolygon, Polygon


Expand Down Expand Up @@ -31,8 +31,8 @@ def test_outline():

def test_polygons():
assert isinstance(grid.polygons, _iterables)
assert all([isinstance(p, _iterables) for p in grid.polygons])
assert all([len(p) == 4 for p in grid.polygons])
assert all((isinstance(p, _iterables) for p in grid.polygons))
assert all((len(p) == 4 for p in grid.polygons))


def test_geometry():
Expand Down
8 changes: 4 additions & 4 deletions tests/test_ugrid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

import gridgeo

import numpy as np

from shapely.geometry import MultiPolygon, Polygon


Expand Down Expand Up @@ -31,8 +31,8 @@ def test_outline():

def test_polygons():
assert isinstance(grid.polygons, _iterables)
assert all([isinstance(p, _iterables) for p in grid.polygons])
assert all([len(p) == 3 for p in grid.polygons])
assert all((isinstance(p, _iterables) for p in grid.polygons))
assert all((len(p) == 3 for p in grid.polygons))


def test_geometry():
Expand Down
8 changes: 4 additions & 4 deletions tests/test_unknown_1d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

import gridgeo

import numpy as np

from shapely.geometry import MultiPolygon, Polygon


Expand Down Expand Up @@ -30,8 +30,8 @@ def test_outline():

def test_polygons():
assert isinstance(grid.polygons, _iterables)
assert all([isinstance(p, _iterables) for p in grid.polygons])
assert all([len(p) == 4 for p in grid.polygons])
assert all((isinstance(p, _iterables) for p in grid.polygons))
assert all((len(p) == 4 for p in grid.polygons))


def test_geometry():
Expand Down
8 changes: 4 additions & 4 deletions tests/test_unknown_2d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

import gridgeo

import numpy as np

from shapely.geometry import MultiPolygon, Polygon


Expand Down Expand Up @@ -31,8 +31,8 @@ def test_outline():

def test_polygons():
assert isinstance(grid.polygons, _iterables)
assert all([isinstance(p, _iterables) for p in grid.polygons])
assert all([len(p) == 4 for p in grid.polygons])
assert all((isinstance(p, _iterables) for p in grid.polygons))
assert all((len(p) == 4 for p in grid.polygons))


def test_geometry():
Expand Down

0 comments on commit f5a1628

Please sign in to comment.