Skip to content

Commit

Permalink
Merge pull request #101 from AllenNeuralDynamics/han_fix_trajectory_page
Browse files Browse the repository at this point in the history
fix trajectory page
  • Loading branch information
hanhou authored Dec 3, 2024
2 parents dae1773 + 4ecbb72 commit a481ad3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions code/pages/1_Learning trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def app():
# -- get cols --
col_task = [s for s in df.metadata.columns
if not any(ss in s for ss in ['lickspout', 'weight', 'water', 'time', 'rig',
'user_name', 'experiment', 'task', 'notes']
'user_name', 'experiment', 'task', 'notes', 'laser']
)
]

Expand All @@ -47,9 +47,13 @@ def app():

def do_pca(df, name):
df = df.dropna(axis=0, how='any')
df = df[~df.isin([np.nan, np.inf, -np.inf]).any(axis=1)]

df_to_pca = df.drop(columns=['subject_id', 'session'])
df_to_pca = df_to_pca.select_dtypes(include=[np.number, float, int])

# Standardize the features
x = StandardScaler().fit_transform(df.drop(columns=['subject_id', 'session']))
x = StandardScaler().fit_transform(df_to_pca)

# Apply PCA
pca = PCA(n_components=10) # Reduce to 2 dimensions for visualization
Expand All @@ -62,6 +66,7 @@ def do_pca(df, name):
principalDf.reset_index(inplace=True)

# -- trajectory --
st.markdown(f'### PCA on {name} metrics')
fig = go.Figure()

for mouse_id in principalDf['subject_id'].unique():
Expand Down Expand Up @@ -108,7 +113,7 @@ def do_pca(df, name):

# -- pca components --
pca_components = pd.DataFrame(pca.components_,
columns=df.drop(columns=['subject_id', 'session']).columns)
columns=df_to_pca.columns)
pca_components
fig = make_subplots(rows=3, cols=1)

Expand Down

0 comments on commit a481ad3

Please sign in to comment.