Skip to content

Instantly share code, notes, and snippets.

@tjlane
Last active February 19, 2020 15:59
Show Gist options
  • Save tjlane/fce205cc28b684b20df57163797ad5af to your computer and use it in GitHub Desktop.
Save tjlane/fce205cc28b684b20df57163797ad5af to your computer and use it in GitHub Desktop.
MeV UED MicroED
import os
import numpy as np
import sys
import fabio
from glob import glob
from scipy.signal import medfilt2d
header = {
'beam_center_x': 512,
'beam_center_y': 512,
'bit_depth_readout': 32,
'count_time': 0.099996,
'countrate_correction_applied': 1,
'description': 'UED',
'detector_distance': 0.150,
'detector_number': 'E-08-0102',
'detector_readout_time': 3.78e-06,
'efficiency_correction_applied': 1,
'flatfield_correction_applied': 1,
'frame_time': 0.1,
'pixel_mask_applied': 0,
'sensor_material': 'Si',
'sensor_thickness': 0.00032,
'threshold_energy': 4680000,
'virtual_pixel_correction_applied': 1,
'x_pixel_size': 9.5e-06,
'y_pixel_size': 9.5e-06,
}
files = sorted(glob(sys.argv[-1]))
print(sys.argv[-1])
print("found %d files" % len(files))
for idx, fn in enumerate(files):
out_fn = "img_%04i.cbf" % (idx+1,)
print(idx, fn, '-->', out_fn)
frame_data = np.genfromtxt(fn)
frame_data[frame_data < 0.0] = 0.0
frame_data = medfilt2d(frame_data, 9)
cbf = fabio.cbfimage.cbfimage(header=header, data=frame_data.astype(np.int32))
cbf.write(out_fn)
os.system('adxv -sa img_%04i.cbf img_%04i.img' % (idx+1,idx+1))
TITL ued1 in P 1 2(1) 1
CELL 0.002650 5.441 7.208 33.988 90.000 86.400 90.000
ZERR 2.00 0.25 0.25 0.25 0.0 3.0 0.0
LATT -1
SYMM -X,Y+1/2,-Z
SFAC C 0.208 0.922 0.702 5.018 1.144 16.523 0.425 47.300 0.030 =
0.0 0.0 0.000 0.770 12.011
SFAC H 0.042 0.991 0.103 3.924 0.205 11.597 0.170 31.984 0.006 =
0.0 0.0 0.000 0.310 1.008
SFAC O 0.308 1.088 0.733 4.593 0.710 13.052 0.185 33.768 0.048 =
0.0 0.0 0.000 0.660 15.999
SFAC N 0.216 0.843 0.649 4.055 0.968 12.693 0.345 36.058 0.032 =
0.0 0.0 0.000 0.700 14.007
SFAC S 0.610 1.173 1.367 6.371 2.268 18.858 0.808 49.703 0.108 =
0.0 0.0 0.000 1.030 32.060
UNIT 38 42 0 0 0
HKLF 4
END
!*****************************************************************************
!
! XDS input file created by TJL Feb 2020 for solving MeV UED structure
! - 4.2 MeV e-
! - yaw geometry
! - median filter spots
!
!*****************************************************************************
!====================== DETECTOR PARAMETERS ==================================
! DETECTOR=UED
MINIMUM_VALID_PIXEL_VALUE=0
OVERLOAD= 32768
GAIN=1.0 ! pixel contents is interpreted as X-ray counts
QX=0.0095 QY=0.0095 ! [mm]
NX= 1024 NY= 1024 ! 1M
UNTRUSTED_ELLIPSE= 445 545 465 565
TRUSTED_REGION=0.02 1.41 !Relative radii limiting trusted detector region
DIRECTION_OF_DETECTOR_X-AXIS= 1.0 0.0 0.0
DIRECTION_OF_DETECTOR_Y-AXIS= 0.0 1.0 0.0
!====================== JOB CONTROL PARAMETERS ===============================
JOB= XYCORR INIT COLSPOT IDXREF DEFPIX INTEGRATE CORRECT
!JOB= CORRECT
!====================== GEOMETRICAL PARAMETERS ===============================
ORGX= 488 ORGY= 510 !Detector origin (pixels). ORGX=NX/2; ORGY=NY/2
DETECTOR_DISTANCE= 1500 !(mm)
ROTATION_AXIS= 0.0 1.0 0.0
OSCILLATION_RANGE=0.2
X-RAY_WAVELENGTH=0.00265 !Angstroem
INCIDENT_BEAM_DIRECTION=0.0 0.0 1.0
FRACTION_OF_POLARIZATION=0.5 !default=0.5 for unpolarized beam
POLARIZATION_PLANE_NORMAL= 0.0 1.0 0.0
!======================= CRYSTAL PARAMETERS =================================
! TJL : only use if known a priori
! SPACE_GROUP_NUMBER=1
! UNIT_CELL_CONSTANTS= 77.4 77.4 77.4 90.0 90.0 90.0
!==================== SELECTION OF DATA IMAGES ==============================
!Generic file name and format (optional) of data images
NAME_TEMPLATE_OF_DATA_FRAMES=../data/corrected_yaw_data/img_????.img
! DATA_RANGE=1 5
DATA_RANGE=1 225
BACKGROUND_RANGE=1 225 !Numbers of first and last data image for background
SPOT_RANGE=1 225 !First and last data image number for finding spots
!================= PARAMETERS CONTROLLING REFINEMENTS =======================
REFINE(IDXREF)=BEAM AXIS ORIENTATION CELL ! POSITION
REFINE(INTEGRATE)= ORIENTATION POSITION BEAM ! CELL AXIS
REFINE(CORRECT)=POSITION BEAM ORIENTATION CELL AXIS
!================== CRITERIA FOR ACCEPTING REFLECTIONS ======================
VALUE_RANGE_FOR_TRUSTED_DETECTOR_PIXELS= 10 30000 !Used by DEFPIX
INCLUDE_RESOLUTION_RANGE=25 1.0 !Angstroem; used by DEFPIX,INTEGRATE,CORRECT
!MINIMUM_ZETA=0.05 !Defines width of 'blind region' (XPLAN,INTEGRATE,CORRECT)
!WFAC1=1.0 !This controls the number of rejected MISFITS in CORRECT;
!a larger value leads to fewer rejections.
!============== DECISION CONSTANTS FOR FINDING CRYSTAL SYMMETRY =============
!Decision constants for detection of lattice symmetry (IDXREF, CORRECT)
! MAX_CELL_AXIS_ERROR=0.03 ! Maximum relative error in cell axes tolerated
! MAX_CELL_ANGLE_ERROR=2.0 ! Maximum cell angle error tolerated
!Decision constants for detection of space group symmetry (CORRECT).
!Resolution range for accepting reflections for space group determination in
!the CORRECT step. It should cover a sufficient number of strong reflections.
TEST_RESOLUTION_RANGE=8.0 4.5
MIN_RFL_Rmeas= 50 ! Minimum #reflections needed for calculation of Rmeas
MAX_FAC_Rmeas=2.0 ! Sets an upper limit for acceptable Rmeas
!============== INTEGRATION AND PEAK PROFILE PARAMETERS =====================
!BEAM_DIVERGENCE= 0.80 !arctan(spot diameter/DETECTOR_DISTANCE)
!BEAM_DIVERGENCE_E.S.D.= 0.080 !half-width (Sigma) of BEAM_DIVERGENCE
!======= PARAMETERS CONTROLLING CORRECTION FACTORS (used by: CORRECT) =======
!MINIMUM_I/SIGMA=3.0 ! min(I/sigma) for reflections used in global refinement
!SNRC=0.1 ! min(I/sigma) for reflections used for finding corrections
!BATCHSIZE=5.0 ! rotation range covered by a batch of consecutive images
!CORRECTIONS= DECAY MODULATION ABSORPTION
!====================== INDEXING PARAMETERS =================================
!SEPMIN=4.0 ! default is 6 for other detectors
!LUSTER_RADIUS=2 ! default is 3 for other detectors
MAXIMUM_ERROR_OF_SPOT_POSITION=6.0
MAXIMUM_ERROR_OF_SPINDLE_POSITION=4.0
MINIMUM_FRACTION_OF_INDEXED_SPOTS=0.1
!=========== PARAMETERS DEFINING BACKGROUND AND PEAK PIXELS =================
! TJL Note: the following are critical parameters for spotfinding
STRONG_PIXEL=2.0 !used by: COLSPOT
MINIMUM_NUMBER_OF_PIXELS_IN_A_SPOT=25 !used by: COLSPOT
NBX=15 NBY=15 !Define a rectangle of size (2*NBX+1)*(2*NBY+1)
BACKGROUND_PIXEL=5.0 !used by: COLSPOT,INTEGRATE
!SIGNAL_PIXEL=3.0 !used by: INTEGRATE
!A pixel above the threshold contributes to the spot centroid
!FIXED_SCALE_FACTOR=TRUE !Default is FALSE; used by : INIT,INTEGRATE
@tjlane
Copy link
Author

tjlane commented Feb 19, 2020

Software Used (that is generally useful)

Install these!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment