Skip to content
Snippets Groups Projects
Commit 855c482b authored by Daniel Brown's avatar Daniel Brown
Browse files

adding code so far

parents
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 27 10:02:41 2013
@author: Daniel
"""
import exceptions
from pykat.components import Component
from pykat.detectors import Detector
class NodeNetwork:
def __init__(self, kat):
self._nodes = {}
self.__kat = kat
def createNode(self, node_name):
if node_name == 'dump':
return DumpNode()
if node_name in self._nodes:
n = self._nodes[node_name]
return n
else:
n = Node(node_name)
self._nodes[node_name] = n
return n
def hasNode(self, name):
return (name in self._nodes)
def dumpInfo(self):
for name in self._nodes:
n = self._nodes[name]
items = n.getComponents()
comp = items[0][:]
det = items[1]
if comp[0] == None:
comp1 = 'dump'
else:
comp1 = comp[0].name
if comp[1] == None:
comp2 = 'dump'
else:
comp2 = comp[1].name
detectors = ""
if len(det) > 0:
detectors = "Detectors: "
for d in det:
detectors = detectors + d.name + " "
print "node: {0} connected:{1} {2}->{3} {4}".format(
n.name,n.isConnected(),comp1, comp2, detectors)
class Node:
def __init__(self, name):
self._comp1 = None
self._comp2 = None
self._detectors = []
self.__name = name
def isConnected(self):
return (self._comp1!=None) and (self._comp2!=None)
def connect(self, obj):
if not (isinstance(obj,Component) or isinstance(obj,Detector)):
raise exceptions.ValueError("Object is not a component or detector")
if isinstance(obj, Component):
if self._comp1 == None:
self._comp1 = obj
elif self._comp2 == None:
self._comp2 = obj
else:
raise exceptions.RuntimeError("Cannot attach {0} to node {1} as it is already connected: {2} and {3}".format(
obj.name, self.__name,self._comp1.name,self._comp2.name))
else:
# we must have a detector as we check above
self._detectors.append(obj)
def getComponents(self):
''' Returns a tuple with the first being the 2 components that
connect to the node. The second item is a list of the detectors at the
node'''
return [(self._comp1, self._comp2),self._detectors]
def __getname(self):
return self.__name
name = property(__getname)
class DumpNode(Node):
def __init__(self):
Node.__init__(self,'dump')
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 02 10:35:04 2013
@author: Daniel
"""
import numpy as np
import matplotlib
BACKEND = 'Qt4Agg'
matplotlib.use(BACKEND)
from matplotlib import rc
import matplotlib.pyplot as plt
from multiprocessing import Process
def plot1D(x,y,hdr, title=""):
plt.ion()
rc('font', **pp.font)
rc('xtick',labelsize=pp.TICK_SIZE)
rc('ytick',labelsize=pp.TICK_SIZE)
rc('text', usetex=pp.USETEX)
rc('axes', labelsize = pp.LABEL_SIZE)
fig=plt.figure()
fig.set_size_inches(pp.fig_size)
fig.set_dpi(pp.FIG_DPI)
#from itertools import cycle
#clist = matplotlib.rcParams['axes.color_cycle']
#colorcycler= cycle(clist)
ax1 = fig.add_subplot(111)
ax1.set_xlim(np.min(x),np.max(x))
traces = ax1.plot(x,y)
ax1.grid(pp.GRID)
if hdr != None:
ax1.set_xlabel(hdr[0])
legends = hdr[1:4]
ax1.legend(traces, legends, loc=0, shadow=pp.SHADOW,prop={'size':pp.LEGEND_SIZE})
if pp.PRINT_TITLE:
plt.title(title)
if pp.SCREEN_TITLE:
fig.canvas.manager.set_window_title(title)
else:
fig.canvas.manager.set_window_title('')
plt.show()
class pp():
# set some gobal settings first
BACKEND = 'Qt4Agg' # matplotlib backend
FIG_DPI=90 # DPI of on sceen plot
# Some help in calculating good figure size for Latex
# documents. Starting with plot size in pt,
# get this from LaTeX using \showthe\columnwidth
fig_width_pt = 484.0
inches_per_pt = 1.0/72.27 # Convert TeX pt to inches
golden_mean = (np.sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt # width in inches
fig_height = fig_width*golden_mean # height in inches
fig_size = [fig_width,fig_height]
# some plot options:
LINEWIDTH = 1 # linewidths of traces in plot
AA = True # antialiasing of traces
USETEX = False # use Latex encoding in text
SHADOW = False # shadow of legend box
GRID = True # grid on or off
# font sizes for normal text, tick labels and legend
FONT_SIZE = 10 # size of normal text
TICK_SIZE = 10 # size of tick labels
LABEL_SIZE = 10 # size of axes labels
LEGEND_SIZE = 10 # size of legend
# font family and type
font = {'family':'sans-serif','sans-serif':['Helvetica'],'size':FONT_SIZE}
DPI=300 # DPI for saving via savefig
# print options given to savefig command:
print_options = {'dpi':DPI, 'transparent':True, 'bbox_inches':'tight', 'pad_inches':0.1}
# for Palatino and other serif fonts use:
#font = {'family':'serif','serif':['Palatino']}
SCREEN_TITLE = True # show title on screen?
PRINT_TITLE = False # show title in saved file?
\ No newline at end of file
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 2001, in main
mainwindow = run_spyder(app, options)
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 1913, in run_spyder
main.setup()
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 649, in setup
self.workingdirectory = WorkingDirectory(self, self.init_workdir)
File "C:\Python27\lib\site-packages\spyderlib\plugins\workingdirectory.py", line 207, in __init__
self.chdir(workdir)
File "C:\Python27\lib\site-packages\spyderlib\plugins\workingdirectory.py", line 334, in chdir
self.refresh_plugin()
File "C:\Python27\lib\site-packages\spyderlib\plugins\workingdirectory.py", line 258, in refresh_plugin
self.save_wdhistory()
File "C:\Python27\lib\site-packages\spyderlib\plugins\workingdirectory.py", line 289, in save_wdhistory
encoding.writelines(text, self.LOG_PATH)
File "C:\Python27\lib\site-packages\spyderlib\utils\encoding.py", line 200, in writelines
return write(os.linesep.join(lines), filename, encoding, mode)
File "C:\Python27\lib\site-packages\spyderlib\utils\encoding.py", line 191, in write
with open(filename, mode) as textfile:
IOError: [Errno 22] invalid mode ('wb') or filename: u'C:\\Users\\Daniel\\.spyder2\\.workingdir'
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 28 12:00:29 2013
@author: Daniel
"""
class Scale:
linear = 'lin'
logarithmic = 'log'
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 02 12:17:50 2013
@author: Daniel
"""
from pykat.components import *
def isSpace(obj):
if obj == None:
return False
else:
return isinstance(obj,space)
\ No newline at end of file
#!/usr/bin/env python
"""Finesse file for plotting test.out, Sat Feb 2 09:25:00 2013 """
"""-----------------------------------------------------------------
- Run from command line as: python test.py
- Load from python script as: impoty test
And then use:
test.run() for plotting only
x,y=test.run() for plotting and loading the data
x,y=test.run(1) for only loading the data
-----------------------------------------------------------------"""
__author__ = "Finesse, http://www.gwoptics.org/finesse"
import numpy as np
import matplotlib
BACKEND = 'Qt4Agg'
matplotlib.use(BACKEND)
from matplotlib import rc
import matplotlib.pyplot as plt
def run(noplot=None):
data = np.loadtxt('test.out',comments='%')
rows,cols=data.shape
x=data[:,0]
y=data[:,1:cols]
mytitle='test Sat Feb 2 09:25:00 2013'
if (noplot==None):
# setting default font sizes
rc('font',**pp.font)
rc('xtick',labelsize=pp.TICK_SIZE)
rc('ytick',labelsize=pp.TICK_SIZE)
rc('text', usetex=pp.USETEX)
rc('axes', labelsize = pp.LABEL_SIZE)
fig=plt.figure()
fig.set_size_inches(pp.fig_size)
fig.set_dpi(pp.FIG_DPI)
from itertools import cycle
clist = matplotlib.rcParams['axes.color_cycle']
colorcycler= cycle(clist)
ax1 = fig.add_subplot(111)
ax1.set_xlim(0,360)
ax1.set_xlabel('phi [deg] (m2)')
trace1=ax1.plot(x, y[:,0], '-', color = next(colorcycler), label = 'pd2 n5 : ')
trace2=ax1.plot(x, y[:,1], '-', color = next(colorcycler), label = 'pd1 n4 : ')
traces = trace1 + trace2
legends = [t.get_label() for t in traces]
ax1.legend(traces, legends, loc=0, shadow=pp.SHADOW,prop={'size':pp.LEGEND_SIZE})
ax1.grid(pp.GRID)
if pp.PRINT_TITLE:
plt.title(mytitle)
if pp.SCREEN_TITLE:
fig.canvas.manager.set_window_title(mytitle)
else:
fig.canvas.manager.set_window_title('')
return (x,y)
class pp():
# set some gobal settings first
BACKEND = 'Qt4Agg' # matplotlib backend
FIG_DPI=90 # DPI of on sceen plot
# Some help in calculating good figure size for Latex
# documents. Starting with plot size in pt,
# get this from LaTeX using \showthe\columnwidth
fig_width_pt = 484.0
inches_per_pt = 1.0/72.27 # Convert TeX pt to inches
golden_mean = (np.sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt # width in inches
fig_height = fig_width*golden_mean # height in inches
fig_size = [fig_width,fig_height]
# some plot options:
LINEWIDTH = 1 # linewidths of traces in plot
AA = True # antialiasing of traces
USETEX = False # use Latex encoding in text
SHADOW = False # shadow of legend box
GRID = True # grid on or off
# font sizes for normal text, tick labels and legend
FONT_SIZE = 10 # size of normal text
TICK_SIZE = 10 # size of tick labels
LABEL_SIZE = 10 # size of axes labels
LEGEND_SIZE = 10 # size of legend
# font family and type
font = {'family':'sans-serif','sans-serif':['Helvetica'],'size':FONT_SIZE}
DPI=300 # DPI for saving via savefig
# print options given to savefig command:
print_options = {'dpi':DPI, 'transparent':True, 'bbox_inches':'tight', 'pad_inches':0.1}
# for Palatino and other serif fonts use:
#font = {'family':'serif','serif':['Palatino']}
SCREEN_TITLE = True # show title on screen?
PRINT_TITLE = False # show title in saved file?
if __name__=="__main__":
run()
import sys
sys.path.append('../')
from pykat import finesse
from pykat.detectors import *
from pykat.components import *
from pykat.commands import *
from pykat.structs import *
from pykat.plotting import *
kat = finesse.kat()
laser(kat,'l1','n1',1)
space(kat,'s1','n1','n2',1)
mirror(kat,'m1','n2','n3',0.8,0.2)
space(kat,'s2','n3','n4',1)
mirror(kat,'m2','n4','n5',0.7,0.3)
photodiode(kat,'pd_cav','n4')
photodiode(kat,'pd_ref','n2')
photodiode(kat,'pd_trs','n5')
xaxis(kat, Scale.linear, [0,1e-6], kat.m2, kat.m2.xbeta, 100)
kat.maxtem = 1
[x,y_0,hdr] = kat.run(printout=0,printerr=0)
plot1D(x,y,hdr)
setup.py 0 → 100644
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 27 09:43:16 2013
@author: Daniel
"""
from distutils.core import setup
setup(
name='PyKat',
version='0.0.1',
author='Daniel Brown',
author_email='danielbrown87@gmail.com',
packages=['pykat'],
url='http://www.gwoptics.org/pykat',
license='LICENSE.txt',
description='Python interface and tools for FINESSE',
long_description=open('README.txt').read(),
install_requires=[
],
)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment