idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
31,400 | def is_timeseries_profile_single_station ( nc , variable ) : dims = nc . variables [ variable ] . dimensions cmatrix = coordinate_dimension_matrix ( nc ) for req in ( 'x' , 'y' , 'z' , 't' ) : if req not in cmatrix : return False if len ( cmatrix [ 'x' ] ) != 0 : return False if cmatrix [ 'x' ] != cmatrix [ 'y' ] : ret... | Returns true if the variable is a time - series profile that represents a single station and each profile is the same length . |
31,401 | def is_timeseries_profile_ortho_depth ( nc , variable ) : dims = nc . variables [ variable ] . dimensions cmatrix = coordinate_dimension_matrix ( nc ) for req in ( 'x' , 'y' , 'z' , 't' ) : if req not in cmatrix : return False if len ( cmatrix [ 'x' ] ) != 1 : return False if cmatrix [ 'x' ] != cmatrix [ 'y' ] : return... | Returns true if the variable is a time - series profile with orthogonal depth only . |
31,402 | def is_trajectory_profile_orthogonal ( nc , variable ) : dims = nc . variables [ variable ] . dimensions cmatrix = coordinate_dimension_matrix ( nc ) for req in ( 'x' , 'y' , 'z' , 't' ) : if req not in cmatrix : return False if len ( cmatrix [ 'x' ] ) != 2 : return False if cmatrix [ 'x' ] != cmatrix [ 'y' ] : return ... | Returns true if the variable is a trajectory profile with orthogonal depths . |
31,403 | def is_mapped_grid ( nc , variable ) : dims = nc . variables [ variable ] . dimensions variable_coordinates = getattr ( nc . variables [ variable ] , 'coordinates' , '' ) . split ( ) lons = get_longitude_variables ( nc ) for lon in lons : if lon in variable_coordinates : break else : lon = get_lon_variable ( nc ) if lo... | Returns true if the feature - type of variable corresponds to a mapped grid type . Characterized by Appedix F of CF - 1 . 6 |
31,404 | def is_reduced_grid ( nc , variable ) : axis_map = get_axis_map ( nc , variable ) if 'X' not in axis_map : return False if 'Y' not in axis_map : return False if 'C' not in axis_map : return False compressed_coordinates = axis_map [ 'C' ] if len ( compressed_coordinates ) > 1 : return False compressed_coordinate = axis_... | Returns True if the feature - type of the variable corresponds to a reduced horizontal grid . |
31,405 | def guess_feature_type ( nc , variable ) : if is_point ( nc , variable ) : return 'point' if is_timeseries ( nc , variable ) : return 'timeseries' if is_multi_timeseries_orthogonal ( nc , variable ) : return 'multi-timeseries-orthogonal' if is_multi_timeseries_incomplete ( nc , variable ) : return 'multi-timeseries-inc... | Returns a string describing the feature type for this variable |
31,406 | def units_convertible ( units1 , units2 , reftimeistime = True ) : try : u1 = Unit ( units1 ) u2 = Unit ( units2 ) except ValueError : return False return u1 . is_convertible ( u2 ) | Return True if a Unit representing the string units1 can be converted to a Unit representing the string units2 else False . |
31,407 | def setup ( self , ds ) : self . _find_coord_vars ( ds ) self . _find_aux_coord_vars ( ds ) self . _find_ancillary_vars ( ds ) self . _find_clim_vars ( ds ) self . _find_boundary_vars ( ds ) self . _find_metadata_vars ( ds ) self . _find_cf_standard_name_table ( ds ) self . _find_geophysical_vars ( ds ) | Initialize various special variable types within the class . Mutates a number of instance variables . |
31,408 | def _find_cf_standard_name_table ( self , ds ) : standard_name_vocabulary = getattr ( ds , 'standard_name_vocabulary' , '' ) version = None try : if 'cf standard name table' in standard_name_vocabulary . lower ( ) : version = [ s . strip ( '(' ) . strip ( ')' ) . strip ( 'v' ) . strip ( ',' ) for s in standard_name_voc... | Parse out the standard_name_vocabulary attribute and download that version of the cf standard name table . If the standard name table has already been downloaded use the cached version . Modifies _std_names attribute to store standard names . Returns True if the file exists and False if it fails to download . |
31,409 | def _find_ancillary_vars ( self , ds , refresh = False ) : if self . _ancillary_vars . get ( ds , None ) and refresh is False : return self . _ancillary_vars [ ds ] self . _ancillary_vars [ ds ] = [ ] for name , var in ds . variables . items ( ) : if hasattr ( var , 'ancillary_variables' ) : for anc_name in var . ancil... | Returns a list of variable names that are defined as ancillary variables in the dataset ds . |
31,410 | def _find_metadata_vars ( self , ds , refresh = False ) : if self . _metadata_vars . get ( ds , None ) and refresh is False : return self . _metadata_vars [ ds ] self . _metadata_vars [ ds ] = [ ] for name , var in ds . variables . items ( ) : if name in self . _find_ancillary_vars ( ds ) or name in self . _find_coord_... | Returns a list of netCDF variable instances for those that are likely metadata variables |
31,411 | def _find_geophysical_vars ( self , ds , refresh = False ) : if self . _geophysical_vars . get ( ds , None ) and refresh is False : return self . _geophysical_vars [ ds ] self . _geophysical_vars [ ds ] = cfutil . get_geophysical_variables ( ds ) return self . _geophysical_vars [ ds ] | Returns a list of geophysical variables . Modifies self . _geophysical_vars |
31,412 | def _find_boundary_vars ( self , ds , refresh = False ) : if self . _boundary_vars . get ( ds , None ) and refresh is False : return self . _boundary_vars [ ds ] self . _boundary_vars [ ds ] = cfutil . get_cell_boundary_variables ( ds ) return self . _boundary_vars [ ds ] | Returns dictionary of boundary variables mapping the variable instance to the name of the variable acting as a boundary variable . |
31,413 | def check_data_types ( self , ds ) : fails = [ ] total = len ( ds . variables ) for k , v in ds . variables . items ( ) : if ( v . dtype . kind != 'S' and all ( v . dtype . type != t for t in ( np . character , np . dtype ( '|S1' ) , np . dtype ( 'b' ) , np . dtype ( 'i2' ) , np . dtype ( 'i4' ) , np . float32 , np . d... | Checks the data type of all netCDF variables to ensure they are valid data types under CF . |
31,414 | def check_naming_conventions ( self , ds ) : ret_val = [ ] variable_naming = TestCtx ( BaseCheck . MEDIUM , self . section_titles [ '2.3' ] ) dimension_naming = TestCtx ( BaseCheck . MEDIUM , self . section_titles [ '2.3' ] ) attribute_naming = TestCtx ( BaseCheck . MEDIUM , self . section_titles [ '2.3' ] ) ignore_att... | Checks the variable names to ensure they are valid CF variable names under CF . |
31,415 | def check_names_unique ( self , ds ) : fails = [ ] total = len ( ds . variables ) names = defaultdict ( int ) for k in ds . variables : names [ k . lower ( ) ] += 1 fails = [ 'Variables are not case sensitive. Duplicate variables named: %s' % k for k , v in names . items ( ) if v > 1 ] return Result ( BaseCheck . MEDIU... | Checks the variable names for uniqueness regardless of case . |
31,416 | def check_dimension_names ( self , ds ) : fails = [ ] total = len ( ds . variables ) for k , v in ds . variables . items ( ) : dims = defaultdict ( int ) for d in v . dimensions : dims [ d ] += 1 for dimension , count in dims . items ( ) : if count > 1 : fails . append ( "%s has two or more dimensions named %s" % ( k ,... | Checks variables contain no duplicate dimension names . |
31,417 | def _get_coord_axis_map ( self , ds ) : expected = [ 'T' , 'Z' , 'Y' , 'X' ] coord_vars = self . _find_coord_vars ( ds ) coord_axis_map = { } time_variables = cfutil . get_time_variables ( ds ) lat_variables = cfutil . get_latitude_variables ( ds ) lon_variables = cfutil . get_longitude_variables ( ds ) z_variables = c... | Returns a dictionary mapping each coordinate to a letter identifier describing the _kind_ of coordinate . |
31,418 | def _get_instance_dimensions ( self , ds ) : ret_val = [ ] for variable in ds . get_variables_by_attributes ( cf_role = lambda x : isinstance ( x , basestring ) ) : if variable . ndim > 0 : ret_val . append ( variable . dimensions [ 0 ] ) return ret_val | Returns a list of dimensions marked as instance dimensions |
31,419 | def _get_pretty_dimension_order ( self , ds , name ) : dim_names = [ ] for dim in ds . variables [ name ] . dimensions : dim_name = dim if ds . dimensions [ dim ] . isunlimited ( ) : dim_name += ' (Unlimited)' dim_names . append ( dim_name ) return ', ' . join ( dim_names ) | Returns a comma seperated string of the dimensions for a specified variable |
31,420 | def _get_dimension_order ( self , ds , name , coord_axis_map ) : retval = [ ] variable = ds . variables [ name ] for dim in variable . dimensions : retval . append ( coord_axis_map [ dim ] ) return retval | Returns a list of strings corresponding to the named axis of the dimensions for a variable . |
31,421 | def check_convention_globals ( self , ds ) : attrs = [ 'title' , 'history' ] valid_globals = TestCtx ( BaseCheck . MEDIUM , self . section_titles [ '2.6' ] ) for attr in attrs : dataset_attr = getattr ( ds , attr , None ) is_string = isinstance ( dataset_attr , basestring ) valid_globals . assert_true ( is_string and l... | Check the common global attributes are strings if they exist . |
31,422 | def _split_standard_name ( self , standard_name ) : if isinstance ( standard_name , basestring ) and ' ' in standard_name : return standard_name . split ( ' ' , 1 ) else : return standard_name , None | Returns a tuple of the standard_name and standard_name modifier |
31,423 | def _check_valid_cf_units ( self , ds , variable_name ) : deprecated = [ 'level' , 'layer' , 'sigma_level' ] variable = ds . variables [ variable_name ] units = getattr ( variable , 'units' , None ) standard_name_full = getattr ( variable , 'standard_name' , None ) standard_name , standard_name_modifier = self . _split... | Checks that the variable contains units attribute the attribute is a string and the value is not deprecated by CF |
31,424 | def _check_valid_udunits ( self , ds , variable_name ) : variable = ds . variables [ variable_name ] units = getattr ( variable , 'units' , None ) standard_name = getattr ( variable , 'standard_name' , None ) standard_name , standard_name_modifier = self . _split_standard_name ( standard_name ) std_name_units_dimension... | Checks that the variable s units are contained in UDUnits |
31,425 | def _check_valid_standard_units ( self , ds , variable_name ) : variable = ds . variables [ variable_name ] units = getattr ( variable , 'units' , None ) standard_name = getattr ( variable , 'standard_name' , None ) valid_standard_units = TestCtx ( BaseCheck . HIGH , self . section_titles [ "3.1" ] ) std_name_units_dim... | Checks that the variable s units are appropriate for the standard name according to the CF standard name table and coordinate sections in CF 1 . 6 |
31,426 | def check_standard_name ( self , ds ) : ret_val = [ ] coord_vars = self . _find_coord_vars ( ds ) aux_coord_vars = self . _find_aux_coord_vars ( ds ) axis_vars = cfutil . get_axis_variables ( ds ) flag_vars = cfutil . get_flag_variables ( ds ) geophysical_vars = self . _find_geophysical_vars ( ds ) variables_requiring_... | Check a variables s standard_name attribute to ensure that it meets CF compliance . |
31,427 | def check_ancillary_variables ( self , ds ) : ret_val = [ ] for ncvar in ds . get_variables_by_attributes ( ancillary_variables = lambda x : x is not None ) : name = ncvar . name valid_ancillary = TestCtx ( BaseCheck . HIGH , self . section_titles [ "3.4" ] ) ancillary_variables = ncvar . ancillary_variables valid_anci... | Checks the ancillary_variable attribute for all variables to ensure they are CF compliant . |
31,428 | def check_flags ( self , ds ) : ret_val = [ ] for name in cfutil . get_flag_variables ( ds ) : variable = ds . variables [ name ] flag_values = getattr ( variable , "flag_values" , None ) flag_masks = getattr ( variable , "flag_masks" , None ) valid_flags_var = TestCtx ( BaseCheck . HIGH , self . section_titles [ '3.5'... | Check the flag_values flag_masks and flag_meanings attributes for variables to ensure they are CF compliant . |
31,429 | def _check_flag_values ( self , ds , name ) : variable = ds . variables [ name ] flag_values = variable . flag_values flag_meanings = getattr ( variable , 'flag_meanings' , None ) valid_values = TestCtx ( BaseCheck . HIGH , self . section_titles [ '3.5' ] ) valid_values . assert_true ( isinstance ( flag_values , np . n... | Checks a variable s flag_values attribute for compliance under CF |
31,430 | def _check_flag_masks ( self , ds , name ) : variable = ds . variables [ name ] flag_masks = variable . flag_masks flag_meanings = getattr ( ds , 'flag_meanings' , None ) valid_masks = TestCtx ( BaseCheck . HIGH , self . section_titles [ '3.5' ] ) valid_masks . assert_true ( isinstance ( flag_masks , np . ndarray ) , "... | Check a variable s flag_masks attribute for compliance under CF |
31,431 | def _check_flag_meanings ( self , ds , name ) : variable = ds . variables [ name ] flag_meanings = getattr ( variable , 'flag_meanings' , None ) valid_meanings = TestCtx ( BaseCheck . HIGH , self . section_titles [ '3.5' ] ) valid_meanings . assert_true ( flag_meanings is not None , "{}'s flag_meanings attribute is req... | Check a variable s flag_meanings attribute for compliance under CF |
31,432 | def check_coordinate_types ( self , ds ) : ret_val = [ ] for variable in ds . get_variables_by_attributes ( axis = lambda x : x is not None ) : name = variable . name if cfutil . is_compression_coordinate ( ds , name ) : continue variable = ds . variables [ name ] if hasattr ( variable , 'cf_role' ) : continue if varia... | Check the axis attribute of coordinate variables |
31,433 | def _check_axis ( self , ds , name ) : allowed_axis = [ 'T' , 'X' , 'Y' , 'Z' ] variable = ds . variables [ name ] axis = variable . axis valid_axis = TestCtx ( BaseCheck . HIGH , self . section_titles [ '4' ] ) axis_is_string = isinstance ( axis , basestring ) , valid_axis . assert_true ( axis_is_string and len ( axis... | Checks that the axis attribute is a string and an allowed value namely one of T X Y or Z . |
31,434 | def check_dimensional_vertical_coordinate ( self , ds ) : ret_val = [ ] z_variables = cfutil . get_z_variables ( ds ) for name in z_variables : variable = ds . variables [ name ] standard_name = getattr ( variable , 'standard_name' , None ) units = getattr ( variable , 'units' , None ) positive = getattr ( variable , '... | Check units for variables defining vertical position are valid under CF . |
31,435 | def check_dimensionless_vertical_coordinate ( self , ds ) : ret_val = [ ] z_variables = cfutil . get_z_variables ( ds ) deprecated_units = [ 'level' , 'layer' , 'sigma_level' ] for name in z_variables : variable = ds . variables [ name ] standard_name = getattr ( variable , 'standard_name' , None ) units = getattr ( va... | Check the validity of dimensionless coordinates under CF |
31,436 | def _check_formula_terms ( self , ds , coord ) : variable = ds . variables [ coord ] standard_name = getattr ( variable , 'standard_name' , None ) formula_terms = getattr ( variable , 'formula_terms' , None ) valid_formula_terms = TestCtx ( BaseCheck . HIGH , self . section_titles [ '4.3' ] ) valid_formula_terms . asse... | Checks a dimensionless vertical coordinate contains valid formula_terms |
31,437 | def check_time_coordinate ( self , ds ) : ret_val = [ ] for name in cfutil . get_time_variables ( ds ) : variable = ds . variables [ name ] has_units = hasattr ( variable , 'units' ) if not has_units : result = Result ( BaseCheck . HIGH , False , self . section_titles [ '4.4' ] , [ '%s does not have units' % name ] ) r... | Check variables defining time are valid under CF |
31,438 | def check_aux_coordinates ( self , ds ) : ret_val = [ ] geophysical_variables = self . _find_geophysical_vars ( ds ) for name in geophysical_variables : variable = ds . variables [ name ] coordinates = getattr ( variable , 'coordinates' , None ) dim_set = set ( variable . dimensions ) if not isinstance ( coordinates , ... | Chapter 5 paragraph 3 |
31,439 | def check_duplicate_axis ( self , ds ) : ret_val = [ ] geophysical_variables = self . _find_geophysical_vars ( ds ) for name in geophysical_variables : no_duplicates = TestCtx ( BaseCheck . HIGH , self . section_titles [ '5' ] ) axis_map = cfutil . get_axis_map ( ds , name ) axes = [ ] for axis , coordinates in axis_ma... | Checks that no variable contains two coordinates defining the same axis . |
31,440 | def check_multi_dimensional_coords ( self , ds ) : ret_val = [ ] for coord in self . _find_aux_coord_vars ( ds ) : variable = ds . variables [ coord ] if variable . ndim < 2 : continue not_matching = TestCtx ( BaseCheck . MEDIUM , self . section_titles [ '5' ] ) not_matching . assert_true ( coord not in variable . dime... | Checks that no multidimensional coordinate shares a name with its dimensions . |
31,441 | def check_grid_coordinates ( self , ds ) : ret_val = [ ] latitudes = cfutil . get_true_latitude_variables ( ds ) longitudes = cfutil . get_true_longitude_variables ( ds ) check_featues = [ '2d-regular-grid' , '2d-static-grid' , '3d-regular-grid' , '3d-static-grid' , 'mapped-grid' , 'reduced-grid' ] for variable in self... | 5 . 6 When the coordinate variables for a horizontal grid are not longitude and latitude it is required that the true latitude and longitude coordinates be supplied via the coordinates attribute . |
31,442 | def check_reduced_horizontal_grid ( self , ds ) : ret_val = [ ] lats = set ( cfutil . get_latitude_variables ( ds ) ) lons = set ( cfutil . get_longitude_variables ( ds ) ) for name in self . _find_geophysical_vars ( ds ) : coords = getattr ( ds . variables [ name ] , 'coordinates' , None ) axis_map = cfutil . get_axis... | 5 . 3 A reduced longitude - latitude grid is one in which the points are arranged along constant latitude lines with the number of points on a latitude line decreasing toward the poles . |
31,443 | def check_grid_mapping ( self , ds ) : ret_val = [ ] grid_mapping_variables = cfutil . get_grid_mapping_variables ( ds ) for variable in ds . get_variables_by_attributes ( grid_mapping = lambda x : x is not None ) : grid_mapping = getattr ( variable , 'grid_mapping' , None ) defines_grid_mapping = TestCtx ( BaseCheck .... | 5 . 6 When the coordinate variables for a horizontal grid are not longitude and latitude it is required that the true latitude and longitude coordinates be supplied via the coordinates attribute . If in addition it is desired to describe the mapping between the given coordinate variables and the true latitude and longi... |
31,444 | def check_geographic_region ( self , ds ) : ret_val = [ ] region_list = [ 'africa' , 'antarctica' , 'arabian_sea' , 'aral_sea' , 'arctic_ocean' , 'asia' , 'atlantic_ocean' , 'australia' , 'baltic_sea' , 'barents_opening' , 'barents_sea' , 'beaufort_sea' , 'bellingshausen_sea' , 'bering_sea' , 'bering_strait' , 'black_s... | 6 . 1 . 1 When data is representative of geographic regions which can be identified by names but which have complex boundaries that cannot practically be specified using longitude and latitude boundary coordinates a labeled axis should be used to identify the regions . |
31,445 | def check_cell_boundaries ( self , ds ) : ret_val = [ ] reasoning = [ ] for variable_name , boundary_variable_name in cfutil . get_cell_boundary_map ( ds ) . items ( ) : variable = ds . variables [ variable_name ] valid = True reasoning = [ ] if boundary_variable_name not in ds . variables : valid = False reasoning . a... | Checks the dimensions of cell boundary variables to ensure they are CF compliant . |
31,446 | def check_packed_data ( self , ds ) : ret_val = [ ] for name , var in ds . variables . items ( ) : add_offset = getattr ( var , 'add_offset' , None ) scale_factor = getattr ( var , 'scale_factor' , None ) if not ( add_offset or scale_factor ) : continue valid = True reasoning = [ ] if not add_offset : add_offset = scal... | 8 . 1 Simple packing may be achieved through the use of the optional NUG defined attributes scale_factor and add_offset . After the data values of a variable have been read they are to be multiplied by the scale_factor and have add_offset added to them . |
31,447 | def check_compression_gathering ( self , ds ) : ret_val = [ ] for compress_var in ds . get_variables_by_attributes ( compress = lambda s : s is not None ) : valid = True reasoning = [ ] compress_set = set ( compress_var . compress . split ( ' ' ) ) if compress_var . ndim != 1 : valid = False reasoning . append ( "Compr... | At the current time the netCDF interface does not provide for packing data . However a simple packing may be achieved through the use of the optional NUG defined attributes scale_factor and add_offset . After the data values of a variable have been read they are to be multiplied by the scale_factor and have add_offset ... |
31,448 | def check_all_features_are_same_type ( self , ds ) : all_the_same = TestCtx ( BaseCheck . HIGH , self . section_titles [ '9.1' ] ) feature_types_found = defaultdict ( list ) for name in self . _find_geophysical_vars ( ds ) : feature = cfutil . guess_feature_type ( ds , name ) if feature is not None : feature_types_foun... | Check that the feature types in a dataset are all the same . |
31,449 | def check_cf_role ( self , ds ) : valid_roles = [ 'timeseries_id' , 'profile_id' , 'trajectory_id' ] variable_count = 0 for variable in ds . get_variables_by_attributes ( cf_role = lambda x : x is not None ) : variable_count += 1 name = variable . name valid_cf_role = TestCtx ( BaseCheck . HIGH , self . section_titles ... | Check variables defining cf_role for legal cf_role values . |
31,450 | def check_variable_features ( self , ds ) : ret_val = [ ] feature_list = [ 'point' , 'timeSeries' , 'trajectory' , 'profile' , 'timeSeriesProfile' , 'trajectoryProfile' ] feature_type = getattr ( ds , 'featureType' , None ) if feature_type not in feature_list : return [ ] feature_type_map = { 'point' : [ 'point' ] , 't... | Checks the variable feature types match the dataset featureType attribute |
31,451 | def check_hints ( self , ds ) : ret_val = [ ] ret_val . extend ( self . _check_hint_bounds ( ds ) ) return ret_val | Checks for potentially mislabeled metadata and makes suggestions for how to correct |
31,452 | def _check_hint_bounds ( self , ds ) : ret_val = [ ] boundary_variables = cfutil . get_cell_boundary_variables ( ds ) for name in ds . variables : if name . endswith ( '_bounds' ) and name not in boundary_variables : msg = ( '{} might be a cell boundary variable but there are no variables that define it ' 'as a boundar... | Checks for variables ending with _bounds if they are not cell methods make the recommendation |
31,453 | def is_netcdf ( url ) : if url . startswith ( 'http' ) : return False if url . endswith ( 'nc' ) : return True with open ( url , 'rb' ) as f : magic_number = f . read ( 4 ) if len ( magic_number ) < 4 : return False if is_classic_netcdf ( magic_number ) : return True elif is_hdf5 ( magic_number ) : return True return F... | Returns True if the URL points to a valid local netCDF file |
31,454 | def get_safe ( dict_instance , keypath , default = None ) : try : obj = dict_instance keylist = keypath if type ( keypath ) is list else keypath . split ( '.' ) for key in keylist : obj = obj [ key ] return obj except Exception : return default | Returns a value with in a nested dict structure from a dot separated path expression such as system . server . host or a list of key entries |
31,455 | def download_cf_standard_name_table ( version , location = None ) : if location is None : location = resource_filename ( 'compliance_checker' , 'data/cf-standard-name-table.xml' ) url = "http://cfconventions.org/Data/cf-standard-names/{0}/src/cf-standard-name-table.xml" . format ( version ) r = requests . get ( url , a... | Downloads the specified CF standard name table version and saves it to file |
31,456 | def find_coord_vars ( ncds ) : coord_vars = [ ] for d in ncds . dimensions : if d in ncds . variables and ncds . variables [ d ] . dimensions == ( d , ) : coord_vars . append ( ncds . variables [ d ] ) return coord_vars | Finds all coordinate variables in a dataset . |
31,457 | def is_time_variable ( varname , var ) : satisfied = varname . lower ( ) == 'time' satisfied |= getattr ( var , 'standard_name' , '' ) == 'time' satisfied |= getattr ( var , 'axis' , '' ) == 'T' satisfied |= units_convertible ( 'seconds since 1900-01-01' , getattr ( var , 'units' , '' ) ) return satisfied | Identifies if a variable is represents time |
31,458 | def is_vertical_coordinate ( var_name , var ) : satisfied = var_name . lower ( ) in _possiblez satisfied |= getattr ( var , 'standard_name' , '' ) in _possiblez satisfied |= getattr ( var , 'axis' , '' ) . lower ( ) == 'z' is_pressure = units_convertible ( getattr ( var , 'units' , '1' ) , 'dbar' ) satisfied |= is_pres... | Determines if a variable is a vertical coordinate variable |
31,459 | def get_applicable_variables ( self , ds ) : if self . _applicable_variables is None : self . applicable_variables = cfutil . get_geophysical_variables ( ds ) varname = cfutil . get_time_variable ( ds ) if varname and ( varname not in self . applicable_variables ) : self . applicable_variables . append ( varname ) varn... | Returns a list of variable names that are applicable to ACDD Metadata Checks for variables . This includes geophysical and coordinate variables only . |
31,460 | def check_var_long_name ( self , ds ) : results = [ ] for variable in self . get_applicable_variables ( ds ) : msgs = [ ] long_name = getattr ( ds . variables [ variable ] , 'long_name' , None ) check = long_name is not None if not check : msgs . append ( "long_name" ) results . append ( Result ( BaseCheck . HIGH , che... | Checks each applicable variable for the long_name attribute |
31,461 | def check_var_standard_name ( self , ds ) : results = [ ] for variable in self . get_applicable_variables ( ds ) : msgs = [ ] std_name = getattr ( ds . variables [ variable ] , 'standard_name' , None ) check = std_name is not None if not check : msgs . append ( "standard_name" ) results . append ( Result ( BaseCheck . ... | Checks each applicable variable for the standard_name attribute |
31,462 | def check_var_units ( self , ds ) : results = [ ] for variable in self . get_applicable_variables ( ds ) : msgs = [ ] unit_check = hasattr ( ds . variables [ variable ] , 'units' ) no_dim_check = ( getattr ( ds . variables [ variable ] , 'dimensions' ) == tuple ( ) ) if no_dim_check : continue if not unit_check : msgs ... | Checks each applicable variable for the units attribute |
31,463 | def verify_geospatial_bounds ( self , ds ) : var = getattr ( ds , 'geospatial_bounds' , None ) check = var is not None if not check : return ratable_result ( False , "Global Attributes" , [ "geospatial_bounds not present" ] ) try : from_wkt ( ds . geospatial_bounds ) except AttributeError : return ratable_result ( Fals... | Checks that the geospatial bounds is well formed OGC WKT |
31,464 | def _check_total_z_extents ( self , ds , z_variable ) : msgs = [ ] total = 2 try : vert_min = float ( ds . geospatial_vertical_min ) except ValueError : msgs . append ( 'geospatial_vertical_min cannot be cast to float' ) try : vert_max = float ( ds . geospatial_vertical_max ) except ValueError : msgs . append ( 'geospa... | Check the entire array of Z for minimum and maximum and compare that to the vertical extents defined in the global attributes |
31,465 | def _check_scalar_vertical_extents ( self , ds , z_variable ) : vert_min = ds . geospatial_vertical_min vert_max = ds . geospatial_vertical_max msgs = [ ] total = 2 zvalue = ds . variables [ z_variable ] [ : ] . item ( ) if not np . isclose ( vert_min , vert_max ) : msgs . append ( "geospatial_vertical_min != geospatia... | Check the scalar value of Z compared to the vertical extents which should also be equivalent |
31,466 | def verify_convention_version ( self , ds ) : try : for convention in getattr ( ds , "Conventions" , '' ) . replace ( ' ' , '' ) . split ( ',' ) : if convention == 'ACDD-' + self . _cc_spec_version : return ratable_result ( ( 2 , 2 ) , None , [ ] ) m = [ "Conventions does not contain 'ACDD-{}'" . format ( self . _cc_sp... | Verify that the version in the Conventions field is correct |
31,467 | def check_metadata_link ( self , ds ) : if not hasattr ( ds , u'metadata_link' ) : return msgs = [ ] meta_link = getattr ( ds , 'metadata_link' ) if 'http' not in meta_link : msgs . append ( 'Metadata URL should include http:// or https://' ) valid_link = ( len ( msgs ) == 0 ) return Result ( BaseCheck . LOW , valid_li... | Checks if metadata link is formed in a rational manner |
31,468 | def check_id_has_no_blanks ( self , ds ) : if not hasattr ( ds , u'id' ) : return if ' ' in getattr ( ds , u'id' ) : return Result ( BaseCheck . MEDIUM , False , 'no_blanks_in_id' , msgs = [ u'There should be no blanks in the id field' ] ) else : return Result ( BaseCheck . MEDIUM , True , 'no_blanks_in_id' , msgs = [ ... | Check if there are blanks in the id field |
31,469 | def check_var_coverage_content_type ( self , ds ) : results = [ ] for variable in cfutil . get_geophysical_variables ( ds ) : msgs = [ ] ctype = getattr ( ds . variables [ variable ] , 'coverage_content_type' , None ) check = ctype is not None if not check : msgs . append ( "coverage_content_type" ) results . append ( ... | Check coverage content type against valid ISO - 19115 - 1 codes |
31,470 | def no_missing_terms ( formula_name , term_set ) : reqd_terms = dimless_vertical_coordinates [ formula_name ] def has_all_terms ( reqd_termset ) : return len ( reqd_termset ^ term_set ) == 0 if isinstance ( reqd_terms , set ) : return has_all_terms ( reqd_terms ) else : return any ( has_all_terms ( req ) for req in req... | Returns true if the set is not missing terms corresponding to the entries in Appendix D False otherwise . The set of terms should be exactly equal and not contain more or less terms than expected . |
31,471 | def attr_check ( kvp , ds , priority , ret_val , gname = None ) : msgs = [ ] name , other = kvp if other is None : res = std_check ( ds , name ) if not res : msgs = [ "%s not present" % name ] else : try : att_strip = getattr ( ds , name ) . strip ( ) if not att_strip : res = False msgs = [ "%s is empty or completely w... | Handles attribute checks for simple presence of an attribute presence of one of several attributes and passing a validation function . Returns a status along with an error message in the event of a failure . Mutates ret_val parameter |
31,472 | def fix_return_value ( v , method_name , method = None , checker = None ) : method_name = ( method_name or method . __func__ . __name__ ) . replace ( "check_" , "" ) if v is None or not isinstance ( v , Result ) : v = Result ( value = v , name = method_name ) v . name = v . name or method_name v . checker = checker v .... | Transforms scalar return values into Result . |
31,473 | def ratable_result ( value , name , msgs ) : return lambda w : Result ( w , value , name , msgs ) | Returns a partial function with a Result that has not been weighted . |
31,474 | def score_group ( group_name = None ) : warnings . warn ( 'Score_group is deprecated as of Compliance Checker v3.2.' ) def _inner ( func ) : def _dec ( s , ds ) : ret_val = func ( s , ds ) if not isinstance ( ret_val , list ) : ret_val = [ ret_val ] def dogroup ( r ) : cur_grouping = r . name if isinstance ( cur_groupi... | Warning this is deprecated as of Compliance Checker v3 . 2! |
31,475 | def serialize ( self ) : return { 'name' : self . name , 'weight' : self . weight , 'value' : self . value , 'msgs' : self . msgs , 'children' : [ i . serialize ( ) for i in self . children ] } | Returns a serializable dictionary that represents the result object |
31,476 | def _get_generator_plugins ( cls ) : if not hasattr ( cls , 'suite_generators' ) : gens = working_set . iter_entry_points ( 'compliance_checker.generators' ) cls . suite_generators = [ x . resolve ( ) for x in gens ] return cls . suite_generators | Return a list of classes from external plugins that are used to generate checker classes |
31,477 | def load_generated_checkers ( cls , args ) : for gen in cls . _get_generator_plugins ( ) : checkers = gen . get_checkers ( args ) cls . checkers . update ( checkers ) | Load checker classes from generator plugins |
31,478 | def load_all_available_checkers ( cls ) : for x in working_set . iter_entry_points ( 'compliance_checker.suites' ) : try : xl = x . resolve ( ) cls . checkers [ ':' . join ( ( xl . _cc_spec , xl . _cc_spec_version ) ) ] = xl except AttributeError : cls . checkers [ getattr ( xl , 'name' , None ) or xl . _cc_spec ] = xl... | Helper method to retrieve all sub checker classes derived from various base classes . |
31,479 | def _get_checks ( self , checkclass , skip_checks ) : meths = inspect . getmembers ( checkclass , inspect . ismethod ) returned_checks = [ ] for fn_name , fn_obj in meths : if ( fn_name . startswith ( "check_" ) and skip_checks [ fn_name ] != BaseCheck . HIGH ) : returned_checks . append ( ( fn_obj , skip_checks [ fn_n... | Helper method to retreive check methods from a Checker class . Excludes any checks in skip_checks . |
31,480 | def _run_check ( self , check_method , ds , max_level ) : val = check_method ( ds ) if isinstance ( val , list ) : check_val = [ ] for v in val : res = fix_return_value ( v , check_method . __func__ . __name__ , check_method , check_method . __self__ ) if max_level is None or res . weight > max_level : check_val . appe... | Runs a check and appends a result to the values list . |
31,481 | def _get_check_versioned_name ( self , check_name ) : if ':' not in check_name or ':latest' in check_name : check_name = ':' . join ( ( check_name . split ( ':' ) [ 0 ] , self . checkers [ check_name ] . _cc_spec_version ) ) return check_name | The compliance checker allows the user to specify a check without a version number but we want the report to specify the version number . |
31,482 | def run ( self , ds , skip_checks , * checker_names ) : ret_val = { } checkers = self . _get_valid_checkers ( ds , checker_names ) if skip_checks is not None : skip_check_dict = CheckSuite . _process_skip_checks ( skip_checks ) else : skip_check_dict = defaultdict ( lambda : None ) if len ( checkers ) == 0 : print ( "N... | Runs this CheckSuite on the dataset with all the passed Checker instances . |
31,483 | def dict_output ( self , check_name , groups , source_name , limit ) : aggregates = self . build_structure ( check_name , groups , source_name , limit ) return self . serialize ( aggregates ) | Builds the results into a JSON structure and writes it to the file buffer . |
31,484 | def serialize ( self , o ) : if isinstance ( o , ( list , tuple ) ) : return [ self . serialize ( i ) for i in o ] if isinstance ( o , dict ) : return { k : self . serialize ( v ) for k , v in o . items ( ) } if isinstance ( o , datetime ) : return o . isoformat ( ) if isinstance ( o , Result ) : return self . serializ... | Returns a safe serializable object that can be serialized into JSON . |
31,485 | def checker_html_output ( self , check_name , groups , source_name , limit ) : from jinja2 import Environment , PackageLoader self . j2 = Environment ( loader = PackageLoader ( self . templates_root , 'data/templates' ) ) template = self . j2 . get_template ( 'ccheck.html.j2' ) template_vars = self . build_structure ( ... | Renders the HTML output for a single test using Jinja2 and returns it as a string . |
31,486 | def html_output ( self , checkers_html ) : template = self . j2 . get_template ( 'ccheck_wrapper.html.j2' ) return template . render ( checkers = checkers_html ) | Renders the HTML output for multiple tests and returns it as a string . |
31,487 | def standard_output ( self , ds , limit , check_name , groups ) : score_list , points , out_of = self . get_points ( groups , limit ) issue_count = out_of - points check_name = self . _get_check_versioned_name ( check_name ) check_url = self . _get_check_url ( check_name ) width = 2 * self . col_width print ( '\n' ) pr... | Generates the Terminal Output for Standard cases |
31,488 | def standard_output_generation ( self , groups , limit , points , out_of , check ) : if points < out_of : self . reasoning_routine ( groups , check , priority_flag = limit ) else : print ( "All tests passed!" ) | Generates the Terminal Output |
31,489 | def reasoning_routine ( self , groups , check , priority_flag = 3 , _top_level = True ) : sort_fn = lambda x : x . weight groups_sorted = sorted ( groups , key = sort_fn , reverse = True ) result = { key : [ v for v in valuesiter if v . value [ 0 ] != v . value [ 1 ] ] for key , valuesiter in itertools . groupby ( grou... | print routine performed |
31,490 | def process_doc ( self , doc ) : xml_doc = ET . fromstring ( doc ) if xml_doc . tag == "{http://www.opengis.net/sos/1.0}Capabilities" : ds = SensorObservationService ( None , xml = doc ) ds . _root = xml_doc elif xml_doc . tag == "{http://www.opengis.net/sensorML/1.0.1}SensorML" : ds = SensorML ( xml_doc ) else : raise... | Attempt to parse an xml string conforming to either an SOS or SensorML dataset and return the results |
31,491 | def generate_dataset ( self , cdl_path ) : if '.cdl' in cdl_path : ds_str = cdl_path . replace ( '.cdl' , '.nc' ) else : ds_str = cdl_path + '.nc' subprocess . call ( [ 'ncgen' , '-o' , ds_str , cdl_path ] ) return ds_str | Use ncgen to generate a netCDF file from a . cdl file Returns the path to the generated netcdf file |
31,492 | def load_dataset ( self , ds_str ) : pr = urlparse ( ds_str ) if pr . netloc : return self . load_remote_dataset ( ds_str ) return self . load_local_dataset ( ds_str ) | Returns an instantiated instance of either a netCDF file or an SOS mapped DS object . |
31,493 | def load_remote_dataset ( self , ds_str ) : if opendap . is_opendap ( ds_str ) : return Dataset ( ds_str ) else : response = requests . get ( ds_str , allow_redirects = True ) if 'text/xml' in response . headers [ 'content-type' ] : return self . process_doc ( response . content ) raise ValueError ( "Unknown service wi... | Returns a dataset instance for the remote resource either OPeNDAP or SOS |
31,494 | def load_local_dataset ( self , ds_str ) : if cdl . is_cdl ( ds_str ) : ds_str = self . generate_dataset ( ds_str ) if netcdf . is_netcdf ( ds_str ) : return MemoizedDataset ( ds_str ) if os . path . isfile ( ds_str ) : return GenericFile ( ds_str ) raise ValueError ( "File is an unknown format" ) | Returns a dataset instance for the local resource |
31,495 | def _group_raw ( self , raw_scores , cur = None , level = 1 ) : def trim_groups ( r ) : if isinstance ( r . name , tuple ) or isinstance ( r . name , list ) : new_name = r . name [ 1 : ] else : new_name = [ ] return Result ( r . weight , r . value , new_name , r . msgs ) terminal = [ len ( x . name ) for x in raw_score... | Internal recursive method to group raw scores into a cascading score summary . Only top level items are tallied for scores . |
31,496 | def get_all_logger_names ( include_root = False ) : rv = list ( logging . Logger . manager . loggerDict . keys ( ) ) if include_root : rv . insert ( 0 , '' ) return rv | Return list of names of all loggers than have been accessed . |
31,497 | def queuify_logger ( logger , queue_handler , queue_listener ) : if isinstance ( logger , str ) : logger = logging . getLogger ( logger ) handlers = [ handler for handler in logger . handlers if handler not in queue_listener . handlers ] if handlers : queue_listener . handlers = tuple ( list ( queue_listener . handlers... | Replace logger s handlers with a queue handler while adding existing handlers to a queue listener . |
31,498 | def _alter_umask ( self ) : if self . umask is None : yield else : prev_umask = os . umask ( self . umask ) try : yield finally : os . umask ( prev_umask ) | Temporarily alter umask to custom setting if applicable |
31,499 | def get_imports ( self , option ) : if option : if len ( option ) == 1 and option [ 0 ] . isupper ( ) and len ( option [ 0 ] ) > 3 : return getattr ( settings , option [ 0 ] ) else : codes = [ e for e in option if e . isupper ( ) and len ( e ) == 3 ] if len ( codes ) != len ( option ) : raise ImproperlyConfigured ( "In... | See if we have been passed a set of currencies or a setting variable or look for settings CURRENCIES or SHOP_CURRENCIES . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.