Repository: climate Updated Branches: refs/heads/master d73c3c21c -> 91ec7f31c
CLIMATE-842 - Add shape files to package installation Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/27c1c94b Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/27c1c94b Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/27c1c94b Branch: refs/heads/master Commit: 27c1c94b7177a234f23fed5c7bbd63e533de2223 Parents: d73c3c2 Author: Alex Goodman <ago...@users.noreply.github.com> Authored: Wed Aug 3 13:48:14 2016 -0700 Committer: Alex Goodman <ago...@users.noreply.github.com> Committed: Wed Aug 3 13:48:14 2016 -0700 ---------------------------------------------------------------------- MANIFEST.in | 1 + ocw/dataset.py | 56 +++++++++++++++++++++--------------------- ocw/shape/us_states.dbf | Bin 0 -> 12962 bytes ocw/shape/us_states.shp | Bin 0 -> 222344 bytes ocw/shape/us_states.shx | Bin 0 -> 508 bytes ocw/shape/usa_states.dbf | Bin 12962 -> 0 bytes ocw/shape/usa_states.shp | Bin 222344 -> 0 bytes ocw/shape/usa_states.shx | Bin 508 -> 0 bytes setup.py | 14 ++++++++--- 9 files changed, 40 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/27c1c94b/MANIFEST.in ---------------------------------------------------------------------- diff --git a/MANIFEST.in b/MANIFEST.in index a68e4b8..943fa95 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,4 @@ include distribute_setup.py recursive-include docs *.txt +recursive-include ocw/shape * include README.md http://git-wip-us.apache.org/repos/asf/climate/blob/27c1c94b/ocw/dataset.py ---------------------------------------------------------------------- diff --git a/ocw/dataset.py b/ocw/dataset.py index cc2043e..562c014 100644 --- a/ocw/dataset.py +++ b/ocw/dataset.py @@ -22,6 +22,7 @@ Classes: for operations on a Dataset. ''' +import os import numpy import logging import datetime as dt @@ -237,9 +238,9 @@ class Bounds(object): boundary_type may be one of the following: * 'rectangular' * 'CORDEX (CORDEX region name)': pre-defined CORDEX boundary - * 'us_states': an array of US states abbreviation is required (ex) us_states = ['CA','NV']) + * 'us_states': an array of US states abbreviation is required (ex) us_states = ['CA','NV']) * 'countries': an array of county names is required (ex) countries = ['United States','Canada','Mexico'] - * 'user': user_mask_file in a netCDF format with two dimensional mask variable is required. + * 'user': user_mask_file in a netCDF format with two dimensional mask variable is required. If boundary_type == 'rectangular', spatial and temporal bounds must follow the following guidelines. @@ -251,10 +252,10 @@ class Bounds(object): Temporal bounds must a valid datetime object ''' - def __init__(self, boundary_type='rectangular', - us_states=None, countries=None, - user_mask_file=None, mask_variable_name=None, longitude_name=None, latitude_name=None, - lat_min=-90, lat_max=90, lon_min=-180, lon_max=180, + def __init__(self, boundary_type='rectangular', + us_states=None, countries=None, + user_mask_file=None, mask_variable_name=None, longitude_name=None, latitude_name=None, + lat_min=-90, lat_max=90, lon_min=-180, lon_max=180, start=None, end=None): '''Default Bounds constructor :param boundary_type: The type of spatial subset boundary. @@ -309,7 +310,7 @@ class Bounds(object): self.mask_longitude, self.mask_latitude = numpy.meshgrid(mask_longitude, mask_latitude) elif mask_longitude.ndim == 2 and mask_latitude.ndim == 2: self.mask_longitude = mask_longitude - self.mask_latitude = mask_latitude + self.mask_latitude = mask_latitude if boundary_type == 'rectangular': if not (-90 <= float(lat_min) <=90) or float(lat_min) > float(lat_max): error = "Attempted to set lat_min to invalid value: %s" % (lat_min) @@ -327,7 +328,7 @@ class Bounds(object): error = "Attempted to set lat_max to invalid value: %s" % (lon_max) logger.error(error) raise ValueError(error) - + self.lat_min = float(lat_min) self.lat_max = float(lat_max) self.lon_min = float(lon_min) @@ -371,19 +372,18 @@ def shapefile_boundary(boundary_type, region_names): :param region_names: An array of regions for spatial subset :type region_names: :mod:'list' ''' - + # Read the shapefile map_read = Basemap() - regions =[] + regions = [] + shapefile_dir = os.sep.join([os.path.dirname(__file__), 'shape']) + map_read.readshapefile(os.path.join(shapefile_dir, boundary_type), + boundary_type) if boundary_type == 'us_states': - map_read.readshapefile(ocw.__path__[0]+'/shape/usa_states','usa_states') - #map_read.readshapefile('/home/huikyole/climate/ocw'+'/shape/usa_states','usa_states') for region_name in region_names: - for iregion, region_info in enumerate(map_read.usa_states_info): + for iregion, region_info in enumerate(map_read.us_states_info): if region_info['st'] == region_name: - regions.append(numpy.array(map_read.usa_states[iregion])) - if boundary_type == 'countries': - map_read.readshapefile(ocw.__path__[0]+'/shape/countries','countries') - #map_read.readshapefile('/home/huikyole/climate/ocw'+'/shape/countries','countries') + regions.append(numpy.array(map_read.us_states[iregion])) + elif boundary_type == 'countries': for region_name in region_names: for iregion, region_info in enumerate(map_read.countries_info): if region_info['COUNTRY'] == region_name: @@ -402,24 +402,24 @@ def CORDEX_boundary(domain_name): if domain_name =='northamerica': return 12.55, 75.88, 189.26-360., 336.74-360. if domain_name =='europe': - return 22.20, 71.84, 338.23-360., 64.4 + return 22.20, 71.84, 338.23-360., 64.4 if domain_name =='africa': - return -45.76, 42.24, 335.36-360., 60.28 + return -45.76, 42.24, 335.36-360., 60.28 if domain_name =='southasia': - return -15.23, 45.07, 19.88, 115.55 + return -15.23, 45.07, 19.88, 115.55 if domain_name =='eastasia': - return -0.10, 61.90, 51.59, 179.99 + return -0.10, 61.90, 51.59, 179.99 if domain_name =='centralasia': - return 18.34, 69.37, 11.05, 139.13 + return 18.34, 69.37, 11.05, 139.13 if domain_name =='australasia': - return -52.36, 12.21, 89.25, 179.99 + return -52.36, 12.21, 89.25, 179.99 if domain_name =='antartica': - return -89.48,-56.00, -179.00, 179.00 + return -89.48,-56.00, -179.00, 179.00 if domain_name =='artic': - return 46.06, 89.50, -179.00, 179.00 + return 46.06, 89.50, -179.00, 179.00 if domain_name =='mediterranean': - return 25.63, 56.66, 339.79-360.00, 50.85 + return 25.63, 56.66, 339.79-360.00, 50.85 if domain_name =='middleeastnorthafrica': - return -7.00, 45.00, 333.00-360.00, 76.00 + return -7.00, 45.00, 333.00-360.00, 76.00 if domain_name =='southeastasia': - return -15.14, 27.26, 89.26, 146.96 + return -15.14, 27.26, 89.26, 146.96 http://git-wip-us.apache.org/repos/asf/climate/blob/27c1c94b/ocw/shape/us_states.dbf ---------------------------------------------------------------------- diff --git a/ocw/shape/us_states.dbf b/ocw/shape/us_states.dbf new file mode 100755 index 0000000..ae67cce Binary files /dev/null and b/ocw/shape/us_states.dbf differ http://git-wip-us.apache.org/repos/asf/climate/blob/27c1c94b/ocw/shape/us_states.shp ---------------------------------------------------------------------- diff --git a/ocw/shape/us_states.shp b/ocw/shape/us_states.shp new file mode 100755 index 0000000..4e52c28 Binary files /dev/null and b/ocw/shape/us_states.shp differ http://git-wip-us.apache.org/repos/asf/climate/blob/27c1c94b/ocw/shape/us_states.shx ---------------------------------------------------------------------- diff --git a/ocw/shape/us_states.shx b/ocw/shape/us_states.shx new file mode 100755 index 0000000..b707b99 Binary files /dev/null and b/ocw/shape/us_states.shx differ http://git-wip-us.apache.org/repos/asf/climate/blob/27c1c94b/ocw/shape/usa_states.dbf ---------------------------------------------------------------------- diff --git a/ocw/shape/usa_states.dbf b/ocw/shape/usa_states.dbf deleted file mode 100755 index ae67cce..0000000 Binary files a/ocw/shape/usa_states.dbf and /dev/null differ http://git-wip-us.apache.org/repos/asf/climate/blob/27c1c94b/ocw/shape/usa_states.shp ---------------------------------------------------------------------- diff --git a/ocw/shape/usa_states.shp b/ocw/shape/usa_states.shp deleted file mode 100755 index 4e52c28..0000000 Binary files a/ocw/shape/usa_states.shp and /dev/null differ http://git-wip-us.apache.org/repos/asf/climate/blob/27c1c94b/ocw/shape/usa_states.shx ---------------------------------------------------------------------- diff --git a/ocw/shape/usa_states.shx b/ocw/shape/usa_states.shx deleted file mode 100755 index b707b99..0000000 Binary files a/ocw/shape/usa_states.shx and /dev/null differ http://git-wip-us.apache.org/repos/asf/climate/blob/27c1c94b/setup.py ---------------------------------------------------------------------- diff --git a/setup.py b/setup.py index 83ddf69..20d746b 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,8 @@ # specific language governing permissions and limitations # under the License. -import os.path +import os +import glob from setuptools import find_packages, setup # Package data @@ -45,8 +46,8 @@ _name = 'ocw' _namespaces = [] _testSuite = 'ocw.tests' _url = 'http://climate.apache.org/' -_version = '1.1.0' -_zipSafe = True +_version = '1.2.0' +_zipSafe = False # Setup Metadata # -------------- @@ -61,6 +62,12 @@ _longDescription = '\n\n'.join([ ]) open('doc.txt', 'w').write(_longDescription) +# Include shapefiles +_pathout = os.path.join('ocw', 'shape') +_shapefiles = glob.glob(os.path.join(_pathout, '*')) +_shapefiles = [os.path.join('shape', os.path.basename(f)) for f in _shapefiles] +_package_data = {'ocw': _shapefiles} + setup( author=_author, author_email=_authorEmail, @@ -79,4 +86,5 @@ setup( url=_url, version=_version, zip_safe=_zipSafe, + package_data=_package_data )