Ejemplo n.º 1
0
def _parse_xml(filename):
    tree = ET.parse(filename)
    om = convert_xml_to_dict(tree.getroot())

    info = {
        'raw_filename': om.root.raw_file.filename,
        'width': 128,
        'height': 128,
        'raw_height': 130,
        'record-by': 'image'
    }
    if om.has_item('root.count'):
        # Stack of images
        info.update(
            {'series_count': int(om.root.scan_parameters.series_count)})
    elif om.has_item('root.pix_x') and om.has_item('root.pix_y'):
        # 2D x 2D
        info.update({
            'scan_x': int(om.root.pix_x),
            'scan_y': int(om.root.pix_y)
        })
    else:
        raise IOError("Unsupported Empad file: the scan parameters cannot "
                      "be imported.")

    return om, info
Ejemplo n.º 2
0
def _axes_jeol_sightx(tiff, op, shape, names):
    # convert xml text to dictionary of tiff op['ImageDescription']
    # convert_xml_to_dict need to remove white spaces before decoding XML
    scales, offsets, units = _axes_defaults()

    jeol_xml = ''.join([line.strip(" \r\n\t\x01\x00") for line in op['ImageDescription'].split('\n')])
    from hyperspy.misc.io.tools import convert_xml_to_dict
    jeol_dict = convert_xml_to_dict(jeol_xml)
    op['ImageDescription'] = jeol_dict['TemReporter']
    eos = op["ImageDescription"]["Eos"]["EosMode"]
    illumi = op["ImageDescription"]["IlluminationSystem"]
    imaging = op["ImageDescription"]["ImageFormingSystem"]

    # TEM/STEM
    is_STEM = eos == "modeASID"
    mode_strs = []
    mode_strs.append("STEM" if is_STEM else "TEM")
    mode_strs.append(illumi["ImageField"][4:])  # Bright Fiels?
    if is_STEM:
        mode_strs.append(imaging["ScanningImageFormingMode"][4:])
    else:
        mode_strs.append(imaging["ImageFormingMode"][4:])
    mode_strs.append(imaging["SelectorString"])  # Mag / Camera Length
    op["SightX_Notes"] = ", ".join(mode_strs)

    res_unit_tag = op['ResolutionUnit']
    if res_unit_tag == TIFF.RESUNIT.INCH:
        scale = 0.0254  # inch/m
    else:
        scale = 0.01  # tiff scaling, cm/m
    # TEM - MAG
    if (eos == "eosTEM") and (imaging["ModeString"] == "MAG"):
        mag = float(imaging["SelectorValue"])
        scales['x'], scales['y'] = _get_scales_from_x_y_resolution(op, factor=scale / mag * 1e9)
        units = {"x": "nm", "y": "nm", "z": "nm"}
    # TEM - DIFF
    elif (eos == "eosTEM") and (imaging["ModeString"] == "DIFF"):
        def wave_len(ht):
            import scipy.constants as constants
            momentum = 2 * constants.m_e * constants.elementary_charge * ht * \
                (1 + constants.elementary_charge * ht / (2 * constants.m_e * constants.c ** 2))
            return constants.h / np.sqrt(momentum)

        camera_len = float(imaging["SelectorValue"])
        ht = float(op["ImageDescription"]["ElectronGun"]["AccelerationVoltage"])
        if imaging["SelectorUnitString"] == "mm":  # convert to "m"
            camera_len /= 1000
        elif imaging["SelectorUnitString"] == "cm":  # convert to "m"
            camera_len /= 100
        scale /= camera_len * wave_len(ht) * 1e9  # in nm
        scales['x'], scales['y'] = _get_scales_from_x_y_resolution(op, factor=scale)
        units = {"x": "1 / nm", "y": "1 / nm", "z": t.Undefined}

    scales, offsets, units = _order_axes_by_name(names, scales, offsets, units)

    axes = _build_axes_dictionaries(shape, names, scales, offsets, units)

    return axes