Skip to content

Commit

Permalink
Merge pull request NOAA-GFDL#35 from aradhakrishnanGFDL/cfname-realm
Browse files Browse the repository at this point in the history
Get standard name considering realm
  • Loading branch information
Ciheim authored Aug 15, 2024
2 parents cb007c1 + 509aae9 commit f0b2cff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
10 changes: 7 additions & 3 deletions catalogbuilder/intakebuilder/getinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
Expand All @@ -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):
Expand All @@ -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)
19 changes: 14 additions & 5 deletions catalogbuilder/scripts/gen_intake_gfdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f0b2cff

Please sign in to comment.