Skip to content

Instantly share code, notes, and snippets.

View ximeg's full-sized avatar

RKiselev ximeg

View GitHub Profile
@ximeg
ximeg / TC waveform.c
Created October 24, 2024 18:53
TC waveform output on SAM3X
void init_TC0_waveform()
{
sysclk_enable_peripheral_clock(ID_TC0);
tc_init(TC0, 0,
TC_CMR_TCCLKS_TIMER_CLOCK4 | // select clock source
TC_CMR_WAVE | // waveform mode
TC_CMR_EEVT_XC0 | // external event selection - enables TIOB output!
TC_CMR_ASWTRG_SET | // set A on timer start
TC_CMR_ACPA_CLEAR | // clear A on compare event A
@ximeg
ximeg / quanterix2470_custom_layout.py
Last active October 16, 2024 20:13
Microarrayer layout generator
HEADER = """\
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<IndirectPrinting>
"""
FOOTER = """\
<Attributes>
<PrintName>CustomPrint</PrintName>
<Originals>4</Originals>
<Replicants>{Replicants}</Replicants>
@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 / 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 / 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 / napari_save_layer.py
Created June 11, 2022 22:32
Save napari layer as displayed at full resolution
LAYER = 'Cy3'
OUT = 'my_exported_image_' + LAYER
from matplotlib import pyplot as plt
import numpy as np
layer = viewer.layers[LAYER]
img = layer.data