diff --git a/catalogbuilder/intakebuilder/getinfo.py b/catalogbuilder/intakebuilder/getinfo.py index 2f94254..34a5e55 100644 --- a/catalogbuilder/intakebuilder/getinfo.py +++ b/catalogbuilder/intakebuilder/getinfo.py @@ -242,7 +242,7 @@ def getInfoFromGlobalAtts(fname,dictInfo,filexra=None): dictInfo["frequency"] = frequency return dictInfo -def getStandardName(list_variable_id): +def getStandardName(list_variable_id,list_realm): ''' Returns dict standard name for the variable in question ''' @@ -256,7 +256,9 @@ def getStandardName(list_variable_id): sys.exit(1) #search for variable and its cf name for variable_id in list_variable_id: - cfname = (df[df['GFDL_varname'] == variable_id]["standard_name"]) + for realm in list_realm: + cfname = df[(df['GFDL_varname'] == variable_id) & (realm in df['modeling_realm'])]["standard_name"] + #cfname = (df[df['GFDL_varname'] == variable_id]["standard_name"]) #print(cfname,variable_id) list_cfname = cfname.tolist() if(len(list_cfname) == 0): @@ -266,5 +268,7 @@ def getStandardName(list_variable_id): #print(list_cfname) if len(list_cfname) > 0: unique_cf = list(set(list_cfname))[0] - dictCF[variable_id] = unique_cf + varrealm = "{0},{1}".format(variable_id,realm) + dictCF[varrealm] = unique_cf + #print(varrealm,unique_cf) return (dictCF) diff --git a/catalogbuilder/scripts/gen_intake_gfdl.py b/catalogbuilder/scripts/gen_intake_gfdl.py index 16cdb53..b8213a2 100755 --- a/catalogbuilder/scripts/gen_intake_gfdl.py +++ b/catalogbuilder/scripts/gen_intake_gfdl.py @@ -100,13 +100,22 @@ def create_catalog(input_path=None, output_path=None, config=None, filter_realm= #If we badly need standard name, we use gfdl cmip mapping tables especially when one does not prefer the slow option. Useful for MDTF runs df = pd.read_csv(os.path.abspath(csv_path), sep=",", header=0,index_col=False) list_variable_id = [] - list_variable_id = df["variable_id"].tolist() - dictVarCF = getinfo.getStandardName(list_variable_id) + list_variable_id = df["variable_id"].unique().tolist() + list_realm = df["realm"].unique().tolist() + dictVarCF = getinfo.getStandardName(list_variable_id,list_realm) #print("standard name from look-up table-", dictVarCF) for k, v in dictVarCF.items(): - #if(df['variable_id'].eq(k)).any(): - df['standard_name'].loc[(df['variable_id'] == k)] = v - #df['standard_name'] = v + try: + var = k.split(",")[0] + except ValueError: + continue + try: + realm = k.split(",")[1] + except ValueError: + continue + if(var is not None) & (realm is not None): + df['standard_name'].loc[(df['variable_id'] == var) & (df['realm'] == realm) ] = v + #df['standard_name'].loc[(df['variable_id'] == k)] = v if(slow == False) & ('standard_name' in headers): if ((df is not None) & (len(df) != 0) ): with open(csv_path, 'w') as csvfile: