Skip to content
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

ValueError raised when reading ascii OP4 where floating point number does not contain "E" #29

Open
meshing-monkey opened this issue Oct 4, 2023 · 2 comments

Comments

@meshing-monkey
Copy link

meshing-monkey commented Oct 4, 2023

Hello,

I'm getting an exception when reading ascii OP4 files using the op4.load function. This happens with files containing floating point numbers that don't have an "E" before the exponent, because these strings can't be converted to Python floats. The exception is shown below, and originates in the op4.op4 _put_ascii_values method. I patched op4.py to deal with this case (attached in the zip file as op4_patched.py): I just insert an E to get the float conversion to work; it looks like there are other methods in op4 that could be affected.

The offending op4 matrix is in the attached zip file (test.op4).

mats = op4.load('test.op4')


ValueError Traceback (most recent call last)
Cell In[2], line 1
----> 1 mk = op4.load('test.op4')

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:2291, in load(filename, namelist, into, justmatrix, sparse)
2289 filename = guitools.get_file_name(filename, read=True)
2290 if into == "dct":
-> 2291 return OP4().dctload(filename, namelist, justmatrix, sparse)
2292 elif into == "list":
2293 return OP4().listload(filename, namelist, sparse)

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:1779, in OP4.dctload(self, filename, namelist, justmatrix, sparse)
1777 loadfunc = self._loadop4_binary
1778 while 1:
-> 1779 name, X, form, mtype = loadfunc(patternlist=namelist, sparse=sparse)
1780 if not name:
1781 break

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:718, in OP4._loadop4_ascii(self, patternlist, listonly, sparse)
715 sparse, sparsefunc = OP4._get_sparsefunc(sparse)
717 rdfunc, funcs = self._get_funcs("ascii", rows, r,
mtype, sparse, c >= cols)
--> 718 X = rdfunc(wper, r, c, abs(rows), cols, line, numlen, perline, linelen, funcs)
720 if sparsefunc and sp.issparse(X):
721 X = sparsefunc(X)

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:496, in OP4._rd_bigmat_ascii(self, wper, r, c, rows, cols, line, numlen, perline, linelen, funcs)
494 L //= wper
495 s = self._get_ascii_block(L, perline, linelen)
--> 496 put(X, r, c, s, L, numlen)
497 line = self._fileh.readline()
498 c = int(line[c_slice]) - 1

File ~\AppData\Local\anaconda3\Lib\site-packages\pyyeti\nastran\op4.py:402, in OP4._put_ascii_values(X, r, c, s, L, numlen)
400 for i in range(L):
401 b = a + numlen
--> 402 X[r + i, c] = s[a:b]
403 a = b

ValueError: could not convert string to float: ' 1.679082097391476-318'

@meshing-monkey
Copy link
Author

Patched file attached as op4_patched.py, along with original file op4_baseline.py.
op4_exception.zip

@twmacro
Copy link
Owner

twmacro commented Oct 8, 2023

Thank you @meshing-monkey for the report! :-) I'll look into this. Note that it might take me a few weeks to really dig in.

I'm curious, was this file written by Nastran? If so, which flavor / version? (This is the first time I've seen this float format in an op4 file, doh!)

Many thanks,
Tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants