Skip to content

Instantly share code, notes, and snippets.

@margulies
margulies / x.discord_backup.sh
Created February 14, 2023 11:14
Shell script for backing up discord server
#!/bin/bash
# Install DiscordChatExporter.Cli from:
# https://github.com/Tyrrrz/DiscordChatExporter
#
# .NET runtime also needs to be installed:
# https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Dotnet.md
#
# Find your token and server ID ('guild'):
# https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs/Token-and-IDs.md
@margulies
margulies / x.calc_gradient_extrema_zones.sh
Created March 26, 2021 16:31
To calculate the DMN nodes on the individual level based on the principal gradient
#!/bin/bash
# set global variables:
subject_list = "XXXXX1 XXXXX2 XXXXX3 XXXXX4"
comp = 0 # for the first component
dir = "/XXXX/XXX" # location of data
zone_rois = "....
# find local extrema within each zone for each individual
# run the following conversion for each individual left and right hemisphere matrix separately
# convert matrices to nifti1:
wb_command -cifti-convert -to-nifti input.dconn.nii output.nii
# convert matrices to vista:
# after install lipsia:
export dir=[directory with data]
docker run -v ${dir}:${dir} lipsia vnifti -in ${dir}/output.nii -out ${dir}/output.v
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IPyWidget export</title>
</head>
<body>
<!-- Load require.js. Delete this if your page already loads require.js -->
import numpy as np
import nibabel as nib
from surfdist.load import load_freesurfer_label, get_freesurfer_label
from surfdist.utils import surf_keep_cortex, translate_src
import gdist
import os
base_dir = '/Applications/freesurfer/subjects/'
surf = nib.freesurfer.read_geometry(os.path.join(base_dir, 'fsaverage5/surf/lh.pial'))
cort = np.sort(nib.freesurfer.read_label(os.path.join(base_dir, 'fsaverage5/label/lh.cortex.label')))
def plot_surf_stat_multidim(coords, faces, face_colors=None, stat_map=None,
elev=0, azim=0,
cmap=None,
threshold=None, bg_map=None,
mask=None,
bg_on_stat=False,
alpha='auto',
vmax=None, symmetric_cbar="auto",
figsize=(14,11), label=None, lenient=None,
**kwargs):
@margulies
margulies / dist_calc_matrix.py
Last active August 1, 2018 15:33
function to calculate distance matrix between freesurfer labels
import nibabel as nib, numpy as np, os, sys
#sys.path.insert(0,'../')
import surfdist as sd
from surfdist import viz, load, utils
# function to calculate distance matrix:
def dist_calc_matrix(surf, cortex, labels, exceptions = ['Unknown', 'Medial_wall'], dist_type='min'):
"""
dist_type='min' or 'mean'
returns:
import nipype.pipeline.engine as pe
import nipype.interfaces.utility as util
import nipype.interfaces.io as nio
from nipype.interfaces.freesurfer import SampleToSurface
'''directories'''
preprocDir = "/scr/adenauer1/Franz/nki_nilearn"
freesurferDir = "/scr/ilz2/nilearn_vol2surf_wd/freesurfer"
workingDir = "/scr/ilz2/nilearn_vol2surf_wd/"
sinkDir = "/scr/ilz1/nilearn_vol2surf_sink/"
import numpy as np
import nibabel as nib # git clone --branch enh/cifti2 https://github.com/satra/nibabel.git
from sklearn.metrics import pairwise_distances
# install mapalign: (comment if already installed)
! pip install git+https://github.com/satra/mapalign
from mapalign import embed
# Load data and Fisher's z-to-r transform
# load connectivity matrix as numpy array
def write_cifti(data, fname, dtype = 'dscalar', labels = None, tpl = None):
import subprocess
import os
assert data.shape[0] == 91282, "You must have 91282 vertices on the first dimension (rows)"
if tpl is None:
tpl = '/Users/marcel/projects/HCP/Connectivity_coordinate_system/rsFC_eigenvectors.dscalar.nii'