안녕하세요 여러분,
FTIR 스펙트럼 실험에서 얻은 여러 다른 열이 있는데, 기준선을 수정하기 위해 각 열에 Fit Spline을 수행해야 합니다(열 하나 = 스펙트럼 하나). JSL을 사용하여 자동으로 이 작업을 수행하여 수백 개의 "예측된 값"을 수동으로 저장할 필요가 없도록 하려고 합니다.
코드를 만들려고 했지만 어떻게 된 일인지 값을 저장하지 않고 각 열에 0을 넣지 않습니다.
누구든지 도와줄 수 있나요?
내 코드는 다음과 같습니다.
dt = Current Data Table();
// Define the columns for the fit (assuming multiple Y columns and one X column)
x_col = Column("Wavenumber"); // Replace with the name of your X column
y_cols = {};
For(i = 1, i <= N Col(dt), i++,
col_name = Column(i) << Get Name;
// Check if the column name contains "Absorbance at t="
If(Contains(col_name, "Absorbance at t="),
Insert Into(y_cols, col_name); // Add to the list
);
);
// Create a list to store fit reports
fit_reports = {};
// Perform Fit Y by X for each Y column separately and display the fit
For(i = 1, i <= N Items(y_cols), i++,
y_col = y_cols[i];
fit_report = dt << Fit Y by X(
Y(Column(y_col)),
X(x_col),
Fit Spline(1000) // Adjust the lambda (smoothing parameter) as needed
);
Insert Into(fit_reports, fit_report);
);
Show(
"All fits have been displayed. Please review them and adjust the lambda value in the script if needed."
);
// Wait for user to review fits
Wait(0);
// Use a Yes/No dialog to prompt the user to continue or stop
result = New Window("Save Predicted Values?",
Text Box("Are you satisfied with the fits? Click Yes to save predicted values, No to stop."),
Button Box("Yes",
// Save predicted values as columns in the dataset
For(i = 1, i <= N Items(y_cols), i++,
y_col = y_cols[i];
fit_report = fit_reports[i];
predicted_col_name = "Spline Predictor for " || y_col;
dt << New Column(predicted_col_name, Numeric);
Column(predicted_col_name) << Set Values(fit_report["Prediction Formula"]);
);
Show("Predicted values saved successfully.");
),
Button Box("No",
Show("Predicted values were not saved.");
)
);
// Close all fit reports
For(i = 1, i <= N Items(fit_reports), i++,
Close(fit_reports[i], No Save);
);
Close(result); // Close the dialog window
2024-09-24 jthi 편집: jsl 포맷 추가
이것은 몇 가지 아이디어를 줄 수 있습니다
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Semiconductor Capability.jmp");
xcol = "NPN1";
ycols = {"PNP1", "NPN2"};
fits = {};
For Each({ycol}, ycols,
Insert Into(fits,
dt << Fit Y by X(
Y(Eval(ycol)),
X(Eval(xcol)),
Fit Spline(1000)
);
);
);
close_expr = Expr(
For Each({fit}, fits,
fit << close window;
);
nw << Close Window;
);
nw = New Window("Save Predicted Values?",
Text Box("Are you satisfied with the fits? Click Yes to save predicted values, No to stop."),
Button Box("Yes",
For Each({fit}, fits,
fit << (Curve["Smoothing Spline Fit, lambda=1000"] << Save Predicteds);
);
wait(0);
close_expr;
Show("Predicted values saved successfully.");
),
Button Box("No",
Show("Predicted values were not saved.");
close_expr;
)
);
또한 여러 개의 별도 창을 여는 대신 모든 Fit Y by X를 단일 창으로 수집하여 확인하기 쉽게 만들 것입니다.
정말 잘 작동했어요, 정말 감사합니다! 저는 ChatGPT로 몇 시간 동안 해결책을 찾기 위해 고군분투했습니다. 