【问题标题】:How to exclude certain images from autosave in Gatan Digital Micrograph (GMS) in DM-script如何在 DM 脚本中的 Gatan Digital Micrograph (GMS) 中从自动保存中排除某些图像
【发布时间】:2021-03-31 22:07:08
【问题描述】:

我正在尝试模仿 GMS v3 中的自动保存功能,以便可以在版本 1 和 2 中使用。我想首先承认脚本的主要内容来自 Bernhard Schaffer 博士的“如何编写脚本...数字显微照片脚本手册”。我对其进行了一些修改,以便相机记录的任何新图像都可以自动保存到文件中。但是,我遇到了一些问题,因为如果我决定单击实时取景图像并移动图像,或者使用 live-fft,实时取景图像或 FFT 图像也会被保存。我的想法之一是使用标记组信息,例如“Acquisition:Parameters:Parameter Set Name”,因为对于实时视图或实时 FFT,这将处于搜索或焦点模式。另一个想法是使用文档 ID,例如 iDocID = idoc.ImageDocumentGETID() 来定位实时图像的 ID。但是,我不知道如何使用这些信息将它们排除在自动保存之外。谁能指出我如何继续这个脚本? 下面是脚本

Class PeriodicAutoSave : Object
    {
    
    Number output
    PeriodicAutoSave(Object self) Result("\n Object ID"+self.ScriptObjectGetID()+" created.")
    ~PeriodicAutoSave(Object self) Result("\n Object ID"+self.ScriptObjectGetID()+" destroyed")
    
    Void Init2(Object self, Number op) 
    output=op

    
    Void AutoSave_SaveAll(Object self)
        {
        String path, name, targettype, targettype1, area, mag, mode, search, result1
        ImageDocument idoc
        Number nr_idoc, count, index_i, index, iDocID, iDocID_search
        path = "c:\\path\\"
        name = "test"
        targettype=="Gatan Format (*.dm4)"
        targettype1 = "dm4"
        If (output) Result("\n AutoSave...")
        nr_idoc = CountImageDocuments()
        For (count = 1; count<nr_idoc; count++)
            {
            idoc = GetImageDocument(count) //imagedocument
            index = 1 // user decide the index to start with
            index_i= nr_idoc - index
            If (idoc.ImageDocumentIsDirty())
                {
                idoc = getfrontimagedocument()  
                iDocID = idoc.ImageDocumentGetID()
                TagGroup tg = ImageGetTagGroup(idoc.ImageDocumentGetImage(0)) // cannot declare an 'img' for this line as it will prompt an error?
                tg.TagGroupGetTagAsString("Microscope Info:Formatted Indicated Mag", mag)
            
                        
                
            
                
                    Try{
                        
                    
                            {
                            idoc.ImageDocumentSavetoFile( "Gatan Format", path+index_i+"-"+name+"-"+mag+".dm4")
                            idoc.ImageDocumentSetName(index_i + "-"+name+"-"+mag+".dm4")
                            idoc.ImageDocumentClean()
                            
                            }
                        If (Output) Result("\n\t saving: "+idoc.ImageDocumentGetCurrentFile())
                        }
                    Catch{
                        Result("\n image cannot be saved at the moment:" + GetExceptionString())
                        Break
                        }
                    Result("\ Continue autosave...")
                }
            }
        }
    }
    



Void LaunchAutoSave()
    {
    Object obj = Alloc(PeriodicAutoSave)
    obj.Init2(2)
    Number task_id = obj.AddMainThreadPeriodicTask("AutoSave_SaveALL",6)
                                            
    //Sleep(10)
    while(!shiftdown()) 1==2
    RemoveMainThreadTask(task_id)
    }

LaunchAutoSave()

【问题讨论】:

    标签: dm-script


    【解决方案1】:

    您的过滤想法不错,但您的 for 循环有些奇怪。

     nr_idoc = CountImageDocuments()
            For (count = 1; count<nr_idoc; count++)
                {
                idoc = GetImageDocument(count) //imagedocument
    

    您遍历所有当前打开的 imageDocuments(第一个除外!?)并一个接一个地获取它们,然后在

     If (idoc.ImageDocumentIsDirty())
                    {
                    idoc = getfrontimagedocument()     
    

    实际上,您每次都会获得最前面(选定)的文档。你为什么要这样做?

    为什么不去:

    number nr_idoc = CountImageDocuments()
    for (number count = 0; count<nr_idoc; count++)
    {
        imagedocument idoc = GetImageDocument(count)
        If (idoc.ImageDocumentIsDirty())
        {
            // now find out what is a filter condition and skip if it is true
            number skip = 0
            
            TagGroup tg = idoc.ImageDocumentGetImage(0).ImageGetTagGroup()
            skip = tg.TagGroupDoesTagExist("Microscope Info:Formatted Indicated Mag")
            if (skip) continue
            
            // do saving
        }
    }
    

    【讨论】:

      【解决方案2】:

      非常感谢您的指点!我已经尝试过了,它与我的脚本配合得很好。由于 'TagGroupDoesTagExist' 仅指标签组,我进一步修改以包含我想要过滤的标签,例如“搜索”或“焦点”,它似乎运作良好。我修改为您现有的脚本如下:

      If (idoc.ImageDocumentIsDirty())
                          {
                              
                              //now find out what is a filter condition and skip if it is true
                              skip = 0
                              TagGroup tg = idoc.ImageDocumentGetImage(0).ImageGetTagGroup()
                              tg.TagGroupGetTagAsString("Microscope Info:Formatted Indicated Mag", mag)
                              tg.TagGroupGetTagAsString("Acquisition:Parameters:Parameter Set Name", mode)
                              skip = tg.TagGroupDoesTagExist("Acquisition:Parameters:Parameter Set Name")
                      
                              if(skip && (mode == "Search" || mode== "Focus")) continue
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-14
        • 2013-10-25
        • 2019-03-22
        • 1970-01-01
        相关资源
        最近更新 更多