-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
bugSomething isn't workingSomething isn't working
Description
When reading an input file with BoutOptionsFile, the method recalculate_xyz is called during class init and fails:
inputfile = BoutOptionsFile(inputfile_path, gridfilename = "/home/mike/work/hermes3v/builds/newbuild/tests/integrated/dmplex/example_cdn.grd.nc")
/home/mike/work/hermes3v/views/gcc/lib/python3.11/site-packages/boutdata/data.py:765: AlwaysWarning: While building x, y, z coordinate arrays, an exception occured: 'float' object cannot be interpreted as an integer
Evaluating non-scalar options not available
alwayswarn(
Digging deeper shows that it's caused by np.linspace getting a float instead of an integer:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[35], [line 1](vscode-notebook-cell:?execution_count=35&line=1)
----> [1](vscode-notebook-cell:?execution_count=35&line=1) inputfile.recalculate_xyz()
File ~/work/hermes3v/views/gcc/lib/python3.11/site-packages/boutdata/data.py:846, in BoutOptionsFile.recalculate_xyz(self, nx, ny, nz)
842 myg = self._keys.get("MYG", 2)
844 # make self.x, self.y, self.z three dimensional now so
845 # that expressions broadcast together properly.
--> [846](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225030373238227d.vscode-resource.vscode-cdn.net/home/mike/work/notebooks/vantage/~/work/hermes3v/views/gcc/lib/python3.11/site-packages/boutdata/data.py:846) self.x = numpy.linspace(
847 (0.5 - mxg) / (self.nx - 2 * mxg),
848 1.0 - (0.5 - mxg) / (self.nx - 2 * mxg),
849 self.nx,
850 )[:, numpy.newaxis, numpy.newaxis]
851 self.y = (
852 2.0
853 * numpy.pi
(...)
858 )[numpy.newaxis, :, numpy.newaxis]
859 )
860 self.z = (
861 2.0
862 * numpy.pi
(...)
865 ]
866 )
File ~/work/hermes3v/views/gcc/lib/python3.11/site-packages/numpy/core/function_base.py:122, in linspace(start, stop, num, endpoint, retstep, dtype, axis)
24 @array_function_dispatch(_linspace_dispatcher)
25 def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None,
26 axis=0):
27 """
28 Return evenly spaced numbers over a specified interval.
29
(...)
120
121 """
--> [122](https://vscode-remote+ssh-002dremote-002b7b22686f73744e616d65223a225030373238227d.vscode-resource.vscode-cdn.net/home/mike/work/notebooks/vantage/~/work/hermes3v/views/gcc/lib/python3.11/site-packages/numpy/core/function_base.py:122) num = operator.index(num)
123 if num < 0:
124 raise ValueError("Number of samples, %s, must be non-negative." % num)
TypeError: 'float' object cannot be interpreted as an integer
As you can see, nx is specifically loaded as a float:
Lines 819 to 821 in 7164a89
| with DataFile(gridfilename) as gridfile: | |
| self.nx = float(gridfile["nx"]) | |
| self.ny = float(gridfile["ny"]) |
And here is the bit where it should've been an integer:
Lines 840 to 846 in 7164a89
| # make self.x, self.y, self.z three dimensional now so | |
| # that expressions broadcast together properly. | |
| self.x = numpy.linspace( | |
| (0.5 - mxg) / (self.nx - 2 * mxg), | |
| 1.0 - (0.5 - mxg) / (self.nx - 2 * mxg), | |
| self.nx, | |
| )[:, numpy.newaxis, numpy.newaxis] |
This seems like a very obvious fix, but I'm a bit hesitant, because I can't see how other users could have avoided getting the same error.
I appreciate this is probably very old code by now, but maybe someone has some ideas about this.
If not, I can just issue a PR to do the simple fix.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working