Commit 9546c4b7 authored by Daniel Toyra's avatar Daniel Toyra
Browse files

Added proper error handling in

parent eb6ecbe4
Pipeline #1551 failed with stage
in 22 seconds
......@@ -19,6 +19,8 @@ from scipy.optimize import minimize
from pykat.math.zernike import *
from pykat.exceptions import BasePyKatException
from copy import deepcopy
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import math
......@@ -119,13 +121,13 @@ class surfacemap(object):
# Checking so new suggested "center" is within the the mirror surface
if (x0new>0 and x0new<self.size[0]-1 and y0new>0 and y0new<self.size[1]-1 and
self.notNan[round(y0new), round(x0new)]): = (x0new, y0new)
self._xyOffset = (offset[0], offset[1])
print(('Error in xyOffset: ({:.2e}, {:.2e}) m --> pos = ({:.2f}, {:.2f}) '+
raise BasePyKatException( ('Error in xyOffset: ({:.2e}, {:.2e}) m --> pos = ({:.2f}, {:.2f}) '+
'is outside mirror surface.').format(offset[0],offset[1],x0new,y0new))
......@@ -409,7 +411,6 @@ class surfacemap(object):
# xlim and ylim given in centimeters
def plot(self, show=True, clabel=None, xlim=None, ylim=None, isBlock=False):
import pylab
if xlim is not None:
# Sorts out the x-values within xlim
......@@ -448,22 +449,22 @@ class surfacemap(object):
yRange = 100*self.y
# xRange, yRange = np.meshgrid(xRange,yRange)
fig = pylab.figure()
fig = plt.figure()
# Important to remember here is that xRange corresponds to column and
# yRange to row indices of the matrix
pcm = pylab.pcolormesh(xRange, yRange,
pcm = plt.pcolormesh(xRange, yRange,
pylab.xlabel('x [cm]')
pylab.ylabel('y [cm]')
plt.xlabel('x [cm]')
plt.ylabel('y [cm]')
if xlim is not None: pylab.xlim(xlim)
if ylim is not None: pylab.ylim(ylim)
if xlim is not None: plt.xlim(xlim)
if ylim is not None: plt.ylim(ylim)
pylab.title('Surface map {0}, type {1}'.format(, self.type))
plt.title('Surface map {0}, type {1}'.format(, self.type))
cbar = pylab.colorbar()
cbar = plt.colorbar()
cbar.set_clim(zmin, zmax)
# cbar.set_clim(-1.86, 1.04)
......@@ -471,7 +472,7 @@ class surfacemap(object):
if show:
return fig
......@@ -580,7 +581,7 @@ class surfacemap(object):
# x and y step sizes are different.
elif method=='area' or method=='Area' or method=='AREA':
if unit == 'meters' or unit == 'metres' or unit=='Meters' or unit=='Metres':
r = step_size[0]*math.sqrt(len(cIndx)/math.pi)
r = self.step_size[0]*math.sqrt(len(cIndx)/math.pi)
r = math.sqrt(len(cIndx)/math.pi)
elif method=='min':
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