Skip to content

Instantly share code, notes, and snippets.

View DanPorter's full-sized avatar

Dan Porter DanPorter

  • Diamond Light Source Ltd.
View GitHub Profile
@DanPorter
DanPorter / i16_read_nxs_files_babelscan.py
Created August 14, 2023 13:21
Read I16 Nexus files in Python with Babelscan
# module load python/3
# or pip install babelscan
import sys
sys.path.insert(0, '/dls_sw/i16/software/python/babelscan')
from babelscan import file_loader, FolderMonitor
# Load scan object
scan = file_loader('/dls/i16/data/2021/mm29566-1/12345.nxs')
print(scan)
@DanPorter
DanPorter / i16_read_nxs_files_h5py.py
Created August 14, 2023 13:17
Read I16 Nexus Files in Python using h5py
# module load python/3
# or pip install h5py (comes with anaconda python)
import h5py
with h5py.File('example_nexus/794932.nxs', 'r') as nx:
print(nx['entry1']['measurement'].keys())
dataset = nx['entry1/measurement/eta']
@DanPorter
DanPorter / i16_read_dat_files_dnp.py
Created August 14, 2023 13:13
Read I16 Dat Files in Python using Scisoftpy
# module load python/3
# or pip install scisoftpy
import scisoftpy as dnp
path = '/dls/i16/data/2021/mm29566-1/%d.dat'
d = dnp.io.load(path % 12345)
eta_array = d.eta
@DanPorter
DanPorter / i16_read_dat_files_py16.py
Created August 14, 2023 13:07
Read I16 Dat Files in Python using Py16
# module load python/3
# or copy "py16progs.py" from https://github.com/DanPorter/Py16
import sys,os
import numpy as np
import matplotlib.pyplot as plt # Plotting
from mpl_toolkits.mplot3d import Axes3D # 3D plotting
# Load Py16progs
sys.path.insert(0,'/dls_sw/i16/software/python/Py16/Py16progs.py') # location of Py16progs
@DanPorter
DanPorter / diffcalc_example.py
Created August 9, 2023 14:28
Example sample alignment using DiffCalc commands on I16 in GDA
# Create new UB
newub # interactive... you will need sample name and lattice parameters
# Add constraints (vertical geometry)
con gam 0 mu 0 phi phi() # phi fixed
con gam 0 mu 0 bisect # bisecting
# Move to position (with pilatus)
pos do do.pil # set delta offset to pilatus detector
pos delta c2th([h,k,l]) eta c2th([h,k,l])/2
@DanPorter
DanPorter / i16_diffractometer_rotations.py
Created August 9, 2023 14:09
Collection of 6-axis diffractometer rotation functions
"""
Python module: Diffractometer Rotations
Set of functions to define diffractometer rotations.
Based on definitions set by:
Busing & Levy Acta Cryst. 22, 457 (1967)
H. You, J. Appl. Cryst. 32 (1999), 614-623
By Dan Porter
@DanPorter
DanPorter / multiple_scattering.py
Created April 22, 2021 18:21
Multiple Scattering Example
"""
Dans_Diffraction Examples
Run multiple scattering calculations
Install Dans_Diffraction from pip:
pip install Dans-Diffraction
Or, download the latest version from Github:
$ git clone https://github.com/DanPorter/Dans_Diffraction.git
"""
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
print('This is version 1.2')
import subprocess
subprocess.call(['pip', 'install', 'Dans_Diffraction'])
#import git
#git.Git().clone("https://github.com/DanPorter/Dans_Diffraction.git")
#!pip install Dans_Diffraction
#import pip, site, importlib
#pip.main(['install', '--user', 'Dans_Diffraction']) # ystockquote could be any package on PyPI
@DanPorter
DanPorter / start_Dans_Diffraction.sh
Last active May 27, 2021 08:18
Download latest version of Dans_Diffraction.py and run ipython
# To install Dans_Diffraction, choose one of the following three options:
# 1. To copy the folder into the local directory:
git clone https://github.com/DanPorter/Dans_Diffraction.git
cd Dans_Diffraction
# 2. To install the last stabel version:
pip install Dans-Diffraction
# 3. To install the latest version directly from github: