commands.py 2.43 KB
Newer Older
Daniel Brown's avatar
Daniel Brown committed
1
2
3
4
5
6
7
8
9
10
11
12
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 28 11:58:09 2013

@author: Daniel
"""
import numpy
from numpy import min,max
import exceptions
from components import *
from structs import *

13
class Command(object):
Daniel Brown's avatar
Daniel Brown committed
14
15
16
17
    def getFinesseText(self):
        """ Base class for individual finesse optical components """    
        raise NotImplementedError("This function is not implemented")
        
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class cavity(Command):
    def __init__(self, kat, name, c1, n1, c2, n2):
        self.__name = name
        self.__c1 = c1
        self.__c2 = c2
        self.__n1 = n1
        self.__n2 = n2
    
        kat.add(self)
        
    def getFinesseText(self):
        return 'cav {0} {1} {2} {3} {4}'.format(
                self.__name, self.__c1, self.__n1, self.__c2, self.__n2);
    
    
Daniel Brown's avatar
Daniel Brown committed
33
34
35
36
class xaxis(Command):
    
    def __init__(self, kat, scale, limits, comp, param, steps):
        
37
38
39
40
41
42
43
44
        if scale == "lin":
            scale = Scale.linear
        elif scale == "log":
            scale = Scale.logarithmic
        elif isinstance(scale, str): 
            # else we have a string but not a recognisable one
            raise exceptions.ValueError("scale argument '{0}' is not valid, must be 'lin' or 'log'".format(scale))
         
Daniel Brown's avatar
Daniel Brown committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
        if scale != Scale.linear and scale != Scale.logarithmic:
            raise exceptions.ValueError("scale is not Scale.linear or Scale.logarithmic")            
            
        self.scale = scale
        
        if numpy.size(limits) != 2 :
            raise exceptions.ValueError("limits input should be a 2x1 vector of limits for the xaxis")
            
        self.limits = limits
        
        if steps <= 0 :
            raise exceptions.ValueError("steps value should be > 0")            
            
        self.steps = steps
        
        if not isinstance(comp, Component):
            raise exceptions.ValueError("comp is not a Component")
            
        self.__comp = comp
        
        if not isinstance(param, Param) :
            raise exceptions.ValueError("param argument is not of type Param")
                
        self._param = param
        
        kat.add(self)
        
    def getFinesseText(self):
        
        return 'xaxis {0} {1} {2} {3} {4} {5}'.format(
                self.__comp.name, self._param.name, self.scale,
                min(self.limits), max(self.limits), self.steps);