def __init__(self, table_path): # ------------------------------------------------------------------- # Reset CV error switch # ------------------------------------------------------------------- self.errors = 0 # ------------------------------------------------------------------- # Initialize table path # ------------------------------------------------------------------- self.cmip6_table_path = os.path.normpath(table_path) # ------------------------------------------------------------------- # Initialize attributes dictionaries # ------------------------------------------------------------------- self.dictGbl = dict() self.dictVar = dict() # ------------------------------------------------------------------- # call setup() to clean all 'C' internal memory. # ------------------------------------------------------------------- cmip6_cv.setup(inpath="../Tables", exit_control=cmip6_cv.CMOR_EXIT_ON_WARNING) # ------------------------------------------------------------------- # Set Control Vocabulary file to use (default from cmor.h) # ------------------------------------------------------------------- cmip6_cv.set_cur_dataset_attribute(cmip6_cv.GLOBAL_CV_FILENAME, cmip6_cv.TABLE_CONTROL_FILENAME) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_PATH_TEMPLATE, cmip6_cv.CMOR_DEFAULT_PATH_TEMPLATE) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_NAME_TEMPLATE, cmip6_cv.CMOR_DEFAULT_FILE_TEMPLATE) cmip6_cv.set_cur_dataset_attribute( cmip6_cv.GLOBAL_ATT_FURTHERINFOURLTMPL, cmip6_cv.CMOR_DEFAULT_FURTHERURL_TEMPLATE) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.CMOR_AXIS_ENTRY_FILE, "CMIP6_coordinate.json") cmip6_cv.set_cur_dataset_attribute(cmip6_cv.CMOR_FORMULA_VAR_FILE, "CMIP6_formula_terms.json")
def __init__(self, args): # ------------------------------------------------------------------- # Initilaze arrays # ------------------------------------------------------------------- self.cmip6_table = args.cmip6_table # ------------------------------------------------------------------- # call setup() to clean all 'C' internal memory. # ------------------------------------------------------------------- cmip6_cv.setup(inpath="../Tables", exit_control=cmip6_cv.CMOR_NORMAL) # ------------------------------------------------------------------- # Set Control Vocabulary file to use (default from cmor.h) # ------------------------------------------------------------------- cmip6_cv.set_cur_dataset_attribute(cmip6_cv.GLOBAL_CV_FILENAME, cmip6_cv.TABLE_CONTROL_FILENAME) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_PATH_TEMPLATE, cmip6_cv.CMOR_DEFAULT_PATH_TEMPLATE) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_NAME_TEMPLATE, cmip6_cv.CMOR_DEFAULT_FILE_TEMPLATE) cmip6_cv.set_cur_dataset_attribute( cmip6_cv.GLOBAL_ATT_FURTHERINFOURLTMPL, cmip6_cv.CMOR_DEFAULT_FURTHERURL_TEMPLATE) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.CMOR_AXIS_ENTRY_FILE, "CMIP6_coordinate.json") cmip6_cv.set_cur_dataset_attribute(cmip6_cv.CMOR_FORMULA_VAR_FILE, "CMIP6_formula_terms.json") # ------------------------------------------------------------------- # Load CMIP6 table into memory # ------------------------------------------------------------------- self.table_id = cmip6_cv.load_table(self.cmip6_table)
def __init__(self, args): # ------------------------------------------------------------------- # Initilaze arrays # ------------------------------------------------------------------- self.cmip6_table = args.cmip6_table self.infile = args.infile self.attributes = self.infile.listglobal() self.variables = self.infile.listvariable() # ------------------------------------------------------------------- # find variable that contains a "history" (should only be one) # ------------------------------------------------------------------- self.var = [var for var in self.variables if 'history' in self.infile.listattribute(var)] if((self.var == []) or (len(self.var) > 1)): raise KeyboardInterrupt self.keys = self.infile.listattribute(var) # ------------------------------------------------------------------- # call setup() to clean all 'C' internal memory. # ------------------------------------------------------------------- cmip6_cv.setup(inpath="../Tables", exit_control=cmip6_cv.CMOR_NORMAL) # ------------------------------------------------------------------- # Set Control Vocabulary file to use (default from cmor.h) # ------------------------------------------------------------------- cmip6_cv.set_cur_dataset_attribute(cmip6_cv.GLOBAL_CV_FILENAME, cmip6_cv.TABLE_CONTROL_FILENAME) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_PATH_TEMPLATE, cmip6_cv.CMOR_DEFAULT_PATH_TEMPLATE) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_NAME_TEMPLATE, cmip6_cv.CMOR_DEFAULT_FILE_TEMPLATE) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.GLOBAL_ATT_FURTHERINFOURLTMPL, cmip6_cv.CMOR_DEFAULT_FURTHERURL_TEMPLATE) # ------------------------------------------------------------------- # Create alist of all Global Attributes and set "dataset" # ------------------------------------------------------------------- self.dictGbl = {key: self.infile.getglobal(key) for key in self.attributes} ierr = [cmip6_cv.set_cur_dataset_attribute(key, value) for key, value in self.dictGbl.iteritems()] # ------------------------------------------------------------------- # Create a dictionnary of attributes for var # ------------------------------------------------------------------- self.dictVars = dict((y, x) for y, x in [(key, value) for key in self.keys if self.infile.getattribute(self.var[0], key) is not None for value in [self.infile.getattribute(self.var[0], key)]]) # ------------------------------------------------------------------- # Load CMIP6 table into memory # ------------------------------------------------------------------- self.table_id = cmip6_cv.load_table(self.cmip6_table)
def __init__(self, table_path): # ------------------------------------------------------------------- # Reset CV error switch # ------------------------------------------------------------------- self.errors = 0 # ------------------------------------------------------------------- # Initialize table path # ------------------------------------------------------------------- self.cmip6_table_path = os.path.normpath(table_path) # ------------------------------------------------------------------- # Initialize attributes dictionaries # ------------------------------------------------------------------- self.dictGbl = dict() self.dictVar = dict() # ------------------------------------------------------------------- # call setup() to clean all 'C' internal memory. # ------------------------------------------------------------------- cmip6_cv.setup(inpath="../Tables", exit_control=cmip6_cv.CMOR_EXIT_ON_WARNING) # ------------------------------------------------------------------- # Set Control Vocabulary file to use (default from cmor.h) # ------------------------------------------------------------------- cmip6_cv.set_cur_dataset_attribute( cmip6_cv.GLOBAL_CV_FILENAME, cmip6_cv.TABLE_CONTROL_FILENAME) cmip6_cv.set_cur_dataset_attribute( cmip6_cv.FILE_PATH_TEMPLATE, cmip6_cv.CMOR_DEFAULT_PATH_TEMPLATE) cmip6_cv.set_cur_dataset_attribute( cmip6_cv.FILE_NAME_TEMPLATE, cmip6_cv.CMOR_DEFAULT_FILE_TEMPLATE) cmip6_cv.set_cur_dataset_attribute( cmip6_cv.GLOBAL_ATT_FURTHERINFOURLTMPL, cmip6_cv.CMOR_DEFAULT_FURTHERURL_TEMPLATE) cmip6_cv.set_cur_dataset_attribute( cmip6_cv.CMOR_AXIS_ENTRY_FILE, "CMIP6_coordinate.json") cmip6_cv.set_cur_dataset_attribute( cmip6_cv.CMOR_FORMULA_VAR_FILE, "CMIP6_formula_terms.json")
def __init__(self, args): # ------------------------------------------------------------------- # Initilaze arrays # ------------------------------------------------------------------- self.cmip6_table = args.cmip6_table self.infile = args.infile self.attributes = self.infile.listglobal() self.variables = self.infile.listvariable() if args.variable is not None: self.var = [args.variable] else: # ------------------------------------------------------------------- # find variable that contains a "history" (should only be one) # ------------------------------------------------------------------- self.var = [ var for var in self.variables if 'history' in self.infile.listattribute(var) ] if ((self.var == []) or (len(self.var) > 1)): print bcolors.FAIL print "!!!!!!!!!!!!!!!!!!!!!!!!!" print "! Error: The input file does not have an history attribute and the CMIP6 variable could not be found" print "! Please use the --variable option to specify your CMIP6 variable" print "! Check your file or use CMOR 3.x to achieve compliance for ESGF publication." print "!!!!!!!!!!!!!!!!!!!!!!!!!" print bcolors.ENDC raise KeyboardInterrupt try: self.keys = self.infile.listattribute(self.var[0]) except: print bcolors.FAIL print "!!!!!!!!!!!!!!!!!!!!!!!!!" print "! Error: The variable " + self.var[ 0] + " could not be found" print "! Check your file variables " print "!!!!!!!!!!!!!!!!!!!!!!!!!" print bcolors.ENDC raise # ------------------------------------------------------------------- # call setup() to clean all 'C' internal memory. # ------------------------------------------------------------------- cmip6_cv.setup(inpath="../Tables", exit_control=cmip6_cv.CMOR_NORMAL) # ------------------------------------------------------------------- # Set Control Vocabulary file to use (default from cmor.h) # ------------------------------------------------------------------- cmip6_cv.set_cur_dataset_attribute(cmip6_cv.GLOBAL_CV_FILENAME, cmip6_cv.TABLE_CONTROL_FILENAME) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_PATH_TEMPLATE, cmip6_cv.CMOR_DEFAULT_PATH_TEMPLATE) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_NAME_TEMPLATE, cmip6_cv.CMOR_DEFAULT_FILE_TEMPLATE) cmip6_cv.set_cur_dataset_attribute( cmip6_cv.GLOBAL_ATT_FURTHERINFOURLTMPL, cmip6_cv.CMOR_DEFAULT_FURTHERURL_TEMPLATE) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.CMOR_AXIS_ENTRY_FILE, "CMIP6_coordinate.json") cmip6_cv.set_cur_dataset_attribute(cmip6_cv.CMOR_FORMULA_VAR_FILE, "CMIP6_formula_terms.json") # ------------------------------------------------------------------- # Create alist of all Global Attributes and set "dataset" # ------------------------------------------------------------------- self.dictGbl = { key: self.infile.getglobal(key) for key in self.attributes } ierr = [ cmip6_cv.set_cur_dataset_attribute(key, value) for key, value in self.dictGbl.iteritems() ] # ------------------------------------------------------------------- # Create a dictionnary of attributes for var # ------------------------------------------------------------------- self.dictVars = dict( (y, x) for y, x in [(key, value) for key in self.keys if self.infile.getattribute(self.var[0], key) is not None for value in [self.infile.getattribute(self.var[0], key)]]) # ------------------------------------------------------------------- # Load CMIP6 table into memory # ------------------------------------------------------------------- self.table_id = cmip6_cv.load_table(self.cmip6_table)
def __init__(self, args): # ------------------------------------------------------------------- # Initilaze arrays # ------------------------------------------------------------------- self.cmip6_table = args.cmip6_table self.infile = args.infile self.attributes = self.infile.listglobal() self.variables = self.infile.listvariable() # ------------------------------------------------------------------- # find variable that contains a "cell_methods" (should only be one) # ------------------------------------------------------------------- self.var = [ var for var in self.variables if 'history' in self.infile.listattribute(var) ] if ((self.var == []) or (len(self.var) > 1)): raise KeyboardInterrupt self.keys = self.infile.listattribute(var) # ------------------------------------------------------------------- # call setup() to clean all 'C' internal memory. # ------------------------------------------------------------------- # cmip6_cv.setup(inpath="../Tables", exit_control=cmip6_cv.CMOR_EXIT_ON_WARNING) cmip6_cv.setup(inpath="../Tables", exit_control=cmip6_cv.CMOR_NORMAL) # ------------------------------------------------------------------- # Set Control Vocabulary file to use (default from cmor.h) # ------------------------------------------------------------------- cmip6_cv.set_cur_dataset_attribute(cmip6_cv.GLOBAL_CV_FILENAME, cmip6_cv.TABLE_CONTROL_FILENAME) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_PATH_TEMPLATE, cmip6_cv.CMOR_DEFAULT_PATH_TEMPLATE) cmip6_cv.set_cur_dataset_attribute(cmip6_cv.FILE_NAME_TEMPLATE, cmip6_cv.CMOR_DEFAULT_FILE_TEMPLATE) cmip6_cv.set_cur_dataset_attribute( cmip6_cv.GLOBAL_ATT_FURTHERINFOURLTMPL, cmip6_cv.CMOR_DEFAULT_FURTHERURL_TEMPLATE) # ------------------------------------------------------------------- # Create alist of all Global Attributes and set "dataset" # ------------------------------------------------------------------- self.dictGbl = { key: self.infile.getglobal(key) for key in self.attributes } ierr = [ cmip6_cv.set_cur_dataset_attribute(key, value) for key, value in self.dictGbl.iteritems() ] # ------------------------------------------------------------------- # Create a dictionnary of attributes for var # ------------------------------------------------------------------- self.dictVars = dict( (y, x) for y, x in [(key, value) for key in self.keys if self.infile.getattribute(self.var[0], key) is not None for value in [self.infile.getattribute(self.var[0], key)]]) # ------------------------------------------------------------------- # Load CMIP6 table into memory # ------------------------------------------------------------------- self.table_id = cmip6_cv.load_table(self.cmip6_table)