Skip to content

Instantly share code, notes, and snippets.

View graeme-winter's full-sized avatar
💭
Always trying to make the campsite nicer

Graeme Winter graeme-winter

💭
Always trying to make the campsite nicer
View GitHub Profile
@graeme-winter
graeme-winter / make_shoeboxes.py
Last active April 11, 2024 09:31
Script to take predictions, add some fixed shoebox size and then extract to shoeboxes.refl
# to get to the starting point:
#
# dials.import ~/data/i04_bag_training/*gz
# dials.find_spots imported.expt
# dials.index imported.expt strong.refl
# dials.refine indexed.*
# dials.predict refined.expt
#
# then
#
@graeme-winter
graeme-winter / unbitshufflelz4.py
Created April 3, 2024 05:37
Manually unpack bitshuffle / lz4 data in Python
# Proof of work is computing the sha1 hash of the uncompressed and unshuffled
# data and comparing with the result of doing the operation on the h5py
# extracted data
import binascii
import hashlib
import struct
import sys
import lz4.block
@graeme-winter
graeme-winter / jpg_mp4.py
Created September 23, 2023 06:27
JPG sequence conversion to MP4 - N.B. set up for monochrome, includes overlay with time
import sys
import os
import numpy as np
from PIL import Image, ImageFont, ImageDraw
import cv2
def main(file_template, start, end):
font = ImageFont.truetype("FreeMono.ttf", 32)
@graeme-winter
graeme-winter / quilt.py
Created May 14, 2023 18:48
Quilt combination generator - ensure each 3x3 block contains a unique permutation of 5 coloured pieces
import random
# FIXME fill in numbers of each unique piece here
tiles = {
"a": 10,
"b": 10,
"c": 10,
"d": 10,
"e": 10,
@graeme-winter
graeme-winter / reciprocal_xyz.py
Created May 9, 2023 09:09
Map strong spots to reciprocal space and print x, y, z positions
# Print reciprocal space positions from DIALS strong reflections
# after spot finding
#
# Usage:
#
# dials.import (data)
# dials.find_spots imported.expt
# dials.python reciprocal_xyz.py strong.refl imported.expt
#
# Prints long list of x, y, z positions
@graeme-winter
graeme-winter / blink.dis
Created March 1, 2023 07:11
Disassembled blink code
@graeme-winter
graeme-winter / fetch-7085897.sh
Created February 24, 2023 11:25
Shell script to download i24 multi-crystal data for a dials tutorial from Zenodo
for filename in ins11_b200_1_000001.h5 ins11_b200_1_master.h5 ins11_b200_1_meta.h5 ins11_b200_1.nxs ins11_b295_1_000001.h5 ins11_b295_1_master.h5 ins11_b295_1_meta.h5 ins11_b295_1.nxs ins11_b299_1_000001.h5 ins11_b299_1_master.h5 ins11_b299_1_meta.h5 ins11_b299_1.nxs ins11_b302_1_000001.h5 ins11_b302_1_master.h5 ins11_b302_1_meta.h5 ins11_b302_1.nxs ins11_b365_1_000001.h5 ins11_b365_1_master.h5 ins11_b365_1_meta.h5 ins11_b365_1.nxs ins11_b391_1_000001.h5 ins11_b391_1_master.h5 ins11_b391_1_meta.h5 ins11_b391_1.nxs ins11_b453_1_000001.h5 ins11_b453_1_master.h5 ins11_b453_1_meta.h5 ins11_b453_1.nxs ins11_b474_1_000001.h5 ins11_b474_1_master.h5 ins11_b474_1_meta.h5 ins11_b474_1.nxs ins11_b487_1_000001.h5 ins11_b487_1_master.h5 ins11_b487_1_meta.h5 ins11_b487_1.nxs ins11_b508_1_000001.h5 ins11_b508_1_master.h5 ins11_b508_1_meta.h5 ins11_b508_1.nxs ins11_b566_1_000001.h5 ins11_b566_1_master.h5 ins11_b566_1_meta.h5 ins11_b566_1.nxs ins11_b616_1_000001.h5 ins11_b616_1_master.h5 ins11_b616_1_meta.h5 ins11_b616_1.nxs
@graeme-winter
graeme-winter / movify.py
Created June 11, 2022 05:07
Python script to make movie from stack of jpeg images
import sys
import os
import numpy as np
from PIL import Image, ImageFont, ImageDraw
import cv2
def main(file_template, start=0, end=100000):
@graeme-winter
graeme-winter / camera.sh
Last active June 11, 2022 11:15
Raspberry pi wildlife camera script
#!/bin/bash
# any questions to my.name@gmail.com
TODAY=$(date +%Y%m%d)
START=${1}
HOURS=${2}
# how many ms to run
MS=$((3600 * ${HOURS} * 1000))
@graeme-winter
graeme-winter / verify.py
Created February 9, 2022 09:18
Verify that the frames of an HDF5 file are all identical, and return the hash
import h5py
import hdf5plugin
import sys
def verify(filename):
with h5py.File(filename, "r") as f:
data = f["data"]
nn = data.shape[0]
h = None