New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network
constructor fails if file
is a StringIO
stream
#594
Comments
Assign a name property on the stream as a quick workaround stream = io.StringIO(contents)
stream.name = 'simple-network.s2p'
net = rf.Network(stream) Not sure, if this is a bug or a feature :) |
It is a kind of feature let's say ;) The documentation of Touchstone reading is under update in #587 but not merged yet. It will be: Examples
--------
From filename
>>> t = rf.Touchstone('network.s2p')
File encoding can be specified to help parsing the special characters:
>>> t = rf.Touchstone('network.s2p', encoding='ISO-8859-1')
From file-object
>>> file = open('network.s2p')
>>> t = rf.Touchstone(file)
From a io.StringIO object
>>> link = 'https://raw.githubusercontent.com/scikit-rf/scikit-rf/master/examples/basic_touchstone_plotting/horn antenna.s1p'
>>> r = requests.get(link)
>>> stringio = io.StringIO(r.text)
>>> stringio.name = 'horn.s1p' # must be provided for the Touchstone parser
>>> horn = rf.Touchstone(stringio) |
I'm not sure if requiring the user to add a property to the (standard) In fact, by definition, a file-like object is only required to implement I understand that the complication arises because, according to the Touchstone File Format Specification, in v1.0 files, the number of ports is (indirectly) embedded into the file extension rather than being recorded inside the file. |
I don't really like the idea of adding a mandatory name to pass. I'd rather prefer to document how creating a Network from a |
The constructor of
Network
class allows thefile
argument to be either a string (path to the touchstone) or a file-like object (as the comment here states).However, passing a file-like stream to the constructor raises an
AttributeError
, as the following MWE shows:The issue is that
StringIO
does not have aname
attribute. And it seems that knowing the file name is necessary for constructing the network. (As the number of ports need to be determined from the file extension.)The text was updated successfully, but these errors were encountered: