Skip to content

Commit fdc6333

Browse files
committed
Also plot curves in the analysis
1 parent ce081da commit fdc6333

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tests/IVIMmodels/unit_tests/analyze.r

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,23 @@ Dp_model <- lm(Dp ~ Dp_fitted_IAR_LU_biexp + Dp_fitted_IAR_LU_modified_mix + Dp_
4242
# Dp_model <- lm(Dp ~ Dp_fitted_ETP_SRI_LinearFitting + Dp_fitted_IAR_LU_biexp + Dp_fitted_IAR_LU_modified_mix + Dp_fitted_IAR_LU_modified_topopro + Dp_fitted_IAR_LU_segmented_2step + Dp_fitted_IAR_LU_segmented_3step + Dp_fitted_IAR_LU_subtracted, data=data_new_wide)
4343
# predict new data from existing model
4444
predict(object = f_model, newdata = data_wide)
45+
46+
47+
ivim_decay <- function(f, D, Dp, bvalues) {
48+
return(f*exp(-Dp*bvalues) + (1-f)*exp(-D*bvalues))
49+
}
50+
bvalues <- c(0.0, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0, 50.0, 75.0, 100.0, 150.0, 250.0, 350.0, 400.0, 550.0, 700.0, 850.0, 1000.0)
51+
52+
generate_curves <- function(data, bvalues, appended_string) {
53+
curves <-apply(data[,c(paste("f", appended_string, sep=""), paste("D", appended_string, sep=""), paste("Dp", appended_string, sep=""))], 1, function(x) ivim_decay(x[1], x[2], x[3], bvalues))
54+
curves <- transpose(data.frame(curves))
55+
colnames(curves) <- paste("b", bvalues, sep="_")
56+
data_curves <- cbind(data, curves)
57+
data_curves <- pivot_longer(data_curves, starts_with("b_"), names_to="bvalue", values_to=paste("signal", appended_string, sep=""), names_prefix="b_", names_transform=list(bvalue = as.numeric))
58+
return(data_curves)
59+
}
60+
curves_restricted_fitted <- generate_curves(data_restricted, bvalues, "_fitted")
61+
curves_restricted <- generate_curves(data_restricted, bvalues, "")
62+
63+
data_curves_restricted <- cbind(curves_restricted, signal_fitted=curves_restricted_fitted$signal_fitted)
64+
ggplot(data_curves_restricted, aes(x=bvalue)) + facet_grid(Region ~ SNR) + geom_line(alpha=0.2, aes(y=signal_fitted, group=interaction(Algorithm, index), color=Algorithm)) + geom_line(aes(y=signal)) + ylim(0, 1) + ylab("Signal (a.u.)")

tests/IVIMmodels/unit_tests/test_ivim_synthetic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_generated(ivim_algorithm, ivim_data, SNR, rtol, atol, fit_count, rician
3535
# else:
3636
# signal = data["data"]
3737
start_time = datetime.datetime.now()
38-
[f_fit, Dp_fit, D_fit] = fit.osipi_fit(signal, bvals) # prior_in=prior
38+
[f_fit, Dp_fit, D_fit] = fit.osipi_fit(signal, bvals) #, prior_in=prior
3939
time_delta += datetime.datetime.now() - start_time
4040
if save_file:
4141
save_results(save_file, ivim_algorithm, name, SNR, idx, [f, Dp, D], [f_fit, Dp_fit, D_fit])

0 commit comments

Comments
 (0)