Skip to content

Commit 28100ba

Browse files
committed
STY: Plottools
Added docstring for resax and fixed minor formatting errors
1 parent 9b6776e commit 28100ba

1 file changed

Lines changed: 25 additions & 19 deletions

File tree

tools/plottools.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def plot_ellipsdata(
1212
xaxis="aoi",
1313
plot_labels=True,
1414
legend=True,
15-
resAx=None
15+
resax=None
1616
):
1717
"""
1818
Plots delta and psi values as a function of wavelength or angle of incidence.
@@ -34,31 +34,33 @@ def plot_ellipsdata(
3434
The default is None.
3535
objective : refellips.objectiveSE.ObjectiveSE, optional
3636
Objective (containing model and data) to plot. If the objective is provided,
37-
neither model or data should be provided. The default is None.
37+
neither model nor data should be provided. The default is None.
3838
xaxis : String, optional
3939
Either 'aoi' or 'wavelength'. The default is 'aoi'.
4040
plot_labels : Bool, optional
4141
Whether to plot axis labels. The default is True.
4242
legend : Bool, optional
4343
Whether to plot the legend. The default is True.
44-
44+
resax : matplotlib.axes._subplots.AxesSubplot, optional
45+
Axis object on which delta and psi residuals. If not provided,
46+
no residual will be plotted.
4547
Returns
4648
-------
4749
None.
4850
4951
"""
5052

51-
if objective != None:
53+
if objective is not None:
5254
assert (
53-
data == None and model == None
55+
data is None and model is None
5456
), "If objective is supplied, model and data should not be passed"
5557
data = objective.data
5658
model = objective.model
57-
elif model != None:
58-
assert data != None, "If you supply a model, you must also supply data"
59+
elif model is not None:
60+
assert data is not None, "If you supply a model, you must also supply data"
5961
else:
6062
assert (
61-
data != None
63+
data is not None
6264
), "must supply at least one of data, model or objective"
6365

6466
assert (
@@ -73,7 +75,7 @@ def plot_ellipsdata(
7375
x = data.aoi
7476
xlab = "AOI (°)"
7577

76-
if model != None:
78+
if model is not None:
7779
for wav in unique_wavs:
7880
psis, deltas = model(np.c_[np.ones_like(aois) * wav, aois])
7981
ax.plot(aois, psis, color="r")
@@ -85,8 +87,9 @@ def plot_ellipsdata(
8587
np.min(data.wavelength) - 50, np.max(data.wavelength) + 50
8688
)
8789
x = data.wavelength
90+
xlab = "Wavelength (nm)"
8891

89-
if model != None:
92+
if model is not None:
9093
wavelength_aois = np.c_[wavs, data.aoi[0]*np.ones_like(wavs)]
9194
psi, delta = model(wavelength_aois)
9295
ax.plot(wavs, psi, color="r")
@@ -100,16 +103,19 @@ def plot_ellipsdata(
100103
# ax.plot(np.ones_like(psi) * wavelength, psi, color="r")
101104
# axt.plot(np.ones_like(delta) * wavelength, delta, color="b")
102105

103-
xlab = "Wavelength (nm)"
106+
107+
else:
108+
assert False, "xaxis must be 'aoi' or 'wavelength'"
104109

105110
# Plot data
106111
p = ax.scatter(x, data.psi, color="r", alpha=0.5)
107112
d = axt.scatter(x, data.delta, color="b", alpha=0.5)
108113

109-
# ax.legend(handles=[p, d], labels=["Psi", "Delta"], loc='center right')
114+
if legend:
115+
ax.legend(handles=[p, d], labels=["Psi", "Delta"], loc='center right')
110116

111-
if resAx != None:
112-
assert objective != None, 'To plot residuals you must supply an objective'
117+
if resax is not None:
118+
assert objective is not None, 'To plot residuals you must supply an objective'
113119
res = objective.residuals()
114120
numdp = int(len(res)/2)
115121
psires = res[:numdp]
@@ -125,7 +131,7 @@ def plot_ellipsdata(
125131
ax.set_xlabel(xlab)
126132

127133
axt.set_ylabel("Delta", color='blue')
128-
if resAx != None:
134+
if resAx is not None:
129135
resAx.set(ylabel='error')
130136

131137
def plot_structure(
@@ -151,7 +157,7 @@ def plot_structure(
151157
objective : refellips.objectiveSE.ObjectiveSE, optional
152158
Objective (containing model and data) to plot. If the objective is provided,
153159
structure should not be provided. The default is None.
154-
structure : refnx.reflect.structure.Structure
160+
structure : refnx.reflect.structure.Structure.
155161
Structure (which represents the interface) to be plotted. If structure is provided,
156162
objective should not be provided. The default is None.
157163
reverse_structure : bool
@@ -164,15 +170,15 @@ def plot_structure(
164170
None.
165171
166172
"""
167-
if objective != None:
173+
if objective is not None:
168174
assert (
169-
structure == None
175+
structure is None
170176
), "you must supply either an objective or structure, not both"
171177
structure = objective.model.structure
172178
wavelengths = np.unique(objective.data.wavelength)
173179
else:
174180
assert (
175-
structure != None
181+
structure is not None
176182
), "you must supply either an objective or structure"
177183
wavelengths = [658]
178184

0 commit comments

Comments
 (0)