From 9bfe88ad047b58aa726886f5c3f11cb6642d2c68 Mon Sep 17 00:00:00 2001
From: ilyas <ikuhlem@gwdg.de>
Date: Tue, 14 Apr 2020 12:05:49 +0200
Subject: [PATCH 1/2] now use linear encoder parameters multiplier = 1, offset
 = 0 if no encoder parameters present

---
 SDF/convert/sdf2forcesdf.py | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/SDF/convert/sdf2forcesdf.py b/SDF/convert/sdf2forcesdf.py
index c6836af..40a7a04 100644
--- a/SDF/convert/sdf2forcesdf.py
+++ b/SDF/convert/sdf2forcesdf.py
@@ -278,12 +278,25 @@ def _parse_dataset(ds_sdf: sdf_object, channel_parameters: sdf_par,
 
 def _extract_conversion_parameters(par: sdf_par) -> Tuple[float, float]:
     conv_set = par['conversion-set']
-    try:
-        encoder = par['data']['encoder']['scaling']
-    except KeyError:
+    if 'encoder' in par:
         encoder = par['encoder']['scaling']
-    mult = float(encoder['multiplier'].value)
-    offs = float(encoder['offset'].value)
+        mult = float(encoder['multiplier'].value)
+        offs = float(encoder['offset'].value)
+    elif 'data' in par:
+        if 'encoder' in par['data']:
+            encoder = par['data']['encoder']['scaling']
+            mult = float(encoder['multiplier'].value)
+            offs = float(encoder['offset'].value)
+        else:
+            # no encoder parameters found.
+            # => data is already converted into physical data
+            mult = 1.0
+            offs = 0.0
+    else:
+        # no encoder parameters found.
+        # => data is already converted into physical data
+        mult = 1.0
+        offs = 0.0
 
     conversions = _determine_conversions(conv_set)
 
-- 
GitLab


From d50c30dab51510297cc81cfbc89ae957c81c071c Mon Sep 17 00:00:00 2001
From: Niklas Mertsch <niklas.mertsch@stud.uni-goettingen.de>
Date: Wed, 15 Apr 2020 11:31:59 +0200
Subject: [PATCH 2/2] Restructuring and renaming

---
 SDF/convert/sdf2forcesdf.py | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/SDF/convert/sdf2forcesdf.py b/SDF/convert/sdf2forcesdf.py
index 40a7a04..6be5441 100644
--- a/SDF/convert/sdf2forcesdf.py
+++ b/SDF/convert/sdf2forcesdf.py
@@ -277,29 +277,26 @@ def _parse_dataset(ds_sdf: sdf_object, channel_parameters: sdf_par,
 
 
 def _extract_conversion_parameters(par: sdf_par) -> Tuple[float, float]:
-    conv_set = par['conversion-set']
+    # extract scaling parameters
     if 'encoder' in par:
-        encoder = par['encoder']['scaling']
-        mult = float(encoder['multiplier'].value)
-        offs = float(encoder['offset'].value)
-    elif 'data' in par:
-        if 'encoder' in par['data']:
-            encoder = par['data']['encoder']['scaling']
-            mult = float(encoder['multiplier'].value)
-            offs = float(encoder['offset'].value)
-        else:
-            # no encoder parameters found.
-            # => data is already converted into physical data
-            mult = 1.0
-            offs = 0.0
+        scaling_parameters = par['encoder']['scaling']
+    elif 'data' in par and 'encoder' in par['data']:
+        scaling_parameters = par['data']['encoder']['scaling']
+    else:
+        scaling_parameters = None
+
+    # set initial multiplier and offset
+    if scaling_parameters is not None:
+        mult = float(scaling_parameters['multiplier'].value)
+        offs = float(scaling_parameters['offset'].value)
     else:
-        # no encoder parameters found.
-        # => data is already converted into physical data
+        # no encoder parameters found => data is already converted into physical data
         mult = 1.0
         offs = 0.0
 
+    # apply conversions to multiplier and offset
+    conv_set = par['conversion-set']
     conversions = _determine_conversions(conv_set)
-
     for conv in conversions:
         m = float(conv_set['conversion'][conv]['scaling']['multiplier'].value)
         b = float(conv_set['conversion'][conv]['scaling']['offset'].value)
-- 
GitLab