You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过DM脚本及GMS 3.4 Python接口转换光谱类型为EELS?

Spectrum to EELS Conversion via DM Script & GMS 3.4 Python Interface

Hey there! I’ve got you covered on automating that spectrum type conversion—no more manual trips to the Spectrum → Convert Data to menu. Here’s how to do it both with DM Script and the GMS 3.4 Python API:

Using DM Script

You can directly call image type conversion functions in DM Script to handle the conversion programmatically. Here’s a ready-to-use script:

// Grab the frontmost (active) spectrum image
image spectrum = GetFrontImage()

// First, verify it's actually a spectrum
if (spectrum.ImageIsSpectrum()) {
    // Convert the spectrum to EELS type
    image eels_data = spectrum.ImageConvertToType("EELS")
    // Display the converted dataset
    eels_data.ShowImage()
    OKDialog("Spectrum successfully converted to EELS!")
} else {
    ErrorDialog("Error: The active image isn't a valid spectrum.")
}

Just run this script in DM’s script editor, and it’ll handle the conversion without any manual menu clicks. It checks if the active image is a spectrum first to avoid errors.

Using GMS 3.4 Python Interface

If you’re working with the GMS Python API, the process is just as straightforward. Here’s the code snippet:

import DigitalMicrograph as dm

# Get the currently active spectrum image
spectrum_img = dm.GetFrontImage()

# Validate the image type before conversion
if spectrum_img.IsSpectrum():
    # Convert to EELS dataset
    eels_img = spectrum_img.ConvertToType("EELS")
    # Show the converted data
    eels_img.Show()
    print("Successfully converted spectrum to EELS dataset!")
else:
    print("Warning: Selected image is not a spectrum.")

This code leverages the DigitalMicrograph Python module to interact with DM’s core functions. It mirrors the DM Script logic: check the image type, convert, and display the result.

Both methods directly replicate the functionality of the manual menu operation—they’re just calling the same underlying conversion logic programmatically. Perfect for integrating into automated workflows!

内容的提问来源于stack exchange,提问作者TomNorway

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 22:02:48