ZeroDivisionError: division by zero in chess.py - python

I have created an chess seeing video and when it completes i got an error
ZeroDivisionError: division by zero
my whole code: https://onlinegdb.com/HJR_9t2nD
board = [ ['Rb', 'Nb', 'Bb', 'Qb', 'Kb', 'Bb', 'Nb', 'Rb'], #8
['Pb', 'Pb', 'Pb', 'Pb', 'Pb', 'Pb', 'Pb', 'Pb'], #7
[ 0, 0, 0, 0, 0, 0, 0, 0], #6
[ 0, 0, 0, 0, 0, 0, 0, 0], #5
[ 0, 0, 0, 0, 0, 0, 0, 0], #4
[ 0, 0, 0, 0, 0, 0, 0, 0], #3
['Pw', 'Pw', 'Pw', 'Pw', 'Pw', 'Pw', 'Pw', 'Pw'], #2
['Rw', 'Nw', 'Bw', 'Qw', 'Kw', 'Bw', 'Nw', 'Rw'] ]#1
# a b c d e f g h
def isOccupiedby(board,x,y,color):
if board[x / y]==0:
#the square has nothing on it.
return False
Here's full error
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python37\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\Python37\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "chess.py", line 1054, in negamax
moves = allMoves(position, colorsign)
File "chess.py", line 842, in allMoves
listofpieces = getallpieces(position,color)
File "chess.py", line 831, in getallpieces
if isOccupiedby(board,i,j,color):
File "chess.py", line 458, in isOccupiedby
if board[x / y]==0:
ZeroDivisionError: division by zero
Traceback (most recent call last):
File "chess.py", line 1713, in <module>
createShades([])
File "chess.py", line 955, in createShades
if isCheck(position,'white'):
File "chess.py", line 801, in isCheck
return isAttackedby(position,x,y,enemy)
File "chess.py", line 496, in isAttackedby
findPossibleSquares(position,x,y,True)) #The true argument
File "chess.py", line 569, in findPossibleSquares
if isOccupiedby(board,kx,y,enemy_color):
File "chess.py", line 458, in isOccupiedby
if board[x / y]==0:
ZeroDivisionError: division by zero

/ is the division operator. If the divisor is zero, you will get an exception.
Very likely you tried to access an element of the grid. If board is a list of lists, you must use the subscription operator twice in a row. Since the grid is organized in rows, the first subscription index is y and the second is x:
if board[x / y]==0:
if board[y][x]==0:

Related

I have a Python script that is not working in python3

I have a script:
if (enviar_ftp(mounted_usb) >= 0): # ML: enviar_ftp()->enviar_ftp(ser)
# Se agrega la captura de schedule online
s = get_schedule_online(get_id())
log("Programa en servidor: {0}".format(s))
if (s != ""):
save_programa(s)
enviar_situacion(get_id(), get_programa(), get_free_space()[3], 0, 0, str(100-int(get_free_space()[4])), battery_status(voltaje), voltaje, 0, 0)
# ser_write("<txt>\n")
else:
log('enviar_ftp() failed') # ser_write("<txn>\n")
Works fine in python2 but in python3 I get:
Traceback (most recent call last):
File "/home/pi/main.py", line 511, in <module>
app_main()
File "/home/pi/main.py", line 499, in app_main
send_pics()
File "/home/pi/main.py", line 241, in send_pics
enviar_situacion(get_id(), get_programa(), get_free_space()[3], 0, 0, str(100-int(get_free_space()[4])), battery_status(voltaje), voltaje, 0, 0)
TypeError: 'NoneType' object is not subscriptable
Any ideas?
Expect the script to work!!

How to retrieve conflicting location in shapely TopologicalError?

When trying to plot a 2D array in cartopy projected axes using contourf, I am receiving a TopologicalError. This is the code:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
from shapely.geos import TopologicalError
data = np.array(
[[ 8, 10, 2, 5, 3, 6, 5, 3, 0, 0, 0, 0, 0, 0, 0],
[ 7, 5, 3, 6, 5, 4, 2, 1, 1, 0, 0, 0, 0, 0, 0],
[ 8, 10, 2, 7, 1, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0],
[14, 8, 12, 9, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[15, 8, 10, 5, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 7, 7, 9, 5, 2, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[ 4, 5, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 2, 4, 1, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 2, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
])
x = np.array([-9.05365, -9.05266, -9.05167, -9.05068, -9.04969,
-9.0487, -9.04771, -9.04672, -9.04573, -9.04474,
-9.04375, -9.04276, -9.04177, -9.04078, -9.03979])
y = np.array([53.2024, 53.203, 53.2036, 53.2042, 53.2048,
53.2054, 53.206, 53.2065, 53.2071, 53.2077])
data = np.ma.masked_where(data==0, data)
ax = plt.axes(projection=ccrs.Mercator(central_longitude=-9))
try:
ax.contourf(x, y, data, transform=ccrs.PlateCarree())
except TopologicalError as exc:
pass # Do something to get the conflicting location (x, y)
When running this code, I am getting the TopologyException message below, followed by a rather long traceback (see below). The TopologyException is:
TopologyException: side location conflict at -9.0506799999999998 53.206000000000003
Now, under the except block, I would like to fix the array in the location indicated by the TopologyException (-9.0506799999999998 53.206000000000003), and try to plot it again. I would use a while loop to fix the array as many times as needed, retrieving the conflicting location and fixing the array at that location. I have to repeat this procedure for many other arrays like this.
Even though the message is displayed in the screen, I don't know how to get the location -9.0506799999999998 53.206000000000003 from the script, since I can't find it in exc. I would be very grateful if somebody could explain how to get those numbers as new variables lon and lat.
This error can be avoided if not using a masked array, but I am masking the 0's because I don't want to plot them.
Below is the traceback. Many thanks.
TopologyException: side location conflict at -9.0506799999999998 53.206000000000003
TopologyException: side location conflict at -9.0506799999999998 53.206000000000003
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x00000204E9F74280> (for post_execute):
Traceback (most recent call last):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\predicates.py", line 15, in __call__
return self.fn(this._geom, other._geom, *args)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\geos.py", line 584, in errcheck_predicate
raise PredicateError("Failed to evaluate %s" % repr(func))
PredicateError: Failed to evaluate <_FuncPtr object at 0x00000204EB13ED40>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\pyplot.py", line 139, in post_execute
draw_all()
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\_pylab_helpers.py", line 137, in draw_all
manager.canvas.draw_idle()
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\backend_bases.py", line 2055, in draw_idle
self.draw(*args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\backends\backend_agg.py", line 406, in draw
self.figure.draw(self.renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\figure.py", line 2790, in draw
mimage._draw_list_compositing_images(
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\geoaxes.py", line 558, in draw
return matplotlib.axes.Axes.draw(self, renderer=renderer, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\_api\deprecation.py", line 431, in wrapper
return func(*inner_args, **inner_kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\axes\_base.py", line 2921, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 1012, in draw
super().draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 352, in draw
transform, transOffset, offsets, paths = self._prepare_points()
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 329, in _prepare_points
paths = [transform.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 329, in <listcomp>
paths = [transform.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\transforms.py", line 2396, in transform_path_non_affine
return self._a.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\geoaxes.py", line 186, in transform_path_non_affine
geoms = cpatch.path_to_geos(src_path,
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\patch.py", line 178, in path_to_geos
collection[-1][0].contains(geom.exterior)):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\geometry\base.py", line 747, in contains
return bool(self.impl['contains'](self, other))
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\predicates.py", line 18, in __call__
self._check_topology(err, this, other)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\topology.py", line 35, in _check_topology
raise TopologicalError(
TopologicalError: The operation 'GEOSContains_r' could not be performed. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at 0x000002048290D820>
TopologyException: side location conflict at -9.0506799999999998 53.206000000000003
Traceback (most recent call last):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\predicates.py", line 15, in __call__
return self.fn(this._geom, other._geom, *args)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\geos.py", line 584, in errcheck_predicate
raise PredicateError("Failed to evaluate %s" % repr(func))
PredicateError: Failed to evaluate <_FuncPtr object at 0x00000204EB13ED40>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\IPython\core\formatters.py", line 341, in __call__
return printer(obj)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\IPython\core\pylabtools.py", line 253, in <lambda>
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\IPython\core\pylabtools.py", line 137, in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\backend_bases.py", line 2230, in print_figure
self.figure.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\figure.py", line 2790, in draw
mimage._draw_list_compositing_images(
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\geoaxes.py", line 558, in draw
return matplotlib.axes.Axes.draw(self, renderer=renderer, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\_api\deprecation.py", line 431, in wrapper
return func(*inner_args, **inner_kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\axes\_base.py", line 2921, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 1012, in draw
super().draw(renderer)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 352, in draw
transform, transOffset, offsets, paths = self._prepare_points()
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 329, in _prepare_points
paths = [transform.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\collections.py", line 329, in <listcomp>
paths = [transform.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\matplotlib\transforms.py", line 2396, in transform_path_non_affine
return self._a.transform_path_non_affine(path)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\geoaxes.py", line 186, in transform_path_non_affine
geoms = cpatch.path_to_geos(src_path,
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\cartopy\mpl\patch.py", line 178, in path_to_geos
collection[-1][0].contains(geom.exterior)):
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\geometry\base.py", line 747, in contains
return bool(self.impl['contains'](self, other))
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\predicates.py", line 18, in __call__
self._check_topology(err, this, other)
File "C:\Users\dpereiro\Miniconda3\envs\opendrift\lib\site-packages\shapely\topology.py", line 35, in _check_topology
raise TopologicalError(
TopologicalError: The operation 'GEOSContains_r' could not be performed. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at 0x00000204E87FDD90>
<Figure size 432x288 with 1 Axes>

New to scientific python. I'm getting an AttributeError: 'ImmutableDensNDimArray' error and I don't understand why

I recently got accepted to grad school and my PI works with python and wanted me to learn how to use it through a series of exercises. I was given an equation and told to make it work. But I am getting an error and I just can't see why. Here is the portion of the code that causes the problem (I included the values of each summation function and the numeric sequence as comments since I did not include the code for the functions):
import scipy.optimize as sciop
import sympy as sp
import math as mt
#Calculates coefficients and builds the function
def Function(x, raw_input, N):
sequence_numeric = sequence_numeric_value_parser(raw_input) #[0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, -1, -1, 1, 1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, -1, -1, 0, 0, -1, -1, 0, 1, 0]
Q_summation = Q_Summation(sequence_numeric) ##-0.0011654102397665102
O_summation = O_Summation(N) ##-3.7169446884230575
B_summation = B_Summation(N) ##16.674533284328376
FiTC = 3/2 ##1st term constant
STC = ((3/(2*mt.pi))**(3/2))*O_summation ##2nd term constant
TTC = 0.1*((3/mt.pi)**3)*(1/16)*B_summation ##3rd term constant
FoTC = (7.2/3.8)*mt.sqrt(6/mt.pi)*Q_summation ##4th term constant
funct = FiTC*(x-sp.log(x)) + STC*x**(-3/2) + TTC*x**(-3) + FoTC*x**(-1/2)
print ("x = {} , funct = {}".format(x,funct))
return funct
#Minimizes function
def Minimizer():
x = 1.0
result = sciop.minimize(Function, x, args=(raw_input, N))
print("Minima at: ")
print("x = {}, funct = {}".format(result.x, result.funct))
Minimizer()
The error I get is:
Traceback (most recent call last):
File "C:\Users\Richard Miller\Desktop\A2v0.2.py", line 184, in <module>
Minimizer()
File "C:\Users\Richard Miller\Desktop\A2v0.2.py", line 178, in Minimizer
result = sciop.minimize(Function, x, args=(raw_input, N))
File "C:\Anaconda3\lib\site-packages\scipy\optimize\_minimize.py", line 604, in minimize
return _minimize_bfgs(fun, x0, args, jac, callback, **options)
File "C:\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 1003, in _minimize_bfgs
old_fval = f(x0)
File "C:\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 327, in function_wrapper
return function(*(wrapper_args + args))
File "C:\Users\Richard Miller\Desktop\A2v0.2.py", line 167, in Function
funct = FiTC*(x-sp.log(x)) + STC*x**(-3/2) + TTC*x**(-3) + FoTC*x**(-1/2)
File "C:\Anaconda3\lib\site-packages\sympy\core\function.py", line 473, in __new__
result = super(Function, cls).__new__(cls, *args, **options)
File "C:\Anaconda3\lib\site-packages\sympy\core\function.py", line 288, in __new__
evaluated = cls.eval(*args)
File "C:\Anaconda3\lib\site-packages\sympy\functions\elementary\exponential.py", line 659, in eval
coeff = arg.as_coefficient(I)
AttributeError: 'ImmutableDenseNDimArray' object has no attribute 'as_coefficient'
I've uploaded the full file I wrote to: https://github.com/rmiller415/A2

Trouble using PyUSB to read from usb device in different systems

I have written a small python script to read data from a digital thermometer, and everything works just fine in my computer. however, i need to run this same script in other systems, but i keep getting a "[Errno 10060] Operation timed out" error.
in the second computer i can see the device, it's endpoints and everything, but it's when i try to read from it that i'm getting the error.
this is the code (i intentionally did not set the configuration for the device, as i'm trying to speed up the reading, and in my system it proved not to be necessary):
import usb.core
def get_temp(T):
# find our device
dev = usb.core.find(idVendor=0x04d9, idProduct=0xe000)
# was it found?
if dev is None:
raise ValueError('Device not found')
# poll the thermometer for current temperature
t = dev.read(0x83, 32) # gets 32 bytes from ENDPOINT address 0x83
so, in the computer where i wrote this, it works as expected, and it returns a nice 32-byte array. but in other systems, i got the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\usb\core.py", line 402, in read
return self.device.read(self, size_or_buffer, timeout)
File "C:\Python27\lib\site-packages\usb\core.py", line 988, in read
self.__get_timeout(timeout))
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 851, in
intr_read
timeout)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 936, in
__read
_check(retval)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 595, in
_check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 10060] Operation timed out
i tried also setting device configuration this time, but still same error.
any ideas on what i might be missing?
edit: this is my output log with PYUSB_DEBUG environment variable set to debug:
>>> dev.read(0x83,32)
2019-01-11 10:35:06,951 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration(<usb.backend.libusb1._DeviceHandle object at 0x02A2A610>)
2019-01-11 10:35:06,953 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0)
2019-01-11 10:35:06,954 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0, 0, 0)
2019-01-11 10:35:06,956 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.get_endpoint_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0, 0, 0, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0, 0, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x02A2A650>, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.claim_interface(<usb.backend.libusb1._DeviceHandle object at 0x02A2A610>, 0)
2019-01-11 10:35:06,957 DEBUG:usb.backend.libusb1:_LibUSB.intr_read(<usb.backend.libusb1._DeviceHandle object at 0x02A2A610>, 131, 0, array('B', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 1000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\usb\core.py", line 988, in read
self.__get_timeout(timeout))
File "C:\Python27\lib\site-packages\usb\_debug.py", line 60, in do_trace
return f(*args, **named_args)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 851, in intr_read
timeout)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 936, in __read
_check(retval)
File "C:\Python27\lib\site-packages\usb\backend\libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 10060] Operation timed out
>>>

python rotate an image around an axis

I thought I had found the solution to my probelm (and the code) fro Idan:
MoviePy + Vapory code
from moviepy.editor import concatenate, ImageClip, VideoClip
from vapory import *
img_path = "E:/Programming/Python/coffee.png"
img_clip = ImageClip(img_path)
W, H = img_clip.w, img_clip.h
AR = 1.0*W/H
t_rev = 2.0
t_half = t_rev/2.0 # The time required for a half revolution
t_still = 0.8 # How long (in seconds) to hold the half rotated image still
cam = Camera('location', [ 0, 0, -1],
'look_at', [ 0, 0, 0])
light = LightSource([0, 0, -1]) # Light at camera location
bg = Background('color', [0, 0, 0]) # Black background
def scene(t):
""" Returns the scene at time 't' (in seconds) """
s = Scene(camera = cam, objects = [light, bg])
s = s.add_objects([
Box([0, 0, 0],
[W, H, 0],
Texture(Pigment(ImageMap('"{}"'.format(img_path), 'once')),
Finish('ambient', 1.0)),
'translate', [-0.5, -0.5, 0],
'scale', [AR, 1, 0],
'rotate', [0, (360/t_rev)*t, 0])])
return s
def make_frame(t):
return scene(t).render(width=W, height=H, antialiasing=0.1)
still_1 = VideoClip(make_frame).to_ImageClip(t=0).set_duration(t_still)
half_1 = VideoClip(make_frame).subclip(0, t_half)
still_2 = VideoClip(make_frame).to_ImageClip(t=t_half).set_duration(t_still)
half_2 = VideoClip(make_frame).subclip(t_half, t_rev)
final_clip = concatenate([still_1, half_1, still_2, half_2])
final_clip.write_gif("E:/Programming/Python/coffee_rot.gif", fps=15)
BUT when I try to run it with Python 3.6 I get (full traceback):
Hope this makes things clearer
Traceback (most recent call last):
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\test2a.py", line 44, in <module>
still_1 = VideoClip(make_frame).to_ImageClip(t=0).set_duration(t_still)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\video\VideoClip.py", line 86, in __init__
self.size = self.get_frame(0).shape[:2][::-1]
File "<decorator-gen-10>", line 2, in get_frame
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\moviepy\Clip.py", line 94, in get_frame
return self.make_frame(t)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\test2a.py", line 41, in make_frame
return scene(t).render(width=W, height=H, antialiasing=0.1)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\vapory\vapory.py", line 102, in render
quality, antialiasing, remove_temp)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\site-packages\vapory\io.py", line 106, in render_povstring
stdout=subprocess.PIPE)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 710, in __init__
restore_signals, start_new_session)
File "C:\Users\Us\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 998, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Searches find similar errors but none relevant to my situation. Help much appreciated. Idan are you still there?
Could comment re windows file paths be expanded a little?

Categories

Resources