Esempio n. 1
0
    def _init_dict(self):
        """Get list of functions and their doc strings from the uninitialized class"""
        from instamatic.camera.camera import get_cam
        cam = get_cam(self.name)

        self._dct = {key:value for key, value in  cam.__dict__.items() if not key.startswith("_")}
        self._dct["get_attrs"] = None
Esempio n. 2
0
def main():
    """
    This tool will help to set up the configuration files for `instamatic`
    It establishes a connection to the microscope and reads out the camera lengths
    and magnification ranges
    """

    ### Connect to microscope

    tem_name = choice_prompt(choices="jeol fei simulate".split(),
                             default="simulate",
                             question="Which microscope can I connect to?")

    ### Connect to camera

    cam_name = choice_prompt(choices="None gatan tvips simulate".split(),
                             default="simulate",
                             question="Which camera can I connect to?")

    ## Fetch camera config

    drc = Path(__file__).parent
    choices = list(drc.glob("camera/*.yaml"))
    choices.append(None)

    cam_config = choice_prompt(choices=choices,
                               default=None,
                               question="Which camera type do you want to use (select closest one and modify if needed)?")

    ### Instantiate microscope / camera connection

    from instamatic.TEMController.microscope import get_tem
    from instamatic.camera.camera import get_cam
    from instamatic.TEMController.TEMController import TEMController

    cam = get_cam(cam_name)() if cam_name else None
    tem = get_tem(tem_name)()

    ctrl = TEMController(tem=tem, cam=cam)
    ranges = ctrl.magnification.get_ranges()

    ht = ctrl.high_tension  # in V

    wavelength = relativistic_wavelength(ht)

    tem_config = {}
    tem_config["name"] = tem_name
    tem_config["wavelength"] = wavelength

    for mode, rng in ranges.items():
        tem_config["range_"+mode] = rng

    calib_config = {}
    calib_config["name"] = tem_name

    ### Find magnification ranges

    for mode, rng in ranges.items():
        if cam_name == "tvips":
            pixelsizes = get_tvips_calibs(ctrl=ctrl, rng=rng, mode=mode, wavelength=wavelength)
        else:
            pixelsizes = {r: 1.0 for r in rng}
        calib_config["pixelsize_"+mode] = pixelsizes

        stagematrices = {r: [1, 0, 0, 1] for r in rng}

        calib_config["stagematrix_"+mode] = stagematrices

    ### Write/copy configs

    tem_config_fn = f"{tem_name}_tem.yaml"
    calib_config_fn = f"{tem_name}_calib.yaml"
    if cam_config:
        cam_config_fn = f"{cam_name}_cam.yaml"
        shutil.copyfile(cam_config, cam_config_fn)

    yaml.dump(tem_config, open(tem_config_fn, "w"), sort_keys=False)
    yaml.dump(calib_config, open(calib_config_fn, "w"), sort_keys=False)
    
    print()
    print(f"Wrote files config files:")
    print(f"    Copy {tem_config_fn} -> `{config.config_drc / tem_config_fn}`")
    print(f"    Copy {calib_config_fn} -> `{config.config_drc / calib_config_fn}`")
    if cam_config:
        print(f"    Copy {cam_config_fn} -> `{config.config_drc / cam_config_fn}`")
    print()
    print(f"In `{config.config_drc / 'global.yaml'}`:")
    print(f"    microscope: {tem_name}_tem")
    print(f"    calibration: {tem_name}_calib")
    if cam_config:
        print(f"    camera: {cam_name}_cam")
    print()
    print(f"Todo: Check and update the pixelsizes in `{calib_config_fn}`")
    print( "    In real space, pixelsize in nm")
    print( "    In reciprocal space, pixelsize in px/Angstrom")
Esempio n. 3
0
def main():
    import argparse

    description = """
This tool will help to set up the configuration files for `instamatic`.
It establishes a connection to the microscope and reads out the camera lengths and magnification ranges.
"""

    parser = argparse.ArgumentParser(
        description=description,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    options = parser.parse_args()

    # Connect to microscope

    tem_name = choice_prompt(choices='jeol fei simulate'.split(),
                             default='simulate',
                             question='Which microscope can I connect to?')

    # Connect to camera

    cam_name = choice_prompt(choices=[None, 'gatan', 'tvips', 'simulate'],
                             default='simulate',
                             question='Which camera can I connect to?')

    # Fetch camera config

    drc = Path(__file__).parent
    choices = list(drc.glob('camera/*.yaml'))
    choices.append(None)

    cam_config = choice_prompt(choices=choices,
                               default=None,
                               question='Which camera type do you want to use (select closest one and modify if needed)?')

    # Instantiate microscope / camera connection

    from instamatic.TEMController.microscope import get_tem
    from instamatic.camera.camera import get_cam
    from instamatic.TEMController.TEMController import TEMController

    cam = get_cam(cam_name)() if cam_name else None
    tem = get_tem(tem_name)()

    ctrl = TEMController(tem=tem, cam=cam)

    try:
        ranges = ctrl.magnification.get_ranges()
    except BaseException:
        print('Warning: Cannot access magnification ranges')
        ranges = {}

    ht = ctrl.high_tension  # in V

    wavelength = relativistic_wavelength(ht)

    tem_config = {}
    tem_config['name'] = tem_name
    tem_config['wavelength'] = wavelength

    for mode, rng in ranges.items():
        tem_config['ranges'] = {mode: rng}

    calib_config = {}
    calib_config['name'] = tem_name

    # Find magnification ranges

    for mode, rng in ranges.items():
        calib_config[mode] = {}

        if cam_name == 'tvips':
            pixelsizes = get_tvips_calibs(ctrl=ctrl, rng=rng, mode=mode, wavelength=wavelength)
        else:
            pixelsizes = {r: 1.0 for r in rng}
        calib_config[mode]['pixelsize'] = pixelsizes

        stagematrices = {r: [1, 0, 0, 1] for r in rng}

        calib_config[mode]['stagematrix'] = stagematrices

    # Write/copy configs

    tem_config_fn = f'{tem_name}_tem.yaml'
    calib_config_fn = f'{tem_name}_calib.yaml'
    if cam_config:
        cam_config_fn = f'{cam_name}_cam.yaml'
        shutil.copyfile(cam_config, cam_config_fn)

    yaml.dump(tem_config, open(tem_config_fn, 'w'), sort_keys=False)
    yaml.dump(calib_config, open(calib_config_fn, 'w'), sort_keys=False)

    microscope_drc = config.locations['microscope']
    camera_drc = config.locations['camera']
    calibration_drc = config.locations['calibration']
    settings_yaml = config.locations['settings']

    print()
    print(f'Wrote files config files:')
    print(f'    Copy {tem_config_fn} -> `{microscope_drc / tem_config_fn}`')
    print(f'    Copy {calib_config_fn} -> `{calibration_drc / calib_config_fn}`')
    if cam_config:
        print(f'    Copy {cam_config_fn} -> `{camera_drc / cam_config_fn}`')
    print()
    print(f'In `{settings_yaml}`:')
    print(f'    microscope: {tem_name}_tem')
    print(f'    calibration: {tem_name}_calib')
    if cam_config:
        print(f'    camera: {cam_name}_cam')
    print()
    print(f'Todo: Check and update the pixelsizes in `{calib_config_fn}`')
    print('    In real space, pixelsize in nm')
    print('    In reciprocal space, pixelsize in px/Angstrom')