<s> import arcpy <EOL> import collections <EOL> import mds <EOL> import mds . messages <EOL> import numpy <EOL> import numpy . lib . recfunctions <EOL> import os <EOL> import tempfile <EOL> class MultidimensionalZonalStatisticsAsTable ( object ) : <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . label = "<STR_LIT>" <EOL> self . description = "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" <EOL> self . canRunInBackground = False <EOL> statistics_numpy = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> statistics_numpycateg = { '<STR_LIT>' : '<STR_LIT>' } <EOL> statistics_categorical = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> statistics_multiple = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> statistics_multiple_cat = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . statistics_multiple_values = { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] } <EOL> self . statistics = [ [ numpy . ma , statistics_numpy , False ] , [ self , statistics_categorical , True ] , [ numpy . ma , statistics_numpycateg , True ] , [ self , statistics_multiple , False ] , [ self , statistics_multiple_cat , True ] ] <EOL> self . default_statistic = '<STR_LIT>' <EOL> def majority ( self , var1 ) : <EOL> """<STR_LIT>""" <EOL> vunique = numpy . ma . compressed ( numpy . unique ( var1 ) ) <EOL> vcounts = numpy . zeros_like ( vunique ) <EOL> for vindex in range ( <NUM_LIT:0> , vunique . size ) : <EOL> vcounts [ vindex ] = numpy . ma . sum ( var1 == vunique [ vindex ] ) <EOL> return vunique [ numpy . argmax ( vcounts ) ] <EOL> def minority ( self , var1 ) : <EOL> """<STR_LIT>""" <EOL> vunique = numpy . ma . compressed ( numpy . unique ( var1 ) ) <EOL> vcounts = numpy . zeros_like ( vunique ) <EOL> for vindex in range ( <NUM_LIT:0> , vunique . size ) : <EOL> vcounts [ vindex ] = numpy . ma . sum ( var1 == vunique [ vindex ] ) <EOL> return vunique [ numpy . argmax ( vcounts ) ] <EOL> def variety ( self , var1 ) : <EOL> """<STR_LIT>""" <EOL> return numpy . ma . compressed ( numpy . unique ( var1 ) ) . size <EOL> def multistats ( self , var1 , statistic ) : <EOL> """<STR_LIT>""" <EOL> stat_dtype = [ ( stat , numpy . float ) for stat in self . statistics_multiple_values [ statistic ] ] <EOL> result = numpy . zeros ( <NUM_LIT:1> , numpy . dtype ( stat_dtype ) ) <EOL> for stat in self . statistics_multiple_values [ statistic ] : <EOL> result [ stat ] = ( self . calculate_statistic ( var1 , stat ) ) <EOL> return result <EOL> def calculate_statistic ( self , variable , statistic ) : <EOL> """<STR_LIT>""" <EOL> for stat in self . statistics : <EOL> if statistic in stat [ <NUM_LIT:1> ] : <EOL> func = getattr ( stat [ <NUM_LIT:0> ] , stat [ <NUM_LIT:1> ] [ statistic ] ) <EOL> break <EOL> else : <EOL> statistic = '<STR_LIT>' <EOL> func = getattr ( self , '<STR_LIT>' ) <EOL> if statistic in self . statistics_multiple_values : <EOL> return func ( variable , statistic ) <EOL> else : <EOL> return func ( variable ) <EOL> def getParameterInfo ( self ) : <EOL> """<STR_LIT>""" <EOL> parameters = [ ] <EOL> parameters . append ( arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) ) <EOL> parameters . append ( arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) ) <EOL> parameters . append ( arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = "<STR_LIT>" , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) ) <EOL> parameters [ - <NUM_LIT:1> ] . parameterDependencies = [ parameters [ - <NUM_LIT:2> ] . name ] <EOL> parameters . append ( arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = "<STR_LIT>" , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) ) <EOL> parameters . append ( arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = "<STR_LIT>" , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) ) <EOL> parameters [ - <NUM_LIT:1> ] . filter . type = "<STR_LIT>" <EOL> parameters [ - <NUM_LIT:1> ] . filter . list = sorted ( [ key for stat in self . statistics for key in stat [ <NUM_LIT:1> ] . keys ( ) ] ) <EOL> parameters [ - <NUM_LIT:1> ] . value = self . default_statistic <EOL> parameters . append ( arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = "<STR_LIT>" , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) ) <EOL> parameters [ - <NUM_LIT:1> ] . filter . list = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> parameters [ - <NUM_LIT:1> ] . value = '<STR_LIT>' <EOL> parameters . append ( arcpy . Parameter ( <EOL> displayName = "<STR_LIT>" , <EOL> name = "<STR_LIT>" , <EOL> datatype = "<STR_LIT>" , <EOL> parameterType = "<STR_LIT>" , <EOL> direction = "<STR_LIT>" ) ) <EOL> parameters [ - <NUM_LIT:1> ] . parameterDependencies = [ parameters [ - <NUM_LIT:7> ] . name ] <EOL> return parameters <EOL> def isLicensed ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if arcpy . CheckExtension ( "<STR_LIT>" ) == "<STR_LIT>" : <EOL> return True <EOL> else : <EOL> return False <EOL> except : <EOL> return False <EOL> return True <EOL> def updateParameters ( self , parameters ) : <EOL> """<STR_LIT>""" <EOL> zone_parameter = parameters [ <NUM_LIT:0> ] <EOL> input_parameter = parameters [ <NUM_LIT:1> ] <EOL> variable_parameter = parameters [ <NUM_LIT:2> ] <EOL> output_parameter = parameters [ <NUM_LIT:3> ] <EOL> type_parameter = parameters [ <NUM_LIT:4> ] <EOL> ignore_parameter = parameters [ <NUM_LIT:5> ] <EOL> zonefield_parameter = parameters [ <NUM_LIT:6> ] <EOL> if ( variable_parameter . value is not None ) and ( not output_parameter . altered ) : <EOL> out_file_name = variable_parameter . valueAsText + '<STR_LIT>' <EOL> i = <NUM_LIT:1> <EOL> temp_name = out_file_name + '<STR_LIT>' <EOL> while arcpy . Exists ( temp_name ) : <EOL> temp_name = out_file_name + str ( i ) + '<STR_LIT>' <EOL> i += <NUM_LIT:1> <EOL> out_file_name = temp_name <EOL> workspace = arcpy . env . workspace <EOL> output_parameter . value = os . path . join ( workspace , out_file_name ) <EOL> if ( zone_parameter . value is not None ) and ( not zonefield_parameter . altered ) : <EOL> valid_raster_types = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> valid_feature_types = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> desc = arcpy . Describe ( zone_parameter . value ) <EOL> if desc . dataType in valid_raster_types : <EOL> zonefield_parameter . value = "<STR_LIT>" <EOL> else : <EOL> zonefield_parameter . value = "<STR_LIT>" <EOL> return <EOL> def updateMessages ( self , parameters ) : <EOL> """<STR_LIT>""" <EOL> zone_parameter = parameters [ <NUM_LIT:0> ] <EOL> input_parameter = parameters [ <NUM_LIT:1> ] <EOL> variable_parameter = parameters [ <NUM_LIT:2> ] <EOL> output_parameter = parameters [ <NUM_LIT:3> ] <EOL> type_parameter = parameters [ <NUM_LIT:4> ] <EOL> ignore_parameter = parameters [ <NUM_LIT:5> ] <EOL> zonefield_parameter = parameters [ <NUM_LIT:6> ] <EOL> dataset = None <EOL> if zone_parameter . value is not None : <EOL> valid_raster_types = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> valid_feature_types = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> desc = arcpy . Describe ( zone_parameter . value ) <EOL> if desc . dataType in valid_raster_types : <EOL> if not hasattr ( desc , '<STR_LIT>' ) or not desc . isInteger : <EOL> zone_parameter . setErrorMessage ( <EOL> mds . messages . ZONE_RASTER_NOT_INTEGER . format ( <EOL> zone_parameter . valueAsText ) ) <EOL> else : <EOL> if hasattr ( desc , '<STR_LIT>' ) : <EOL> zonefield_parameter . filter . type = "<STR_LIT>" <EOL> validtypes = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> zonefield_parameter . filter . list = [ zonefield . name for zonefield in desc . fields if zonefield . type in validtypes ] <EOL> else : <EOL> zonefield_parameter . filter . type = "<STR_LIT>" <EOL> zonefield_parameter . filter . list = [ '<STR_LIT>' ] <EOL> elif desc . dataType in valid_feature_types : <EOL> zonefield_parameter . filter . type = "<STR_LIT>" <EOL> validtypes = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> zonefield_parameter . filter . list = [ zonefield . name for zonefield in desc . fields if zonefield . type in validtypes ] <EOL> else : <EOL> zonefield_parameter . filter . type = "<STR_LIT>" <EOL> zonefield_parameter . filter . list = [ ] <EOL> else : <EOL> zonefield_parameter . filter . type = "<STR_LIT>" <EOL> zonefield_parameter . filter . list = [ ] <EOL> if input_parameter . value is not None : <EOL> try : <EOL> dataset = mds . netcdf . Dataset ( input_parameter . valueAsText , '<STR_LIT>' ) <EOL> except RuntimeError , exception : <EOL> if "<STR_LIT>" in str ( exception ) or "<STR_LIT>" in str ( exception ) : <EOL> input_parameter . setErrorMessage ( <EOL> mds . messages . INPUT_FILE_DOES_NOT_EXIST . format ( <EOL> input_parameter . valueAsText ) ) <EOL> elif "<STR_LIT>" in str ( exception ) : <EOL> input_parameter . setErrorMessage ( <EOL> mds . messages . INPUT_DATASET_URL_MALFORMED . format ( <EOL> input_parameter . valueAsText ) ) <EOL> else : <EOL> input_parameter . setErrorMessage ( <EOL> mds . messages . INPUT_DATASET_GENERIC_ERROR . format ( <EOL> input_parameter . valueAsText , str ( exception ) ) ) <EOL> except Exception , exception : <EOL> input_parameter . setErrorMessage ( <EOL> mds . messages . INPUT_DATASET_GENERIC_ERROR . format ( <EOL> input_parameter . valueAsText , str ( exception ) ) ) <EOL> if dataset is not None : <EOL> var_list = list ( dataset . spatial_data_variable_names ( ) ) <EOL> if var_list != [ ] : <EOL> variable_parameter . filter . type = "<STR_LIT>" <EOL> variable_parameter . filter . list = var_list <EOL> else : <EOL> var_list = list ( dataset . data_variable_names ( ) ) <EOL> var_filter = [ ] <EOL> for var_item in var_list : <EOL> var_stat , var_x , var_y = self . get_dependent_variables ( <EOL> dataset , var_item ) <EOL> if ( var_stat is not None ) and ( var_x is not None ) and ( <EOL> var_y is not None ) : <EOL> var_filter = self . get_variables_by_dimension ( <EOL> dataset , var_stat ) <EOL> break <EOL> variable_parameter . filter . type = "<STR_LIT>" <EOL> variable_parameter . filter . list = var_filter <EOL> else : <EOL> variable_parameter . filter . type = "<STR_LIT>" <EOL> variable_parameter . filter . list = [ ] <EOL> variable_parameter . value = "<STR_LIT>" <EOL> if variable_parameter . value is not None : <EOL> if ( dataset is not None ) and ( variable_parameter . value in dataset . variable_names ( ) ) : <EOL> var = dataset . variable ( variable_parameter . value ) <EOL> ispacked = hasattr ( var , '<STR_LIT>' ) or hasattr ( var , '<STR_LIT>' ) <EOL> flag = ( '<STR_LIT:int>' in str ( var . dtype ) ) and not ispacked <EOL> type_parameter . filter . list = sorted ( [ key for stat in self . statistics if flag or not stat [ <NUM_LIT:2> ] for key in stat [ <NUM_LIT:1> ] . keys ( ) ] ) <EOL> else : <EOL> type_parameter . filter . list = sorted ( [ key for stat in self . statistics for key in stat [ <NUM_LIT:1> ] . keys ( ) ] ) <EOL> if output_parameter . value is not None : <EOL> output_filename = output_parameter . valueAsText <EOL> if os . path . splitext ( output_filename ) [ <NUM_LIT:1> ] != "<STR_LIT>" : <EOL> output_parameter . setErrorMessage ( <EOL> mds . messages . OUTPUT_FILE_EXTENSION_MUST_BE_DBF ) <EOL> return <EOL> def execute ( self , parameters , messages ) : <EOL> """<STR_LIT>""" <EOL> zone_parameter = parameters [ <NUM_LIT:0> ] <EOL> input_parameter = parameters [ <NUM_LIT:1> ] <EOL> variable_parameter = parameters [ <NUM_LIT:2> ] <EOL> output_parameter = parameters [ <NUM_LIT:3> ] <EOL> type_parameter = parameters [ <NUM_LIT:4> ] <EOL> ignore_parameter = parameters [ <NUM_LIT:5> ] <EOL> zonefield_parameter = parameters [ <NUM_LIT:6> ] <EOL> dataset_name = input_parameter . valueAsText <EOL> output_filename = output_parameter . valueAsText <EOL> var_name = variable_parameter . valueAsText <EOL> try : <EOL> dataset = mds . netcdf . Dataset ( dataset_name , '<STR_LIT>' ) <EOL> except RuntimeError , exception : <EOL> messages . addErrorMessage ( str ( exception ) ) <EOL> raise arcpy . ExecuteError <EOL> if list ( dataset . spatial_data_variable_names ( ) ) != [ ] : <EOL> self . zonal_statistics_as_table_for_grid ( parameters , messages , dataset ) <EOL> else : <EOL> self . zonal_statistics_as_table_for_discrete ( parameters , messages , dataset ) <EOL> return <EOL> def zonal_statistics_as_table_for_grid ( self , parameters , messages , dataset ) : <EOL> """<STR_LIT>""" <EOL> zone_parameter = parameters [ <NUM_LIT:0> ] <EOL> input_parameter = parameters [ <NUM_LIT:1> ] <EOL> variable_parameter = parameters [ <NUM_LIT:2> ] <EOL> output_parameter = parameters [ <NUM_LIT:3> ] <EOL> type_parameter = parameters [ <NUM_LIT:4> ] <EOL> ignore_parameter = parameters [ <NUM_LIT:5> ] <EOL> zonefield_parameter = parameters [ <NUM_LIT:6> ] <EOL> dataset_name = input_parameter . valueAsText <EOL> output_filename = output_parameter . valueAsText <EOL> var_name = variable_parameter . valueAsText <EOL> arr_var = dataset . variable ( var_name ) <EOL> cell_size_x = None <EOL> cell_size_y = None <EOL> spat_list = list ( dataset . space_dimension_names ( var_name ) ) <EOL> assert len ( spat_list ) >= <NUM_LIT:2> <EOL> spat_var = dataset . variable ( spat_list [ <NUM_LIT:0> ] ) <EOL> blfirst = True <EOL> if spat_var . size > <NUM_LIT:1> : <EOL> for i in range ( spat_var . size - <NUM_LIT:1> ) : <EOL> cell_size_x = spat_var [ i + <NUM_LIT:1> ] - spat_var [ i ] <EOL> if ( not blfirst ) and ( cell_size_x != last_cell_size ) : <EOL> messages . addErrorMessage ( <EOL> mds . messages . VARIABLE_NOT_REGULARLY_GRIDDED . format ( <EOL> var_name , spat_list [ <NUM_LIT:0> ] ) ) <EOL> raise arcpy . ExecuteError <EOL> break <EOL> last_cell_size = cell_size_x <EOL> blfirst = False <EOL> cell_size_x = float ( cell_size_x ) <EOL> spat_var = dataset . variable ( spat_list [ <NUM_LIT:1> ] ) <EOL> blfirst = True <EOL> if spat_var . size > <NUM_LIT:1> : <EOL> for i in range ( spat_var . size - <NUM_LIT:1> ) : <EOL> cell_size_y = spat_var [ i + <NUM_LIT:1> ] - spat_var [ i ] <EOL> if ( not blfirst ) and ( cell_size_y != last_cell_size ) : <EOL> messages . addErrorMessage ( <EOL> mds . messages . VARIABLE_NOT_REGULARLY_GRIDDED . format ( <EOL> var_name , spat_list [ <NUM_LIT:1> ] ) ) <EOL> raise arcpy . ExecuteError <EOL> break <EOL> last_cell_size = cell_size_y <EOL> blfirst = False <EOL> cell_size_y = float ( cell_size_y ) <EOL> if ( cell_size_x is None ) and ( cell_size_y is None ) : <EOL> messages . addErrorMessage ( <EOL> mds . messages . VARIABLE_CONTAINS_INSUFFICIENT_VALUES . format ( <EOL> var_name ) ) <EOL> raise arcpy . ExecuteError <EOL> if cell_size_x is None : <EOL> cell_size_x = cell_size_y <EOL> messages . addWarningMessage ( <EOL> ( "<STR_LIT>" + "<STR_LIT>" ) . format ( spat_list [ <NUM_LIT:0> ] , cell_size_y , spat_list [ <NUM_LIT:1> ] ) ) <EOL> if cell_size_y is None : <EOL> cell_size_y = cell_size_x <EOL> messages . addWarningMessage ( <EOL> ( "<STR_LIT>" + "<STR_LIT>" ) . format ( spat_list [ <NUM_LIT:1> ] , cell_size_x , spat_list [ <NUM_LIT:0> ] ) ) <EOL> if dataset . convention . is_x_dimension_variable ( dataset . variable ( spat_list [ <NUM_LIT:0> ] ) ) : <EOL> ncol = len ( dataset . variable ( spat_list [ <NUM_LIT:0> ] ) ) <EOL> nrow = len ( dataset . variable ( spat_list [ <NUM_LIT:1> ] ) ) <EOL> bltranspose = True <EOL> else : <EOL> ncol = len ( dataset . variable ( spat_list [ <NUM_LIT:1> ] ) ) <EOL> nrow = len ( dataset . variable ( spat_list [ <NUM_LIT:0> ] ) ) <EOL> cell_size_x , cell_size_y = cell_size_y , cell_size_x <EOL> bltranspose = False <EOL> var_extent = dataset . extent ( var_name ) <EOL> xl = float ( var_extent [ <NUM_LIT:0> ] ) <EOL> yl = float ( var_extent [ <NUM_LIT:1> ] ) <EOL> blflipx = False <EOL> blflipy = False <EOL> if cell_size_y > <NUM_LIT:0> : <EOL> blflipx = True <EOL> if cell_size_x < <NUM_LIT:0> : <EOL> blflipy = True <EOL> cell_size_x = abs ( cell_size_x ) <EOL> cell_size_y = abs ( cell_size_y ) <EOL> var_extent = arcpy . Extent ( var_extent [ <NUM_LIT:0> ] , var_extent [ <NUM_LIT:1> ] , var_extent [ <NUM_LIT:2> ] , var_extent [ <NUM_LIT:3> ] ) <EOL> bltempRaster = False <EOL> desc = arcpy . Describe ( zone_parameter . value ) <EOL> arcpy . env . outputCoordinateSystem = desc . spatialReference <EOL> temp_snap = arcpy . NumPyArrayToRaster ( numpy . zeros ( ( <NUM_LIT:1> , <NUM_LIT:1> ) ) , arcpy . Point ( xl , yl ) , cell_size_x , cell_size_y ) <EOL> arcpy . env . snapRaster = temp_snap <EOL> valid_raster_types = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> valid_feature_types = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> if desc . dataType in valid_feature_types : <EOL> if cell_size_x != cell_size_y : <EOL> messages . addErrorMessage ( <EOL> "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" % var_name ) <EOL> raise arcpy . ExecuteError <EOL> temp_raster = '<STR_LIT>' <EOL> arcpy . FeatureToRaster_conversion ( zone_parameter . value , zonefield_parameter . value , temp_raster , cell_size_x ) <EOL> bltempRaster = True <EOL> noDataValue = arcpy . Describe ( temp_raster ) . noDataValue <EOL> elif desc . dataType in valid_raster_types : <EOL> if zonefield_parameter . value != '<STR_LIT>' : <EOL> in_raster = arcpy . sa . Lookup ( zone_parameter . value , zonefield_parameter . value ) <EOL> if '<STR_LIT>' in in_raster . pixelType : <EOL> noDataValue = - <NUM_LIT> <EOL> else : <EOL> noDataValue = - <NUM_LIT> <EOL> else : <EOL> in_raster = zone_parameter . valueAsText <EOL> noDataValue = desc . noDataValue <EOL> if ( desc . meanCellHeight != cell_size_y ) or ( desc . meanCellWidth != cell_size_x ) : <EOL> temp_raster = '<STR_LIT>' <EOL> arcpy . Resample_management ( in_raster , temp_raster , "<STR_LIT>" % ( cell_size_x , cell_size_y ) ) <EOL> bltempRaster = True <EOL> else : <EOL> temp_raster = in_raster <EOL> else : <EOL> messages . addErrorMessage ( "<STR_LIT>" ) <EOL> raise arcpy . ExecuteError <EOL> if not isinstance ( temp_raster , arcpy . Raster ) : <EOL> temp_raster = arcpy . Raster ( temp_raster ) <EOL> def convert_coord ( num , islon = True ) : <EOL> lim = <NUM_LIT> if islon else <NUM_LIT> <EOL> if num > lim : <EOL> out = num % - lim <EOL> elif num < - lim : <EOL> out = num % lim <EOL> else : <EOL> out = num <EOL> if not islon : <EOL> mult = - <NUM_LIT:1.0> if num < <NUM_LIT:0> else <NUM_LIT:1.0> <EOL> out = mult * abs ( out ) <EOL> return out <EOL> if ( temp_raster . spatialReference . exporttostring ( ) == temp_raster . spatialReference . GCS . exporttostring ( ) ) : <EOL> if temp_raster . extent . disjoint ( var_extent ) : <EOL> var_extent_temp = arcpy . Extent ( <EOL> convert_coord ( var_extent . XMin , True ) , <EOL> convert_coord ( var_extent . YMin , True ) , <EOL> convert_coord ( var_extent . XMax , False ) , <EOL> convert_coord ( var_extent . YMax , False ) ) <EOL> xl = var_extent_temp . XMin <EOL> yl = var_extent_temp . YMin <EOL> if temp_raster . extent . disjoint ( var_extent_temp ) : <EOL> messages . addWarningMessage ( "<STR_LIT>" ) <EOL> else : <EOL> if ( not temp_raster . extent . overlaps ( var_extent ) ) and ( <EOL> not temp_raster . extent . equals ( var_extent ) ) : <EOL> messages . addWarningMessage ( "<STR_LIT>" ) <EOL> arr_zone = arcpy . RasterToNumPyArray ( temp_raster , arcpy . Point ( xl , yl ) , ncol , nrow ) <EOL> if blflipx : <EOL> arr_zone = numpy . flipud ( arr_zone ) <EOL> if blflipy : <EOL> arr_zone = numpy . fliplr ( arr_zone ) <EOL> if bltranspose : <EOL> arr_zone = numpy . transpose ( arr_zone ) <EOL> if bltempRaster : <EOL> arcpy . Delete_management ( temp_raster ) <EOL> ispacked = hasattr ( arr_var , '<STR_LIT>' ) or hasattr ( arr_var , '<STR_LIT>' ) <EOL> new_var_dtype = False <EOL> for stat in self . statistics : <EOL> if type_parameter . valueAsText in stat [ <NUM_LIT:1> ] . keys ( ) : <EOL> new_var_dtype = stat [ <NUM_LIT:2> ] <EOL> break <EOL> type_changed = False <EOL> if ( '<STR_LIT:int>' in str ( arr_var . dtype ) ) and ( not new_var_dtype ) and ( <EOL> not ispacked ) : <EOL> type_changed = True <EOL> def multi_for ( iterables ) : <EOL> if not iterables : <EOL> yield ( ) <EOL> else : <EOL> if isinstance ( iterables [ <NUM_LIT:0> ] , collections . Iterable ) : <EOL> for item in iterables [ <NUM_LIT:0> ] : <EOL> for rest_tuple in multi_for ( iterables [ <NUM_LIT:1> : ] ) : <EOL> yield ( item , ) + rest_tuple <EOL> else : <EOL> for rest_tuple in multi_for ( iterables [ <NUM_LIT:1> : ] ) : <EOL> yield ( iterables [ <NUM_LIT:0> ] , ) + rest_tuple <EOL> dim_shape = arr_var . shape <EOL> dim_name = arr_var . dimensions <EOL> dim_slices = [ ] <EOL> dim_dims = [ ] <EOL> dim_prod = <NUM_LIT:1> <EOL> for dim_index , dim_item in enumerate ( dim_name ) : <EOL> if not dim_item in spat_list : <EOL> dim_prod *= dim_shape [ dim_index ] <EOL> dim_slices . append ( xrange ( dim_shape [ dim_index ] ) ) <EOL> dim_dims . append ( ( str ( dim_item ) , numpy . int ) ) <EOL> else : <EOL> dim_slices . append ( Ellipsis ) <EOL> blstructcreated = False <EOL> def hstack_struct ( arr1 , arr2 ) : <EOL> dt = numpy . lib . recfunctions . zip_descr ( ( arr1 , arr2 ) , flatten = True ) <EOL> return numpy . array ( arr1 . tolist ( ) + arr2 . tolist ( ) , dtype = dt ) <EOL> if noDataValue is not None : <EOL> zones = numpy . setdiff1d ( numpy . unique ( arr_zone ) , [ noDataValue ] ) <EOL> else : <EOL> zones = numpy . unique ( arr_zone ) <EOL> dim_prod *= zones . size <EOL> arcpy . ResetProgressor ( ) <EOL> arcpy . SetProgressor ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0> , dim_prod , <NUM_LIT:1> ) <EOL> index = <NUM_LIT:0> <EOL> valid_indices = [ ] <EOL> for varslice in multi_for ( dim_slices ) : <EOL> if type_changed : <EOL> arr_slice = arr_var [ varslice ] . astype ( '<STR_LIT>' ) <EOL> else : <EOL> arr_slice = arr_var [ varslice ] <EOL> if hasattr ( arr_slice , '<STR_LIT>' ) : <EOL> arr_mask = arr_slice . mask . copy ( ) <EOL> else : <EOL> arr_mask = numpy . ma . make_mask_none ( arr_slice . shape ) <EOL> arr_slice = numpy . ma . asarray ( arr_slice ) <EOL> for z in zones : <EOL> if ignore_parameter . value or ( not numpy . any ( ( arr_zone == z ) & arr_mask ) ) : <EOL> arr_slice . mask = arr_mask <EOL> arr_slice [ arr_zone != z ] = numpy . ma . masked <EOL> result = self . calculate_statistic ( arr_slice [ : ] , type_parameter . valueAsText ) <EOL> struct_data = [ dataset . variable ( dim_name [ it_ind ] ) [ it ] for it_ind , it in enumerate ( list ( varslice ) ) if it != Ellipsis ] <EOL> struct_data . append ( z ) <EOL> struct_data . append ( numpy . ma . count ( arr_slice ) ) <EOL> if numpy . isscalar ( result ) : <EOL> struct_data . append ( result ) <EOL> else : <EOL> struct_data += [ it2 for it in result . tolist ( ) for it2 in it ] <EOL> if not blstructcreated : <EOL> struct_dtype = dim_dims [ : ] <EOL> struct_dtype . append ( ( str ( zonefield_parameter . value ) , numpy . int ) ) <EOL> struct_dtype . append ( ( '<STR_LIT>' , numpy . int ) ) <EOL> if type_parameter . valueAsText in self . statistics_multiple_values : <EOL> struct_dtype += [ ( it , numpy . float ) for it in list ( <EOL> result . dtype . names ) ] <EOL> else : <EOL> struct_dtype . append ( ( str ( <EOL> type_parameter . valueAsText ) , numpy . float ) ) <EOL> struct = numpy . zeros ( ( dim_prod , ) , numpy . dtype ( struct_dtype ) ) <EOL> blstructcreated = True <EOL> struct [ index ] = numpy . array ( tuple ( struct_data ) , numpy . dtype ( struct_dtype ) ) <EOL> valid_indices . append ( index ) <EOL> index += <NUM_LIT:1> <EOL> arcpy . SetProgressorPosition ( ) <EOL> arcpy . ResetProgressor ( ) <EOL> if '<STR_LIT:time>' in dim_name : <EOL> temp_table = os . path . join ( tempfile . gettempdir ( ) , '<STR_LIT>' ) <EOL> if arcpy . Exists ( temp_table ) : <EOL> arcpy . Delete_management ( temp_table ) <EOL> arcpy . da . NumPyArrayToTable ( struct [ valid_indices ] , temp_table ) <EOL> temp_mdtable = r"<STR_LIT>" <EOL> arcpy . MakeNetCDFTableView_md ( dataset_name , '<STR_LIT:time>' , temp_mdtable , '<STR_LIT:time>' ) <EOL> desc_fields = arcpy . ListFields ( temp_mdtable ) <EOL> time_field = desc_fields [ [ field . name for field in desc_fields ] . index ( '<STR_LIT:time>' ) ] <EOL> arcpy . CreateTable_management ( * os . path . split ( output_filename ) ) <EOL> desc_fields = arcpy . ListFields ( temp_table ) <EOL> for index , field in enumerate ( desc_fields ) : <EOL> if field . type != '<STR_LIT>' : <EOL> if field . name == '<STR_LIT:time>' : <EOL> arcpy . AddField_management ( output_filename , time_field . name , time_field . type , time_field . precision , time_field . scale , time_field . length , time_field . aliasName , time_field . isNullable , time_field . required , time_field . domain ) <EOL> else : <EOL> arcpy . AddField_management ( output_filename , field . name , field . type , field . precision , field . scale , field . length , field . aliasName , field . isNullable , field . required , <EOL> field . domain ) <EOL> arcpy . DeleteField_management ( output_filename , "<STR_LIT>" ) <EOL> time_arc = [ ] <EOL> with arcpy . da . SearchCursor ( temp_mdtable , '<STR_LIT:time>' ) as cursor : <EOL> for row in cursor : <EOL> time_arc . append ( row [ <NUM_LIT:0> ] ) <EOL> del cursor <EOL> time_var = dataset . variable ( '<STR_LIT:time>' ) [ : ] . tolist ( ) <EOL> with arcpy . da . InsertCursor ( output_filename , '<STR_LIT:*>' ) as ins_cursor : <EOL> new_time_ind = ins_cursor . fields . index ( '<STR_LIT:time>' ) <EOL> with arcpy . da . SearchCursor ( temp_table , '<STR_LIT:*>' ) as cursor : <EOL> time_ind = cursor . fields . index ( '<STR_LIT:time>' ) <EOL> for row in cursor : <EOL> new_row = list ( row ) <EOL> new_row [ new_time_ind ] = time_arc [ time_var . index ( row [ time_ind ] ) ] <EOL> ins_cursor . insertRow ( tuple ( new_row ) ) <EOL> del ins_cursor <EOL> del cursor <EOL> else : <EOL> if arcpy . env . overwriteOutput : <EOL> arcpy . Delete_management ( output_filename ) <EOL> arcpy . da . NumPyArrayToTable ( struct [ valid_indices ] , output_filename ) <EOL> return <EOL> def zonal_statistics_as_table_for_discrete ( self , parameters , messages , dataset ) : <EOL> """<STR_LIT>""" <EOL> zone_parameter = parameters [ <NUM_LIT:0> ] <EOL> input_parameter = parameters [ <NUM_LIT:1> ] <EOL> variable_parameter = parameters [ <NUM_LIT:2> ] <EOL> output_parameter = parameters [ <NUM_LIT:3> ] <EOL> type_parameter = parameters [ <NUM_LIT:4> ] <EOL> ignore_parameter = parameters [ <NUM_LIT:5> ] <EOL> zonefield_parameter = parameters [ <NUM_LIT:6> ] <EOL> dataset_name = input_parameter . valueAsText <EOL> output_filename = output_parameter . valueAsText <EOL> var_name = variable_parameter . valueAsText <EOL> ( stat_variable , x_variable , y_variable ) = self . get_dependent_variables ( <EOL> dataset , var_name ) <EOL> if ( stat_variable is None ) or ( x_variable is None ) or ( y_variable is None ) : <EOL> messages . addErrorMessage ( '<STR_LIT>' % var_name ) <EOL> raise arcpy . ExecuteError <EOL> arr_var = dataset . variable ( var_name ) <EOL> dim_names = [ ] <EOL> if '<STR_LIT>' in arr_var . ncattrs ( ) : <EOL> dim_names = str ( arr_var . getncattr ( '<STR_LIT>' ) ) . split ( ) <EOL> X = dataset . variable ( x_variable ) <EOL> Y = dataset . variable ( y_variable ) <EOL> if stat_variable in dataset . variable_names ( ) : <EOL> arr_stat = dataset . variable ( stat_variable ) [ : ] <EOL> else : <EOL> arr_stat = numpy . arange ( len ( dataset . dimension ( stat_variable ) ) ) <EOL> zone_stations = { } <EOL> desc = arcpy . Describe ( zone_parameter . value ) <EOL> bltemppoly = False <EOL> valid_raster_types = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> valid_feature_types = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> if desc . dataType in valid_raster_types : <EOL> temp_poly = "<STR_LIT>" <EOL> arcpy . RasterToPolygon_conversion ( in_raster , temp_poly , "<STR_LIT>" , zonefield_parameter . value ) <EOL> temp_field = "<STR_LIT>" <EOL> bltemppoly = True <EOL> elif desc . dataType in valid_feature_types : <EOL> temp_poly = zone_parameter . value <EOL> temp_field = zonefield_parameter . value <EOL> else : <EOL> messages . addErrorMessage ( "<STR_LIT>" ) <EOL> raise arcpy . ExecuteError <EOL> num_recs = int ( arcpy . GetCount_management ( temp_poly ) . getOutput ( <NUM_LIT:0> ) ) <EOL> num_recs *= numpy . prod ( arr_stat . shape ) <EOL> arcpy . SetProgressor ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> , num_recs , <NUM_LIT:1> ) <EOL> desc = arcpy . Describe ( temp_poly ) <EOL> rows = arcpy . SearchCursor ( temp_poly ) <EOL> for row in rows : <EOL> feat = row . getValue ( desc . ShapeFieldName ) <EOL> zone = row . getValue ( temp_field ) <EOL> for station in arr_stat : <EOL> if feat . contains ( arcpy . Point ( float ( X [ station ] ) , float ( Y [ station ] ) ) ) : <EOL> if not zone in zone_stations . keys ( ) : <EOL> zone_stations [ zone ] = [ ] <EOL> zone_stations [ zone ] . append ( station ) <EOL> arcpy . SetProgressorPosition ( ) <EOL> del rows , row <EOL> arcpy . ResetProgressor ( ) <EOL> if bltemppoly : <EOL> arcpy . Delete_management ( temp_poly ) <EOL> ispacked = hasattr ( arr_var , '<STR_LIT>' ) or hasattr ( arr_var , '<STR_LIT>' ) <EOL> new_var_dtype = False <EOL> for stat in self . statistics : <EOL> if type_parameter . valueAsText in stat [ <NUM_LIT:1> ] . keys ( ) : <EOL> new_var_dtype = stat [ <NUM_LIT:2> ] <EOL> break <EOL> type_changed = False <EOL> if ( '<STR_LIT:int>' in str ( arr_var . dtype ) ) and ( not new_var_dtype ) and ( <EOL> not ispacked ) : <EOL> type_changed = True <EOL> def multi_for ( iterables ) : <EOL> if not iterables : <EOL> yield ( ) <EOL> else : <EOL> if isinstance ( iterables [ <NUM_LIT:0> ] , collections . Iterable ) : <EOL> for item in iterables [ <NUM_LIT:0> ] : <EOL> for rest_tuple in multi_for ( iterables [ <NUM_LIT:1> : ] ) : <EOL> yield ( item , ) + rest_tuple <EOL> else : <EOL> for rest_tuple in multi_for ( iterables [ <NUM_LIT:1> : ] ) : <EOL> yield ( iterables [ <NUM_LIT:0> ] , ) + rest_tuple <EOL> dim_shape = arr_var . shape <EOL> dim_name = arr_var . dimensions <EOL> dim_slices = [ ] <EOL> dim_dims = [ ] <EOL> dim_prod = <NUM_LIT:1> <EOL> for dim_index , dim_item in enumerate ( dim_name ) : <EOL> if dim_item != stat_variable : <EOL> dim_prod *= dim_shape [ dim_index ] <EOL> dim_slices . append ( xrange ( dim_shape [ dim_index ] ) ) <EOL> dim_dims . append ( ( str ( dim_item ) , numpy . int ) ) <EOL> stat_position = dim_name . index ( stat_variable ) <EOL> blstructcreated = False <EOL> def hstack_struct ( arr1 , arr2 ) : <EOL> dt = numpy . lib . recfunctions . zip_descr ( ( arr1 , arr2 ) , flatten = True ) <EOL> return numpy . array ( arr1 . tolist ( ) + arr2 . tolist ( ) , dtype = dt ) <EOL> dim_prod *= len ( zone_stations ) <EOL> arcpy . ResetProgressor ( ) <EOL> arcpy . SetProgressor ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0> , dim_prod , <NUM_LIT:1> ) <EOL> index = <NUM_LIT:0> <EOL> valid_indices = [ ] <EOL> for zone in zone_stations : <EOL> zone_indices = zone_stations [ zone ] <EOL> for varslice in multi_for ( dim_slices ) : <EOL> varslice = list ( varslice ) <EOL> varslice . insert ( stat_position , zone_indices ) <EOL> if type_changed : <EOL> arr_slice = arr_var [ varslice ] . astype ( '<STR_LIT>' ) <EOL> else : <EOL> arr_slice = arr_var [ varslice ] <EOL> if hasattr ( arr_slice , '<STR_LIT>' ) : <EOL> arr_mask = arr_slice . mask . copy ( ) <EOL> else : <EOL> arr_mask = numpy . ma . make_mask_none ( arr_slice . shape ) <EOL> arr_slice = numpy . ma . asarray ( arr_slice ) <EOL> if ignore_parameter . value or ( not numpy . any ( arr_mask ) ) : <EOL> arr_slice . mask = arr_mask <EOL> result = self . calculate_statistic ( arr_slice [ : ] , type_parameter . valueAsText ) <EOL> struct_data = [ ] <EOL> for it_ind , it in enumerate ( list ( varslice ) ) : <EOL> if it_ind != stat_position : <EOL> if dim_name [ it_ind ] in dataset . variable_names ( ) : <EOL> struct_data . append ( dataset . variable ( dim_name [ it_ind ] ) [ it ] ) <EOL> else : <EOL> struct_data . append ( it ) <EOL> struct_data . append ( zone ) <EOL> struct_data . append ( numpy . ma . count ( arr_slice ) ) <EOL> if numpy . isscalar ( result ) : <EOL> struct_data . append ( result ) <EOL> else : <EOL> struct_data += [ it2 for it in result . tolist ( ) for it2 in it ] <EOL> if not blstructcreated : <EOL> struct_dtype = dim_dims [ : ] <EOL> struct_dtype . append ( ( str ( zonefield_parameter . value ) , numpy . int ) ) <EOL> struct_dtype . append ( ( '<STR_LIT>' , numpy . int ) ) <EOL> if numpy . isscalar ( result ) : <EOL> struct_dtype . append ( ( str ( type_parameter . valueAsText ) , numpy . float ) ) <EOL> else : <EOL> struct_dtype += [ ( it , numpy . float ) for it in list ( <EOL> result . dtype . names ) ] <EOL> struct = numpy . zeros ( ( dim_prod , ) , numpy . dtype ( struct_dtype ) ) <EOL> blstructcreated = True <EOL> struct [ index ] = numpy . array ( tuple ( struct_data ) , numpy . dtype ( struct_dtype ) ) <EOL> valid_indices . append ( index ) <EOL> index += <NUM_LIT:1> <EOL> arcpy . SetProgressorPosition ( ) <EOL> arcpy . ResetProgressor ( ) <EOL> if '<STR_LIT:time>' in dim_name : <EOL> temp_table = os . path . join ( tempfile . gettempdir ( ) , '<STR_LIT>' ) <EOL> if arcpy . Exists ( temp_table ) : <EOL> arcpy . Delete_management ( temp_table ) <EOL> arcpy . da . NumPyArrayToTable ( struct [ valid_indices ] , temp_table ) <EOL> temp_mdtable = r"<STR_LIT>" <EOL> arcpy . MakeNetCDFTableView_md ( dataset_name , '<STR_LIT:time>' , temp_mdtable , '<STR_LIT:time>' ) <EOL> desc_fields = arcpy . ListFields ( temp_mdtable ) <EOL> time_field = desc_fields [ [ field . name for field in desc_fields ] . index ( '<STR_LIT:time>' ) ] <EOL> arcpy . CreateTable_management ( * os . path . split ( output_filename ) ) <EOL> desc_fields = arcpy . ListFields ( temp_table ) <EOL> for index , field in enumerate ( desc_fields ) : <EOL> if field . type != '<STR_LIT>' : <EOL> if field . name == '<STR_LIT:time>' : <EOL> arcpy . AddField_management ( output_filename , time_field . name , time_field . type , time_field . precision , time_field . scale , time_field . length , time_field . aliasName , time_field . isNullable , time_field . required , time_field . domain ) <EOL> else : <EOL> arcpy . AddField_management ( output_filename , field . name , field . type , field . precision , field . scale , field . length , field . aliasName , field . isNullable , field . required , <EOL> field . domain ) <EOL> arcpy . DeleteField_management ( output_filename , "<STR_LIT>" ) <EOL> time_arc = [ ] <EOL> with arcpy . da . SearchCursor ( temp_mdtable , '<STR_LIT:time>' ) as cursor : <EOL> for row in cursor : <EOL> time_arc . append ( row [ <NUM_LIT:0> ] ) <EOL> del cursor <EOL> time_var = dataset . variable ( '<STR_LIT:time>' ) [ : ] . tolist ( ) <EOL> with arcpy . da . InsertCursor ( output_filename , '<STR_LIT:*>' ) as ins_cursor : <EOL> new_time_ind = ins_cursor . fields . index ( '<STR_LIT:time>' ) <EOL> with arcpy . da . SearchCursor ( temp_table , '<STR_LIT:*>' ) as cursor : <EOL> time_ind = cursor . fields . index ( '<STR_LIT:time>' ) <EOL> for row in cursor : <EOL> new_row = list ( row ) <EOL> new_row [ new_time_ind ] = time_arc [ time_var . index ( row [ time_ind ] ) ] <EOL> ins_cursor . insertRow ( tuple ( new_row ) ) <EOL> del ins_cursor <EOL> del cursor <EOL> else : <EOL> if arcpy . env . overwriteOutput : <EOL> arcpy . Delete_management ( output_filename ) <EOL> arcpy . da . NumPyArrayToTable ( struct [ valid_indices ] , output_filename ) <EOL> return <EOL> def get_variables_by_dimension ( self , dataset , stat_name ) : <EOL> """<STR_LIT>""" <EOL> var_list = dataset . data_variable_names ( ) <EOL> var_dtypes = [ '<STR_LIT:i>' , '<STR_LIT:u>' , '<STR_LIT:f>' , '<STR_LIT:b>' ] <EOL> var_out = [ ] <EOL> for var_item in var_list : <EOL> var_inst = dataset . variable ( var_item ) <EOL> if ( str ( var_inst . dtype . kind ) in var_dtypes ) and ( stat_name in var_inst . dimensions ) : <EOL> var_out . append ( var_item ) <EOL> return var_out <EOL> def get_dependent_variables ( self , dataset , var_name ) : <EOL> """<STR_LIT>""" <EOL> arr_var = dataset . variable ( var_name ) <EOL> if '<STR_LIT>' in arr_var . ncattrs ( ) : <EOL> dim_names = str ( arr_var . getncattr ( '<STR_LIT>' ) ) . split ( ) <EOL> else : <EOL> return ( None , None , None ) <EOL> XCoordNamesList = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> YCoordNamesList = [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> XUnitNamesList = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> YUnitNamesList = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> XAxisNameList = [ "<STR_LIT:X>" ] <EOL> YAxisNameList = [ "<STR_LIT:Y>" ] <EOL> x_variable = "<STR_LIT>" <EOL> y_variable = "<STR_LIT>" <EOL> for dim_name in dim_names : <EOL> if dim_name in dataset . variable_names ( ) : <EOL> dim_var = dataset . variable ( dim_name ) <EOL> if '<STR_LIT>' in dim_var . ncattrs ( ) : <EOL> SNattributeValue = str ( dim_var . getncattr ( '<STR_LIT>' ) ) <EOL> else : <EOL> SNattributeValue = '<STR_LIT>' <EOL> if '<STR_LIT>' in dim_var . ncattrs ( ) : <EOL> UNattributeValue = str ( dim_var . getncattr ( '<STR_LIT>' ) ) <EOL> else : <EOL> UNattributeValue = '<STR_LIT>' <EOL> if '<STR_LIT>' in dim_var . ncattrs ( ) : <EOL> AXattributeValue = str ( dim_var . getncattr ( '<STR_LIT>' ) ) <EOL> else : <EOL> AXattributeValue = '<STR_LIT>' <EOL> if SNattributeValue in XCoordNamesList : <EOL> x_variable = dim_name <EOL> if SNattributeValue in YCoordNamesList : <EOL> y_variable = dim_name <EOL> if UNattributeValue in XUnitNamesList : <EOL> x_variable = dim_name <EOL> if UNattributeValue in YUnitNamesList : <EOL> y_variable = dim_name <EOL> if AXattributeValue in XAxisNameList : <EOL> x_variable = dim_name <EOL> if AXattributeValue in YAxisNameList : <EOL> y_variable = dim_name <EOL> if ( not x_variable ) or ( not y_variable ) : <EOL> return ( None , None , None ) <EOL> stat_variable = dataset . variable_dimension_names ( x_variable ) <EOL> if len ( stat_variable ) > <NUM_LIT:0> : <EOL> stat_variable = stat_variable [ - <NUM_LIT:1> ] <EOL> else : <EOL> stat_variable = None <EOL> return ( stat_variable , x_variable , y_variable ) </s>
