You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@climate.apache.org by jo...@apache.org on 2015/03/31 16:59:28 UTC

[09/13] climate git commit: CLIMATE-581 - Add API for evaluation export to config file

CLIMATE-581 - Add API for evaluation export to config file

- Add export_evaluation_to_config for exporting an Evaluation object to
  a YAML configuration file that can be parsed by OCW.
- Add explicit cast of spatial lat/lon grid step values to floats to
  ensure that PyYAML doesn't encounter a Numpy data type and choke on
  export.


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/9d242b27
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/9d242b27
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/9d242b27

Branch: refs/heads/master
Commit: 9d242b273a65d4021d54f047659a6a7349611158
Parents: b0e7b40
Author: Michael Joyce <jo...@apache.org>
Authored: Wed Mar 25 11:29:26 2015 -0700
Committer: Michael Joyce <jo...@apache.org>
Committed: Wed Mar 25 11:29:26 2015 -0700

----------------------------------------------------------------------
 ocw-config-runner/configuration_writer.py | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/9d242b27/ocw-config-runner/configuration_writer.py
----------------------------------------------------------------------
diff --git a/ocw-config-runner/configuration_writer.py b/ocw-config-runner/configuration_writer.py
index 497c7db..c78f46f 100644
--- a/ocw-config-runner/configuration_writer.py
+++ b/ocw-config-runner/configuration_writer.py
@@ -18,9 +18,28 @@
 import datetime as dt
 import logging
 
+import yaml
+
 logging.basicConfig()
 logger = logging.getLogger(__name__)
 
+def export_evaluation_to_config(evaluation, file_path='./exported_eval.yaml'):
+    ''' Export an evaluation to a config file
+    
+    :param evaluation: The evaluation object to export.
+    :type evaluation: :class:`evaluation.Evaluation`
+
+    :param file_path: Optional file path where the config file should be saved.
+    :type file_path: :mod:`string`
+    '''
+    config = {}
+
+    config['evaluation'] = generate_evaluation_information(evaluation)
+    config['datasets'] = generate_dataset_information(evaluation)
+    config['metrics'] = generate_metric_information(evaluation)
+
+    yaml.dump(config, file(file_path, 'w'))
+
 def generate_dataset_information(evaluation):
     ''' Generate dataset config file output for a given Evaluation object.
     
@@ -219,8 +238,11 @@ def _calc_spatial_lat_lon_grid(datasets):
 
     lats = datasets[0].lats
     lons = datasets[0].lons
-    lat_step = abs(lats[1] - lats[0])
-    lon_step = abs(lons[1] - lons[0])
+    # These explicit float casts are needed to ensure that the type of the
+    # lat/lon steps are not numpy values. PyYAML will choke on export if it
+    # encounters a Numpy value.
+    lat_step = float(abs(lats[1] - lats[0]))
+    lon_step = float(abs(lons[1] - lons[0]))
 
     # We need to add an extra step value onto the end so when we generate a
     # range with these values we don't lose one that we're expecting.