Skip to content

Instantly share code, notes, and snippets.

View benjaminhwilliams's full-sized avatar

Ben Williams benjaminhwilliams

View GitHub Profile
@benjaminhwilliams
benjaminhwilliams / h5py_in_memory.py
Created July 2, 2024 15:19
Create an h5py in-memory file object
hdf5_in_memory = {"driver": "core", "backing_store": False}
with h5py.File(" ", mode="w", **hdf5_in_memory) as f:
...
@benjaminhwilliams
benjaminhwilliams / format_nxmx_dls_i19_2_custom_dac.py
Last active April 5, 2024 13:28
DXTBX format class for DLS I19-2 Eiger data, with custom DAC opening angle
import math
from dxtbx.format.FormatNXmxDLSI19_2 import FormatNXmxDLSI19_2
from dxtbx.masking import GoniometerMaskerFactory
class FormatNXmxDLSI19_2_CustomDAC(FormatNXmxDLSI19_2):
"""
Read NXmx-flavour data from beamline I19-2 at Diamond Light Source.
@benjaminhwilliams
benjaminhwilliams / sbatch-wilson.sh
Last active March 21, 2024 16:38
A useful header for Slurm sbatch submission on the Wilson cluster at Diamond Light Source
#!/bin/bash
#SBATCH --nodes=1
#SBATCH --cpus-per-task=20
#SBATCH --time=04:00:00
#SBATCH --error=job-%J.err
#SBATCH --output=job-%J.out
#SBATCH -A i19-1
#SBATCH -p cs05r
echo "Hello world!"
@benjaminhwilliams
benjaminhwilliams / shadow_mask.py
Last active November 14, 2022 14:22
A prototype tool for creating a mask for a pair of coaxial apex-sharing conical shadows, which rotate with the sample, using the metadata in a NXmx NeXus file. Use cases include shadowing the body of a diamond anvil pressure cell.
"""
Create a conical shadow mask for NXmx-flavour NeXus image data.
From a NXmx NeXus-format HDF5 data file, compute a stack of mask frames corresponding
to the shadow on the detector of a circular object or aperture that rotates with the
sample. This might be used to mask the anvils of a diamond anvil pressure cell or
the sample mount assembly in a complex goniometer apparatus.
It is assumed that the shadowed region is bounded by a double cone, with the apex at
the lab frame origin. You must specify the cones' axis as a vector, and aperture (twice
@benjaminhwilliams
benjaminhwilliams / tqdm_like_dask.py
Created October 6, 2022 14:17
A tqdm progress bar with a format that mimics Dask Distributed's `progress`
from tqdm import tqdm
from dask import diagnostics
class TqdmLikeDask(tqdm):
"""A tqdm progress bar with a format that mimics Dask Distributed's 'progress'."""
@staticmethod
def format_interval(t):
return diagnostics.progress.format_time(t)
@benjaminhwilliams
benjaminhwilliams / background_and_peak_pixels.py
Created December 8, 2018 11:02
Four toy scripts for learning about the DIALS toolkit, created for the CCP4-DLS workshop, December 2018
#!dials.python
# -*- coding:utf-8 -*-
# The lines above just let your computer know how to read this file and
# that this program should be run with the in-built dials python distribution.
u"""
Filter background pixels from signal pixels
This program separates pixels that are likely to be part of reflections