This commit is contained in:
2019-03-20 13:52:00 +01:00
parent 3084fe0510
commit 5db0f78aee
910 changed files with 191152 additions and 322 deletions

View File

@@ -0,0 +1,24 @@
from diffcalc.util import allnum, command, DiffcalcException
def sim(scn, hkl):
"""sim hkl scn -- simulates moving scannable (not all)
"""
if not isinstance(hkl, (tuple, list)):
raise TypeError()
if not allnum(hkl):
raise TypeError()
try:
print scn.simulateMoveTo(hkl)
except AttributeError:
raise TypeError(
"The first argument does not support simulated moves")
def energy_to_wavelength(energy):
try:
return 12.39842 / energy
except ZeroDivisionError:
raise DiffcalcException(
"Cannot calculate hkl position as Energy is set to 0")

View File

@@ -0,0 +1,76 @@
from diffcalc.dc.common import energy_to_wavelength
from diffcalc import settings
from diffcalc.hkl.vlieg.transform import VliegTransformSelector,\
TransformCommands, VliegPositionTransformer
from diffcalc.dc.help import compile_extra_motion_commands_for_help
import diffcalc.hkl.vlieg.calc
# reload to aid testing only
import diffcalc.ub.ub as _ub
reload(_ub)
from diffcalc import hardware as _hardware
#reload(_hardware)
import diffcalc.hkl.vlieg.hkl as _hkl
reload(_hkl)
from diffcalc.ub.ub import * # @UnusedWildImport
from diffcalc.hardware import * # @UnusedWildImport
from diffcalc.hkl.vlieg.hkl import * # @UnusedWildImport
from diffcalc.gdasupport.scannable.sim import sim
_transform_selector = VliegTransformSelector()
_transform_commands = TransformCommands(_transform_selector)
_transformer = VliegPositionTransformer(settings.geometry, settings.hardware,
_transform_selector)
transform = _transform_commands.transform
transforma = _transform_commands.transforma
transformb = _transform_commands.transformb
transformc = _transform_commands.transformc
on = 'on'
off = 'off'
auto = 'auto'
manual = 'manual'
def hkl_to_angles(h, k, l, energy=None):
"""Convert a given hkl vector to a set of diffractometer angles"""
if energy is None:
energy = settings.hardware.get_energy() # @UndefinedVariable
position, params = hklcalc.hklToAngles(h, k, l, energy_to_wavelength(energy))
position = _transformer.transform(position)
angle_tuple = settings.geometry.internal_position_to_physical_angles(position) # @UndefinedVariable
angle_tuple = settings.hardware.cut_angles(angle_tuple) # @UndefinedVariable
return angle_tuple, params
def angles_to_hkl(angleTuple, energy=None):
"""Converts a set of diffractometer angles to an hkl position
((h, k, l), paramDict)=angles_to_hkl(self, (a1, a2,aN), energy=None)"""
if energy is None:
energy = settings.hardware.get_energy() # @UndefinedVariable
i_pos = settings.geometry.physical_angles_to_internal_position(angleTuple) # @UndefinedVariable
return hklcalc.anglesToHkl(i_pos, energy_to_wavelength(energy))
settings.ubcalc_strategy = diffcalc.hkl.vlieg.calc.VliegUbCalcStrategy()
settings.angles_to_hkl_function = diffcalc.hkl.vlieg.calc.vliegAnglesToHkl
settings.include_sigtau = True
ub_commands_for_help = _ub.commands_for_help
hkl_commands_for_help = (_hkl.commands_for_help +
_hardware.commands_for_help +
['Transform',
transform,
transforma,
transformb,
transformc] +
compile_extra_motion_commands_for_help())

View File

@@ -0,0 +1,47 @@
# This file differs from dcyou in only two places
from diffcalc import settings
from diffcalc.dc.common import energy_to_wavelength
from diffcalc.dc.help import compile_extra_motion_commands_for_help
import diffcalc.hkl.willmott.calc
# reload to aid testing only
from diffcalc.ub import ub as _ub
reload(_ub)
from diffcalc import hardware as _hardware
#reload(_hardware)
from diffcalc.hkl.you import hkl as _hkl
reload(_hkl)
from diffcalc.ub.ub import * # @UnusedWildImport
from diffcalc.hardware import * # @UnusedWildImport
from diffcalc.hkl.willmot.hkl import * # @UnusedWildImport
from diffcalc.gdasupport.scannable.sim import sim
def hkl_to_angles(h, k, l, energy=None):
"""Convert a given hkl vector to a set of diffractometer angles"""
if energy is None:
energy = settings.hardware.get_energy() # @UndefinedVariable
(pos, params) = hklcalc.hklToAngles(h, k, l, energy_to_wavelength(energy))
angle_tuple = settings.geometry.internal_position_to_physical_angles(pos) # @UndefinedVariable
angle_tuple = settings.hardware.cut_angles(angle_tuple) # @UndefinedVariable
return angle_tuple, params
def angles_to_hkl(angleTuple, energy=None):
"""Converts a set of diffractometer angles to an hkl position
((h, k, l), paramDict)=angles_to_hkl(self, (a1, a2,aN), energy=None)"""
if energy is None:
energy = settings.hardware.get_energy() # @UndefinedVariable
i_pos = settings.geometry.physical_angles_to_internal_position(angleTuple) # @UndefinedVariable
return hklcalc.anglesToHkl(i_pos, energy_to_wavelength(energy))
settings.ubcalc_strategy = diffcalc.hkl.willmott.calc.WillmottHorizontalUbCalcStrategy()
settings.angles_to_hkl_function = diffcalc.hkl.willmott.calc.angles_to_hkl
ub_commands_for_help = _ub.commands_for_help
hkl_commands_for_help = _hkl.commands_for_help + _hardware.commands_for_help + compile_extra_motion_commands_for_help()

View File

@@ -0,0 +1,56 @@
from diffcalc import settings
from diffcalc.dc.common import energy_to_wavelength
from diffcalc.dc.help import compile_extra_motion_commands_for_help
import diffcalc.hkl.you.calc
settings.ubcalc_strategy = diffcalc.hkl.you.calc.YouUbCalcStrategy()
settings.angles_to_hkl_function = diffcalc.hkl.you.calc.youAnglesToHkl
settings.include_reference = True
# reload to aid testing only
from diffcalc.ub import ub as _ub
reload(_ub)
from diffcalc import hardware as _hardware
#reload(_hardware)
from diffcalc.hkl.you import hkl as _hkl
reload(_hkl)
from diffcalc.ub.ub import * # @UnusedWildImport
from diffcalc.hardware import * # @UnusedWildImport
from diffcalc.hkl.you.hkl import * # @UnusedWildImport
def hkl_to_angles(h, k, l, energy=None):
"""Convert a given hkl vector to a set of diffractometer angles
return angle tuple and params dictionary
"""
if energy is None:
energy = settings.hardware.get_energy() # @UndefinedVariable
(pos, params) = hklcalc.hklToAngles(h, k, l, energy_to_wavelength(energy))
angle_tuple = settings.geometry.internal_position_to_physical_angles(pos) # @UndefinedVariable
angle_tuple = settings.hardware.cut_angles(angle_tuple) # @UndefinedVariable
return angle_tuple, params
def angles_to_hkl(angleTuple, energy=None):
"""Converts a set of diffractometer angles to an hkl position
Return hkl tuple and params dictionary
"""
if energy is None:
energy = settings.hardware.get_energy() # @UndefinedVariable
i_pos = settings.geometry.physical_angles_to_internal_position(angleTuple) # @UndefinedVariable
return hklcalc.anglesToHkl(i_pos, energy_to_wavelength(energy))
ub_commands_for_help = _ub.commands_for_help
hkl_commands_for_help = _hkl.commands_for_help + _hardware.commands_for_help + compile_extra_motion_commands_for_help()

View File

@@ -0,0 +1,161 @@
'''
Created on 6 May 2016
@author: walton
'''
from diffcalc import settings
from diffcalc.gdasupport.scannable.sim import sim
import textwrap
from diffcalc.util import bold
class ExternalCommand(object):
"""Instances found in a command_list by format_command_help will
result in documentation for a command without there actually being one.
"""
def __init__(self, docstring):
"""Set the docstring that will be pulled off by format_command_help.
"""
self.__doc__ = docstring
self.__name__ = ''
WIDTH = 27
INDENT = 3
def format_command_help(command_list):
row_list = _command_list_to_table_cells(command_list)
lines = []
for row_cells in row_list:
if len(row_cells) == 1:
heading = row_cells[0]
lines.append('')
lines.append(bold(heading))
lines.append('')
elif len(row_cells) == 2:
cell1, cell2 = row_cells
cell1_lines = textwrap.wrap(cell1, WIDTH, subsequent_indent=' ')
cell2_lines = textwrap.wrap(cell2, 79 - INDENT - 3 - WIDTH)
first_line = True
while cell1_lines or cell2_lines:
line = ' ' * INDENT
if cell1_lines:
line += cell1_lines.pop(0).ljust(WIDTH)
else:
line += ' ' * (WIDTH)
line += ' : ' if first_line else ' '
if cell2_lines:
line += cell2_lines.pop(0)
lines.append(line)
first_line = False
return '\n'.join(lines)
def format_commands_for_rst_table(title, command_list):
W1 = WIDTH # internal width
W2 = 79 - W1 - 3 # internal width
HORIZ_LINE = '+-' + '-' * W1 + '-+-' + '-' * W2 + '-+'
row_list = _command_list_to_table_cells(command_list)
lines = []
lines.append(HORIZ_LINE) # Top line
for row_cells in row_list:
if len(row_cells) == 1:
lines.append('| ' + ('**' + row_cells[0] + '**').ljust(W1 + W2 + 3) + ' |')
elif len(row_cells) == 2:
cmd_and_args = row_cells[0].split(' ', 1)
cmd = cmd_and_args[0]
args = cmd_and_args[1] if len(cmd_and_args) == 2 else ''
cell1 = '**-- %s** %s' % (cmd, args)
cell1_lines = textwrap.wrap(cell1, W1) #, subsequent_indent=' ')
cell2_lines = textwrap.wrap(row_cells[1], W2)
while cell1_lines or cell2_lines:
line = '| '
line += (cell1_lines.pop(0) if cell1_lines else '').ljust(W1)
line += ' | '
line += (cell2_lines.pop(0) if cell2_lines else '').ljust(W2)
line += ' |'
lines.append(line)
else:
assert False
lines.append(HORIZ_LINE)
return lines
def _command_list_to_table_cells(command_list):
row_list = []
for obj in command_list:
if isinstance(obj, basestring): # group heading
row_list.append([obj.upper()])
else: # individual command
doc_before_empty_line = obj.__doc__.split('\n\n')[0]
doc_lines = [s.strip() for s in doc_before_empty_line.split('\n')]
for doc_line in doc_lines:
if doc_line == '':
continue
if obj.__name__ in ('ub', 'hkl'):
continue
name, args, desc = _split_doc_line(doc_line)
desc = desc.strip()
args = args.strip()
if desc and desc[-1] == '.':
desc = desc[:-1]
row_list.append([name + (' ' if args else '') + args, desc])
return row_list
def _split_doc_line(docLine):
name, _, right = docLine.partition(' ')
args, _, desc = right.partition('-- ')
return name, args, desc
def compile_extra_motion_commands_for_help():
_hwname = settings.hardware.name # @UndefinedVariable
_angles = ', '.join(settings.hardware.get_axes_names()) # @UndefinedVariable
commands = []
commands.append('Motion')
commands.append(sim)
commands.append(ExternalCommand(
'%(_hwname)s -- show Eularian position' % vars()))
commands.append(ExternalCommand(
'pos %(_hwname)s [%(_angles)s] -- move to Eularian position'
'(None holds an axis still)' % vars()))
commands.append(ExternalCommand(
'sim %(_hwname)s [%(_angles)s] -- simulate move to Eulerian position'
'%(_hwname)s' % vars()))
commands.append(ExternalCommand(
'hkl -- show hkl position'))
commands.append(ExternalCommand(
'pos hkl [h k l] -- move to hkl position'))
commands.append(ExternalCommand(
'pos {h | k | l} val -- move h, k or l to val'))
commands.append(ExternalCommand(
'sim hkl [h k l] -- simulate move to hkl position'))
# if engine_name != 'vlieg':
# pass
# # TODO: remove sigtau command and 'Surface' string
return commands