# Prepare Python environment
import scipy.io as sio
from pathlib import Path
from contextlib import contextmanager
import sys, os
from pathlib import Path
@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
sys.stdout = devnull
try:
yield
finally:
sys.stdout = old_stdout
import os
from pathlib import Path
def find_myst_yml_directories(start_dir=None):
"""
Recursively search for directories containing myst.yml file.
Args:
start_dir (str or Path): Starting directory (defaults to current directory)
Returns:
list: List of full paths to directories containing myst.yml
"""
if start_dir is None:
start_dir = Path.cwd()
else:
start_dir = Path(start_dir)
myst_dirs = []
def _search_directory(current_dir):
# Check if myst.yml exists in current directory
myst_file = current_dir / "myst.yml"
if myst_file.exists():
myst_dirs.append(str(current_dir.resolve()))
# Don't search subdirectories if we found myst.yml here
return
# Recursively search all subdirectories
for item in current_dir.iterdir():
if item.is_dir():
try:
_search_directory(item)
except (PermissionError, OSError):
# Skip directories we can't access
continue
_search_directory(start_dir)
return myst_dirs
def find_myst_yml_directories_upwards(start_dir=None):
"""
Search for myst.yml in current directory, if not found go to parent and repeat.
Args:
start_dir (str or Path): Starting directory (defaults to current directory)
Returns:
str or None: Full path of directory containing myst.yml, or None if not found
"""
if start_dir is None:
current_dir = Path.cwd()
else:
current_dir = Path(start_dir)
# Keep going up until we reach the filesystem root
while current_dir != current_dir.parent: # Stop at root
myst_file = current_dir / "myst.yml"
if myst_file.exists():
return str(current_dir.resolve())
# Move to parent directory
current_dir = current_dir.parent
return None
with suppress_stdout():
repo_path = Path(find_myst_yml_directories_upwards())
print(repo_path)
data_req_path = repo_path / "binder" / "data_requirement.json"
data_path = repo_path / "data"
dataset_path = data_path / "qmrlab-mooc"
data_dir = dataset_path / "06-MT-03-MTsat" / "06-MT-03-MTsat"
data_file = "fig0.mat"
#Load either archived or generated plot variables
mat_contents = sio.loadmat(data_dir / data_file)
## Plot
# Module imports
# PYTHON CODE
# Module imports
import matplotlib.pyplot as plt
import plotly.graph_objs as go
import numpy as np
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
config={'showLink': False, 'displayModeBar': False}
init_notebook_mode(connected=True)
# Prepare Python environment
tissues = [
"Healthy Cortical GM",
"Healthy WM",
"NAWM",
"Early WM MS Lesion",
"Late WM MS Lesion",
]
protocols = [
"Helms 2008",
"Weiskopf 2013",
"Campbell 2018",
"Karakuzu 2022 Siemens 1",
"Karakuzu 2022 GE 1",
"York 2022",
]
signal_Helms = mat_contents["MTsats"][0]
signal_Weiskopf = mat_contents["MTsats"][1]
signal_Campbell = mat_contents["MTsats"][2]
signal_KarakuzuSiemens = mat_contents["MTsats"][3]
signal_KarakuzuGE = mat_contents["MTsats"][4]
signal_York = mat_contents["MTsats"][5]
# Plot Figure 1
# Module imports
import matplotlib.pyplot as plt
import plotly.graph_objs as go
import numpy as np
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
config={'showLink': False, 'displayModeBar': False}
init_notebook_mode(connected=True)
# PYTHON CODE
init_notebook_mode(connected=True)
# The polling here is to ensure that plotly.js has already been loaded before
# setting display alignment in order to avoid a race condition.
data_Helms = go.Scatter(
x = tissues,
y = signal_Helms,
name = protocols[0],
text = 'N/A',
hoverinfo = 'y'
)
data_Weiskopf = go.Scatter(
x = tissues,
y = signal_Weiskopf,
name = protocols[1],
hoverinfo = 'y'
)
data_Campbell = go.Scatter(
x = tissues,
y = signal_Campbell,
name = protocols[2],
hoverinfo = 'y'
)
data_KarakuzuSiemens = go.Scatter(
x = tissues,
y = signal_KarakuzuSiemens,
name = protocols[3],
hoverinfo = 'y'
)
data_KarakuzuGE = go.Scatter(
x = tissues,
y = signal_KarakuzuGE,
name = protocols[4],
hoverinfo = 'y'
)
data_York = go.Scatter(
x = tissues,
y = signal_York,
name = protocols[5],
hoverinfo = 'y'
)
data = [data_Helms, data_Weiskopf, data_Campbell, data_KarakuzuSiemens, data_KarakuzuGE, data_York]
layout = go.Layout(
width=750,
height=750,
margin=go.layout.Margin(
l=100,
r=80,
b=100,
t=130,
),
annotations=[
dict(
x=-0.15,
y=0.50,
showarrow=False,
text='MTsat (%)',
font=dict(
family='Times New Roman',
size=22
),
textangle=-90,
xref='paper',
yref='paper'
),
],
xaxis=dict(
showgrid=True,
gridcolor='rgb(169,169,169)',
linecolor='black',
linewidth=2
),
yaxis=dict(
showgrid=True,
gridcolor='rgb(169,169,169)',
linecolor='black',
linewidth=2
),
legend=dict(
x=0.25,
y=1.3,
traceorder='normal',
font=dict(
family='Times New Roman',
size=12,
color='#000'
),
bordercolor='#000000',
borderwidth=2
)
)
fig = dict(data=data, layout=layout)
iplot(fig, filename = 'fig1.html', config = config)
Loading...