Skip to content

Commit a6d9d3a

Browse files
committed
fixed some PEP warnings in PFS module
1 parent ed68826 commit a6d9d3a

File tree

10 files changed

+108
-116
lines changed

10 files changed

+108
-116
lines changed

demos/ipython_tutorials/1_introduction.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"* [Some useful OCELOT functions](small_useful_features.ipynb). [Web version](http://nbviewer.jupyter.org/github/ocelot-collab/ocelot/blob/dev/demos/ipython_tutorials/small_useful_features.ipynb)\n",
102102
" - Aperture, RK tracking \n",
103103
"* [Example of an accelerator section optimization](accelerator_optim.ipynb). [Web version](https://nbviewer.jupyter.org/github/ocelot-collab/ocelot/blob/master/demos/ipython_tutorials/accelerator_optim.ipynb)\n",
104-
" - A simple demo of accelerator section optimization with a stadard scipy numerical optimization method. "
104+
" - A simple demo of accelerator section optimization with a standard scipy numerical optimization method. "
105105
]
106106
},
107107
{

ocelot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
general ocelot description
33
"""
44

5-
__version__ = '20.11.0'
5+
__version__ = '20.11.2'
66

77

88
__all__ = ['Twiss', "Beam", "Particle", "get_current", "get_envelope", "generate_parray", # beam

ocelot/adaptors/genesis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ def calc_spec(self, mode='mid', npad=0):
609609
if self.nSlices == 1:
610610
raise AssertionError('Cannot calculate spectrum from steady-state simulation')
611611

612-
if (npad%1 is not 0) or npad < 0:
612+
if (npad%1 != 0) or npad < 0:
613613
raise ValueError('npad should be positive integer')
614614

615615
if mode == 'ff':

ocelot/common/math_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def find_nearest(array, value):
398398

399399
def n_moment(x, counts, c, n):
400400
x = np.squeeze(x)
401-
if x.ndim is not 1:
401+
if x.ndim != 1:
402402
raise ValueError("scale of x should be 1-dimensional")
403403
if x.size not in counts.shape:
404404
raise ValueError("operands could not be broadcast together with shapes %s %s" %(str(x.shape), str(counts.shape)))

ocelot/gui/dfl_plot.py

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import time
99
import matplotlib
1010
import matplotlib.pyplot as plt
11-
import matplotlib.colors as colors # for wigner log scale
11+
import matplotlib.colors as colors # for wigner log scale
1212
import numpy as np
1313
import logging
1414

@@ -21,8 +21,6 @@
2121
from ocelot.optics.utils import calc_ph_sp_dens
2222
from ocelot.optics.wave import *
2323

24-
25-
2624
from ocelot.gui.colormaps2d.colormap2d import *
2725

2826
# in order to run decorators properly
@@ -250,7 +248,7 @@ def plot_dfl(dfl, domains=None, z_lim=[], xy_lim=[], figsize=4, cmap=def_cmap, l
250248
suffix += '_log'
251249

252250
if fig_name is None:
253-
if dfl_copy.fileName() is '':
251+
if dfl_copy.fileName() == '':
254252
fig = plt.figure('Radiation distribution' + suffix)
255253
else:
256254
fig = plt.figure('Radiation distribution' + suffix + ' ' + dfl_copy.fileName())
@@ -558,7 +556,7 @@ def plot_wigner(wig_or_out, z=np.inf, x_units='um', y_units='ev', x_lim=(None, N
558556
raise ValueError('Unknown object for Wigner plot')
559557

560558
if fig_name is None:
561-
if W.fileName() is '':
559+
if W.fileName() == '':
562560
fig_text = 'Wigner distribution'
563561
else:
564562
fig_text = 'Wigner distribution ' + W.fileName()
@@ -623,24 +621,24 @@ def plot_wigner(wig_or_out, z=np.inf, x_units='um', y_units='ev', x_lim=(None, N
623621

624622
# cmap='RdBu_r'
625623
# axScatter.imshow(wigner, cmap=cmap, vmax=wigner_lim, vmin=-wigner_lim)
626-
624+
627625
if log_scale != 0:
628-
if log_scale==1:
629-
log_scale=0.01
626+
if log_scale == 1:
627+
log_scale = 0.01
630628
wigplot = axScatter.pcolormesh(power_scale[::downsample], spec_scale[::downsample],
631-
wigner[::downsample, ::downsample], cmap=cmap,
632-
norm=colors.SymLogNorm(linthresh=wigner_lim * log_scale, linscale=2,
633-
vmin=-wigner_lim, vmax=wigner_lim),
634-
vmax=wigner_lim, vmin=-wigner_lim)
629+
wigner[::downsample, ::downsample], cmap=cmap,
630+
norm=colors.SymLogNorm(linthresh=wigner_lim * log_scale, linscale=2,
631+
vmin=-wigner_lim, vmax=wigner_lim),
632+
vmax=wigner_lim, vmin=-wigner_lim)
635633
else:
636634
wigplot = axScatter.pcolormesh(power_scale[::downsample], spec_scale[::downsample],
637-
wigner[::downsample, ::downsample], cmap=cmap, vmax=wigner_lim, vmin=-wigner_lim)
638-
635+
wigner[::downsample, ::downsample], cmap=cmap, vmax=wigner_lim, vmin=-wigner_lim)
636+
639637
if plot_cbar:
640638
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
641-
cbaxes = inset_axes(axScatter, width="50%", height="3%", loc=1)
642-
fig.colorbar(wigplot, cax = cbaxes, orientation='horizontal')
643-
639+
cbaxes = inset_axes(axScatter, width="50%", height="3%", loc=1)
640+
fig.colorbar(wigplot, cax=cbaxes, orientation='horizontal')
641+
644642
if plot_text:
645643
if hasattr(wig_or_out, 'is_spectrogram'):
646644
if wig_or_out.is_spectrogram:
@@ -736,23 +734,20 @@ def plot_wigner(wig_or_out, z=np.inf, x_units='um', y_units='ev', x_lim=(None, N
736734

737735
axHistx.set_xlim(x_lim_appl[0], x_lim_appl[1])
738736
axHisty.set_ylim(y_lim_appl[0], y_lim_appl[1])
739-
737+
740738
if log_scale != 0:
741739
axHistx.set_ylim(np.nanmin(power), np.nanmax(power))
742740
axHisty.set_xlim(np.nanmin(spec), np.nanmax(spec))
743741
axHisty.set_xscale('log')
744742
axHistx.set_yscale('log')
745-
743+
746744
else:
747745
axScatter.axis('tight')
748746
axScatter.set_xlabel(p_label_txt)
749747
axScatter.set_ylabel(f_label_txt)
750748

751749
# axScatter.set_xlim(x_lim[0], x_lim[1])
752750
# axScatter.set_ylim(y_lim[0], y_lim[1])
753-
754-
755-
756751

757752
if savefig != False:
758753
if savefig == True:
@@ -782,15 +777,15 @@ def plot_dfl_waistscan(sc_res, fig_name=None, figsize=4, showfig=True, savefig=F
782777
_logger.info('plot dfl waist scan')
783778
if showfig == False and savefig == False:
784779
return
785-
780+
786781
if fig_name is None:
787-
if sc_res.fileName() is '':
782+
if sc_res.fileName() == '':
788783
fig = plt.figure('Waist scan')
789784
else:
790785
fig = plt.figure(sc_res.fileName() + ' waist scan')
791786
else:
792787
fig = plt.figure(fig_name)
793-
788+
794789
plt.clf()
795790
fig.set_size_inches((3 * figsize, 2 * figsize), forward=True)
796791
ax_int = fig.add_subplot(1, 1, 1)
@@ -952,11 +947,11 @@ def plot_stokes_values(S, fig=None, d_pol=0, norm=0, showfig=True, gw=1, directi
952947
if np.size(sc) <= 1:
953948
_logger.warning('plot_stokes_values needs more than a single point to plot (np.size(sc) <= 1)')
954949
return
955-
950+
956951
if d_pol != 0:
957-
gw=0
958-
norm=1
959-
952+
gw = 0
953+
norm = 1
954+
960955
if fig == None:
961956
plt.figure('Stokes S')
962957
plt.clf()
@@ -970,7 +965,7 @@ def plot_stokes_values(S, fig=None, d_pol=0, norm=0, showfig=True, gw=1, directi
970965
mult = 1e-9
971966
plt.ylabel('$S_0$ [GW]')
972967
elif norm:
973-
mult = 1/np.amax(Scp.s0)
968+
mult = 1 / np.amax(Scp.s0)
974969
else:
975970
mult = 1
976971
plt.ylabel('$S_0$ [W]')
@@ -986,10 +981,10 @@ def plot_stokes_values(S, fig=None, d_pol=0, norm=0, showfig=True, gw=1, directi
986981
else:
987982
raise ValueError
988983

989-
if d_pol=='lin':
984+
if d_pol == 'lin':
990985
# plt.step(sc, np.sqrt(S.s1**2+S.s2**2), linewidth=2, where='mid',color=[0.5,0.5,0.5], linestyle='--')
991986
plot_function(sc, Scp.deg_pol_l(), linestyle='-', color='#1f77b4', **kwargs)
992-
elif d_pol==1:
987+
elif d_pol == 1:
993988
plot_function(sc, Scp.deg_pol(), linestyle='-', color='#1f77b4', **kwargs)
994989
else:
995990
pass
@@ -1041,8 +1036,7 @@ def plot_stokes_angles(S, fig=None, showfig=True, direction='z', plot_func='scat
10411036
if np.size(sc) <= 1:
10421037
_logger.warning('plot_stokes_angles needs more than a single point to plot (np.size(sc) <= 1)')
10431038
return
1044-
1045-
1039+
10461040
if fig == None:
10471041
plt.figure('Stokes angles')
10481042
plt.clf()
@@ -1067,7 +1061,7 @@ def plot_stokes_angles(S, fig=None, showfig=True, direction='z', plot_func='scat
10671061

10681062
plot_function(sc, Scp.psi(), color='b', **kwargs)
10691063
# if plot_func == 'scatter':
1070-
# kwargs['s'] = psize
1064+
# kwargs['s'] = psize
10711065
plot_function(sc, Scp.chi(), color='g', **kwargs)
10721066

10731067
# if scatter:

ocelot/gui/genesis4_plot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def plot_gen4_out_z(out, z=np.inf, params=['rad_power+el_current', 'el_energy+el
280280
# z = out.z[zi]
281281

282282
if fig_name is None:
283-
if out.fileName() is '':
283+
if out.fileName() == '':
284284
fig = plt.figure('Bunch profile at ' + str(z) + 'm')
285285
else:
286286
fig = plt.figure('Bunch profile at ' + str(z) + 'm ' + out.fileName())
@@ -348,13 +348,13 @@ def plot_gen4_out_z(out, z=np.inf, params=['rad_power+el_current', 'el_energy+el
348348
axf = len(ax) - axt
349349
# ax[0].set_xlim(out.z[0], out.z[-1])
350350
# ax[-1].set_xlabel('z [m]')
351-
if axt is not 0 and axf is not 0:
351+
if axt != 0 and axf != 0:
352352
fig.subplots_adjust(top=0.95, bottom=0.2, right=0.8, left=0.15)
353353
else:
354354
fig.subplots_adjust(top=0.95, bottom=0.1, right=0.8, left=0.15)
355355

356356
for axi in ax[axt:]:
357-
if axt is not 0:
357+
if axt != 0:
358358
pos1 = axi.get_position() # get the original position
359359
pos2 = [pos1.x0 + 0, pos1.y0 - 0.1, pos1.width / 1.0, pos1.height / 1.0]
360360
axi.set_position(pos2)
@@ -661,7 +661,7 @@ def plot_gen4_out_evo(out, params=['und_quad', 'el_size', 'el_pos', 'el_energy',
661661
out = read_out_file(out, read_level=2)
662662
# add check for output object
663663
if fig_name is None:
664-
if out.fileName() is '':
664+
if out.fileName() == '':
665665
fig = plt.figure(params_str)
666666
_logger.info('plotting ' + params_str)
667667
else:

0 commit comments

Comments
 (0)