diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml.old similarity index 100% rename from .gitlab-ci.yml rename to .gitlab-ci.yml.old diff --git a/pykat/__init__.py b/pykat/__init__.py index 1474e2085f64e36af0c16e10995e65b851a2fd58..8a0e7e0e626da26c301db730b57531a35868b51d 100644 --- a/pykat/__init__.py +++ b/pykat/__init__.py @@ -8,6 +8,7 @@ __version__ = "1.0.8" # This flag is used to switch on the gui features in pkat at import time USE_GUI = False HAS_OPTIVIS = False +HAS_GRAPHVIZ = False import imp @@ -17,6 +18,13 @@ try: except ImportError: HAS_OPTIVIS = False +try: + imp.find_module('pygraphviz') + HAS_GRAPHVIZ = True +except ImportError: + HAS_GRAPHVIZ = False + + import pykat.exceptions as pkex NoGUIException = pkex.BasePyKatException("No PyQt4 module was found so cannot open a GUI") diff --git a/pykat/finesse.py b/pykat/finesse.py index 5f9dd62a4a5a210522a13916da813be0bdea4ebd..959a7f760fc0df525048d8bfdb62cb8a8b4517e2 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -91,7 +91,7 @@ import pykat.external.six as six import pykat.exceptions as pkex -from pykat import USE_GUI, HAS_OPTIVIS, NoGUIException +from pykat import USE_GUI, HAS_OPTIVIS, HAS_GRAPHVIZ, NoGUIException if HAS_OPTIVIS: @@ -277,14 +277,22 @@ class katRun(object): import numpy as np - maxs = np.max(self.y, 0) - mins = np.min(self.y, 0) - - maxlbl = max([len(lbl) for lbl in self.ylabels]) - + imaxs = np.argmax(self.y, 0) + imins = np.argmin(self.y, 0) + + maxs = self.y[imaxs, np.arange(self.y.shape[1])] + mins = self.y[imins, np.arange(self.y.shape[1])] + if not kat.noxaxis: + xmaxs = self.x[imaxs] + xmins = self.x[imins] + else: + xmaxs = np.zeros(self.y.size) + xmins = xmaxs + + maxlbl = max([len(lbl) for lbl in self.ylabels]) for i, lbl in enumerate(self.ylabels): - a = "{0:" + str(maxlbl) + "} : min = {1:.15e} max = {2:.15e}" - print(a.format(lbl, mins[i], maxs[i])) + a = "{0:" + str(maxlbl) + "}: min = {1:.15e} @ {2:.15e},\n\tmax = {3:.15e} @ {4:.15e}" + print(a.format(lbl, mins[i], xmins[i], maxs[i], xmaxs[i])) def plot(self, detectors=None, filename=None, show=True, @@ -1679,7 +1687,8 @@ class kat(object): qx = spqx[0].split("=")[1].replace('i','j').replace(' ','') qy = spqy[0].split("=")[1].replace('i','j').replace(' ','') - traceData[-1][node_name] = (pykat.beam_param(q=complex(qx)), pykat.beam_param(q=complex(qy))) + traceData[-1][node_name] = (pykat.beam_param(q=complex(qx),wavelength=self.lambda0), + pykat.beam_param(q=complex(qy),wavelength=self.lambda0)) finally: ifile.close() @@ -2154,6 +2163,57 @@ class kat(object): return out + def nodeGraph(self, output): + """ + nodeGraph(output) + + Generate node visualisation of pykat node network using the + pygraphviz package. The generated graphics is saved in output, where the + output format is determined from the file extension. The exact formats + available depend on how graphviz was built, but generally .pdf and .png + should work. + """ + if not HAS_GRAPHVIZ: + print('pygraphviz is not installed.') + return + + import pygraphviz as pgv + + def add_kat_node(G, from_id, node): + color = 'black' if node.name == 'dump' else 'red' + G.add_node(node.id, label='', xlabel=node.name, width=0.2, + shape='point', fontsize=11, color=color) + G.add_edge(from_id, node.id) + + G = pgv.AGraph(strict=False) + G.graph_attr['label'] = 'Created by PyKat' + G.graph_attr['pencolor'] = 'black' + G.node_attr['style'] = 'filled' + G.node_attr['fontname'] = 'helvetica' + + # add components and associated nodes + for comp in self.components.itervalues(): + if isinstance(comp, pykat.components.laser): + attr = {'fillcolor': 'Orange', 'shape': 'box'} + elif isinstance(comp, pykat.components.space): + attr = {'fillcolor': 'MediumSlateBlue', 'shape': 'diamond'} + else: + attr = {'fillcolor': 'LightSkyBlue', 'shape': 'box'} + G.add_node(comp.name, **attr) + for node in comp.nodes: + add_kat_node(G, comp.name, node) + + # add detectors and associated nodes + for det in self.detectors.itervalues(): + # slightly ugly, but unfortunately detectors don't have the .nodes + # property like components do. + if len(det._nodes) > 0: + G.add_node(det.name, fillcolor='YellowGreen', shape='ellipse') + for node in det._nodes: + add_kat_node(G, det.name, node) + + G.draw(output, prog='neato') + def optivis(self): if not HAS_OPTIVIS: print("Optivis is not installed")