2

How to reset or remove tag groups and tag lists in a DM script?

Some background:

I am preparing a script for analysing series of EELS spectra in GMS 2. I fit the background to a power-law modele and obtain the fitting parameters, both value and sigma, from the Tags in the background spectrum. However, if a try to analyse various edges in a single script I find that the sigma values of the fit parameters depends on the order of the calculation. To check this I show a script. If I only define the fitting region one time it works OK, but if I do that twice (only for testing, I know that is nonsense), the sigma values decreases. The result is the same if the fitting regions are different. I would like to reset or delete the TagGroup to check if then the problem is solved, but I am unable to do that.

TagGroup Tg
Number a0, sa0, a1, sa1
taggroup bandsTgs = NewTagList()
taggroup bandTg = NewTagGroup()

image spec := GetFrontImage()

// ...............First Time.....................................

bandTg.TagGroupSetTagAsFloat( "start", 600 ) // calibrated value!
bandTg.TagGroupSetTagAsFloat( "end", 800 )   // calibrated value!
bandsTgs.TagGroupInsertTagAsTagGroup( Infinity(), bandTg )

image bkg1 := EELSFitPowerLawBackground( spec, bandsTgs )
bkg1.ShowImage()

tg = bkg1.ImageGetTagGroup() // Fit parameters(in eV) from the BKG spectrum Tags

tg.TagGroupGetTagAsNumber( "Processing:[0]:Parameters:Fit Parameters:a0:value", a0 )
tg.TagGroupGetTagAsNumber( "Processing:[0]:Parameters:Fit Parameters:a0:sigma", sa0 )
tg.TagGroupGetTagAsNumber( "Processing:[0]:Parameters:Fit Parameters:a1:value", a1 )
tg.TagGroupGetTagAsNumber( "Processing:[0]:Parameters:Fit Parameters:a1:sigma", sa1 )

Result("\n Fitting BKG parameters. First time ") 
Result("\n    a0 : " + a0)
Result("\n   sa0 : " + sa0)
Result("\n    a1 : " + a1)
Result("\n   sa1 : " + sa1)

// Second Time........I get a differetn result if a repeat the fit-region definition

bandTg.TagGroupSetTagAsFloat( "start", 600 ) // calibrated value! 
bandTg.TagGroupSetTagAsFloat( "end", 800 )   // calibrated value!
bandsTgs.TagGroupInsertTagAsTagGroup( Infinity(), bandTg )

image bkg2 := EELSFitPowerLawBackground( spec, bandsTgs )
bkg2.ShowImage()

tg = bkg2.ImageGetTagGroup() // Fit parameters(in eV) from the BKG spectrum Tags

tg.TagGroupGetTagAsNumber( "Processing:[0]:Parameters:Fit Parameters:a0:value", a0 )
tg.TagGroupGetTagAsNumber( "Processing:[0]:Parameters:Fit Parameters:a0:sigma", sa0 )
tg.TagGroupGetTagAsNumber( "Processing:[0]:Parameters:Fit Parameters:a1:value", a1 )
tg.TagGroupGetTagAsNumber( "Processing:[0]:Parameters:Fit Parameters:a1:sigma", sa1 )

Result("\n")
Result("\n Fitting BKG parameters. Second time ")
Result("\n    a0 : " + a0)
Result("\n   sa0 : " + sa0)
Result("\n    a1 : " + a1)
Result("\n   sa1 : " + sa1)

bandsTgs.TagGroupOpenBrowserWindow( "BandTags", 0 ) // To show the Tag structure

1 Answer 1

1

I think what you need is an a bit more comprehensive description of tags in DigitalMicrograph:


Be aware that

There exist simplified wrapper commands for simple scripts

such as

image img := RealImage( "", 4, 10 )
SetNumberNote( img, "TagPath:With:SubTag:TagName", 12.2 )
DeleteNote( img, "TagPath:With:SubTag:TagName")

However, the underlaying object is the TagGroup object with a lot of specific commands. You can always also achieve the simple things with the complete object, of course.


Next, it is important to know that

There is a difference between TagGroup and TagList.

Both are TagGroup objects on the surface, but some commands will only work on either of them. TagLists have indexed entries and TagGroups have labelled entries.

TagGroup vs TagList

The difference of the two becomes important when you start to insert into the group / list or want to remove from them, and it also becomes important when you traverse the structure.

Also note that TagGroup entries are alphanumerically sorted while TagList entries are sorted by the index.

Some examples:

  • commands of form TagGroupInsertTagAs... TagGroupGetIndexedTagAs... work only on TagLists

  • commads of form TagGroupSetTagAs... TagGroupGetTagAs... work only on TagGroups

  • To delete a tag from a TagList you need to use TagGroupDeleteTagWithIndex

  • To delete a tag from a TagGroup you need to use TagGroupDeleteTagWithLabel

Sometimes you can work around this issue by using the index in a TagList as a label by putting it in between [ and ] as a tag-path. But there are also some circumstances when you need the difference of 'TagGroup' and 'TagList'


There are different options to delete tags

  • TagGroupDeleteAllTags() deletes 'all' sub-tags of a TagGroup or TagList - but not the group/list entry itself.

  • TagGroupDeleteTagWithLabel() deletes a specif tag within a TagGroup specified by the label.

  • TagGroupDeleteTagWithIndex() deletes a specif tag within a TagList specified by the index. Note, that this changes the indices of the other entries!


Example

The code below creates the tagGroup from the image above:

tagGroup rootTg = NewTagGroup()
tagGroup tg = NewTagGroup()
tagGroup tl = NewTagList()

tg.TagGroupSetTagAsString( "value", "I am a string tag")
tg.TagGroupSetTagAsString( "2", "My tag at #2")
tg.TagGroupSetTagAsString( "Name", "Hello")
tg.TagGroupSetTagAsString( "1", "My tag at #1")

tl.TagGroupInsertTagAsString( 0, "String tag #1" )
tl.TagGroupInsertTagAsString( 1, "String tag #2" )
tl.TagGroupInsertTagAsString( 2, "String tag #3" )
tl.TagGroupInsertTagAsString( 1, "String tag #4" )

rootTg.TagGroupSetTagAsTagGroup( "TagGroup", tg )
rootTg.TagGroupSetTagAsTagGroup( "TagList", tl )

rootTg.TagGroupOpenBrowserWindow( "TagGroup example", 0 )

To delete the "Name: Hello" tag (which is the 3rd tag in the sorted group), we would use either of the three:

rootTg.TagGroupDeleteTagWithLabel( "TagGroup:Name" )
tg.TagGroupDeleteTagWithLabel( "Name" )
tg.TagGroupDeleteTagWithIndex( 2 )

To delete the 3rd entry in the TagList, we would use either of the three:

rootTg.TagGroupDeleteTagWithLabel( "TagList:[2]" )
tl.TagGroupDeleteTagWithLabel( "[2]" )
tl.TagGroupDeleteTagWithIndex( 2 )

To delete the whole TagList, we would use

rootTg.TagGroupDeleteTagWithLabel( "TagList" )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.