""" Create Aqueduct 2.1 shapefile with fluxes.
-------------------------------------------------------------------------------
Author: Rutger Hofste
Date: 20180605
Kernel: python35
Docker: rutgerhofste/gisdocker:ubuntu16.04
Args:
TESTING (boolean) : Testing mode. Uses a smaller geography if enabled.
SCRIPT_NAME (string) : Script name.
EE_INPUT_ZONES_PATH (string) : earthengine input path for zones.
EE_INPUT_VALUES_PATH (string) : earthengine input path for value images.
INPUT_VERSION_ZONES (integer) : input version for zones images.
INPUT_VERSION_VALUES (integer) : input version for value images.
OUTPUT_VERSION (integer) : output version.
EXTRA_PROPERTIES (dictionary) : Extra properties to store in the resulting
pandas dataframe.
Returns:
"""
SCRIPT_NAME = "Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01"
OUTPUT_VERSION = 1
OVERWRITE =1
AQUEDUCT21_URL = "http://data.wri.org/Aqueduct/web/aqueduct_global_maps_21_shp.zip"
FILE_NAME = "aqueduct21"
DETAILED_FILE_NAME = "aqueduct_global_dl_20150409.shp"
ECKERT_IV_PROJ4_STRING1 = "+proj=eck4 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
ECKERT_IV_PROJ4_STRING2 = "+proj=eck4 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs"
s3_output_path = "s3://wri-projects/Aqueduct30/qaData/{}/output_V{:02.0f}".format(SCRIPT_NAME,OUTPUT_VERSION)
ec2_input_path = "/volumes/data/{}/input_V{:02.0f}".format(SCRIPT_NAME,OUTPUT_VERSION)
ec2_output_path = "/volumes/data/{}/output_V{:02.0f}".format(SCRIPT_NAME,OUTPUT_VERSION)
print("Input : " + AQUEDUCT21_URL +
"\nOutput s3: " + s3_output_path)
Input : http://data.wri.org/Aqueduct/web/aqueduct_global_maps_21_shp.zip Output s3: s3://wri-projects/Aqueduct30/qaData/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/output_V01
import time, datetime, sys, logging
dateString = time.strftime("Y%YM%mD%d")
timeString = time.strftime("UTC %H:%M")
start = datetime.datetime.now()
print(dateString,timeString)
sys.version
Y2018M06D05 UTC 14:30
'3.5.4 |Anaconda, Inc.| (default, Nov 20 2017, 18:44:38) \n[GCC 7.2.0]'
import subprocess
import geopandas as gpd
if OVERWRITE:
!rm -r {ec2_input_path}
!rm -r {ec2_output_path}
!mkdir -p {ec2_input_path}
!mkdir -p {ec2_output_path}
command = "wget -O {}/{}.zip {}".format(ec2_input_path,FILE_NAME,AQUEDUCT21_URL)
subprocess.check_output(command,shell=True)
b''
command = "unzip {}/{} -d {}".format(ec2_input_path,FILE_NAME,ec2_input_path)
subprocess.check_output(command,shell=True)
b'Archive: /volumes/data/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/input_V01/aqueduct21.zip\n extracting: /volumes/data/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/input_V01/aqueduct_global_dl_20150409.cpg \n inflating: /volumes/data/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/input_V01/aqueduct_global_dl_20150409.dbf \n inflating: /volumes/data/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/input_V01/aqueduct_global_dl_20150409.prj \n inflating: /volumes/data/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/input_V01/aqueduct_global_dl_20150409.shp \n inflating: /volumes/data/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/input_V01/aqueduct_global_dl_20150409.shp.xml \n inflating: /volumes/data/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/input_V01/aqueduct_global_dl_20150409.shx \n inflating: /volumes/data/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/input_V01/aqueduct_global_maps_21.pdf \n inflating: /volumes/data/Y2018M06D05_RH_QA_Aqueduct21_Flux_Shapefile_V01/input_V01/dictionary_20150409.xlsx \n'
input_file_path = "{}/{}".format(ec2_input_path,DETAILED_FILE_NAME)
gdf = gpd.read_file(input_file_path)
gdf.crs
{'init': 'epsg:4326'}
gdf_eckert4 = gdf.to_crs(ECKERT_IV_PROJ4_STRING1)
gdf_eckert4 = gdf.to_crs(ECKERT_IV_PROJ4_STRING2)
--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-11-419049ecf17f> in <module>() ----> 1 gdf_eckert4 = gdf.to_crs(ECKERT_IV_PROJ4_STRING2) /opt/anaconda3/envs/python35/lib/python3.5/site-packages/geopandas/geodataframe.py in to_crs(self, crs, epsg, inplace) 384 else: 385 df = self.copy() --> 386 geom = df.geometry.to_crs(crs=crs, epsg=epsg) 387 df.geometry = geom 388 df.crs = geom.crs /opt/anaconda3/envs/python35/lib/python3.5/site-packages/geopandas/geoseries.py in to_crs(self, crs, epsg) 284 raise TypeError('Must set either crs or epsg for output.') 285 proj_in = pyproj.Proj(self.crs, preserve_units=True) --> 286 proj_out = pyproj.Proj(crs, preserve_units=True) 287 project = partial(pyproj.transform, proj_in, proj_out) 288 result = self.apply(lambda geom: transform(project, geom)) /opt/anaconda3/envs/python35/lib/python3.5/site-packages/pyproj/__init__.py in __new__(self, projparams, preserve_units, **kwargs) 356 # on case-insensitive filesystems). 357 projstring = projstring.replace('EPSG','epsg') --> 358 return _proj.Proj.__new__(self, projstring) 359 360 def __call__(self, *args, **kw): _proj.pyx in _proj.Proj.__cinit__ (_proj.c:1170)() RuntimeError: b'unknown unit conversion id'