This example shows how to generate an html report of the comparison of the impedance calculation with measured data.
First import the necessary modules
>>> import os >>> import sys >>> import numpy >>> import pylab >>> import wiat >>> from wiat.TM import *
Here, we import an instrument created from the geometry of a real one.
>>> from wiat.instruments.Saxophones import SelmerSerieII >>> DataDir = wiat.MEASUREMENTDIR
The list of sections describing the short cone begin with a diameter Jump, because the diameter of the impedance measurement probe was a little bigger than that of the cone.
>>> short_cone = [Jump(0.0125,0.0123), Cone(0.0123,0.0332,0.402)]
The alto saxophone neck is cylindrical at both end to allow insertion of the mouthpiece and body
>>> alto_saxophone_neck = \ ... [Cylinder(0.0125,0.01), Cone(0.0125,0.0227,0.164), ... Cylinder(0.0227,0.021)]
We now create a list of all the cases we want to process. For each case, there is a data file and an instrument. We can then loop through all the cases and calculate impedances and create the graphics.
>>> cases = [\ ... {'data': '20070416Zcone.mat', ... 'instrument': Instrument("Short Cone", short_cone, ... UnflangedOpenEnd(0.0332))}, ... {'data': '20070416Zneck.mat', ... 'instrument': Instrument("Alto Saxophone Neck", alto_saxophone_neck, ... UnflangedOpenEnd(0.0227))}, ... {'data': '20070416Zneckandlongcone.mat', ... 'instrument': Instrument("Alto Saxophone Neck on a Long Cone ", ... [Cone(0.0125,0.072,1.029)], ... UnflangedOpenEnd(0.072))}]
Create the frequency array and set the temperature.
>>> f = numpy.arange(100,4600,1,dtype=float) >>> T = 25.
Create a WepPage instance
>>> web = wiat.Reports.WebPage('example3_generatedpage.html')
Loop through all the cases and load the data or perform the calculations. A table is added to the web page as well as a link to the graphic.
>>> for case in cases: ... Zs = [] ... for key in case.keys(): ... if key == 'data': ... [f,Z]=wiat.Data.load_from_mat(('freqs','z'), ... DataDir+os.sep+case['data']) ... Zs.append( [f,Z,'mesurement'] ) ... maxima_meas = wiat.Data.interpolate_maxima(f, ... Z,number_of_maxima=5) ... elif key == 'instrument': ... Z = CalculateImpedance(case['instrument'],f,T) ... Zs.append( [f,Z,'simulation'] ) ... maxima_calc = CalculateMaxima(Z,case['instrument'],f,T, ... number_of_maxima=5) ... title = "Impedance of %s"%case['instrument'].name ... Plot = wiat.Plot.ImpedancePlot(title,Zs) ... Plot.plot() ... Plot.save() ... comparison = CompareMaxima(maxima_calc, maxima_meas) ... table = wiat.Reports.ImpedanceMaximaComparison( ... 'Table of impedance maxima comparison for the %s'%title+\ ... ' (theory vs. experimental)', comparison) ... table.html_export(web.file) ... web.add_link(Plot.pngfilename, 'Plot in PNG format') saving ImpedanceofShortCone saving ImpedanceofAltoSaxophoneNeck saving ImpedanceofAltoSaxophoneNeckonaLongCone >>> # pylab.show()