Skip to content

Commit

Permalink
enable save_test_clims options
Browse files Browse the repository at this point in the history
  • Loading branch information
lee1043 committed Feb 22, 2023
1 parent 4a4b5b3 commit f543015
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
8 changes: 8 additions & 0 deletions pcmdi_metrics/mean_climate/lib/create_mean_climate_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ def create_mean_climate_parser():
help="Directory of where to put the results",
required=False,
)

parser.add_argument(
"--diagnostics_output_path",
dest="diagnostics_output_path",
help="Directory of where to put the results",
default=None,
required=False,
)

parser.add_argument(
"--filename_output_template",
Expand Down
27 changes: 23 additions & 4 deletions pcmdi_metrics/mean_climate/mean_climate_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@
regions = parameter.regions
test_data_path = parameter.test_data_path
reference_data_path = parameter.reference_data_path
metrics_output_path = parameter.metrics_output_path.replace('%(case_id)', case_id)

metrics_output_path = parameter.metrics_output_path
diagnostics_output_path = parameter.diagnostics_output_path
debug = parameter.debug
cmec = parameter.cmec

if metrics_output_path is not None:
metrics_output_path = parameter.metrics_output_path.replace('%(case_id)', case_id)

if diagnostics_output_path is None:
diagnostics_output_path = metrics_output_path.replace('metrics_results', 'diagnostic_results')

diagnostics_output_path = diagnostics_output_path.replace('%(case_id)', case_id)

find_all_realizations = False
if realization is None:
realization = ""
Expand Down Expand Up @@ -84,6 +92,7 @@
'test_data_path:', test_data_path, '\n',
'reference_data_path:', reference_data_path, '\n',
'metrics_output_path:', metrics_output_path, '\n',
'diagnostics_output_path:', diagnostics_output_path, '\n',
'debug:', debug, '\n')

print('--- prepare mean climate metrics calculation ---')
Expand Down Expand Up @@ -223,11 +232,21 @@
if region not in list(ds_ref_dict.keys()):
ds_ref_dict[region] = region_subset(ds_ref_tmp, regions_specs, region=region)
print('spatial subset done')

if save_test_clims and ref == reference_data_set[0]:
test_clims_dir = os.path.join(
diagnostics_output_path, var, 'interpolated_model_clims')
os.makedirs(test_clims_dir, exist_ok=True)
test_clims_file = os.path.join(
test_clims_dir,
'_'.join([var, model, run, 'interpolated', regrid_tool, region, 'AC', case_id + '.nc']))
ds_test_dict[region].to_netcdf(test_clims_file)

if debug:
print('ds_test_tmp:', ds_test_tmp)
ds_test_dict[region].to_netcdf('_'.join([var, 'model', region + '.nc']))
ds_ref_dict[region].to_netcdf('_'.join([var, 'ref', region + '.nc']))
ds_test_dict[region].to_netcdf('_'.join([var, 'model', model, run, region + '.nc']))
if model == test_data_set[0] and run == realizations[0]:
ds_ref_dict[region].to_netcdf('_'.join([var, 'ref', region + '.nc']))

# compute metrics
print('compute metrics start')
Expand Down

0 comments on commit f543015

Please sign in to comment.