Skip to content

Instantly share code, notes, and snippets.

View ximeg's full-sized avatar

RKiselev ximeg

View GitHub Profile
@ximeg
ximeg / run ffmpeg for pTIRF movie.py
Created January 31, 2024 23:35
Convert a number of individual frames to a compressed MP4 movie with ffmpeg on Linux from Python
# https://chat.openai.com/c/cff8e0fc-20df-4425-9e2b-7aa8228ab7a1
## Install ffmpeg on RHEL8: https://www.benholcomb.com/ffmpeg-on-rhel8/
## After that
# sudo yum install python3-devel
## Create virtual environment
# python3 -m venv path/to/venv
# cd path/to/venv
# bin/activate
@ximeg
ximeg / make_tirf_movie.ijm
Created January 23, 2024 15:56
Create highly compressed MP4 movie from a TIFF stack with scalebar and a timestamp
Dialog.create("pTIRF movie creator");
Dialog.addNumber("Time interval between frames", 500, 0, 6, "ms");
Dialog.addNumber("Brightness/contrast: black level", 400, 0, 6, "counts");
Dialog.addNumber("Brightness/contrast: white level", 1000, 0, 6, "counts");
Dialog.addNumber("Time point of injection", 10, 1, 6, "s");
Dialog.show();
exp_time = Dialog.getNumber() / 1000.0;
low = Dialog.getNumber();
high = Dialog.getNumber();
@ximeg
ximeg / ThresholdingAlgo.py
Created April 20, 2017 07:20
Python implementation of smoothed z-score algorithm from http://stackoverflow.com/a/22640362/6029703
#!/usr/bin/env python
# Implementation of algorithm from http://stackoverflow.com/a/22640362/6029703
import numpy as np
import pylab
def thresholding_algo(y, lag, threshold, influence):
signals = np.zeros(len(y))
filteredY = np.array(y)
avgFilter = [0]*len(y)
stdFilter = [0]*len(y)
@ximeg
ximeg / quantify_shaking.py
Last active May 30, 2023 17:35
Quantify amount of shaking caused by motorized liquid injection during pTIRF imaging
#!/usr/bin/env python
# coding: utf-8
import skimage.io as skio
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from os.path import basename, splitext, exists
from time import sleep
from os import listdir
@ximeg
ximeg / subplotTight.m
Created September 28, 2022 21:48
subplotTight - MATLAB faster version of subplot with tight plot spacing
function [ax,AxisPos] = subplotTight(nRow, nCol, varargin)
% subplotTight faster version of subplot with tight plot spacing
%
% https://www.mathworks.com/matlabcentral/answers/16458-making-less-space-between-figures-in-subplot
%% Process input arguments
narginchk(2,Inf);
nargoutchk(0,1);
@ximeg
ximeg / knitter
Last active August 17, 2022 10:37
Knitter - command line tool to knit RMarkdown documents
#!/bin/bash
# Adapted from https://stackoverflow.com/a/52543399/6029703
if [ "$#" -gt 2 -o "$#" -lt 1 ]; then
echo "********************************************************************"
echo "* Knitter version 1.1 *"
echo "********************************************************************"
echo -e "This script converts Rmd files into HTML (default) or PDFs. \n"
echo -e "usage: knitter file.Rmd [output_format] \n"
@ximeg
ximeg / nasty_timer_debugger.ino
Last active August 9, 2022 20:10
Arduino debugging - external timer clock
// This creates an external pulse source for an Arduino board - useful for timer debugging!
/* python
from time import sleep
from serial import Serial
from ctypes import c_uint32
from avrpy.mega328P import Mega328P
avr = Mega328P("COM6")
@ximeg
ximeg / timer1.h
Last active August 3, 2022 03:17
Arduino extended timer1
#include <stdint.h>
#include <Arduino.h>
#ifndef _AVR_IOXXX_H_
#include <avr/iom328.h> // Arduino Uno uses AtMega328p microchip
#endif
uint32_t us2cts(uint32_t us)
{
return us >> 2;
}
@ximeg
ximeg / arduino_UART_regs.ino
Created June 25, 2022 00:31
Control of Arduino registers over UART
#define uchar unsigned char
void setup_timer_counter_1(){
/* TCCR1: Timer Counter Control Register */
// bit 7 6 5 4 3 2 1 0
uchar _TCCR1A = 0; // COM1A1 COM1A0 COM1B1 COM1B0 - - WGM10 WGM11
uchar _TCCR1B = 0; // ICNC1 ICES1 - WGM13 WGM12 CS12 CS11 CS10
uchar _TCCR1C = 0; // FOC1A FOC1B - - - - - -
// Set COM (Compare Output Mode) for pins OC1A (#9) and OC1B (#10)
@ximeg
ximeg / .bashrc-parallel-ffmpeg-video-tools.sh
Last active June 17, 2022 05:04
.bashrc parallel ffmpeg video tools
# Video encoding. Arguments to ffmpeg should be passed in quotes
# Example
# ls *.avi | ff_avi2webm "-filter:v 'crop=in_w-100:in_h/2'"
ff_any2webm(){
parallel ffmpeg -i {} $1 -c:v vp9 {.}.webm
}
ff_whatsapp(){
# Convert specified videos to mp4 that are compatible with whatsapp