<jupyter_start><jupyter_text>Loading Example data from dipySince we cannot find publicly available single shell data, we use multishell data from data and transform it to look like single shell data<jupyter_code># !! RUN THIS ONCE ONLY !!
# # Download eddy-current/motion corrected data (a couple of GB will be downloaded)
# fetch_cenir_multib(with_raw=False)
# Read just one shell of data for b-value = 1000
img, gtab = read_cenir_multib([1000])
data = img.get_data()
# Convert multishell data to look like single shell data

# Take an average of all the b0 values
avg_b0_data = data[:,:,:,gtab.b0s_mask].mean(axis=-1)[:,:,:, np.newaxis]
# Concatenate the b0 average with the non-b0 data
ss_data = np.concatenate((avg_b0_data, data[:,:,:, ~gtab.b0s_mask]), axis=-1)

# extract the relevant parts of the bvals and the bvecs
ss_bval = np.concatenate((np.array([0.]), gtab.bvals[~gtab.b0s_mask]))
ss_bvecs = np.concatenate( (np.array([0., 0., 0.])[np.newaxis, :], gtab.bvecs[~gtab.b0s_mask, :]))

# Now we have a single shell gradient table
ss_gtab = gradient_table(ss_bval, ss_bvecs, big_delta=gtab.big_delta, 
                         small_delta=gtab.small_delta, b0_threshold=gtab.b0_threshold)<jupyter_output><empty_output><jupyter_text>Process Single shell data<jupyter_code># we remove the background of the image to avoid unnecessary calculations.
maskdata, mask = median_otsu(ss_data, 4, 2, False, vol_idx=[0], dilate=1)
# plot the b0 image for a few z-axis slices
plot_3d_z_indices(maskdata[:,:,:,0], idx_list=range(30, 41, 2) , num_rows=2, num_cols=3)<jupyter_output><empty_output><jupyter_text>Work with smaller data and get the freewater maps, FA, corrected-FA etc<jupyter_code>fw_runner = FreewaterRunner(maskdata, ss_gtab, 
                                   xslice=slice(10, 90), 
                                   yslice=slice(10, 90), 
                                   zslice=slice(30, 41))
fw_runner.LOG = False # turn off logging for this example
fw_runner.run_model(num_iter=100, dt=0.001)<jupyter_output>Stissue = 0.0001 : Swater = 16227.5042549
Single shell bvalue = 1000.0
Attenuation_min = 0.007, Attenuation_max = 0.990
Ahat.shape = (80, 80, 11, 183)
Awater_k = 0.05
f_init.shape = (80, 80, 11, 1)<jupyter_text>Check for model convergence<jupyter_code>fw_runner.plot_loss()<jupyter_output><empty_output><jupyter_text>Free Water map<jupyter_code># Free water map after iterations
plt.set_cmap("viridis_r")
plot_3d_z_indices(fw_runner.get_fw_map(), idx_list=range(30, 41, 2) , num_rows=2, num_cols=3)<jupyter_output><empty_output><jupyter_text>Mean Diffusivity (free water corrected)<jupyter_code>plt.set_cmap("viridis_r")
plot_3d_z_indices(fw_runner.get_fw_md(), idx_list=range(30, 41, 2) , num_rows=2, num_cols=3)<jupyter_output><empty_output><jupyter_text>Fractional Anisotropy (free water corrected)<jupyter_code>### Freewater corrected Fractional Anisotropy
plt.set_cmap("viridis")
plot_3d_z_indices(fw_runner.get_fw_fa(), idx_list=range(30, 41, 2) , num_rows=2, num_cols=3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11964403427818061, 'fraction_numerical': 0.043177323665128546, 'mean_word_length': 5.322916666666667, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '277491', 'license': 'Unlicense', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1117, 'n_words': 256, 'path': 'notebooks/Example.ipynb', 'repo_name': 'sameerd/DiffusionTensorImaging', 'size': '3034'}