4242
4343from .cmor_helpers import ( print_data_minmax , from_dis_gimme_dis , find_statics_file , create_lev_bnds ,
4444 get_iso_datetime_ranges , check_dataset_for_ocean_grid , get_vertical_dimension ,
45- create_tmp_dir , get_json_file_data , update_grid_and_label , update_calendar_type ,
46- get_exp_cfg_mip_era )
45+ create_tmp_dir , get_json_file_data , update_grid_and_label , update_calendar_type )
4746
4847fre_logger = logging .getLogger (__name__ )
4948
@@ -151,7 +150,8 @@ def rewrite_netcdf_file_var( mip_var_cfgs: dict = None,
151150 fre_logger .error ('should not happen' )
152151 raise ValueError
153152 else :
154- fre_logger .error ('cmip7 case detected but no brands found in the CMOR mip table config had the right dimensions. nothing to do for this var!' )
153+ fre_logger .error ('cmip7 case detected, but dimensions of input data do not match '
154+ 'any of those found for the associated brands.' )
155155 raise ValueError
156156 else :
157157 fre_logger .debug ('non-cmip7 case detected, skipping variable brands' )
@@ -621,9 +621,9 @@ def rewrite_netcdf_file_var( mip_var_cfgs: dict = None,
621621 units = mip_var_cfgs ["variable_entry" ][target_var ]["units" ]
622622 fre_logger .info ("units = %s" , units )
623623
624- #positive = mip_var_cfgs["variable_entry"][target_var]["positive"]
624+ #positive = mip_var_cfgs["variable_entry"][target_var]["positive"]
625625 if GLOBAL_MIP_ERA == 'CMIP7' :
626- positive = mip_var_cfgs ["variable_entry" ][f'{ target_var } _{ var_brand } ' ]["positive" ]
626+ positive = mip_var_cfgs ["variable_entry" ][f'{ target_var } _{ var_brand } ' ]["positive" ]
627627 else :
628628 positive = mip_var_cfgs ["variable_entry" ][target_var ]["positive" ]
629629 fre_logger .info ("positive = %s" , positive )
@@ -890,8 +890,6 @@ def cmorize_all_variables_in_dir(vars_to_run: Dict[str, Any],
890890 except Exception as exc : #uncovered
891891 return_status = 1
892892 fre_logger .warning ('!!!EXCEPTION CAUGHT!!! !!!READ THE NEXT LINE!!!' )
893- # if str(exc) == "made it to break-point for current work, good job": # inl: annoying and i did this to myself
894- # assert False, "made it to break-point for current work, good job"
895893 fre_logger .warning ('exc=%s' , exc )
896894 fre_logger .warning ('this message came from within cmorize_target_var_files' )
897895 fre_logger .warning ('COULD NOT PROCESS: %s/%s...moving on' , local_var , target_var )
@@ -976,17 +974,20 @@ def cmor_run_subtool(indir: str = None,
976974 fre_logger .debug ('cmip7_case = %s' , cmip7_case )
977975 cmip6_case = exp_cfg_mip_era .upper () == 'CMIP6'
978976 fre_logger .debug ('cmip6_case = %s' , cmip6_case )
979- assert cmip7_case != cmip6_case # dont keep this assert, TEMP TODO
980977
981- global GLOBAL_MIP_ERA
982- GLOBAL_MIP_ERA = exp_cfg_mip_era # i don't care that i'm changing a "constant", it's more like a static class member
983- if GLOBAL_MIP_ERA is None :
978+ if exp_cfg_mip_era is None :
984979 raise Exception ('CMOR input experimental configuration must contain a field called "mip_era"' )
985- fre_logger .debug ('GLOBAL_MIP_EREA=%s' ,GLOBAL_MIP_ERA )
986980
987- if cmip7_case :
981+ if exp_cfg_mip_era .upper () not in ['CMIP6' , 'CMIP7' ]:
982+ raise ValueError ('cmor_mixer only supports CMIP6 and CMIP7 cases' )
983+
984+ if exp_cfg_mip_era .upper () == 'CMIP7' :
988985 fre_logger .warning ('CMIP7 configuration detected, will be expecting and enforcing variable brands.' )
989986
987+ global GLOBAL_MIP_ERA
988+ GLOBAL_MIP_ERA = exp_cfg_mip_era .upper () # maybe, change to yet another input arg for down-stream function calls ?
989+ fre_logger .debug ('GLOBAL_MIP_EREA=%s' ,GLOBAL_MIP_ERA )
990+
990991 # CHECK optional grid/grid_label/nom_res inputs from exp config, the function raises the potential error conditions
991992 if any ( [ grid_label is not None ,
992993 grid is not None ,
@@ -1003,24 +1004,21 @@ def cmor_run_subtool(indir: str = None,
10031004 # open CMOR table config file - need it here for checking the TABLE's variable list
10041005 json_table_config = str (Path (json_table_config ).resolve ())
10051006 fre_logger .info ('loading json_table_config = \n %s' , json_table_config )
1006-
10071007 mip_var_cfgs = get_json_file_data (json_table_config )
10081008 mip_fullvar_list = mip_var_cfgs ["variable_entry" ].keys ()
10091009 fre_logger .debug ('the following variables were read from the table: %s' , mip_fullvar_list )
1010- mip_var_list = None
1011- mip_var_brand_list = None
1012- if cmip7_case :
1013- fre_logger . warning ( 'cmip7 capabilities in-development now. extracting brands from variables within MIP cmor table configs' )
1010+ mip_var_list , mip_var_brand_list = None , None
1011+ if GLOBAL_MIP_ERA == 'CMIP7' :
1012+ fre_logger . warning ( 'cmip7 capabilities in-development now. extracting brands from variables '
1013+ ' within MIP cmor table configs' )
10141014 mip_var_list = [ var .split ('_' )[0 ] for var in mip_fullvar_list ]
10151015 fre_logger .debug ('the following unbranded variables were read from the table: %s' , mip_var_list )
10161016 mip_var_brand_list = [ var .split ('_' )[1 ] for var in mip_fullvar_list ]
10171017 fre_logger .debug ('the following brands were extracted from the variables: %s' , mip_var_brand_list )
10181018 if len (mip_var_list ) != len (mip_var_brand_list ):
10191019 raise ValueError ('the number of brands is not one-to-one with the number of variables. check config.' )
1020- elif cmip6_case :
1020+ elif GLOBAL_MIP_ERA == "CMIP6" :
10211021 mip_var_list = mip_fullvar_list
1022- #else:
1023- # raise ValueError('uh oh')
10241022
10251023 fre_logger .debug ('variables in mip_var_cfgs["variable_entry"] is = \n %s' , mip_var_list )
10261024
0 commit comments