orbital icon indicating copy to clipboard operation
orbital copied to clipboard

Encountering TypeError: object of type <class 'float'> cannot be safely interpreted as an integer

Open OrbitalMechanic opened this issue 5 years ago • 2 comments

I attempted to run the example on the GitHub page. See the attached file.

The results I get are

Last login: Fri Jan 10 23:56:44 on ttys001 users-MacBook-Pro:~ user$ python untitled-text-2.py Traceback (most recent call last): File "/Users/user/anaconda3/lib/python3.7/site-packages/numpy/core/function_base.py", line 117, in linspace num = operator.index(num) TypeError: 'float' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "untitled-text-2.py", line 11, in plot(orbit, title='Maneuver 1', maneuver=man) File "/Users/user/anaconda3/lib/python3.7/site-packages/orbital/plotting.py", line 37, in plot2d plotter.plot(orbit, title=title, maneuver=maneuver) File "/Users/user/anaconda3/lib/python3.7/site-packages/orbital/plotting.py", line 78, in plot self._plot_orbit(orbit, label='Initial orbit') File "/Users/user/anaconda3/lib/python3.7/site-packages/orbital/plotting.py", line 136, in _plot_orbit f = np.linspace(f1, f2, num_points) File "<array_function internals>", line 6, in linspace File "/Users/user/anaconda3/lib/python3.7/site-packages/numpy/core/function_base.py", line 121, in linspace .format(type(num))) TypeError: object of type <class 'float'> cannot be safely interpreted as an integer. users-MacBook-Pro:~ user$

Please advise.

Sam Dupree. untitled-text-2.py.txt

OrbitalMechanic avatar Jan 11 '20 05:01 OrbitalMechanic

In doing a dive into the file plotting.py found that on lines 107, 136, 222, 232, and 262 the number of points argument for linspace was of type float as opposed to int. Making the third argument of linspace of type int appears to have corrected the errors.

A text file containing the corrected lines has been attached to this note for review.

Hope this help.

Sam Dupree.

plotting.py.txt

OrbitalMechanic avatar Jan 21 '20 05:01 OrbitalMechanic

I'm facing this same issue.

Here's the example I tried:

from numpy import radians from scipy.constants import kilo from orbital import earth, KeplerianElements, plot orbit1 = KeplerianElements.with_period(90 * 60, body=earth) plot(orbit1, title='Orbit 1')

Here's the error:

TypeError Traceback (most recent call last) /var/folders/dt/n24zstt56zddxk99_357sfmc0000gq/T/ipykernel_40467/863518644.py in 1 orbit1 = KeplerianElements.with_period(90 * 60, body=earth) ----> 2 plot(orbit1, title='Orbit 1')

/usr/local/anaconda3/lib/python3.9/site-packages/orbital/plotting.py in plot2d(orbit, title, maneuver, animate, speedup) 35 return plotter.animate(orbit, title=title, speedup=speedup) 36 else: ---> 37 plotter.plot(orbit, title=title, maneuver=maneuver) 38 39

/usr/local/anaconda3/lib/python3.9/site-packages/orbital/plotting.py in plot(self, orbit, maneuver, title) 73 74 if maneuver is None: ---> 75 self._plot_orbit(orbit) 76 self.pos_dot = self._plot_position(orbit) 77 else:

/usr/local/anaconda3/lib/python3.9/site-packages/orbital/plotting.py in _plot_orbit(self, orbit, f1, f2, label) 134 135 num_points = self.points_per_rad * (f2 - f1) --> 136 f = np.linspace(f1, f2, num_points) 137 138 pos = self._perifocal_coords(orbit, f)

<array_function internals> in linspace(*args, **kwargs)

/usr/local/anaconda3/lib/python3.9/site-packages/numpy/core/function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis) 118 119 """ --> 120 num = operator.index(num) 121 if num < 0: 122 raise ValueError("Number of samples, %s, must be non-negative." % num)

TypeError: 'float' object cannot be interpreted as an integer

**Any guidance around how to resolve this would be great! **

saitanmayi avatar Dec 14 '21 08:12 saitanmayi