From aa064dfba209a6b09a7c487fc71b26de244aa318 Mon Sep 17 00:00:00 2001 From: Andreas Freise <adf@star.bham.ac.uk> Date: Mon, 2 Dec 2013 12:10:53 +0000 Subject: [PATCH] trying to make more example files work: - extending SIfloat to work with lists - adding SIfloat to axis conversion. --- pykat/SIfloat.py | 16 +++++++--------- pykat/commands.py | 4 ++-- pykat/components.py | 2 +- pykat/finesse.py | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pykat/SIfloat.py b/pykat/SIfloat.py index e18a175..e931667 100644 --- a/pykat/SIfloat.py +++ b/pykat/SIfloat.py @@ -1,16 +1,14 @@ import os import re -""" -class SIfloat(value): - def __init__(self, value): - self.__value = value -""" - #staticmethod def SIfloat(value): - value=str(value) - + if type(value)==list: + return [convertToFloat(s) for s in value] + else: + return convertToFloat(value) + +def convertToFloat(value): __prefix = {'y': 1e-24, # yocto 'z': 1e-21, # zepto 'a': 1e-18, # atto @@ -30,7 +28,7 @@ def SIfloat(value): 'Z': 1e21, # zetta 'Y': 1e24, # yotta } + value = str(value) for i, j in __prefix.iteritems(): value=value.replace(i, str(j)) return float(value) - diff --git a/pykat/commands.py b/pykat/commands.py index a86647b..7caa7eb 100644 --- a/pykat/commands.py +++ b/pykat/commands.py @@ -83,7 +83,7 @@ class xaxis(Command): if numpy.size(limits) != 2 : raise exceptions.ValueError("limits input should be a 2x1 vector of limits for the xaxis") - self.limits = numpy.array(limits).astype(float) + self.limits = numpy.array(SIfloat(limits)).astype(float) if steps <= 0 : raise exceptions.ValueError("steps value should be > 0") @@ -128,4 +128,4 @@ class xaxis(Command): comp_name, param_name, self.scale, min(self.limits), max(self.limits), self.steps); - \ No newline at end of file + diff --git a/pykat/components.py b/pykat/components.py index 96c5c68..968a5e8 100644 --- a/pykat/components.py +++ b/pykat/components.py @@ -71,7 +71,7 @@ class Component(object) : class Param(float): def __new__(self,name,value): - return float.__new__(self,value) + return float.__new__(self,SIfloat(value)) def __init__(self,name,value): self.__name = name diff --git a/pykat/finesse.py b/pykat/finesse.py index 158a8b8..05f7530 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -122,7 +122,7 @@ class kat(object): def parseKatCode(self, code): #commands = code.split("\n") - self.parseCommands(commands) + self.parseCommands(code) def parseCommands(self, commands): blockComment = False -- GitLab