diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2019-06-17 16:03:12 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2019-06-17 16:03:12 +0200 |
commit | 071ca9989afa0cdfa29b95b026170b7aa9651f3d (patch) | |
tree | 7bcf2e01d9222262e70a92e039de46dd267e6aa6 /src | |
parent | 14262a97c7697a34430379ddbf1d6f5b12ef729f (diff) |
Arbitrary phase retarders
Diffstat (limited to 'src')
-rw-r--r-- | src/file.py | 4 | ||||
-rw-r--r-- | src/phys.py | 31 | ||||
-rw-r--r-- | src/ui_table.py | 28 | ||||
-rw-r--r-- | src/ui_widgets.py | 2 |
4 files changed, 23 insertions, 42 deletions
diff --git a/src/file.py b/src/file.py index 3c69063..225cee2 100644 --- a/src/file.py +++ b/src/file.py @@ -1,7 +1,7 @@ import re, sys, traceback, json import phys -file_format_version = 5 +file_format_version = 6 def save_system(path, system): ser = dict() @@ -12,7 +12,7 @@ def save_system(path, system): for pol in system.elements: el = { "name": pol.name, - "type": pol.type, + "phase_retardation": pol.phase_retardation, "enable": pol.enable, "angle": pol.angle, "delta": pol.delta, diff --git a/src/phys.py b/src/phys.py index c47a497..8065d14 100644 --- a/src/phys.py +++ b/src/phys.py @@ -63,44 +63,31 @@ class Ellipse: self.theta = np.arcsin(V[3] / R) / 2 class Polarizer: - def __init__(self, type, delta=0): + def __init__(self, delta=0): self.name = "New element" # FIXME - self.type = type + self.phase_retardation = 0 self.angle = 0 self.delta = delta self.ref = False self.t1 = 1 self.t2 = 0 self.enable = True - self.set_type(type) - - def set_type(self, type): - if type == "linear": - self.M = np.array([[1, 0], [0, 0]]) - elif type == "quarterwave": - self.M = np.exp(-1j / 4 * np.pi) * \ - np.array([[1, 0], [0, 1j]]) - else: - raise ValueError("bad Polarizer type: %s" % type) - self.type = type def mul(self, state): # unpolarized light if state is None: - if self.type == "linear": + if self.t2 == 0: # FIXME: this is half-assed return np.dot(R(-self.angle - self.delta), \ np.array([[1], [0]])) * np.sqrt(self.t1) else: return None - if type == "linear": - A = np.sqrt(np.array([[self.t1, 0], [0, self.t2]])) - else: - A = np.sqrt(np.array([[self.t1, 0], [0, self.t1]])) - - M = np.matmul(R(-self.angle - self.delta), \ - np.matmul(np.matmul(self.M, A), R(self.angle + self.delta))) - return np.dot(M, state) + # FIXME: half-assed again + A = np.sqrt(np.array([[self.t1, 0], [0, self.t2]])) + M = np.array([[1, 0], [0, np.exp(1j * self.phase_retardation),]]) + MR = np.matmul(R(-self.angle - self.delta), \ + np.matmul(np.matmul(M, A), R(self.angle + self.delta))) + return np.dot(MR, state) class System: def __init__(self): diff --git a/src/ui_table.py b/src/ui_table.py index 52a4171..bd02a90 100644 --- a/src/ui_table.py +++ b/src/ui_table.py @@ -45,16 +45,12 @@ class ElementEditorWindow(QMainWindow): self.name.textChanged.connect(self.change_name) box.addWidget(self.name) - # OPTICS - root.addWidget(MeinGroßLabel("Optics")) + # PHASE RETARDATION + root.addWidget(MeinGroßLabel("Phase retardation")) - # Type combo - self.type = QComboBox() - self.type.addItem("Linear", "linear",) - self.type.addItem("Quarterwave plate", "quarterwave") - self.type.setCurrentIndex(0 if self.pol.type == "linear" else 1) - self.type.currentIndexChanged.connect(self.change_type) - root.addWidget(self.type) + self.phase_retardation = AngleSlider() + self.phase_retardation.on_change = self.change_optics + root.addLayout(self.phase_retardation) # TRANSMITTANCE root.addWidget(MeinGroßLabel("Transmittance")) @@ -64,10 +60,10 @@ class ElementEditorWindow(QMainWindow): box.addWidget(QLabel("T")) self.t1 = QLineEdit("%g" % self.pol.t1) - self.t1.textChanged.connect(self.change_t) + self.t1.textChanged.connect(self.change_optics) box.addWidget(self.t1) self.t2 = QLineEdit("%g" % self.pol.t2) - self.t2.textChanged.connect(self.change_t) + self.t2.textChanged.connect(self.change_optics) box.addWidget(self.t2) # ARRANGEMENT @@ -95,10 +91,6 @@ class ElementEditorWindow(QMainWindow): self.pol.name = self.name.text() self.row.optbox.name.setText(self.pol.name) - def change_type(self): - self.pol.set_type(self.type.currentData()) - GUI.do_update() - def change_delta(self): try: self.pol.delta = self.delta.angle / 180 * np.pi @@ -106,10 +98,12 @@ class ElementEditorWindow(QMainWindow): except ValueError: pass - def change_t(self): + def change_optics(self): try: self.pol.t1 = float(self.t1.text()) self.pol.t2 = float(self.t2.text()) + self.pol.phase_retardation = \ + float(self.phase_retardation.angle) / 180 * np.pi GUI.do_update() except ValueError: pass @@ -294,7 +288,7 @@ class SystemTable(QTableWidget): i = 0 if before else len(self.rows) if pol is None: - pol = phys.Polarizer("linear") + pol = phys.Polarizer() editor = True else: editor = False diff --git a/src/ui_widgets.py b/src/ui_widgets.py index 42fda7c..07b0369 100644 --- a/src/ui_widgets.py +++ b/src/ui_widgets.py @@ -91,7 +91,7 @@ class EllipseWidget(QWidget): # polarizer axes P.translate(cx, cy) P.rotate(- (self.pol.angle + self.pol.delta) * 180 / np.pi) - if self.pol.type == "linear": + if self.pol.t2 == 0: # FIXME: half-assed P.setPen(Pens.axis_linear) P.drawLine(-20 * r, 0, 20 * r, 0) else: |