from repo2data.repo2data import Repo2Data
import os
import pickle
import matplotlib.pyplot as plt
import chart_studio.plotly as py
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
from IPython.display import display, HTML
from plotly import tools
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_ROOT = dataset_path / "qmrlab-t1-book" / "t1-book-neurolibre"
filename = DATA_ROOT / "02" / 'figure_7.pkl'
with open(filename, 'rb') as f:
T1_map, FA_03, FA_20, B1map, xAxis, yAxis = pickle.load(f)
config={'showLink': False, 'displayModeBar': False}
init_notebook_mode(connected=True)
trace1 = go.Heatmap(x = xAxis,
y = yAxis,
z=FA_03,
colorscale='gray',
showscale = False,
visible=False,
name = 'Signal')
trace2 = go.Heatmap(x = xAxis,
y = yAxis,
z=FA_20,
colorscale='gray',
showscale = False,
visible=True,
name = 'Signal')
trace3 = go.Heatmap(x = xAxis,
y = yAxis,
z=B1map,
zmin=0.7,
zmax=1.3,
colorscale='balance',
showscale = False,
visible=False,
name = 'B1 values')
trace5 = go.Heatmap(x = xAxis,
y = yAxis,
z=T1_map,
zmin=0.0,
zmax=5000,
colorscale='Portland',
xaxis='x2',
yaxis='y2',
visible=True,
name = 'T1 values (ms)')
data=[trace1, trace2, trace3, trace5]
updatemenus = list([
dict(active=1,
x = 0.09,
xanchor = 'left',
y = -0.15,
yanchor = 'bottom',
direction = 'up',
font=dict(
family='Times New Roman',
size=16
),
buttons=list([
dict(label = '3 deg',
method = 'update',
args = [{'visible': [True, False, False, True]},
]),
dict(label = '20 deg',
method = 'update',
args = [{'visible': [False, True, False, True]},
]),
dict(label = 'B<sub>1</sub> map',
method = 'update',
args = [{'visible': [False, False, True, True]},
])
])
)
])
layout = dict(
width=560,
height=345,
margin = dict(
t=40,
r=50,
b=10,
l=50),
annotations=[
dict(
x=0.055,
y=1.15,
showarrow=False,
text='Input Data',
font=dict(
family='Times New Roman',
size=26
),
xref='paper',
yref='paper'
),
dict(
x=0.6,
y=1.15,
showarrow=False,
text='T<sub>1</sub> map',
font=dict(
family='Times New Roman',
size=26
),
xref='paper',
yref='paper'
),
dict(
x=1.22,
y=1.15,
showarrow=False,
text='T<sub>1</sub> (ms)',
font=dict(
family='Times New Roman',
size=26
),
xref='paper',
yref='paper'
),
],
xaxis = dict(range = [0,127], autorange = False,
showgrid = False, zeroline = False, showticklabels = False,
ticks = '', domain=[0, 0.58]),
yaxis = dict(range = [0,127], autorange = False,
showgrid = False, zeroline = False, showticklabels = False,
ticks = '', domain=[0, 1]),
xaxis2 = dict(range = [0,127], autorange = False,
showgrid = False, zeroline = False, showticklabels = False,
ticks = '', domain=[0.40, 0.98]),
yaxis2 = dict(range = [0,127], autorange = False,
showgrid = False, zeroline = False, showticklabels = False,
ticks = '', domain=[0, 1], anchor='x2'),
showlegend = False,
autosize = False,
updatemenus=updatemenus,
plot_bgcolor='white'
)
fig = dict(data=data, layout=layout)
iplot(fig, filename = 'vfa_fig_7.html', config = config)
Loading...