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

Added proper error handling in maps.py

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