Generating an xml file

109 views
Skip to first unread message

evanski...@gmail.com

unread,
Mar 5, 2020, 12:52:03 PM3/5/20
to Acoular-users
Hi, thanks for this great package.

Suppose I have 9 sensors and I would want to generate an xml file, with the locations arranged on a 3*3 grid how would I do it?

Catharina Gallacher

unread,
Mar 6, 2020, 1:19:18 AM3/6/20
to Acoular-users
Hi, I spent a bit of time figuring out how to generate the correct type of XML file using the package R. I did the same with the h5 file. Hopefully it makes sense where to/how to add extra sensors in the code file since it was set up for only two microphones.


https://github.com/KarlssonCatharina/Acoular_Data_File_Creation

Gert Herold

unread,
Mar 6, 2020, 3:57:22 AM3/6/20
to Acoular-users
Hi Evan,

before going into the xml format, I'd like to mention that you do not necessarily need an xml file (or any file) to define a microphone geometry in Acoular.
You also could just define a MicGeom object an directly add the coordinates you want. Say you have an array with five microphones. You then can define the positions via:

--------------
my_mics = acoular.MicGeom()
my_mics.mpos_tot = numpy.array([[x1,x2,x3,x4,x5], [y1,y2,y3,y4,y5], [z1,z2,z3,z4,z5]])

--------------

- and you're good to go. Just remember that Acoular uses a left-oriented coordinate system, so you might have to invert your z-values if they are non-zero.
Exporting Acoular-readable xml mic geometries is not (yet) part of the package, so I'm just going to copy-paste some code I usually use for generating microphone geometry files:

--------------
from pylab import *

x = ...some 1D array with x coords...
y = ...some 1D array with y coords...
z = ...some 1D array with z coords...


name = 'my_mics'
filename = name+'.xml'
f = open(filename,'a')
f.write('<?xml version="1.0" encoding="utf-8"?>\n<MicArray name="%s">\n'%name)

for i in range(len(x)):
    f.write('   <pos Name="Point %s' % str(i+1))
    f.write('"    x="    %1.9f' %x[i])
    f.write('"    y="    %1.9f' %y[i])
    f.write('"    z="    %1.9f" />\n' %z[i])

f.write('</MicArray>\n')
f.close()

--------------

Best regards,

Gert

Reply all
Reply to author
Forward
0 new messages