LoginSignup
0
0

More than 1 year has passed since last update.

DigitalMicrographでangファイルを読み込む

Posted at

angファイル

 EBSD (Electron BackScatter Diffraction) もしくは EBSP (Electron BackScatter Pattern) の測定データをテキストデータ化したファイルフォーマット。オイラー角、xy座標その他の測定値が記録されている。「その他」が具体的に何かは装置依存?ヘッダー中には特に説明がないので自力で解読する必要あり。外部プログラムでいろいろ解析する場合は、測定点のxy座標を正方格子状のデータに変換した方が扱いやすいと思う。

データ例
Materials Science and Engineering: A, 755 (2019), 295.
Site-specific quasi in situ investigation of primary static recrystallization in a low carbon steel
Martin Diehl, Lukas Kertsch, Konstantina Traka, Dirk Helm, Dierk Raabe
https://doi.org/10.1016/j.msea.2019.02.032
文献中のデータ
Data for: Site-Specific Quasi In Situ Investigation of Primary Static Recrystallization in a Low Carbon Steel
DOI: 10.17632/7dn4g8rgzc.1

上記のデータセットの一部で読み込みを試してみたが、ファイルによってはバグがあるかも。上記データの測定点座標は三角格子状。

import-ang.s
//read .ang file
image ReadAng(string filename)
{
    number fileID=OpenFileForReading(filename)
    object fstream=NewStreamFromFileReference(fileID,1)
    //read header
    TagGroup headerTg=NewTagList()
    number pos //stream position
    string text
    string CommentBegin="#"
    number CommentCheck=1
    while(CommentCheck)
    {
        pos=fstream.StreamGetPos()
        fstream.StreamReadTextLine(0,text)
        if(text.left(1)==CommentBegin)
        {
            headerTg.TagGroupInsertTagAsString(infinity(),text)
        }
        else
        {
            CommentCheck=0
        }
    }
    //read data
    fstream.StreamSetPos(0,pos)
    number bLinesAreRows=1
    number bSizeByCount=1
    number kREAL4_DATA=2
    object imgSizeObj=Alloc( "ImageData_ImageDataSize" )
    image ang:=ImageImportTextData(filename.PathExtractBaseName(0),fstream,kREAL4_DATA,imgSizeObj,bLinesAreRows,bSizeByCount)

    //set header Tag
    TagGroup angTg=ang.ImageGetTagGroup()
    angTg.TagGroupSetTagAsTagGroup(filename.PathExtractFileName(0),headerTg)
    return ang
}

//find string
number findkey(string input,string key)
{
    number n=0
    if(input.len()>=key.len())
    {
        if(input.left(key.len())==key)
        {
            n=1
        }
    }
    return n
}
//get string
string getkey(string input,string key)
{
    result(input)
    string output
    output=input.right(input.len()-key.len())
    return output
}

//shaping ang image
image SetAng(image ang)
{
    number angx,angy
    ang.GetSize(angx,angy)
    string name
    ang.GetName(name)
    //extract image information
    TagGroup angTg=ang.ImageGetTagGroup()
    TagGroup headerTg
    angTg.TagGroupGetTagAsTagGroup(name+".ang",headerTg)
    string grid
    number xstep,ystep,col_odd,col_even,row
    string text
    string comment
    string output
    for(number i=0;i<headerTg.TagGroupCountTags();i++)
    {
        headerTg.TagGroupGetTagAsString("["+i+"]",text)
        //grid
        comment="# GRID: "
        if(findkey(text,comment))
        {
            grid=getkey(text,comment)
        }
        //step
        comment="# XSTEP: "
        if(findkey(text,comment))
        {
            xstep=getkey(text,comment).val()
        }
        comment="# YSTEP: "
        if(findkey(text,comment))
        {
            ystep=getkey(text,comment).val()
        }
        //size
        comment="# NCOLS_ODD: "
        if(findkey(text,comment))
        {
            col_odd=getkey(text,comment).val()
        }
        comment="# NCOLS_EVEN: "
        if(findkey(text,comment))
        {
            col_even=getkey(text,comment).val()
        }
        comment="# NROWS: "
        if(findkey(text,comment))
        {
            row=getkey(text,comment).val()
        }
    }
    if(grid=="HexGrid\n")
    {
        result("Warning: Grid is NOT square.\n")
        result("X-position is different from the original file.\n")
        result("And Y-scale of image on screen is enlarged by a factor of 2/sqrt(3).\n")
    }
    //set image
    number x,y
    x=min(col_odd,col_even)
    y=row
    image angcube:=RealImage(name,4,x,y,angx)
    //odd col
    for(number i=0;i<y/2;i++)
    {
        angcube.slice3(0,2*i,0,0,x,1,1,1,1,2,angx,1)=ang.slice3(0,i*(col_odd+col_even),0,1,x,1,2,1,1,0,angx,1)
    }
    //even col
    for(number i=1;i<y/2;i++)
    {
        angcube.slice3(0,2*i-1,0,0,x,1,1,1,1,2,angx,1)=ang.slice3(0,i*(col_odd+col_even)+col_odd,0,1,x,1,2,1,1,0,angx,1)
    }
    //set header Tag
    TagGroup angcubeTg=angcube.ImageGetTagGroup()
    angcubeTg.TagGroupSetTagAsTagGroup(name,headerTg)
    //set step size
    angcube.ImageSetDimensionCalibration(0,0,xstep,"μm",0)
    angcube.ImageSetDimensionCalibration(1,0,ystep,"μm",0)

    return angcube
}

//get file path of ang file
string filename
if(!OpenDialog(Null, "Select ang file", "*.ang", filename)) exit(0)
result("opening the next file\n")
result(filename+"\n")

image ang:=ReadAng(filename)
image angcube:=SetAng(ang)
angcube.showimage()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0