Commit c3188628 authored by Daniel Brown's avatar Daniel Brown

Merge branch 'master' into 'master'

Some updates to fix a few bugs in the adv virgo ifo classes

See merge request finesse/pykat!4
parents 337cc1fb 6816af56
......@@ -773,23 +773,33 @@ def c2r_errsig(z, phase):
return np.real(z*np.exp(-1j*phase*np.pi/180.0))
def isCavsStable(kat):
isStable = True
is_stable = True
kat1 = kat.deepcopy()
code = ''
cp_names = []
for cav in kat1.getAll(pykat.commands.cavity):
code += 'cp {0} x m\ncp {0} y m\n'.format(cav)
cp_names.append('{0}_x_m'.format(cav))
cp_names.append('{0}_y_m'.format(cav))
code += 'noxaxis'
kat1.parse(code)
out = kat1.run()
ymax = np.abs(out.y).max()
cp_outs = []
for name in cp_names:
cp_outs.append(out[name])
ymax = np.abs(cp_outs).max()
if ymax >= 1:
isStable = False
return isStable, ymax
is_stable = False
return is_stable, ymax
def opt_demod_phase(cdata, x, xbounds=None, err_tol=1e-5, xatol=1e-9, isplot=False):
def opt_demod_phase(cdata, x, xbounds=None, err_tol=1e-5, xatol=1e-9, isplot=False,
verbose=False):
'''
Optimizes the demodulation phase of a complex error signal generated by Finesse.
Demands that the error signal is smaller than err_tol to compute the slope or
......@@ -841,7 +851,7 @@ def opt_demod_phase(cdata, x, xbounds=None, err_tol=1e-5, xatol=1e-9, isplot=Fal
#print('hej!')
return -dy1
sol_2 = minimize_scalar(find_op, bounds=xbounds, method='bounded',
options={'maxiter': 500, 'disp': True, 'xatol': xatol})
options={'maxiter': 500, 'disp': verbose, 'xatol': xatol})
# print(sol_2)
return sol_2.fun
......@@ -852,7 +862,7 @@ def opt_demod_phase(cdata, x, xbounds=None, err_tol=1e-5, xatol=1e-9, isplot=Fal
demod_phase_bounds = slice(min_phase, max_phase, step)
phase_bounds = (demod_phase_bounds,)
# Searching for optimal demodulation phase.
sol = brute(max_og, ranges=phase_bounds, full_output=True, finish=fmin, disp=False)
sol = brute(max_og, ranges=phase_bounds, full_output=True, finish=fmin, disp=verbose)
# Reading out results
demod_phase = sol[0][0]
optical_gain = -sol[1]*yscale/xscale
......
......@@ -1119,6 +1119,24 @@ class ADV_IFO(IFO):
for k,v in DCoffset.items():
self.set_DC_offset(DCoffset=v, offset_type=k, verbose=False)
def _strToDOFs(self, DOFs):
dofs = []
for _ in DOFs:
if isinstance(_, six.string_types):
if _ in self.DOFs:
dofs.append(self.DOFs[_])
else:
raise pkex.BasePyKatException(
"Could not find DOF called `%s`. Possible DOF options: %s" % (
_, str(list(self.DOFs.keys()))))
else:
raise pkex.BasePyKatException(
"'%s' not possible DOF options: %s" % (
_, str(list(self.DOFs.keys()))))
return dofs
def assert_adv_ifo_kat(kat):
if not isinstance(kat.IFO, ADV_IFO):
......
......@@ -125,7 +125,7 @@ def error_signals(_kat, xlimits=[-1,1], DOFs=None, plotDOFs=None, replaceDOFSign
toShow = None
if plotDOFs is not None:
toShow = self._strToDOFs(plotDOFs)
toShow = kat.IFO._strToDOFs(plotDOFs)
# Check if other DOF signals we need to include for plotting
for _ in toShow:
......@@ -171,9 +171,11 @@ def error_signals(_kat, xlimits=[-1,1], DOFs=None, plotDOFs=None, replaceDOFSign
else:
for _ in toShow:
if legend is None:
legend = _.name
_legend = _.name
else:
_legend = legend
ax.plot(out.x, out[_.signal_name()] - DC_Offset, label=legend)
ax.plot(out.x, out[_.signal_name()] - DC_Offset, label=_legend)
ax.set_xlim([np.min(out.x), np.max(out.x)])
ax.set_xlabel("{} [deg]".format(d.name))
......
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