def updateParameters(self, parameters): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed.""" try: netCDFSource = parameters[0].valueAsText; if netCDFSource is not None: #Making sure that the layers source is a netCDF file if NetCDFFile.isNetCDF(netCDFSource): #NetCDFFile class deteremines the dimensions and variables that #applies to a lat/lon point netCDFFile = NetCDFFile(netCDFSource) #Getting Avalable Dimensions besides besides lat & lon dimensions = netCDFFile.getDimensions() parameters[2].filter.list = dimensions #if dimensions.count > 0: #parameters[2].value = dimensions[0] #Getting Variables that apply to lat & lon variables = netCDFFile.getVariables() parameters[1].filter.list = variables #if variables.count > 0: #parameters[1].value = variables[0] except Exception: pass return
def execute(self, parameters, messages): """The source code of the tool.""" #Getting the netCDF DataSource Path from the netCDF raster layer netCDFSource = NetCDFFile.getNetCDFPathfromLayer(parameters[0].value) #Making sure that the datasource is a netCDF file. if NetCDFFile.isNetCDF(netCDFSource): netCDFFile = NetCDFFile(netCDFSource) #Get Input Parameters variableName = parameters[1].value rowDim = parameters[2].value inpnt = parameters[3].value #Output Parameters outTableView = parameters[4].value; #Create Table from selected point netCDFFile.makeNetCDFTable(inpnt,variableName,rowDim,outTableView); arcpy.AddMessage("Process Completed") else: arcpy.AddMessage("In valid inputs")
def updateMessages(self, parameters): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation. We are just checking that the datasource of the selected raster layer is a netCDF file. If the layer has already been added to ArcGIS Desktop we can assume that it contains proper lat/lon values and is regularly spaced""" try: if parameters[0].valueAsText is not None: #Getting the netCDF DataSource Path from the netCDF raster layer netCDFLoc = NetCDFFile.getNetCDFPathfromLayer(parameters[0].value) #Making sure that the datasource is a netCDF file. if not NetCDFFile.isNetCDF(netCDFSource): parameters[0].setErrorMessage("Invalid input file. " "A netCDF(.nc) " "is expected.") except Exception: pass return
def updateParameters(self, parameters): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed. We want to populate the variables and dimensions dropdown list with all dimensions that are not lat, lon and only variables that contain lat/lon dimensions. The lat lon are already going to be represented from the point selected on the map""" try: layer = parameters[0].value; if layer is not None: #Getting the netCDF DataSource Path from the netCDF raster layer netCDFSource = NetCDFFile.getNetCDFPathfromLayer(layer) #Making sure that the layers source is a netCDF file if NetCDFFile.isNetCDF(netCDFSource): #NetCDFFile class deteremines the dimensions and variables that #applies to a lat/lon point netCDFFile = NetCDFFile(netCDFSource) #Getting Avalable Dimensions besides besides lat & lon dimensions = netCDFFile.getDimensions() parameters[2].filter.list = dimensions #if dimensions.count > 0: #parameters[2].value = dimensions[0] #Getting Variables that apply to lat & lon variables = netCDFFile.getVariables() parameters[1].filter.list = variables #if variables.count > 0: #parameters[1].value = variables[0] except Exception: pass return
def execute(self, parameters, messages): """The source code of the tool.""" netCDFSource = parameters[0].valueAsText; #Making sure that the datasource is a netCDF file. if NetCDFFile.isNetCDF(netCDFSource): netCDFFile = NetCDFFile(netCDFSource) #Get Input Parameters variableName = parameters[1].value rowDim = parameters[2].value inpnt = parameters[3].value #Output Parameters outTableView = parameters[4].value; #Create Table from selected point netCDFFile.makeNetCDFTable(inpnt,variableName,rowDim,outTableView); arcpy.AddMessage("Process Completed")
def execute(self, parameters, messages): """The source code of the tool.""" #Getting the netCDF DataSource Path from the netCDF raster layer netCDFSource = NetCDFFile.getNetCDFPathfromLayer(parameters[0].value) #Making sure that the datasource is a netCDF file. if NetCDFFile.isNetCDF(netCDFSource): netCDFFile = NetCDFFile(netCDFSource) #Get Input Parameters variableName = parameters[1].value rowDim = parameters[2].value inpnt = parameters[3].value #Output Parameters outTableView = parameters[4].value #Create Table from selected point netCDFFile.makeNetCDFTable(inpnt, variableName, rowDim, outTableView) arcpy.AddMessage("Process Completed") else: arcpy.AddMessage("In valid inputs")
def execute(self, parameters, messages): """The source code of the tool.""" #We need to account for lat, lon dimensions being described differently #Workaround: Didn't want to have to open up file more than once, however, having dificulties with global variables #Getting the netCDF DataSource Path from the netCDF raster layer netCDFSource = NetCDFFile.getNetCDFPathfromLayer(parameters[0].value) #Making sure that the datasource is a netCDF file. if NetCDFFile.isNetCDF(netCDFSource): netCDFFile = NetCDFFile(netCDFSource) #Get Input Parameters variableName = parameters[1].value rowDim = parameters[2].value inpnt = parameters[3].value #Output Parameters outTableView = parameters[4].value; #Create Table from selected point netCDFFile.makeNetCDFTable(inpnt,variableName,rowDim,outTableView); tableViewSource = str(outTableView); #------Create Graph from Table---------------------------------------------# #Graph Template is located within the Layers Directory graph_grf = os.path.join(os.path.dirname(__file__), '..', 'Layer', 'NetCDFPlot.grf') outGraph = parameters[5].value; latValue = netCDFFile.getLatValue() lonValue = netCDFFile.getLonValue() title = "NetCDF Graph: " + variableName + "/" + rowDim + " at (" + str(latValue)[:7] + "," + str(lonValue)[:7] + ")" arcpy.MakeGraph_management(graph_grf, "SERIES=area:vertical DATA=" + tableViewSource + \ " X=" + rowDim + " Y=" + variableName + " SORT=DESC;" + \ "GRAPH=general TITLE=" + title + ";LEGEND=general;" + \ "AXIS=left TITLE=" + variableName + ";" + \ "AXIS=right;AXIS=bottom TITLE=" + rowDim + ";AXIS=top", outGraph) arcpy.AddMessage("Process Completed")
def updateMessages(self, parameters): """Modify the messages created by internal validation for each tool parameter. This method is called after internal validation.""" try: netCDFSource = parameters[0].valueAsText if netCDFSource is not None: #Making sure that the layers source is a netCDF file if not NetCDFFile.isNetCDF(netCDFSource): parameters[0].setErrorMessage("Invalid input file. " "A netCDF(.nc) " "is expected.") except Exception: pass return
def updateParameters(self, parameters): """Modify the values and properties of parameters before internal validation is performed. This method is called whenever a parameter has been changed. We want to populate the variables and dimensions dropdown list with all dimensions that are not lat, lon and only variables that contain lat/lon dimensions. The lat lon are already going to be represented from the point selected on the map""" try: layer = parameters[0].value if layer is not None: #Getting the netCDF DataSource Path from the netCDF raster layer netCDFSource = NetCDFFile.getNetCDFPathfromLayer(layer) #Making sure that the layers source is a netCDF file if NetCDFFile.isNetCDF(netCDFSource): #NetCDFFile class deteremines the dimensions and variables that #applies to a lat/lon point netCDFFile = NetCDFFile(netCDFSource) #Getting Avalable Dimensions besides besides lat & lon dimensions = netCDFFile.getDimensions() parameters[2].filter.list = dimensions #if dimensions.count > 0: #parameters[2].value = dimensions[0] #Getting Variables that apply to lat & lon variables = netCDFFile.getVariables() parameters[1].filter.list = variables #if variables.count > 0: #parameters[1].value = variables[0] except Exception: pass return
import os import sys import math import arcpy inNetCDF = "C:/Sandbox/python/NetCDF/Data/norfolk_slr_1m.nc" ncFileProp = arcpy.NetCDFFileProperties(inNetCDF) variables = ncFileProp.getVariables() dimensions = ncFileProp.getDimensions() timeVariable = ncFileProp.getVariablesByDimension("time") from netCDFFile import NetCDFFile print NetCDFFile.isNetCDF(inNetCDF) netcdfFile = NetCDFFile(inNetCDF) print netcdfFile.getDimensions() print netcdfFile.getVariables() print netcdfFile.getLatDimension() print netcdfFile.getLonDimension() print str(variables)