Skip to content

Commit fb80de1

Browse files
RajeshwriKrajeshwari-kiwad
andauthored
Task/adding step to sweep delay (#26)
Adding step-to-sweep-delay for plots. When there is a non-zero delay the sweep plot starts after the delay period is done --------- Co-authored-by: rajeshwari-kiwad <rajeshwari.kiwad@tektronix.com>
1 parent e3c483b commit fb80de1

File tree

6 files changed

+190
-48
lines changed

6 files changed

+190
-48
lines changed

script-gen-manager/src/instr_metadata/mpsu50_metadata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ impl Mpsu50Metadata {
2727

2828
base.add_range("source.limiti".to_string(), 0.01, 5.1);
2929

30+
base.add_range("source.step_to_sweep_delay".to_string(), 0.0, 100.0);
31+
3032
// Add region maps
3133
// when pulse mode is off
3234
let exclude_i = NumberLimit::new(-10.0e-9, 10.0e-9, false, None);

script-gen-manager/src/instr_metadata/msmu60_metadata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ impl Msmu60Metadata {
4646
base.add_range("source.limiti".to_string(), -1e-8, 1.515);
4747
base.add_range("source.limitv".to_string(), -0.02, 60.6);
4848

49+
base.add_range("source.step_to_sweep_delay".to_string(), 0.0, 100.0);
50+
4951
// Add region maps
5052
// when pulse mode is off
5153
let exclude_v = Some(NumberLimit::new(-0.01, 0.01, false, None));

script-gen-manager/src/model/sweep_data/parameters.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ impl ParameterFloat {
5050
unit,
5151
}
5252
}
53+
54+
pub fn limit(&mut self, min: f64, max: f64) {
55+
if self.value >= min && self.value <= max {
56+
return;
57+
} else if self.value < min {
58+
self.value = min
59+
} else {
60+
self.value = max
61+
}
62+
}
5363
}
5464

5565
impl ParameterString {

script-gen-manager/src/model/sweep_data/sweep_config.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::collections::HashMap;
33

44
use crate::{
55
device::Device,
6+
instr_metadata::{base_metadata::Metadata, enum_metadata::MetadataEnum},
67
model::{
78
chan_data::{
89
bias_channel::BiasChannel, step_channel::StepChannel, sweep_channel::SweepChannel,
@@ -370,9 +371,27 @@ impl SweepConfig {
370371
.sweep_timing_config
371372
.measure_count
372373
.limit(1, 60000);
374+
375+
// Validating Step to Sweep Delay
376+
if !self.step_channels.is_empty() {
377+
let device_metadata = self.step_channels[0]
378+
.start_stop_channel
379+
.common_chan_attributes
380+
.device
381+
.get_metadata();
382+
if let Some((min, max)) =
383+
self.get_range_limits(&device_metadata, "source.step_to_sweep_delay")
384+
{
385+
self.step_global_parameters
386+
.step_to_sweep_delay
387+
.limit(min, max);
388+
}
389+
}
390+
373391
for bias_channel in &mut self.bias_channels {
374392
bias_channel.evaluate();
375393
}
394+
376395
for step_channel in &mut self.step_channels {
377396
step_channel
378397
.start_stop_channel
@@ -383,18 +402,6 @@ impl SweepConfig {
383402
.start_stop_channel
384403
.evaluate(self.sweep_global_parameters.sweep_points.value as usize);
385404
}
386-
387-
// Check if only bias channels exist and display appropriate message
388-
// if !self.bias_channels.is_empty()
389-
// && self.step_channels.is_empty()
390-
// && self.sweep_channels.is_empty()
391-
// {
392-
// self.status_msg = Some(StatusMsg::new(
393-
// StatusType::Warning,
394-
// String::from("Only bias channels are configured. Please add a step or sweep channel to generate a functional script."),
395-
// ));
396-
// println!("Warning: Only bias channels are configured. Please add a step or sweep channel to generate a functional script.");
397-
// }
398405
}
399406

400407
pub fn update_channel_devices(&mut self) {
@@ -593,6 +600,14 @@ impl SweepConfig {
593600
}
594601
}
595602

603+
fn get_range_limits(&self, metadata: &MetadataEnum, key: &str) -> Option<(f64, f64)> {
604+
match metadata {
605+
MetadataEnum::Base(base_metadata) => base_metadata.get_range(key),
606+
MetadataEnum::Msmu60(msmu60_metadata) => msmu60_metadata.get_range(key),
607+
MetadataEnum::Mpsu50(mpsu50_metadata) => mpsu50_metadata.get_range(key),
608+
}
609+
}
610+
596611
pub fn reset(&mut self) {
597612
*self = SweepConfig::new();
598613
}

script-gen-ui/src/app/components/main-sweep/plot-container/plot-step/plot-step.component.ts

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class PlotStepComponent
5757
backgroundColor: '',
5858
color: '',
5959
};
60-
@Input() color = '';
60+
@Input() color = '';
6161
private mutationObserver: MutationObserver | undefined;
6262
private originalBackgroundColor = '';
6363
activeBackgroundColor = '';
@@ -95,6 +95,7 @@ export class PlotStepComponent
9595
size: 9,
9696
},
9797
dtick: 1,
98+
range: [0, 10],
9899
// tick0: 0,
99100
showtickprefix: 'none',
100101
showticksuffix: 'all',
@@ -269,41 +270,88 @@ export class PlotStepComponent
269270
}
270271

271272
private generatePlotData(yData: number[], type: string): void {
272-
if (this.stepPoints) {
273+
if (this.stepPoints && this.stepToSweepDelay) {
274+
const delayTime = this.stepToSweepDelay?.value ?? 0;
273275
const targetLength = Math.max(2, Math.floor(this.plotWidth));
274-
let xData: number[] = [];
276+
let processedYData = [...yData];
277+
let processedXData: number[] = [];
275278

279+
// Handle interpolation first if needed
276280
if (this.stepPoints.value > targetLength) {
277281
if (type == 'LIN') {
278-
const interpolated = PlotUtils.linearInterpolation(
279-
yData,
280-
targetLength
281-
);
282-
xData = interpolated.x;
283-
yData = interpolated.y;
282+
const interpolated = PlotUtils.linearInterpolation(processedYData, targetLength);
283+
processedXData = interpolated.x;
284+
processedYData = interpolated.y;
284285
} else if (type == 'LOG' || type == 'LIST') {
285-
const interpolated = PlotUtils.minMaxInterpolation(
286-
yData,
287-
targetLength
288-
);
289-
xData = interpolated.x;
290-
yData = interpolated.y;
286+
const interpolated = PlotUtils.minMaxInterpolation(processedYData, targetLength);
287+
processedXData = interpolated.x;
288+
processedYData = interpolated.y;
291289
}
292290
} else {
293-
xData = Array.from({ length: this.stepPoints.value }, (_, i) => i)
291+
processedXData = Array.from({ length: this.stepPoints.value }, (_, i) => i)
294292
.concat(this.stepPoints.value)
295293
.flat();
296294
}
297-
this.plotData1.x = xData;
298-
this.plotData1.y = yData;
299-
console.log('Plot data generated:', {
300-
x: this.plotData1.x,
301-
y: this.plotData1.y,
302-
});
303-
this.plotLayout.xaxis.dtick = this.stepPoints.value / 10;
295+
296+
if (delayTime > 0) {
297+
const { x, y } = this.generateDataWithDelay(processedYData, processedXData, delayTime);
298+
this.plotData1.x = x;
299+
this.plotData1.y = y;
300+
} else {
301+
this.generateDataWithoutDelay(processedYData, processedXData);
302+
}
303+
304+
// console.log('Plot data generated:', {
305+
// x: this.plotData1.x,
306+
// y: this.plotData1.y,
307+
// });
308+
// this.plotLayout.xaxis.dtick = (this.stepPoints.value + this.stepToSweepDelay?.value) / 10;
309+
// Update x-axis range to include delay time for each step
310+
// const delayTime = this.stepToSweepDelay?.value ?? 0;
311+
const totalTime = this.stepPoints.value * (1 + delayTime); // Each step now takes (1 + delayTime) units
312+
313+
this.plotLayout.xaxis.dtick = totalTime / 10;
314+
this.plotLayout.xaxis.range = [0, totalTime];
304315
}
305316
}
306317

318+
private generateDataWithDelay(yData: number[], xData: number[], delayTime: number): { x: number[], y: number[] } {
319+
const finalX: number[] = [];
320+
const finalY: number[] = [];
321+
const delayPoints = Math.max(5, Math.floor(delayTime * 10));
322+
const numSteps = yData.length - 1; // Exclude the final repeated point
323+
324+
// Generate data for each step with delay
325+
for (let step = 0; step < numSteps; step++) {
326+
const stepStartTime = step * (1 + delayTime);
327+
const currentYValue = yData[step];
328+
329+
// Add delay period (repeat current y value) at the beginning of each step
330+
for (let d = 0; d < delayPoints; d++) {
331+
finalX.push(stepStartTime + (d * delayTime) / delayPoints);
332+
finalY.push(currentYValue);
333+
}
334+
335+
// Add the actual step point after delay
336+
finalX.push(stepStartTime + delayTime);
337+
finalY.push(currentYValue);
338+
}
339+
340+
// Add final point
341+
if (yData.length > 0) {
342+
const finalStepTime = numSteps * (1 + delayTime);
343+
finalX.push(finalStepTime);
344+
finalY.push(yData[yData.length - 1]);
345+
}
346+
347+
return { x: finalX, y: finalY };
348+
}
349+
350+
private generateDataWithoutDelay(yData: number[], xData: number[]): void {
351+
this.plotData1.x = xData;
352+
this.plotData1.y = yData;
353+
}
354+
307355
private stepListPlot() {
308356
if (this.listStep && this.stepPoints && this.stop) {
309357
const stepValues = this.listStep

script-gen-ui/src/app/components/main-sweep/plot-container/plot-sweep/plot-sweep.component.ts

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export class PlotSweepComponent
7676
list = true;
7777
listSweep: ParameterFloat[] = [];
7878
numSteps: number | undefined;
79+
stepToSweepDelay: ParameterFloat | undefined;
80+
7981
plotUtils = new PlotUtils();
8082

8183
plotLayout = {
@@ -239,6 +241,7 @@ export class PlotSweepComponent
239241
this.numPoints = this.sweepGlobalParameters?.sweep_points;
240242
this.list = this.sweepGlobalParameters?.list_sweep;
241243
this.numSteps = this.stepGlobalParameters?.step_points.value;
244+
this.stepToSweepDelay = this.stepGlobalParameters?.step_to_sweep_delay;
242245
// this.list = this.sweepGlobalParameters?.list_sweep;
243246
this.listSweep = this.sweepChannel.start_stop_channel.list;
244247

@@ -295,19 +298,76 @@ export class PlotSweepComponent
295298
if (this.numPoints && this.numSteps) {
296299
const numSteps = this.numSteps;
297300
const numberOfPoints = this.numPoints?.value;
298-
this.plotData1.y = Array.from({ length: numSteps }, () => sweepValues)
299-
.flat()
300-
.concat(sweepValues[sweepValues.length - 1]);
301-
302-
if (xData) {
303-
this.plotData1.x = xData;
301+
const delayTime = this.stepToSweepDelay?.value ?? 0;
302+
303+
if (delayTime > 0) {
304+
const { x, y } = this.generateDataWithDelay(sweepValues, numSteps, numberOfPoints, delayTime, xData);
305+
this.plotData1.x = x;
306+
this.plotData1.y = y;
304307
} else {
305-
this.plotData1.x = Array.from({ length: numSteps }, (_, i) =>
306-
Array.from({ length: numberOfPoints }, (_, j) => i + j / numberOfPoints)
307-
)
308-
.flat()
309-
.concat(numSteps);
308+
this.generateDataWithoutDelay(sweepValues, numSteps, numberOfPoints, xData);
309+
}
310+
}
311+
}
312+
313+
private generateDataWithDelay(
314+
sweepValues: number[],
315+
numSteps: number,
316+
numberOfPoints: number,
317+
delayTime: number,
318+
xData?: number[]
319+
): { x: number[], y: number[] } {
320+
const finalX: number[] = [];
321+
const finalY: number[] = [];
322+
const delayPoints = Math.max(5, Math.floor(delayTime * 10));
323+
324+
// Generate data for each step with delay
325+
for (let step = 0; step < numSteps; step++) {
326+
const stepStartTime = step * (1 + delayTime);
327+
328+
// Add delay period (zeros) at the beginning of each step
329+
for (let d = 0; d < delayPoints; d++) {
330+
finalX.push(stepStartTime + (d * delayTime) / delayPoints);
331+
finalY.push(0);
310332
}
333+
334+
// Add the actual sweep data for this step
335+
for (let j = 0; j < numberOfPoints; j++) {
336+
if (xData) {
337+
const originalIndex = step * numberOfPoints + j;
338+
if (originalIndex < xData.length) {
339+
finalX.push(stepStartTime + delayTime + (j / numberOfPoints));
340+
}
341+
} else {
342+
finalX.push(stepStartTime + delayTime + (j / numberOfPoints));
343+
}
344+
finalY.push(sweepValues[j]);
345+
}
346+
}
347+
348+
// Add final point
349+
if (sweepValues.length > 0) {
350+
const finalStepTime = numSteps * (1 + delayTime);
351+
finalX.push(finalStepTime);
352+
finalY.push(sweepValues[sweepValues.length - 1]);
353+
}
354+
355+
return { x: finalX, y: finalY };
356+
}
357+
358+
private generateDataWithoutDelay(sweepValues: number[], numSteps: number, numberOfPoints: number, xData?: number[]) {
359+
this.plotData1.y = Array.from({ length: numSteps }, () => sweepValues)
360+
.flat()
361+
.concat(sweepValues[sweepValues.length - 1]);
362+
363+
if (xData) {
364+
this.plotData1.x = xData;
365+
} else {
366+
this.plotData1.x = Array.from({ length: numSteps }, (_, i) =>
367+
Array.from({ length: numberOfPoints }, (_, j) => i + j / numberOfPoints)
368+
)
369+
.flat()
370+
.concat(numSteps);
311371
}
312372
}
313373

@@ -335,8 +395,13 @@ export class PlotSweepComponent
335395
} else {
336396
this.generatePlotDataxy(sweepValues);
337397
}
338-
this.plotLayout.xaxis.dtick = this.numSteps / 10;
339-
this.plotLayout.xaxis.range = [0, this.numSteps];
398+
399+
// Update x-axis range to include delay time for each step
400+
const delayTime = this.stepToSweepDelay?.value ?? 0;
401+
const totalTime = this.numSteps * (1 + delayTime); // Each step now takes (1 + delayTime) units
402+
403+
this.plotLayout.xaxis.dtick = totalTime / 10;
404+
this.plotLayout.xaxis.range = [0, totalTime];
340405
}
341406
}
342407

0 commit comments

Comments
 (0)