Commit 6816af56 authored by Michele Valentini's avatar Michele Valentini

Merge branch 'master' of git.ligo.org:finesse/pykat

parents 003845bb 3b286d5c
v0.0, 23/07/2013 -- Initial release.
\ No newline at end of file
PyKat-1.1.297
Adding in A+ model and files
pykat.ifo plot_strain_sensitivity now returns the kat object that it runs to get the plot
Plotting is now done using Matplotlib styles now
Pykat can be run without having Finesse installed now
\ No newline at end of file
This diff is collapsed.
......@@ -22,6 +22,7 @@ import six
########################
# Global helper functions
isContainer = lambda c: (not isinstance(c, six.string_types)) and hasattr(c, "__iter__")
is_container = lambda c: (not isinstance(c, six.string_types)) and hasattr(c, "__iter__")
########################
import imp
......@@ -49,17 +50,19 @@ from pykat.style import use as set_plot_style
from .SIfloat import SIfloat
msg = "Could not find the finesse executable 'kat'" \
"or you do not have the permissions to run it."
class nokat(object):
def __getattribute__(self, attr):
warn(msg)
try:
kat = finesse.kat()
v = kat.finesse_version()
except pkex.MissingFinesse:
from warnings import warn
msg = "Could not find the finesse executable 'kat'" \
"or you do not have the permissions to run it."
warn(msg)
class nokat(object):
def __getattribute__(self, attr):
warn(msg)
kat = nokat()
v = str(__min_req_finesse__)
if float(v.split('-')[0]) < __min_req_finesse__:
......@@ -67,6 +70,16 @@ if float(v.split('-')[0]) < __min_req_finesse__:
str(__min_req_finesse__),
v))
def info():
print("Pykat version: " + __version__)
print("Pykat loaded from: " + __file__)
if kat != nokat():
print("Finesse version: " + str(v))
print("Finesse loaded from: " + str(kat._finesse_exec()))
else:
print("Finesse could not be initialised")
SI = {'yocto': 1E-24, # yocto
'zepto': 1E-21, # zepto
'atto': 1E-18, # atto
......
......@@ -343,7 +343,8 @@ class cavity(Command):
base: The kat object to do the tracing with
"""
kat = self._kat.deepcopy()
kat.maxtem = 0 # always need a maxtem
for cav in kat.getAll(pykat.commands.cavity):
if self.name != cav.name:
cav.remove()
......@@ -357,7 +358,7 @@ class cavity(Command):
kat.parse("pd p %s" % self.__n1)
_, T = kat.run(getTraceData=True)
qx, qy, _ = T[0][node]
qx, qy, _ = T[0][str(node)]
return qx, qy
......
......@@ -479,17 +479,6 @@ class KatRun(object):
if yaxis is not None:
kat.yaxis = yaxis
if "log" in kat.yaxis:
if kat.xaxis.scale == "log":
plot_cmd = pyplot.loglog
else:
plot_cmd = pyplot.semilogy
else:
if kat.xaxis.scale == "log":
plot_cmd = pyplot.semilogx
else:
plot_cmd = pyplot.plot
dual_plot = False
_func1 = np.abs
_func2 = None
......@@ -497,20 +486,43 @@ class KatRun(object):
plot_cmd1 = None
plot_cmd2 = None
if "re:im" in kat.yaxis or "abs:deg" in kat.yaxis or "db:deg" in kat.yaxis:
dual_plot = True
if dual_plot:
fig = plt.figure(width="full", height=1)
ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2)
else:
fig = plt.figure(width="full")
ax1 = fig.add_subplot(1, 1, 1)
ax2 = ax1
if "log" in kat.yaxis:
if kat.xaxis.scale == "log":
plot_cmd1 = ax1.loglog
plot_cmd2 = ax2.loglog
else:
plot_cmd1 = ax1.semilogy
plot_cmd2 = ax2.semilogy
else:
if kat.xaxis.scale == "log":
plot_cmd1 = ax1.semilogx
plot_cmd2 = ax2.semilogx
else:
plot_cmd1 = ax1.plot
plot_cmd2 = ax2.plot
if "re:im" in kat.yaxis:
_func1 = np.real
_func2 = np.imag
plot_cmd1 = plot_cmd2 = plot_cmd
dual_plot = True
elif "abs:deg" in kat.yaxis:
_func1 = np.abs
_func2 = lambda x: np.rad2deg(np.angle(x))
plot_cmd1 = plot_cmd
plot_cmd2 = pyplot.plot if kat.xaxis.scale == "lin" else pyplot.semilogx
plot_cmd2 = ax2.plot if kat.xaxis.scale == "lin" else ax2.semilogx
dual_plot = True
elif "db:deg" in kat.yaxis:
if "db" not in original_yaxis:
_func1 = lambda x: 10*np.log10(x)
......@@ -519,33 +531,24 @@ class KatRun(object):
_func2 = lambda x: np.rad2deg(np.angle(x))
plot_cmd1 = plot_cmd
plot_cmd2 = pyplot.plot if kat.xaxis.scale == "lin" else pyplot.semilogx
plot_cmd2 = ax2.plot if kat.xaxis.scale == "lin" else ax2.semilogx
dual_plot = True
elif "abs" in kat.yaxis:
# _func1 = np.abs
_func1 = np.real
plot_cmd1 = plot_cmd
elif "db" in kat.yaxis:
if "db" not in original_yaxis:
_func1 = lambda x: 10*np.log10(x)
else:
_func1 = lambda x: x
plot_cmd1 = plot_cmd
elif "deg" in kat.yaxis:
_func1 = lambda x: np.rad2deg(np.angle(x))
plot_cmd1 = plot_cmd
if dual_plot:
fig = plt.figure(width="full", height=1)
else:
fig = plt.figure(width="full")
if detectors is None:
detectors = [lbl.split()[0] for lbl in self.ylabels]
detectors = list(set(detectors))
detectors.sort()
......@@ -553,17 +556,12 @@ class KatRun(object):
for det in detectors:
if not hasattr(kat, det) or (hasattr(kat, det) and not getattr(kat, det).noplot):
if dual_plot:
ax = pyplot.subplot(2,1,1)
if styles is not None and det in styles:
l, = plot_cmd1(_x, _func1(self[det])/pykat.SI[y1scale], styles[det], label=det)
else:
l, = plot_cmd1(_x, _func1(self[det])/pykat.SI[y1scale], label=det)
if dual_plot:
pyplot.subplot(2,1,2)
plot_cmd2(_x, _func2(self[det])/pykat.SI[y2scale], color=l.get_color(), ls=l.get_linestyle(), label=det)
if dual_plot:
......@@ -598,33 +596,33 @@ class KatRun(object):
font_label_size = pyplot.rcParams["font.size"]-1
if dual_plot:
ax = pyplot.subplot(2,1,1)
pyplot.xlabel(xlabel, fontsize=font_label_size)
pyplot.ylabel(ylabel, fontsize=font_label_size)
pyplot.xlim(xlim[0], xlim[1])
#ax = plt.subplot(2,1,1)
ax1.set_xlabel(xlabel, fontsize=font_label_size)
ax1.set_ylabel(ylabel, fontsize=font_label_size)
ax1.set_xlim(xlim[0], xlim[1])
if ylim is not None:
pyplot.ylim(ylim[0],ylim[1])
ax1.set_ylim(ylim[0],ylim[1])
if title is not None:
pyplot.title(title, fontsize=font_label_size)
ax1.set_title(title, fontsize=font_label_size)
pyplot.subplot(2,1,2)
pyplot.xlabel(x2label, fontsize=font_label_size)
pyplot.ylabel(y2label, fontsize=font_label_size)
#plt.subplot(2,1,2)
ax2.set_xlabel(x2label, fontsize=font_label_size)
ax2.set_ylabel(y2label, fontsize=font_label_size)
pyplot.xlim(x2lim[0], x2lim[1])
ax2.set_xlim(x2lim[0], x2lim[1])
if y2lim is not None:
pyplot.ylim(y2lim[0],y2lim[1])
ax2.set_ylim(y2lim[0],y2lim[1])
else:
pyplot.xlabel(xlabel, fontsize=font_label_size)
pyplot.ylabel(ylabel)
pyplot.xlim(xlim[0], xlim[1])
ax1.set_xlabel(xlabel, fontsize=font_label_size)
ax1.set_ylabel(ylabel)
ax1.set_xlim(xlim[0], xlim[1])
if title is not None:
pyplot.title(title, fontsize=font_label_size)
ax1.set_title(title, fontsize=font_label_size)
if ylim is not None:
pyplot.ylim(ylim[0],ylim[1])
ax1.set_ylim(ylim[0],ylim[1])
pyplot.margins(0, 0.05)
pyplot.tight_layout()
......
This diff is collapsed.
......@@ -749,22 +749,11 @@ def make_kat(name="design", katfile=None, verbose = False, debug=False, use_RF_D
The `name` argument selects from default aLIGO files included in Pykat:
- design: A file based on the design parameters for the final aLIGO setup.
125W input, T_SRM = 20%.
- design_low_power: A file based on the design parameters for the final aLIGO setup.
20W input, T_SRM = 35%. The higher SRM transmission mirror is used for low power
operation. 20W input power from O1 observation.
- design_with_IMC_HAM2: A file based on `design` but has the IMC and HAM2 blocks
which contain design parameter input optics
- design_with_IMC_HAM2_FI_OMC: A file with the OMC and IMC, most complete file
keepComments: If true it will keep the original comments from the file
preserveComments: If true it will keep the const commands in the kat
"""
names = ['design', 'design_low_power', 'design_with_IMC_HAM2', 'design_with_IMC_HAM2_FI_OMC']
names = ['design']
if debug:
kat = finesse.kat(tempdir=".",tempname="test")
......@@ -834,13 +823,15 @@ def make_kat(name="design", katfile=None, verbose = False, debug=False, use_RF_D
# If we don't have an OMC then we need to attach
# directly to the AS node. Otherwise use OMC refl
if "OMC" in kat.getBlocks():
nAS_RF = ["nOMC_ICb","nAS"] # Output() class accepts list of node names and match to the first one it finds
alt_nAS = "nAS"
nAS_RF = "nOMC_ICb"
else:
alt_nAS = None
nAS_RF = "nAS"
kat.IFO.AS_f1 = Output(kat.IFO, "AS_f1", nAS_RF, "f1", phase=101)
kat.IFO.AS_f2 = Output(kat.IFO, "AS_f2", nAS_RF, "f2", phase=14)
kat.IFO.AS_f36 = Output(kat.IFO, "AS_f36", nAS_RF, "f36M", phase=14)
kat.IFO.AS_f1 = Output(kat.IFO, "AS_f1", nAS_RF, "f1", phase=101, alternate_node_name=alt_nAS)
kat.IFO.AS_f2 = Output(kat.IFO, "AS_f2", nAS_RF, "f2", phase=14, alternate_node_name=alt_nAS)
kat.IFO.AS_f36 = Output(kat.IFO, "AS_f36", nAS_RF, "f36M", phase=14, alternate_node_name=alt_nAS)
kat.IFO.AS_DC = Output(kat.IFO, "AS_DC", "nAS")
kat.IFO.POW_BS = Output(kat.IFO, "PowBS", "nPRBS*")
......@@ -1126,62 +1117,6 @@ def pretune_SRCL(_kat, verbose=False, debug=False):
deg = (out.x[SRCL_metric.argmin()] % 360) - 180
IFO.preSRCL.apply_tuning(-deg)
def setup(base, old=True, DC_offset_pm=20, verbose=False):
"""
Runs a preparation routine to produce a LIGO model at a resonable operating point.
This uses the pretune2 and pretune_SRCL methods which allow you
"""
assert_aligo_ifo_kat(base)
base = base.deepcopy()
base.verbose = False
base.removeBlock('locks', False)
base.removeBlock('errsigs', False)
base.removeBlock('powers', False)
base.phase = 2
base.IFO.fix_mirrors()
kat = base.deepcopy()
kat.IFO.remove_modulators()
if old:
pretune(kat,pretune_precision=1e-3, verbose=verbose)
else:
pretune_2(kat, pretune_precision=1e-3, verbose=verbose)
# Apply the tunings to our base kat file
base.IFO.apply_tunings(kat.IFO.get_tunings())
base.IFO.adjust_PRC_length(verbose=verbose)
if verbose:
pretune_status(base)
base.IFO.lengths_status()
# Set DC offset and plot
DCoffset = DC_offset_pm*1e-12 / base.lambda0 * 180.0
base.IFO.set_DC_offset(DCoffset=DCoffset, verbose=verbose)
if not old:
pretune_SRCL(base, verbose=verbose)
errsigs_cmds = base.IFO.add_errsigs_block()
# Generates a dictionary of the lock values to use
locks = generate_locks(base, verbose=verbose)
# Takes these values and then generates the commands and adds them to
# the lock block of the kat
lock_cmds = base.IFO.add_locks_block(locks, verbose=verbose)
base.SRCL_lock.accuracy /= 10
return base
......@@ -1204,7 +1139,7 @@ def pretune_status(_kat):
tunings = kat.IFO.get_tunings()
if tunings['keys']["maxtem"] == -1:
if tunings['keys']["maxtem"] is None or tunings['keys']["maxtem"] == -1:
_maxtemStr="off"
else:
_maxtemStr = "{:3}".format(tunings['keys']["maxtem"])
......@@ -1358,7 +1293,7 @@ def generate_locks(kat, gainsAdjustment = [0.5, 0.005, 1.0, 0.5, 0.025],
return data
def setup(base, DC_offset_pm=20, verbose=False, debug=False):
def setup(_base, DC_offset_pm=20, verbose=False, debug=False):
"""
Runs a preparation routine to produce a LIGO model at a resonable operating point.
......@@ -1371,9 +1306,9 @@ def setup(base, DC_offset_pm=20, verbose=False, debug=False):
# Will change later when this works with the
old = True
assert_aligo_ifo_kat(base)
assert_aligo_ifo_kat(_base)
base = base.deepcopy()
base = _base.deepcopy()
base.verbose = False
base.removeBlock('locks', False)
......@@ -1399,6 +1334,7 @@ def setup(base, DC_offset_pm=20, verbose=False, debug=False):
if not old:
_pretune_PRCL(base, verbose=verbose, debug=debug)
# Set DC offset
DCoffset = DC_offset_pm*1e-12 / base.lambda0 * 180.0
base.IFO.set_DC_offset(DCoffset=DCoffset, verbose=verbose)
......@@ -1418,4 +1354,4 @@ def setup(base, DC_offset_pm=20, verbose=False, debug=False):
#the lock block of the kat
lock_cmds = base.IFO.add_locks_block(locks, verbose=verbose)
return base
\ No newline at end of file
return base
This diff is collapsed.
At the time of writing:
design_with_IMC_HAM2_FI_OMC.kat
and
design.kat
are identical. We keep the former for
backwards compatibility with some
examples. Please change/use only
design.kat in the future.
Andreas Freise, 21/11/2018
This diff is collapsed.
This diff is collapsed.
These files were moved here for reference on 21/11/2018
- design: A file based on the design parameters for the final aLIGO setup.
125W input, T_SRM = 20%
- design_low_power: A file based on the design parameters for the final aLIGO setup.
20W input, T_SRM = 35%. The higher SRM transmission mirror is used for low power
operation. 20W input power from O1 observation.
- design_with_IMC_HAM2: A file based on `design` but has the IMC and HAM2 blocks
which contain design parameter input optics
- design_with_IMC_HAM2_FI_OMC: A file with the OMC and IMC, most complete file
The file 'design_with_IMC_HAM2_FI_OMC' has now been renamed design.kat in the
aligo/files folder.
......@@ -404,11 +404,11 @@ def strain_sensitivity(base,lower=10,upper=5000,steps=100, ax=None, plot_cmds={}
kat.parse(kat.IFO.DARM_h.transfer())
if kat.IFO.DARM_h.port.f is None:
kat.parse("qnoisedS NSR 1 $fs {node}".format(node=kat.IFO.DARM_h.port.nodeName))
kat.parse("qnoisedS NSR 1 $fs {node}".format(node=kat.IFO.DARM_h.port.nodeName[0]))
else:
kat.parse("qnoisedS NSR 2 {f} {phi} $fs {node}".format(f=kat.IFO.DARM_h.port.f,
phi=kat.IFO.DARM_h.port.phase,
node=kat.IFO.DARM_h.port.nodeName))
node=kat.IFO.DARM_h.port.nodeName[0]))
if ax is None:
ax = plt.subplot(111)
......@@ -423,3 +423,5 @@ def strain_sensitivity(base,lower=10,upper=5000,steps=100, ax=None, plot_cmds={}
if ax is None:
plt.gcf().tight_layout()
plt.show()
return kat
from .aplus import *
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -8,6 +8,7 @@ style_dir = os.path.split(os.path.realpath(__file__))[0]
available = [os.path.splitext(f)[0]
for f in os.listdir(style_dir) if f.endswith(".mplstyle")]
def get_style_path(style):
if isinstance(style, str) or hasattr(style, 'keys'):
# If name is a single str or dict, make it a single element list.
......@@ -18,10 +19,12 @@ def get_style_path(style):
styles))
return styles
def use(style):
import matplotlib.pyplot as plt
plt.style.use(get_style_path(style))
def context(style, after_reset=False):
import matplotlib.pyplot as plt
return plt.style.context(get_style_path(style), after_reset)
......@@ -3,15 +3,18 @@ patch.facecolor: r
# FONT
font.size : 11
font.family : serif
# TEXT
text.usetex : False
# AXES
axes.grid : True
axes.formatter.useoffset : True
axes.formatter.useoffset : False
axes.formatter.use_locale : False
axes.prop_cycle: cycler('color', ['0000FF', 'FF0000', '000000', '00FF00', 'FF00FF'])
axes.prop_cycle : cycler('color', ['0000FF', 'FF0000', '000000', '00FF00', 'FF00FF'])
axes.axisbelow : True
axes.xmargin : 0
#TICKS
xtick.labelsize : 9
......@@ -27,6 +30,9 @@ figure.titlesize : 12
figure.figsize : 6, 3.708
figure.dpi : 96
# LINES
lines.linewidth : 1.2
# IMAGES
image.cmap : magma
image.origin : lower
......@@ -34,6 +40,7 @@ image.origin : lower
# SAVING FIGURES
savefig.dpi : 300
savefig.bbox : tight
savefig.pad_inches : 0.05
pdf.compression : 9
pdf.fonttype : 42
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment