Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sebastian Steinlechner
pykat
Commits
9546c4b7
Commit
9546c4b7
authored
Jun 23, 2016
by
Daniel Toyra
Browse files
Added proper error handling in maps.py
parent
eb6ecbe4
Changes
1
Hide whitespace changes
Inline
Side-by-side
pykat/optics/maps.py
View file @
9546c4b7
...
...
@@ -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,15 +121,15 @@ 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
(
x
0new
),
round
(
y
0new
)]):
self
.
notNan
[
round
(
y
0new
),
round
(
x
0new
)]):
self
.
center
=
(
x0new
,
y0new
)
self
.
_xyOffset
=
(
offset
[
0
],
offset
[
1
])
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
))
@
property
def
betaRemoved
(
self
):
return
self
.
_betaRemoved
...
...
@@ -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
=
p
ylab
.
figure
()
fig
=
p
lt
.
figure
()
# Important to remember here is that xRange corresponds to column and
# yRange to row indices of the matrix self.data.
pcm
=
p
ylab
.
pcolormesh
(
xRange
,
yRange
,
self
.
data
)
pcm
=
p
lt
.
pcolormesh
(
xRange
,
yRange
,
self
.
data
)
pcm
.
set_rasterized
(
True
)
p
ylab
.
xlabel
(
'x [cm]'
)
p
ylab
.
ylabel
(
'y [cm]'
)
p
lt
.
xlabel
(
'x [cm]'
)
p
lt
.
ylabel
(
'y [cm]'
)
if
xlim
is
not
None
:
p
ylab
.
xlim
(
xlim
)
if
ylim
is
not
None
:
p
ylab
.
ylim
(
ylim
)
if
xlim
is
not
None
:
p
lt
.
xlim
(
xlim
)
if
ylim
is
not
None
:
p
lt
.
ylim
(
ylim
)
p
ylab
.
title
(
'Surface map {0}, type {1}'
.
format
(
self
.
name
,
self
.
type
))
p
lt
.
title
(
'Surface map {0}, type {1}'
.
format
(
self
.
name
,
self
.
type
))
cbar
=
p
ylab
.
colorbar
()
cbar
=
p
lt
.
colorbar
()
cbar
.
set_clim
(
zmin
,
zmax
)
# cbar.set_clim(-1.86, 1.04)
...
...
@@ -471,7 +472,7 @@ class surfacemap(object):
cbar
.
set_label
(
clabel
)
if
show
:
p
ylab
.
show
(
block
=
isBlock
)
p
lt
.
show
(
block
=
isBlock
)
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
)
else
:
r
=
math
.
sqrt
(
len
(
cIndx
)
/
math
.
pi
)
elif
method
==
'min'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment