Skip to content

Instantly share code, notes, and snippets.

View clane9's full-sized avatar

Connor Lane clane9

  • Child Mind Institute
  • Baltimore, MD
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@clane9
clane9 / ssh_forward.sh
Created October 17, 2023 14:11
Multi-hop SSH port forwarding
#!/bin/bash
ssh_forward() {
if [[ $# == 0 || $1 == "-h" || $1 == "--help" ]]; then
echo "Multi-hop SSH port forwarding"
echo
echo "Usage: ssh_forward [--dryrun, -d] --port PORT HOST [HOST2 ...]"
return 1
fi
@clane9
clane9 / icc.py
Last active June 17, 2023 20:25
Compute the intraclass correlation coefficient of an array of observations along an axis of repeated measurements.
import numpy as np
def icc(obs: np.ndarray, axis: Optional[int] = -1, center: bool = True):
"""
Compute the intraclass correlation coefficient of an array of observations along an
axis of repeated measurements.
Args:
obs: observations array, at least 2d
@clane9
clane9 / vscode_on_psc_compute_nodes.md
Last active July 9, 2023 00:26
Running VS code on PSC compute nodes

Running VS code on PSC compute nodes

Here are some quick instructions for running VS code on a PSC/Access/bridges compute node.

Why? It makes your VS Code session faster, and lets you run notebooks within VS Code without guilt.

1. Create an SSH route to the compute node

It's awkward to connect to a compute node through VS code, since you have to go through a login node first. You can make it easier by setting up a new "host" in your ~/.ssh/config file that defines the multi-hop connection.

@clane9
clane9 / tree_to_list.py
Last active February 24, 2023 20:37
Parse the output of the linux `tree` command to json.
"""
Parse the output of the linux `tree` command to a flat list of files
Example::
python tree_to_list.py tree.txt
"""
import argparse
import logging
@clane9
clane9 / plotly_dash_crossfilter_recipe.py
Created November 21, 2022 15:57
Fixed generic crossfilter recipe for Plotly Dash
from dash import Dash, dcc, html
import numpy as np
import pandas as pd
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
import plotly.express as px
def get_figure(df, x_col, y_col, selectedpoints=None, selectedpoints_local=None, pad=0.04):
if selectedpoints is None:
@clane9
clane9 / corr_ratio.py
Last active November 8, 2022 19:41
Correlation ratio cost function
import numpy as np
def corr_ratio(x: np.ndarray, y: np.ndarray, bins: int = 256) -> float:
"""
Flirt correlation ratio cost function between `x` and `y`. Measures the variance
in `y` over each iso-set of `x`.
See [Jenkinson, NeuroImage 2002](https://doi.org/10.1006/nimg.2002.1132),
Table 1 for the definition. Also [here](https://www.fmrib.ox.ac.uk/datasets/techrep/tr02mj1/tr02mj1/node4.html).
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.