This example shows how to use pyMez to load a touchstone s2p file, convert it to xml and then to html.
from pyMez import *
from pyMez.Code.DataHandlers.Translations import *
s2p_file_path=os.path.join(os.getcwd(),"./S2p_to_Xml_Files/20160301_30ft_cable_0.s2p")
s2p=S2PV1(s2p_file_path)
# if you want to see the file use the .show() method, for a pop-out plot use the %matplotlib wx magic
s2p.show();
# use the function found in Translations.py
xml=S2PV1_to_XmlDataTable(s2p)
# to know the format of the xml file we can use .get_attribute_names()
xml.get_attribute_names()
#now we set the proper xsl style sheet, they are currently in DataHandlers/XSL
xml.options["style_sheet"]=os.path.join(TESTS_DIRECTORY,"../XSL/S2P_DB_STYLE.xsl")
# now we can convert to text or save_HTML, note xml.to_HTML(xsl_path) works also
html_text=xml.to_HTML()
# if we want to visualize and change it as a python object we can use
html=HTMLBase(None,html_text=html_text)
html.show()
html.save("./S2p_to_Xml_Files/20160301_30ft_cable_0_db_format.html")
# this can be done for all three of the common formats
xml_RI=S2PV1_to_XmlDataTable(s2p,format="RI",style_sheet=os.path.join(TESTS_DIRECTORY,"../XSL/S2P_RI_STYLE.xsl"))
html_RI=HTMLBase(html_text=xml_RI.to_HTML())
html_RI.show()
xml_MA=S2PV1_to_XmlDataTable(s2p,format="MA",style_sheet=os.path.join(TESTS_DIRECTORY,"../XSL/S2P_MA_STYLE.xsl"))
html_MA=HTMLBase(html_text=xml_MA.to_HTML())
html_MA.show()