Skip to content

Commit 1ce731d

Browse files
committed
Adds function to align profiles
1 parent 337eb43 commit 1ce731d

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

ratapi/utils/plotting.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,46 @@ def plot_ref_sld_helper(
234234
plt.pause(0.005)
235235

236236

237+
def _align_profiles(data: PlotEventData):
238+
"""Align SLD profiles and resampled layers.
239+
240+
Aligns the A/L SLD profiles so that the substrates line up by padding the
241+
start of any shorter than the longest profile.
242+
243+
Parameters
244+
----------
245+
data : PlotEventData
246+
The plot event data that contains all the information
247+
to generate the ref and sld plots
248+
"""
249+
slds = data.sldProfiles
250+
size = (len(slds), len(slds[0]))
251+
252+
# Find the length of the longest profile.
253+
lengths = [[sld.shape[0] for sld in sld_row] for sld_row in slds]
254+
max_value = np.max(lengths)
255+
max_index = np.unravel_index(np.argmax(lengths), shape=size)
256+
257+
max_x = slds[max_index[0]][max_index[1]][:, 0]
258+
max_x_value = max_x[-1]
259+
260+
for i in range(size[0]):
261+
for j in range(size[1]):
262+
cur_sld = slds[i][j]
263+
diff = max_value - cur_sld.shape[0]
264+
if diff:
265+
pad = np.zeros((max_value, 2))
266+
pad[:, 0] = max_x
267+
pad[diff:, 1] = cur_sld[:, 1]
268+
slds[i][j] = pad
269+
270+
cur_resample_layer = data.resampledLayers[i][j]
271+
if not np.all(cur_resample_layer):
272+
total_length = sum(cur_resample_layer[:, 0])
273+
pad = max_x_value - total_length
274+
data.resampledLayers[i][j] = np.vstack([[pad, 0, 0], cur_resample_layer])
275+
276+
237277
def plot_ref_sld(
238278
project: ratapi.Project,
239279
results: ratapi.outputs.Results | ratapi.outputs.BayesResults,

0 commit comments

Comments
 (0)