def test_hkl_help_visually(self):
     print "-" * 80 + "\nhkl:"
     print format_command_help(self.dc.hkl.commands)
Esempio n. 2
0
def create_objects(
    dummy_axis_names=None,               # list of strings
    axis_scannable_list=None,            # list of single axis scannables
    axes_group_scannable=None,           # single scannable group
    dummy_energy_name=None,
    energy_scannable=None,
    energy_scannable_multiplier_to_get_KeV=1,
    geometry=None,                       # instance or name
    hkl_name='hkl',
    hkl_virtual_angles_to_report=(),
    hklverbose_name='hklverbose',
    hklverbose_virtual_angles_to_report=('2theta', 'Bin', 'Bout', 'azimuth'),
    diffractometer_scannable_name=None,   # e.g. SixCircleGammaOnArmGeometry.
                                          # or determined by geometry
    demo_commands=[],
    simulated_crystal_counter_name=None,
    engine_name='vlieg',
    raise_exceptions_for_all_errors=True):
    if VERBOSE:
        print "=" * 80
    objects = {}

    if engine_name.lower() not in AVAILABLE_ENGINES:
        raise KeyError("The engine '%s' was not recognised. "
                       "Try %r" % (engine_name, AVAILABLE_ENGINES))

    # Obtain geometry instance
    if engine_name.lower() == 'vlieg':
        geometry = _determine_vlieg_geometry(geometry)
    elif engine_name.lower() == 'you':
        geometry = _determine_you_geometry(geometry)
    else:
        raise ValueError()

    # Create diffractometer scannable and possibly dummy axes
    diffractometer_scannable_name = _determine_diffractometer_scannable_name(
        diffractometer_scannable_name, geometry)

    objects.update(_create_diff_and_dummies(dummy_axis_names,
                                        axis_scannable_list,
                                        axes_group_scannable,
                                        diffractometer_scannable_name))
    diff_scannable = objects[diffractometer_scannable_name]

    # Create dummy energy (if needed) and wavelength scannable
    objects_, energy_scannable = _create_wavelength_and_energy(
        dummy_energy_name, energy_scannable,
        energy_scannable_multiplier_to_get_KeV)
    objects.update(objects_)

    # Create hardware adapter
    hardware = ScannableHardwareAdapter(diff_scannable, energy_scannable,
                                        energy_scannable_multiplier_to_get_KeV)

    # Instantiate diffcalc

    dc = create_diffcalc(engine_name.lower(),
                          geometry,
                          hardware,
                          raise_exceptions_for_all_errors,
                          UBCalculationPersister())

    objects['dc'] = dc
    diff_scannable.diffcalc = dc

    # Create hkl, h, k and l scannables
    objects.update(
        _create_hkl(hkl_name, diff_scannable, dc,
                    hkl_virtual_angles_to_report))

    # Create verbose hkl
    objects.update(
        _create_hkl_verbose(hklverbose_name, diff_scannable, dc,
                            hklverbose_virtual_angles_to_report))

    # Create parameter/constraint scannables
    objects.update(_create_constraint_scannables(dc))

    if engine_name.lower() == 'you':
        objects['a_eq_b'] = 'a_eq_b'

    # Create simulated crystal counter
    if simulated_crystal_counter_name:
        ct = SimulatedCrystalCounter(simulated_crystal_counter_name,
                                     diff_scannable, geometry, objects['wl'])
        ct.level = 10
        objects.update({ct.name: ct})
        if VERBOSE:
            print "\nCreated Simulated Crystal Counter:\n   ", ct.name

    # expose and alias ub and hkl commands from diffcalc object
    if VERBOSE:
        print "UB"
        print "=="
    objects.update(_expose_and_alias_commands(dc.ub.commands))
    if VERBOSE:
        print "hkl"
        print "==="
    objects.update(_expose_and_alias_commands(dc.hkl.commands))
    if VERBOSE:
        print "Tutorial"
        print ""
    if demo_commands:
        objects.update(_create_and_alias_diffcalcdemo(demo_commands))

    if engine_name.lower() == 'vlieg':
        # add strings for transformX commands
        objects.update(
            {'on': 'on', 'off': 'off', 'auto': 'auto', 'manual': 'manual'})

    if VERBOSE:
        print "=" * 80
    objects['ub'].im_func.__doc__ = format_command_help(dc.ub.commands)
    Hkl.dynamic_docstring = format_command_help(dc.hkl.commands)
    print "-" * 80
    print "For help type 'help ub' and 'help hkl'."
    print "-" * 80
    return objects
 def test_ub_help_visually(self):
     print "-" * 80 + "\nub:"
     print format_command_help(self.dc.ub.commands)