Download the zip file from github and uncompress the zip file into your project folder. For ArcGIS, load the python toolbox into your ArcGIS Project and use the tools in the toolbox. For Python, import the libarary and use the different modules as needed.
Open the Get Data from API in the Cal-Adapt - API Toolset, populate the parameter in the toolbox (see image below), and execute the tool by clicking run. After the tool successfully runs the data returned from the Cal-Adapt API will be saved in the File Geodatabase you specified in the tool.
Open the Chart Data from API in the Cal-Adapt - API Toolset, populate the parameter in the toolbox (see image below), and execute the tool by clicking run. After the tool successfully runs the chart will be added to the map within ArcGIS Pro. Open the chart and it will look similar to the image below.
import os
import arcpy
# Import Cal-Adapt Python Toolbox into the Jupyter Notebook
arcpy.ImportToolbox(r'D:\Data\ArcGIS\Projects\CalAdaptpy_Test\CalAdaptLib\CalAdapt.pyt','')
# Import Cal-Adapt Library into the Jupyter Notebook. This library exposes helper functions that are used to work with the Cal-Adapt api and Cal-Adapt Data Server
import CalAdaptLib as cal
# Custom Area of Interest (AOI), in this case the Russian River Basin in the north coast of California
polygon = r'D:\Data\ArcGIS\Projects\CalAdaptpy_Test\CalAdaptpy_Test.gdb\RussianRiver_HUC10'
# Run the Get Data from API Tool fropm the toolbox. The result will be added to the map that is in your project
arcpy.GetDataAPI(polygon, None, '', "tair", "gfdl-cm3", "month", True, True, True, False, "mean", r"D:\Data\ArcGIS\Projects\CalAdaptpy_Test\CalAdaptpy_Test.gdb\GetDataAPI_Single")
# Run the Chart Data from API Tool from the toolbox. The result will be added to the map that is in your project
# Needs to be run from within ArcGIS Pro
arcpy.CreateChart("GetDataAPI_Single", "DateTime", "Scenario", "Value")
The steps to complete this task using the Cal-Adapt library are the following:
# get the local path to the Cal-Adapt Library, the resourcelist is stored there as well
libPath = os.path.dirname(cal.__file__)
resourceFile = ('%s/%s') % (libPath, 'datasets.txt')
cal.freshResourceList(resourceFile)
Note the maximum size of an AOI is the size of San Bernadino County (20,105 miĀ²).
help(cal.createWKT)
geom = r'D:\Data\ArcGIS\Projects\CalAdaptpy_Test\CalAdaptpy_Test.gdb\RussianRiver_HUC10'
wkt = cal.createWKT(geom)
# Uncomment to see WKT
# wkt[0][0]
Not all parameters of the function need to be populated for it to return results. You will need to narrow your reults down to one option before running the folling tools
help(cal.getResourceName)
variable='tair'
gcm='miroc5'
period='month'
scenario='rcp45'
CalAdaptFilename = cal.getResourceName(resourceFile, variable, gcm, period, scenario)
# Uncomment the following line to see the results is not all paramters are completed.
#cal.getResourceName(resourceFile, variable='tair', gcm='miroc5', period='month')
help(cal.returnData)
stat = 'mean'
results = cal.returnData(wkt[0], stat, CalAdaptFilename[0])
# Uncomment to see results
#results
help(cal.createTable)
workspace = r"D:\Data\ArcGIS\Projects\CalAdaptpy_Test\CalAdaptpy_Test.gdb"
tableName = "GetDataAPI1"
chartParameters = cal.createTable(results,workspace,tableName, wkt, variable, gcm, scenario, period, stat)
# Uncomment to see chartParameters returned from the createTable function
#chartParameters
Note this tool will only work if run from within ArcGIS Pro
help(cal.createChart)
# Needs to be run from within ArcGIS Pro
#cal.createChart(chartParameters[0],chartParameters[1],chartParameters[2],chartParameters[3])
libPath = os.path.dirname(cal.__file__)
resourceFile = ('%s/%s') % (libPath, 'datasets.txt')
cal.freshResourceList(resourceFile)
workspace = r'D:\Data\ArcGIS\Projects\CalAdaptpy_Test\CalAdaptpy_Test.gdb'
geom = r'D:\Data\ArcGIS\Projects\CalAdaptpy_Test\CalAdaptpy_Test.gdb\RussianRiver_HUC10'
tableName = "GetDataAPI_Multiple"
gcms = ['gfdl-cm3','miroc5']
scenarios = ['historical','rcp45','rcp85']
variable='tair'
period='month'
stat = 'mean'
wkt = cal.createWKT(geom)
table = '%s/%s' % (workspace, tableName)
if (arcpy.Exists(table)) == True:
arcpy.management.Delete(table)
for gcm in gcms:
for scenario in scenarios:
CalAdaptFilename = cal.getResourceName(resourceFile, variable, gcm, period, scenario)
results = cal.returnData(wkt[0], stat, CalAdaptFilename[0])
chartParameters = cal.createTable(results,workspace,tableName, wkt, variable, gcm, scenario, period, stat)
try :
cal.createChart(chartParameters[0],chartParameters[1],chartParameters[2],chartParameters[3])
except OSError as error :
print("createChart needs to be run from within ArcGIS Pro")
After the script successfully (in ArcGIS Pro) runs the chart will be added to the map within ArcGIS Pro. Open the chart and it will look similar to the image below.