From c3c1f9c7767833b1fcb7cc89a6bd4d232f8db726 Mon Sep 17 00:00:00 2001
From: jlaura <jlaura@usgs.gov>
Date: Wed, 5 Sep 2018 09:26:53 -0700
Subject: [PATCH] moves isd creation into correct py class and adds exceptions
 to RasterGM (#7)

* moves isd creation into correct py class

* Adds exception handling to RasterGM.
---
 isd.i      | 45 +++++++++++++++++++++++----------------------
 rastergm.i | 10 ++++++++++
 2 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/isd.i b/isd.i
index f2e8886..625bcd2 100644
--- a/isd.i
+++ b/isd.i
@@ -11,28 +11,29 @@
 
 %include <std_string.i>
 
-%include "Isd.h"
 %pythoncode %{
-  import json
-  import numpy as np
-  @classmethod
-  def loads(cls, stream):
-      isd = cls()
-      if not isinstance(stream, dict):
-          stream = json.loads(stream)
-      for k, v in stream.items():
-          if isinstance(v, np.ndarray):
-              v = v.tolist()
-          if isinstance(v, list):
-              for i in v:
-                  isd.addParam(k, str(i))
-          isd.addParam(k, str(v))
-      return isd
+    import json    
+%}
 
-  @classmethod
-  def load(cls, fp):
-      return cls.loads(fp.read())
+%include "Isd.h"
+%extend csm::Isd {
+    %pythoncode %{
+        import json
+        import numpy as np
+        @classmethod
+        def loads(cls, stream):
+            isd = cls()
+            if not isinstance(stream, dict):
+                stream = json.loads(stream)
+            for k, v in stream.items():
+                if isinstance(v, list):
+                    for i in v:
+                        isd.addParam(k, str(i))
+                isd.addParam(k, str(v))
+            return isd
 
-  Isd.load = load
-  Isd.loads = loads
-%}
\ No newline at end of file
+        @classmethod
+        def load(cls, fp):
+            return cls.loads(fp.read())
+    %}
+}
\ No newline at end of file
diff --git a/rastergm.i b/rastergm.i
index 93ef9e2..60fc6c1 100644
--- a/rastergm.i
+++ b/rastergm.i
@@ -4,8 +4,18 @@
 %}
 
 %ignore CSM_RASTER_FAMILY;
+%include exception.i
+%exception {
+    try {
+        $action
+    } catch (const std::exception &e) {
+        SWIG_exception(SWIG_RuntimeError, e.what());
+    }
+} 
+
 
 %import model.i
 %import geometricmodel.i
 %import csm.i
+
 %include RasterGM.h
-- 
GitLab