NameError: name 'product' is not defined ; error in python3 but works in python2 (original) (raw)
My python3 code for plotting is shown below but in my directory there is no output being saved although terminal says (‘Saving frame’, ‘image.0000.png’)
(‘Saving frame’, ‘balongphi.0000.png’) at the end of terminal output.
What changes should i do so that it can work in python3.
# Make, name and save plot
fname = 'image.%04d.png' % t
print(('Saving frame', fname))
plt.savefig(dir + fname,bbox_inches='tight')
# plt.show()
# Define next plot(s),
fig = plt.figure(figsize=(20, 7))
# ax = plt.subplot(111)
# Plot B_p or B_phi at chosen R, Theta in Phi direction
bporbphi=0#0 for Bp, 1 for B_phi
plt.clf()
x1 = [i for i in range (0,nphi)]
plt.xticks(size=45)#it is fontsize
plt.yticks(size=45)
plt.tick_params(width=2, which='both', size=15)
plt.tick_params(width=4, which='major', size=22)
plt.minorticks_on()
plt.xlabel(r"$i(\varphi)$", size=60)
if bporbphi == 0:
plt.ylabel(r"B", size=60)
else:
plt.ylabel(r"B$_\varphi$", size=60)
if bporbphi == 0:
plt.plot(x1, B_p[:,jrms,irms], color='black', ls='dashdot',label=r"B$_{p}$",linewidth=6)
plt.plot(x1, br[:,jrms,irms], color='r', ls='solid',label=r"B$_{r}$",linewidth=2)
plt.plot(x1, btheta[:,jrms,irms], color='r', ls='dashed',label=r"B$_{\theta}$",linewidth=3)
plt.plot(x1, bphi[:,jrms,irms], color='r', ls='dotted',label=r"B$_{\varphi}$",linewidth=3)
# Plot a horizontal black line at y=0
x1 = np.linspace(0,70)
y1 = np.zeros(len(x1))
plt.plot(x1, y1, color='black', linewidth=1.5)
plt.legend(loc='best', fontsize='30',ncol=1)
# Make, name and save plot
fname = 'balongphi.%04d.png' % t
print(('Saving frame',fname))
plt.savefig(dir + fname,bbox_inches='tight')
# plt.show()
I am getting following warnings while plotiing
/home/raman/Pictures/MikiFor2to3/m2c_read_athdata.py:306: DeprecationWarning: `interp2d` is deprecated in SciPy 1.10 and will be removed in SciPy 1.14.0.
For legacy code, nearly bug-for-bug compatible replacements are
`RectBivariateSpline` on regular grids, and `bisplrep`/`bisplev` for
scattered 2D data.
In new code, for regular grids use `RegularGridInterpolator` instead.
For scattered data, prefer `LinearNDInterpolator` or
`CloughTocher2DInterpolator`.
For more details see
`https://scipy.github.io/devdocs/notebooks/interp_transition_guide.html`
b2_phi = b_phi(x_stream, z_stream)
('shape(b2_phi)=', (50, 1000))
('shapes of rr,x3,y3=', (288,), (288, 65), (288, 65))
('shape x,z=', (288, 128), (288, 128))
/home/raman/Pictures/MikiFor2to3/m2c_read_athdata.py:864: DeprecationWarning: 'scipy.integrate.cumtrapz' is deprecated in favour of 'scipy.integrate.cumulative_trapezoid' and will be removed in SciPy 1.14.0
psib = integrate.cumtrapz(np.sqrt(-gdet_grid)*br_grid*2*np.pi,
/home/raman/Pictures/MikiFor2to3/m2c_read_athdata.py:463: UserWarning: The input coordinates to pcolormesh are interpreted as cell centers, but are not monotonically increasing or decreasing. This may lead to incorrectly calculated cell edges, in which case, please supply explicit cell edges to pcolormesh.
density = ax.pcolormesh(x, z, transpose(d[phic,:,:]),cmap=colormap,
/home/raman/Pictures/MikiFor2to3/m2c_read_athdata.py:468: UserWarning: The input coordinates to pcolormesh are interpreted as cell centers, but are not monotonically increasing or decreasing. This may lead to incorrectly calculated cell edges, in which case, please supply explicit cell edges to pcolormesh.
pressuref = ax.pcolormesh(x, z, transpose(prs[phic,:,:]),#/d[phic,:,:]),
/home/raman/Pictures/MikiFor2to3/m2c_read_athdata.py:474: UserWarning: The input coordinates to pcolormesh are interpreted as cell centers, but are not monotonically increasing or decreasing. This may lead to incorrectly calculated cell edges, in which case, please supply explicit cell edges to pcolormesh.
Bpfieldf = ax.pcolormesh(x, z, transpose(B_p[phic,:,:]),
/home/raman/Pictures/MikiFor2to3/m2c_read_athdata.py:478: UserWarning: The input coordinates to pcolormesh are interpreted as cell centers, but are not monotonically increasing or decreasing. This may lead to incorrectly calculated cell edges, in which case, please supply explicit cell edges to pcolormesh.
sigmapf = ax.pcolormesh(x, z, transpose(sigmap[phic,:,:])
/home/raman/Pictures/MikiFor2to3/m2c_read_athdata.py:482: UserWarning: The input coordinates to pcolormesh are interpreted as cell centers, but are not monotonically increasing or decreasing. This may lead to incorrectly calculated cell edges, in which case, please supply explicit cell edges to pcolormesh.
sigmatf = ax.pcolormesh(x, z, transpose(sigmat[phic,:,:])
/home/raman/Pictures/MikiFor2to3/m2c_read_athdata.py:498: UserWarning: The input coordinates to pcolormesh are interpreted as cell centers, but are not monotonically increasing or decreasing. This may lead to incorrectly calculated cell edges, in which case, please supply explicit cell edges to pcolormesh.
density = ax.pcolormesh(x, z, transpose(d[phic,:,:]),
====================================
++++++++++++++++++++++++++++++++++++
('t,rsph,ryl,zcyl,phic(rad)', 18000.0, np.float64(29.989018067368654), np.float64(24.304815561226043), np.float64(-17.567502531086994), np.float64(0.04908738521234052))
('i,j,phic,theta(rad),line_angle(r,theta)[deg]=,phic(deg)', 127, 89, 0, array([-0.94493217]), array([125.859375]), np.float64(0.0))
('vr,vtheta,vphi_plasmoidcenter=', np.float64(0.019714652411814283), np.float64(0.005371713597019614), np.float64(0.18112011678931444))
++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++
('t,rsph,rcyl,zcyl,phic(rad)', 18000.0, np.float64(22.2425806999513), np.float64(19.48605976895527), np.float64(10.725011462676814), np.float64(0.0))
('i,j,phic,theta(rad),line_angle(r,theta)[deg]=,phic(deg)', 114, 43, 0, array([1.06765063]), array([61.171875]), np.float64(0.0))
('vr,vtheta,vphi_plasmoidcenter=', np.float64(-0.009327810459887252), np.float64(0.0020440667265488), np.float64(0.1980705800083126))
++++++++++++++++++++++++++++++++++++
====================================
('Saving frame', 'image.0000.png')
('Saving frame', 'balongphi.0000.png')