Skip to content

Instantly share code, notes, and snippets.

View valosekj's full-sized avatar

Jan Valosek valosekj

View GitHub Profile
@valosekj
valosekj / load_python_colormap_to_fsleyes.md
Created October 23, 2023 23:24
Load a Python colormap to FSLeyes

Load a Python colormap to FSLeyes

Get RGB colors, one per line, for a given Python colormap. In the script below, we get RGB colors for the jet matplotlib colormap.

import matplotlib.pyplot as plt
import numpy as np

# Generate the jet colormap
cmap = plt.cm.get_cmap('jet')
@valosekj
valosekj / custom_FSLeyes_scene.png
Last active September 18, 2023 20:34
Set up a custom scene using the FSLeyes API via a custom Python script
custom_FSLeyes_scene.png
@valosekj
valosekj / template_script_sct_run_batch.md
Created July 18, 2023 19:36
Template script for `sct_run_batch`

Template script for sct_run_batch

This gist contains a template script that can be run across multiple subjects using the sct_run_batch wrapper script.

The template bash script below can be run from you command line using the following command:

sct_run_batch -script example_script.sh -path-data <DATA> -path-output <DATA>_202X-XX-XX -jobs 16
import os
import glob
import hashlib
import argparse
def compute_checksum(file_path):
with open(file_path, 'rb') as f:
file_bytes = f.read()
return hashlib.md5(file_bytes).hexdigest()
@valosekj
valosekj / change_itk_direction.py
Last active February 25, 2023 20:32
Fix ITK direction for nnU-Net
# Set ITK direction from image1 to image2
#
# Usage:
# python change_itk_orientation.py <image1> <image2>
# Example:
# python change_itk_orientation.py sub-001_T1w.nii.gz sub-001_T1w_seg.nii.gz
#
# Jan Valosek
#
@valosekj
valosekj / ssh_configuration.md
Last active September 27, 2022 06:45
Configuration of `ssh` connection #blog

Configuration of ssh connection

Unix and MacOS

Let's say we want to configure an ssh connection between machine alpha and beta.

  1. Go to your home folder at machine alpha:
$ cd ~
@valosekj
valosekj / git_collaboration.md
Last active November 7, 2022 14:54
Simple workflow of collaboration in small team using git and GitHub

Simple workflow of collaboration in small team using git and GitHub

This gist describes example of simple workflow on repository whose changes are tracked by git and GitHub

1) Clone (download repository from GitHub to your computer)

# Go to directory where repository will be cloned (downloaded)
cd ~/Documents
# Clone repository from GitHub
@valosekj
valosekj / virtual_enviroments.md
Last active November 11, 2023 19:24
How to create and use virtual environments (venv and conda)

How to create and use virtual environments (venv and conda)

venv and conda are environment manager tools allowing to create virtual environments. Virtual environment separates the dependencies (Python packages) for different projects. This mean that each project can have its own dependencies. Usage of virtual environments allows you to avoid installing Python packages globally (to the system Python) which could break system tools or other projects.

venv environment

  1. Create venv

MacOS or Linux (without or with site-packages)

@valosekj
valosekj / run_python_from_shell.md
Last active June 20, 2023 15:14
Run python script from shell #blog

Run python script from shell (bash, zsh)

Sometimes, I need to call/run python script with arguments from shell. I use bash or zsh as my shell and following workaround works great for me.

Using shell wrapper

  1. Some example python script which I need to run from bash:

my_python_script.py:

@valosekj
valosekj / matplotlib_tips.md
Last active October 31, 2023 16:26
Tips and hacks for plotting in python

Tips and hacks for plotting in python

This gist containts several useful tips, tricks and hacks for plotting of figures, plots and charts using python (matplotlib and seaborn packages).

Fix warning about matplotlib backend in PyCharm

import matplotlib
matplotlib.use('TkAgg')