Skip to content

Commit

Permalink
correct output one per json
Browse files Browse the repository at this point in the history
  • Loading branch information
doutriaux1 committed Jul 18, 2019
1 parent 10aeda6 commit 92ca4b2
Show file tree
Hide file tree
Showing 10 changed files with 1,248 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pcmdi_metrics/driver/outputmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def check_save_test_clim(self, ref):

def write_on_exit(self):
''' Output the metrics_dictionary as a json and text file. '''
self.setup_out_file()
self.metrics_dictionary['METRICS'] = self.metrics_def_dictionary
if len(self.metrics_def_dictionary) == 0:
raise RuntimeError("No results generated, cannot write to file")
Expand All @@ -301,4 +302,4 @@ def write_on_exit(self):
indent=4,
separators=(',', ': '),
mode="r+")
self.out_file.write(self.metrics_dictionary, type='txt')
#self.out_file.write(self.metrics_dictionary, type='txt')
2 changes: 1 addition & 1 deletion pcmdi_metrics/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def write(self, data, type='json', mode="w", *args, **kwargs):
else:
out_dict = OrderedDict({"provenance": generateProvenance()})
f = open(file_name, "w")
out_dict.update(data)
update_dict(out_dict, data)
json.dump(out_dict, f, cls=CDMSDomainsEncoder, *args, **kwargs)
f.close()

Expand Down
13 changes: 7 additions & 6 deletions pcmdi_metrics/pcmdi/mean_climate_metrics_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,18 @@ def run_diags(self):
'Variable %s not in obs_dict' % self.var)
continue

self.output_metric = OutputMetrics(self.parameter, self.var_name_long,
self.obs_dict, sftlf=self.sftlf)

for region in self.regions_dict[self.var]:
logging.getLogger("pcmdi_metrics").info("REGION: {}".format(region))
self.region = self.create_region(region)
# Need to add the region to the output dict now b/c
# otherwise if done later, sometimes it's not added due to
# premature break in the for loops for reference and test.
self.output_metric.add_region(self.region)
# Runs obs vs obs, obs vs model, or model vs model
#self.output_metric = OutputMetrics(self.parameter, self.var_name_long,
# self.obs_dict, sftlf=self.sftlf)
#self.output_metric.add_region(self.region)
self.run_reference_and_test_comparison()
self.output_metric.setup_out_file()
self.output_metric.write_on_exit()

def load_obs_dict(self):
''' Loads obs_info_dictionary.json and appends
Expand Down Expand Up @@ -151,7 +149,6 @@ def create_region(self, region):

def run_reference_and_test_comparison(self):
''' Does the (obs or model) vs (obs or model) comparison. '''

reference_data_set = self.parameter.reference_data_set
test_data_set = self.parameter.test_data_set

Expand Down Expand Up @@ -182,6 +179,9 @@ def run_reference_and_test_comparison(self):

for test in test_data_set:
logging.getLogger("pcmdi_metrics").info("TEST DATA IS: {}".format(test))
self.output_metric = OutputMetrics(self.parameter, self.var_name_long,
self.obs_dict, sftlf=self.sftlf)
self.output_metric.add_region(self.region)
try:
tst = self.determine_obs_or_model(test_data_set_is_obs,
test, self.parameter.test_data_path)
Expand All @@ -194,6 +194,7 @@ def run_reference_and_test_comparison(self):
logging.getLogger("pcmdi_metrics").info("Unexpected error:".format(err))
break


try:
self.output_metric.calculate_and_output_metrics(ref, tst)
except RuntimeError:
Expand Down
4 changes: 2 additions & 2 deletions pcmdi_metrics/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = 'v1.2'
__git_tag_describe__ = 'v1.2-60-g04ad61a'
__git_sha1__ = '04ad61a8bdf52af8af61698c64a9dd553d05ed45'
__git_tag_describe__ = 'v1.2-61-g10aeda6'
__git_sha1__ = '10aeda62665ba4bc671da10a0ff8facc708487f5'
2 changes: 1 addition & 1 deletion tests/pcmdi/basic_test_parameters_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
'interpolated_model_clims')

# Filename template for json files:
output_json_template = "%(variable)%(level)_%(model_version)_%(target_grid_name)_%(regrid_tool)_%(regrid_method)_metricsssss"
output_json_template = "%(variable)%(level)_%(model_version)_%(target_grid_name)_%(regrid_tool)_%(regrid_method)_metrics"

# FILENAME FOR INTERPOLATED CLIMATOLOGIES OUTPUT
filename_output_template = "%(variable)%(level)_" + \
Expand Down
Loading

0 comments on commit 92ca4b2

Please sign in to comment.