Skip to content

Commit

Permalink
Keep params for plots in session_state
Browse files Browse the repository at this point in the history
  • Loading branch information
gurayerus committed Sep 18, 2024
1 parent 76ca290 commit ede10c9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
13 changes: 7 additions & 6 deletions src/NiChart_Viewer/src/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
if 'instantiated' not in st.session_state:

# Dataframe to keep plot ids
st.session_state.plots = pd.DataFrame({'PID':[]})
st.session_state.pid = 1
st.session_state.plots = pd.DataFrame(columns = ['pid', 'xvar', 'yvar', 'hvar', 'trend'])
st.session_state.plot_index = 1

# Path to root folder
st.session_state.path_root = os.path.dirname(os.path.dirname(os.path.dirname(os.getcwd())))
st.session_state.path_root = os.path.join(st.session_state.path_root, 'test')

# Path to input folder (used as the init path in file selection)
st.session_state.path_input = st.session_state.path_root
Expand All @@ -20,11 +21,11 @@
st.session_state.path_output = ''

# Default values for plotting parameters
st.session_state.default_x_var = 'Age'
st.session_state.default_y_var = 'GM'
st.session_state.default_hue_var = 'Sex'
st.session_state.plot_xvar = 'Age'
st.session_state.plot_yvar = 'GM'
st.session_state.plot_hvar = 'Sex'
st.session_state.trend_types = ['none', 'ols', 'lowess']
st.session_state.default_trend_type = 'none'
st.session_state.plot_trend = 'none'

# ID selected by user
st.session_state.sel_mrid = ''
Expand Down
18 changes: 7 additions & 11 deletions src/NiChart_Viewer/src/pages/view_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
import numpy as np
from nibabel.orientations import axcodes2ornt, ornt_transform

# # Initiate Session State Values
# if 'instantiated' not in st.session_state:
# st.session_state.plots = pd.DataFrame({'PID':[]})
# st.session_state.pid = 1
# st.session_state.instantiated = True

# Parameters for viewer
VIEWS = ["axial", "sagittal", "coronal"]
VIEW_AXES = [0, 2, 1]
Expand All @@ -27,7 +21,6 @@
MASK_COLOR = np.array([0.0, 1.0, 0.0]) # RGB format
OLAY_ALPHA = 0.2


def reorient_nifti(nii_in, ref_orient = 'LPS'):
'''
Initial img is reoriented to a standard orientation
Expand Down Expand Up @@ -192,7 +185,6 @@ def prep_images(f_img, f_mask, sel_var_ind, dict_derived):
# Read derived roi list and convert to a dict
dict_derived = read_derived_roi_list(st.session_state.list_MUSE_derived)


# Page controls in side bar
with st.sidebar:

Expand Down Expand Up @@ -234,10 +226,14 @@ def prep_images(f_img, f_mask, sel_var_ind, dict_derived):
# Select roi index
sel_var_ind = dict_roi[sel_var]


# File names for img and mask
f_img = os.path.join(st.session_state.path_output, st.session_state.folder_img_t1, sel_mrid + st.session_state.suffix_t1img)
f_mask = os.path.join(st.session_state.path_output, st.session_state.folder_img_dlmuse, sel_mrid + st.session_state.suffix_dlmuse)
f_img = os.path.join(st.session_state.path_output,
st.session_state.folder_img_t1,
sel_mrid + st.session_state.suffix_t1img)

f_mask = os.path.join(st.session_state.path_output,
st.session_state.folder_img_dlmuse,
sel_mrid + st.session_state.suffix_dlmuse)

if os.path.exists(f_img) & os.path.exists(f_mask):

Expand Down
2 changes: 1 addition & 1 deletion test/test4_adni3

0 comments on commit ede10c9

Please sign in to comment.