Commit eb03fce5 authored by Daniel Brown's avatar Daniel Brown
Browse files

KatRun.plot now accepts xscale, y1scale, and y2scale. These should be an SI...

KatRun.plot now accepts xscale, y1scale, and y2scale. These should be an SI scaling from the pykat.SI dictionary. e.g. `xscale='milli'`

Hopefully fixing bug reported in `pykat.optics.maps.rmZernike` where `m='all'` was not being processed correctly. Problems with if statements not handling all cases and leading to undefined variables along with type checking issues.
parent a692eeb0
......@@ -1503,7 +1503,7 @@ class modulator(Component):
def type(self): return self.__type
@type.setter
def type(self, value):
accepted = ["am", "pm", "yaw", "pitch"]
accepted = ["am", "pm", "yaw", "pitch", "w0", 'z']
if value not in accepted:
raise pkex.BasePyKatException("Modulator type must be: " + ", ".join(accepted))
......
......@@ -430,7 +430,8 @@ class KatRun(object):
def plot(self, detectors=None, filename=None, show=True,
yaxis=None, legend=True, loc=0, title=None, styles=None,
ylabel=None, y2label=None, xlabel=None, x2label=None,
xlim=None, x2lim=None, ylim=None, y2lim=None, return_fig=False):
xlim=None, x2lim=None, ylim=None, y2lim=None, return_fig=False,
xscale=None, y1scale=None, y2scale=None):
"""
This will generate a plot for the output data of this particular pykat run.
It will attempt to generate a plot that shows all the various traces and plots
......@@ -457,6 +458,8 @@ class KatRun(object):
of length 2.
x2lim, y2lim: Limits of x- and y-axes of the second plot. List or tuple
of length 2.
xscale, y1scale SI scale either axes. See pykat.SI dictionary for possible
y2scale: values
"""
import matplotlib.pyplot as pyplot
import pykat.plotting as plt
......@@ -546,6 +549,8 @@ class KatRun(object):
detectors = list(set(detectors))
detectors.sort()
_x = self.x/pykat.SI[xscale]
for det in detectors:
if not hasattr(kat, det) or (hasattr(kat, det) and not getattr(kat, det).noplot):
......@@ -553,13 +558,13 @@ class KatRun(object):
ax = pyplot.subplot(2,1,1)
if styles is not None and det in styles:
l, = plot_cmd1(self.x, _func1(self[det]), styles[det], label=det)
l, = plot_cmd1(_x, _func1(self[det])/pykat.SI[y1scale], styles[det], label=det)
else:
l, = plot_cmd1(self.x, _func1(self[det]), label=det)
l, = plot_cmd1(_x, _func1(self[det])/pykat.SI[y1scale], label=det)
if dual_plot:
pyplot.subplot(2,1,2)
plot_cmd2(self.x, _func2(self[det]), color=l.get_color(), ls=l.get_linestyle(), label=det)
plot_cmd2(_x, _func2(self[det])/pykat.SI[y2scale], color=l.get_color(), ls=l.get_linestyle(), label=det)
if dual_plot:
if ylabel is None:
......@@ -571,17 +576,17 @@ class KatRun(object):
if "im" in kat.yaxis: y2label = "Imaginary part [au]"
if xlim is None:
xlim = (self.x.min(), self.x.max())
xlim = (_x.min(), _x.max())
if x2lim is None:
x2lim = (self.x.min(), self.x.max())
x2lim = (_x.min(), _x.max())
else:
if ylabel is None:
ylabel = "[au]"
if xlim is None:
xlim = (self.x.min(), self.x.max())
xlim = (_x.min(), _x.max())
if xlabel is None:
......@@ -614,7 +619,7 @@ class KatRun(object):
else:
pyplot.xlabel(xlabel, fontsize=font_label_size)
pyplot.ylabel(ylabel)
pyplot.xlim(self.x.min(), self.x.max())
pyplot.xlim(xlim[0], xlim[1])
if title is not None:
pyplot.title(title, fontsize=font_label_size)
......
......@@ -1233,6 +1233,21 @@ class IFO(object):
return dofs
def update(self):
"""
Iterates through the IFO and updates the DOFs and Outputs dictionaries with the latest ports and DOFs that have
been added to the interferometer object.
"""
self.DOFs = {}
for _ in inspect.getmembers(self, lambda x: isinstance(x, DOF)):
self.DOFs[_[0]] = _[1]
self.Outputs = {}
for _ in inspect.getmembers(self, lambda x: isinstance(x, Output)):
self.Outputs[_[0]] = _[1]
def sensing_matrix(self, DOFs, detectors, frequency=1):
"""
Computes a sensing matrix for a collection of DOFs and
......
......@@ -646,6 +646,8 @@ class surfacemap(object):
elif isinstance(m,int):
nVals = range(n,n+1)
mVals.append(range(m,m+1))
else:
raise Exception("Unhandled `m` argument: %s" % m)
# Amplitudes
A = []
......@@ -1410,9 +1412,9 @@ class surfacemap(object):
Returns: A
A - List of amplitudes of the removed Zernike polynomials.
'''
if m=='all':
m = range(-n,n+1,2)
if m == 'all':
m = list(range(-n,n+1,2))
R = self.find_radius(unit='meters')
A = self.zernikeConvol(n,m)
rho, phi= self.createPolarGrid()
......@@ -1423,15 +1425,11 @@ class surfacemap(object):
Z = zernike(m[k], n, rho, phi)
self.data[self.notNan] = self.data[self.notNan]-A[k]*Z[self.notNan]
self.zernikeRemoved = (m[k], n, A[k])
# elif isinstance(m, range):
# for k in range(len(m)):
# Z = zernike(m[k], n, rho, phi)
# self.data[self.notNan] = self.data[self.notNan]-A[k]*Z[self.notNan]
# self.zernikeRemoved = (m[k], n, A[k])
else:
Z = zernike(m, n, rho, phi)
self.data[self.notNan] = self.data[self.notNan]-A*Z[self.notNan]
self.zernikeRemoved = (m, n, A)
return A
class mergedmap:
......
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