components.py 46.9 KB
Newer Older
Daniel Brown's avatar
Daniel Brown committed
1001
1002
1003
1004
    def f(self, value): self.__f.value = SIfloat(value)
    
    @staticmethod
    def parseFinesseText(text):
1005
        values = text.split()
Daniel Brown's avatar
Daniel Brown committed
1006
1007

        if values[0] != "lens":
1008
            raise pkex.BasePyKatException("'{0}' not a valid Finesse lens command".format(text))
Daniel Brown's avatar
Daniel Brown committed
1009
1010
1011
1012
1013
1014

        values.pop(0) # remove initial value
        
        if len(values) == 4:
            return lens(values[0], values[2], values[3], values[1])
        else:
1015
            raise pkex.BasePyKatException("Lens Finesse code format incorrect '{0}'".format(text))
Daniel Brown's avatar
Daniel Brown committed
1016
1017
1018
1019
1020
1021
1022
1023
        
    def getFinesseText(self):
        rtn = ['lens {0} {1} {2} {3}'.format(self.name, self.f.value, self.nodes[0].name, self.nodes[1].name)]
        
        for p in self._params:
            rtn.extend(p.getFinesseText())
            
        return rtn
1024
1025
1026
1027
1028
1029
    
    def getOptivisComponent(self):
        self.setOptivisLabelContent()
        
        if self._optivis_component is None:
            self._optivis_component = optivis_components.ConvexLens(name=self.name, tooltip=self.getOptivisTooltip, paramList=self.getOptivisParameterDict(), pykatObject=weakref.ref(self))
Daniel Brown's avatar
Daniel Brown committed
1030
        
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
        return self._optivis_component
    
    def getOptivisNode(self, mode, kat_node):
        mode = mode.lower()
        
        if mode != "input" and mode.lower() != "output":
            raise pkex.BasePyKatException("Mode must be either input or output")
        
        if mode == "input":
            if kat_node is self.nodes[0]:
                return self._optivis_component.getInputNode("fr")
            elif kat_node is self.nodes[1]:
                return self._optivis_component.getInputNode("bk")
        elif mode == "output":
            if kat_node is self.nodes[0]:
                return self._optivis_component.getnOutputNode("fr")
            elif kat_node is self.nodes[1]:
                return self._optivis_component.getOutputNode("bk")
                
Daniel Brown's avatar
Daniel Brown committed
1050
    def getQGraphicsItem(self):
1051
1052
1053
        if not USE_GUI:
            raise NoGUIException
            
1054
        if self._svgItem is None:
1055
            self._svgItem = pykat.gui.graphics.ComponentQGraphicsItem(":/resources/lens.svg", self ,[(-4,15,self.nodes[0]), (14,15,self.nodes[1])])
Daniel Brown's avatar
Daniel Brown committed
1056
        
1057
        return self._svgItem
Daniel Brown's avatar
Daniel Brown committed
1058
1059
        
class modulator(Component):
1060
    def __init__(self, name, node1, node2, f, midx, order, modulation_type='pm', phase=0):
Daniel Brown's avatar
Daniel Brown committed
1061
1062
1063
1064
        Component.__init__(self, name)
        
        self._requested_node_names.append(node1)
        self._requested_node_names.append(node2)
1065
        self._svgItem = None
Daniel Brown's avatar
Daniel Brown committed
1066
1067
        self.__f = Param("f", self, SIfloat(f))
        self.__midx = Param("midx", self, SIfloat(midx))
Daniel Brown's avatar
Daniel Brown committed
1068
        self.__phase = Param("phase", self, SIfloat(phase), canFsig=True, fsig_name="phase")
Daniel Brown's avatar
Daniel Brown committed
1069
        self.__order = int(order)
Daniel Brown's avatar
Daniel Brown committed
1070
1071
        self.type = modulation_type
        
Daniel Brown's avatar
Daniel Brown committed
1072
        self._default_fsig_param = self.__phase
Daniel Brown's avatar
Daniel Brown committed
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
            
    @property 
    def f(self): return self.__f
    @f.setter
    def f(self, value): self.__f.value = SIfloat(value)
    
    @property 
    def midx(self): return self.__midx
    @midx.setter
    def midx(self, value): self.__midx.value = SIfloat(value)
    
    @property 
    def phase(self): return self.__phase
    @phase.setter
    def phase(self, value): self.__phase.value = SIfloat(value)
    
    @property 
Daniel Brown's avatar
Daniel Brown committed
1090
    def order(self): return int(self.__order)
Daniel Brown's avatar
Daniel Brown committed
1091
1092
    @order.setter
    def order(self, value):
Daniel Brown's avatar
Daniel Brown committed
1093
1094
        value = int(value)
        
1095
        if value <= 1 and value > 6:
Daniel Brown's avatar
Daniel Brown committed
1096
1097
            raise pkex.BasePyKatException("modulator order must be between 1 and 6")
            
Daniel Brown's avatar
Daniel Brown committed
1098
        self.__order = value
Daniel Brown's avatar
Daniel Brown committed
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
    
    @property 
    def type(self): return self.__type
    @type.setter
    def type(self, value):
        if value != "am" and value != "pm":
            raise pkex.BasePyKatException("Modulator type must be am (amplitude modulation) or pm (phase modulation)")
            
        self.__type = str(value)
    
    @staticmethod
    def parseFinesseText(text):
1111
        v = text.split()
Daniel Brown's avatar
Daniel Brown committed
1112
1113

        if v[0] != "mod":
1114
            raise pkex.BasePyKatException("'{0}' not a valid Finesse modulator command".format(text))
Daniel Brown's avatar
Daniel Brown committed
1115
1116
1117
1118

        v.pop(0) # remove initial value
        
        if len(v) == 7:
1119
            return modulator(v[0], v[5], v[6], v[1], v[2], v[3], v[4])
Daniel Brown's avatar
Daniel Brown committed
1120
        if len(v) == 8:
1121
            return modulator(v[0], v[6], v[7], v[1], v[2], v[3], v[4], phase=v[5])
Daniel Brown's avatar
Daniel Brown committed
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
        else:
            raise pkex.BasePyKatException("Modulator Finesse code format incorrect '{0}'".format(text))
        
    def getFinesseText(self):
        rtn = ['mod {0} {1} {2} {3} {4} {5} {6} {7}'.format(self.name, self.f, self.midx, self.order, self.type, self.phase, self.nodes[0].name, self.nodes[1].name)]
        
        for p in self._params:
            rtn.extend(p.getFinesseText())
            
        return rtn
        
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
    def getOptivisComponent(self):
        self.setOptivisLabelContent()
        
        if self._optivis_component is None:
            self._optivis_component = optivis_components.ElectroopticModulator(name=self.name, tooltip=self.getOptivisTooltip, paramList=self.getOptivisParameterDict(), pykatObject=weakref.ref(self))
            
        return self._optivis_component
    
    def getOptivisNode(self, mode, kat_node):
        mode = mode.lower()
        
        if mode != "input" and mode.lower() != "output":
            raise pkex.BasePyKatException("Mode must be either input or output")
        
        if mode == "input":
            if kat_node is self.nodes[0]:
                return self._optivis_component.getInputNode("fr")
            elif kat_node is self.nodes[1]:
                return self._optivis_component.getInputNode("bk")
        elif mode == "output":
            if kat_node is self.nodes[0]:
                return self._optivis_component.getnOutputNode("fr")
            elif kat_node is self.nodes[1]:
                return self._optivis_component.getOutputNode("bk")
                
Daniel Brown's avatar
Daniel Brown committed
1158
    def getQGraphicsItem(self):
1159
1160
1161
        if not USE_GUI:
            raise NoGUIException
            
1162
        if self._svgItem is None:
1163
            self._svgItem = pykat.gui.graphics.ComponentQGraphicsItem(":/resources/modulator.svg", self ,[(-4,15,self.nodes[0]), (14,15,self.nodes[1])])
Daniel Brown's avatar
Daniel Brown committed
1164
        
1165
        return self._svgItem
Daniel Brown's avatar
Daniel Brown committed
1166
1167

class laser(Component):
1168
    def __init__(self, name, node, P=1, f=0, phase=0):
Daniel Brown's avatar
Daniel Brown committed
1169
1170
1171
1172
        Component.__init__(self,name)
        
        self._requested_node_names.append(node)
        
1173
        self.__power = Param("P", self, SIfloat(P), canFsig=True, fsig_name="amp")
1174
        self.__f_offset = Param("f", self, SIfloat(f), canFsig=True, fsig_name="f")
1175
        self.__phase = Param("phase", self, SIfloat(phase), canFsig=True, fsig_name="phase")
1176
        self.__noise = AttrParam("noise", self, None)
1177
        self._svgItem = None
Daniel Brown's avatar
Daniel Brown committed
1178
        
Daniel Brown's avatar
Daniel Brown committed
1179
1180
        self._default_fsig_param = self.__f_offset
        
Daniel Brown's avatar
Daniel Brown committed
1181
    @property
1182
1183
1184
    def P(self): return self.__power
    @P.setter
    def P(self,value): self.__power.value = float(value)
Daniel Brown's avatar
Daniel Brown committed
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
    
    @property
    def f(self): return self.__f_offset
    @f.setter
    def f(self,value): self.__f_offset.value = float(value)
    
    @property
    def phase(self): return self.__phase
    @phase.setter
    def phase(self,value): self.__phase.value = float(value)
    
Daniel Brown's avatar
Daniel Brown committed
1196
1197
1198
1199
1200
1201
1202
1203
    def parseAttributes(self, values):
        
        for key in values.keys():
            if key == "noise":
                self.__noise.value = values[key]
            else:
                raise pkex.BasePyKatException("No attribute {0} at laser".format(key))
    
Daniel Brown's avatar
Daniel Brown committed
1204
1205
    @staticmethod
    def parseFinesseText(text):
1206
        values = text.split()
Daniel Brown's avatar
Daniel Brown committed
1207
1208

        if values[0] != "l":
1209
            raise pkex.BasePyKatException("'{0}' not a valid Finesse laser command".format(text))
Daniel Brown's avatar
Daniel Brown committed
1210
1211
1212
1213

        values.pop(0) # remove initial value
        
        if len(values) == 5:
1214
            return laser(values[0],values[4],P=values[1],f=values[2],phase=values[3])
Daniel Brown's avatar
Daniel Brown committed
1215
        elif len(values) == 4:
1216
            return laser(values[0],values[3],P=values[1],f=values[2], phase=0)
Daniel Brown's avatar
Daniel Brown committed
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
        else:
            raise exceptions.FinesseParse("Laser Finesse code format incorrect '{0}'".format(text))
    
    def getFinesseText(self):
        rtn = ['l {0} {1} {2} {3} {4}'.format(self.name, self.__power.value, self.__f_offset.value, self.__phase.value, self.nodes[0].name)]
        
        for p in self._params:
            rtn.extend(p.getFinesseText())
        
        return rtn
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249

    def getOptivisComponent(self):
        self.setOptivisLabelContent()
        
        if self._optivis_component is None:
            self._optivis_component = optivis_components.Laser(name=self.name, tooltip=self.getOptivisTooltip, paramList=self.getOptivisParameterDict(), pykatObject=weakref.ref(self))
            lbl = optivis_label(text="", position=optivis_coord(0, -1), item=self._optivis_component)
            lbl.content["Name"] = self.name
            self._optivis_component.labels.append(lbl)
            
        return self._optivis_component
    
    def getOptivisNode(self, mode, kat_node):
        mode = mode.lower()
        
        if mode != "input" and mode.lower() != "output":
            raise pkex.BasePyKatException("Mode must be either input or output")
        
        if mode == "input":
            return None
        elif mode == "output":
            return self._optivis_component.getOutputNode("out")
                
Daniel Brown's avatar
Daniel Brown committed
1250
    def getQGraphicsItem(self):
1251
1252
1253
        if not USE_GUI:
            raise NoGUIException
            
1254
        if self._svgItem is None:
Daniel Brown's avatar
Daniel Brown committed
1255
1256
1257
            self._svgItem = pykat.gui.graphics.ComponentQGraphicsItem(":/resources/laser.svg", self, [(65,25,self.nodes[0])])
            
        return self._svgItem
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316

class squeezer(Component):
    def __init__(self, name, node, f=0, db=0, angle=0, phase=0):
        Component.__init__(self,name)
        
        self._requested_node_names.append(node)
        
        self.__f = Param("f", self, SIfloat(f), canFsig=True, fsig_name="f")
        self.__phase = Param("phase", self, SIfloat(phase), canFsig=True, fsig_name="phase")
        self.__db = Param("db", self, SIfloat(db), canFsig=False, fsig_name="r")
        self.__angle = Param("angle", self, SIfloat(angle), canFsig=False, fsig_name="angle")
        self._svgItem = None
        
    @property
    def db(self): return self.__db
    @db.setter
    def db(self,value): self.__db.value = float(value)
    
    @property
    def angle(self): return self.__angle
    @angle.setter
    def angle(self,value): self.__angle.value = float(value)
    
    @property
    def f(self): return self.__f
    @f.setter
    def f(self,value): self.__f.value = float(value)
    
    @property
    def phase(self): return self.__phase
    @phase.setter
    def phase(self,value): self.__phase.value = float(value)
    
    def parseAttributes(self, values):
        pass
    
    @staticmethod
    def parseFinesseText(text):
        values = text.split()

        if values[0] != "sq":
            raise pkex.BasePyKatException("'{0}' not a valid Finesse squeezer command".format(text))

        values.pop(0) # remove initial value
        
        if len(values) == 5:
            return squeezer(values[0], values[4], f=values[1], db=values[2], angle=values[3])
        else:
            raise exceptions.FinesseParse("Squeezer Finesse code format incorrect '{0}'".format(text))
    
    def getFinesseText(self):
        rtn = ['sq {0} {1} {2} {3} {4}'.format(self.name, self.f.value, self.db.value, self.angle.value, self.nodes[0].name)]
        
        for p in self._params:
            rtn.extend(p.getFinesseText())
        
        return rtn
         
    def getQGraphicsItem(self):
1317
1318
1319
        if not USE_GUI:
            raise NoGUIException
            
1320
        if self._svgItem is None:
1321
1322
1323
            self._svgItem = pykat.gui.graphics.ComponentQGraphicsItem(":/resources/laser.svg", self, [(65,25,self.nodes[0])])
            
        return self._svgItem
Daniel Brown's avatar
Daniel Brown committed
1324
            
For faster browsing, not all history is shown. View entire blame