diff --git a/.github/workflows/test_python.yml b/.github/workflows/test_python.yml index 9ceb6bc3..9a1c8928 100644 --- a/.github/workflows/test_python.yml +++ b/.github/workflows/test_python.yml @@ -78,6 +78,6 @@ jobs: - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --extend-exclude=trash_can,pyMayaVi # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --extend-exclude=trash_can,pyMayaVi diff --git a/examples/generate_panel.py b/examples/generate_panel.py index 744ca348..047a6dc0 100644 --- a/examples/generate_panel.py +++ b/examples/generate_panel.py @@ -188,8 +188,8 @@ def cavitoncontours(ax, XmeshXY,YmeshXY, extmaps, requestvariables=False): # it has access to the name of the .vlsv file, and then calls plot_vdf to # create insets on top of the variable map. def insetVDF(ax, XmeshXY,YmeshXY, pass_maps): - if requestvariables==True: - return [] + # if requestvariables==True: # Never triggers, copy-paste leftovers? + # return [] # pass_maps is a list of numpy arrays, not used here. from mpl_toolkits.axes_grid1.inset_locator import inset_axes @@ -365,7 +365,7 @@ def insetVDF(ax, XmeshXY,YmeshXY, pass_maps): vmin=1e-2, vmax=1e0, pass_vars=['E','B','V'], - expression=expr_Slippage) + expression=pt.plot.plot_helpers.expr_Slippage) # Plot beam number density with inset VDF diff --git a/examples/multi_panel_plot.py b/examples/multi_panel_plot.py index 020f10f5..2305683b 100644 --- a/examples/multi_panel_plot.py +++ b/examples/multi_panel_plot.py @@ -7,7 +7,7 @@ # Avoids opening a figure window -if str(matplotlib.get_backend()) is not 'Agg': +if str(matplotlib.get_backend()) != 'Agg': plt.switch_backend('Agg') fileLocation="/proj/vlasov/2D/BCH/bulk/" diff --git a/pyCalculations/cut3d.py b/pyCalculations/cut3d.py index f12c19e5..96ec9fff 100644 --- a/pyCalculations/cut3d.py +++ b/pyCalculations/cut3d.py @@ -63,8 +63,8 @@ def cut3d( vlsvReader, xmin, xmax, ymin, ymax, zmin, zmax, variable, operator="p # Read the cell lengths: ################################################## # Get xmax, xmin and xcells_ini - mesh_limits = f.get_spatial_mesh_extent() - mesh_size = f.get_spatial_mesh_size() + mesh_limits = vlsvReader.get_spatial_mesh_extent() + mesh_size = vlsvReader.get_spatial_mesh_size() xmax = mesh_limits[3] xmin = mesh_limits[0] xcells = mesh_size[0] diff --git a/pyCalculations/find_x_and_o.py b/pyCalculations/find_x_and_o.py index bce401ce..ca5a9866 100755 --- a/pyCalculations/find_x_and_o.py +++ b/pyCalculations/find_x_and_o.py @@ -63,7 +63,7 @@ def findIntersection(v1,v2): elif len(sys.argv)==3: indexes = np.arange(int(sys.argv[1]),int(sys.argv[2])) elif len(sys.argv)==4: - indexes = np.arange(int(sys.argv[1]),int(sys.argv[2]),,int(sys.argv[3])) + indexes = np.arange(int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3])) else: sys.stderr.write("Syntax: size.py \n") sys.stderr.write("or: size.py \n") diff --git a/pyCalculations/themis_observation.py b/pyCalculations/themis_observation.py index b0758b31..9b41f454 100644 --- a/pyCalculations/themis_observation.py +++ b/pyCalculations/themis_observation.py @@ -105,7 +105,7 @@ def simulation_to_observation_frame(x_axis,y_axis): z_axis = np.cross(x_axis,y_axis) return np.array([x_axis,y_axis,z_axis]) -def themis_plot_detector(vlsvReader, cellID, detector_axis=np.array([0,1,0])): +def themis_plot_detector(vlsvReader, cellID, detector_axis=np.array([0,1,0]), pop="proton"): ''' Plots a view of the detector countrates using matplotlib :param vlsvReader: Some VlsvReader class with a file open :type vlsvReader: :class:`vlsvfile.VlsvReader` @@ -134,7 +134,7 @@ def themis_plot_detector(vlsvReader, cellID, detector_axis=np.array([0,1,0])): fig.colorbar(cax) pl.show() -def themis_plot_phasespace_contour(vlsvReader, cellID, plane_x=np.array([1.,0,0]), plane_y=np.array([0,0,1.]), smooth=False, xlabel="Vx", ylabel="Vy"): +def themis_plot_phasespace_contour(vlsvReader, cellID, plane_x=np.array([1.,0,0]), plane_y=np.array([0,0,1.]), smooth=False, xlabel="Vx", ylabel="Vy", pop="proton"): ''' Plots a contour view of phasespace, as seen by a themis detector, at the given cellID :param vlsvReader: Some VlsvReader class with a file open :type vlsvReader: :class:`vlsvfile.VlsvReader` diff --git a/pyPlots/plot_helpers.py b/pyPlots/plot_helpers.py index 98b6ffc4..c4311a04 100644 --- a/pyPlots/plot_helpers.py +++ b/pyPlots/plot_helpers.py @@ -26,6 +26,7 @@ import numpy as np import sys from rotation import rotateTensorToVector +import warnings PLANE = 'XY' # or alternatively, 'XZ' @@ -486,7 +487,9 @@ def expr_timeavg(pass_maps, requestvariables=False): var = next(listofkeys) if var!="dstep": break ntimes = len(pass_maps) - thismap = thesemaps[var] + + warnings.warn("expr_timeavg cleaned to not produce undefined variable errors, see commit e1d2dd8ecaa7a0444ce56215f795a5237f792b1e for applied changes and check the output!") + thismap = pass_maps[var] avgmap = np.zeros(np.array(thismap.shape)) for i in range(ntimes): avgmap = np.add(avgmap, pass_maps[i][var]) @@ -1135,7 +1138,7 @@ def expr_ja(pass_maps, requestvariables=False): def expr_dLstardt(pass_maps, requestvariables=False): if requestvariables==True: - return ['B','E'] + return ['B','E','V'] if type(pass_maps) is not list: # Not a list of time steps, calculating this value does not make sense. @@ -1149,9 +1152,10 @@ def expr_dLstardt(pass_maps, requestvariables=False): thesemaps = pass_maps[curri] pastmaps = pass_maps[previ] - thisB = TransposeVectorArray(thesemaps['B']) - pastB = TransposeVectorArray(pastmaps['B']) - Vddt = (thisV-pastV)/DT + warnings.warn("expr_dLstardt cleaned to not produce undefined variable errors, see commit e1d2dd8ecaa7a0444ce56215f795a5237f792b1e for applied changes and check the output!") + thisV = TransposeVectorArray(thesemaps['V']) + pastV = TransposeVectorArray(pastmaps['V']) + dVdt = (thisV-pastV)/DT Bmap = TransposeVectorArray(thesemaps['B']) upBmag2 = np.linalg.norm(Bmap,axis=-1)**(-2) @@ -1185,7 +1189,8 @@ def overplotvectors(ax, XmeshXY,YmeshXY, pass_maps): step = int(np.sqrt(colors.shape[0] * colors.shape[1]/100.)) # inplane unit length vectors - vectmap = pt.plot.plot_helpers.inplanevec(vectmap) + warnings.warn("usage of inplanevec(vf) is unverified! Used to be inplanevec(vectmap), with vectmap undefined. See changes in commit e1d2dd8ecaa7a0444ce56215f795a5237f792b1e and check if results are as expected!") + vectmap = pt.plot.plot_helpers.inplanevec(vf) vectmap = vectmap / np.linalg.norm(vectmap, axis=-1)[:,:,np.newaxis] X = XmeshXY[::step,::step] @@ -1198,8 +1203,11 @@ def overplotvectors(ax, XmeshXY,YmeshXY, pass_maps): elif PLANE=="YZ": V = vectmap[::step,::step,0] C = colors[::step,::step] - ax.quiver(X,Y,U,V,C, cmap='gray', units='dots', scale=0.03/scale, headlength=2, headwidth=2, - headaxislength=2, scale_units='dots', pivot='middle') + + ax.quiver(X,Y,U,V,C, cmap='gray', units='dots', + #scale=0.03/scale, # scale not defined - if you need to use this, adjust as necessary! + headlength=2, headwidth=2, + headaxislength=2, scale_units='dots', pivot='middle') def overplotstreamlines(ax, XmeshXY,YmeshXY, pass_maps): diff --git a/pyPlots/plot_isosurface.py b/pyPlots/plot_isosurface.py index 17e3e73e..53570633 100644 --- a/pyPlots/plot_isosurface.py +++ b/pyPlots/plot_isosurface.py @@ -590,14 +590,14 @@ def plot_isosurface(filename=None, highresscale = float(highres) if np.isclose(highresscale, 1.0): highresscale = 2 - figsize= [x * highresscale for x in figsize] + # figsize= [x * highresscale for x in figsize] # figsize not defined, neither used in this function fontsize=fontsize*highresscale fontsize2=fontsize2*highresscale fontsize3=fontsize3*highresscale scale=scale*highresscale thick=thick*highresscale - streamlinethick=streamlinethick*highresscale - vectorsize=vectorsize*highresscale + # streamlinethick=streamlinethick*highresscale # streamlinethick not defined, neither used in this function + # vectorsize=vectorsize*highresscale # vectorsize not defined, neither used in this function # Generate virtual bounding box to get equal aspect maxrange = np.array([boxcoords[1]-boxcoords[0], boxcoords[3]-boxcoords[2], boxcoords[5]-boxcoords[4]]).max() / 2.0 diff --git a/pyPlots/plot_vdf.py b/pyPlots/plot_vdf.py index 94e490fa..f62ef297 100644 --- a/pyPlots/plot_vdf.py +++ b/pyPlots/plot_vdf.py @@ -659,7 +659,7 @@ def plot_vdf(filename=None, pass if not os.access(savefigdir, os.W_OK): - logging.info("No write access for directory "+outputdir2+"! Exiting.") + logging.info("No write access for directory "+savefigdir+"! Exiting.") return diff --git a/pyPlots/plot_vdf_profiles.py b/pyPlots/plot_vdf_profiles.py index 4587aab4..60943307 100644 --- a/pyPlots/plot_vdf_profiles.py +++ b/pyPlots/plot_vdf_profiles.py @@ -435,7 +435,7 @@ def plot_vdf_profiles(filename=None, pass if not os.access(savefigdir, os.W_OK): - logging.info("No write access for directory "+outputdir2+"! Exiting.") + logging.info("No write access for directory "+savefigdir+"! Exiting.") return diff --git a/pyPlots/plot_vdfdiff.py b/pyPlots/plot_vdfdiff.py index 017e9f5b..bd1ba058 100644 --- a/pyPlots/plot_vdfdiff.py +++ b/pyPlots/plot_vdfdiff.py @@ -289,7 +289,7 @@ def plot_vdfdiff(filename1=None, filename2=None, pass if not os.access(savefigdir, os.W_OK): - logging.info("No write access for directory "+outputdir2+"! Exiting.") + logging.info("No write access for directory "+savefigdir+"! Exiting.") return diff --git a/pyVlsv/reduction.py b/pyVlsv/reduction.py index 6cf3b390..a5380afe 100644 --- a/pyVlsv/reduction.py +++ b/pyVlsv/reduction.py @@ -637,15 +637,16 @@ def thermalvelocity( variables ): return thermalvelocity def Vstream( variables ): - rhoVstream = variables[0] - rhostream = variables[1] - rhoVNonBackstream = variables[2] - rhoNonBackstream = variables[3] - # get velocity of both populations: - vBackstream = v( [rhoVBackstream, rhoBackstream] ) - vNonBackstream = v( [rhoVNonBackstream, rhoNonBackstream] ) - vBeam = vBackstream - vNonBackstream - return vBeam # <- is a vector quantity + raise NotImplementedError("rhoVBackstream, rhoBackstream not defined here. Check implementaiton if required!") + # rhoVstream = variables[0] + # rhostream = variables[1] + # rhoVNonBackstream = variables[2] + # rhoNonBackstream = variables[3] + # # get velocity of both populations: + # vBackstream = v( [rhoVBackstream, rhoBackstream] ) + # vNonBackstream = v( [rhoVNonBackstream, rhoNonBackstream] ) + # vBeam = vBackstream - vNonBackstream + # return vBeam # <- is a vector quantity def v_beam( variables ): vBackstream = variables[0] diff --git a/pyVlsv/vlsvwriter.py b/pyVlsv/vlsvwriter.py index aa038154..e85d6e3b 100644 --- a/pyVlsv/vlsvwriter.py +++ b/pyVlsv/vlsvwriter.py @@ -210,7 +210,7 @@ def copy_variables_list( self, vlsvReader, vars ): if 'mesh' in child.attrib: mesh = child.attrib['mesh'] else: - if tag in ['VARIABLE']: + if child.tag in ['VARIABLE']: logging.info('MESH required') return mesh = None diff --git a/scripts/create_time_energy_spectrogram.py b/scripts/create_time_energy_spectrogram.py index 7c2060c8..bd7c9f69 100644 --- a/scripts/create_time_energy_spectrogram.py +++ b/scripts/create_time_energy_spectrogram.py @@ -92,6 +92,11 @@ # bin edges of kinetic energy in electron volts (energies below and above the last and first and ) EkinBinEdges = np.logspace(np.log10(100),np.log10(80e3),66) +# Initialize as none +xReq = None +yReq = None +zReq = None + # give a list of cids cids = (4502051,4951951,5551701) @@ -153,7 +158,7 @@ cidsTemp = [] if 'cids' not in locals(): logging.info('Finding nearest cells with vspace from given coordinates') - if ('xReq' not in locals()) or ('yReq' not in locals()) or ('zReq' not in locals()): + if (xReq is None) or (yReq is None) or (zReq is None): logging.info('ERROR: cids or (xReq,yReq,zReq) coordinates must be given') quit() if xReq.shape == yReq.shape == zReq.shape: @@ -258,7 +263,7 @@ def doSpectra(vlsvFile): locs = vlsvReader.get_cellid_locations() cellids = list(locs.keys()) # sort variable array according to cell ids - locs_sorted = sorted(locs.items()), key=oper.itemgetter(0)) + locs_sorted = sorted(locs.items(), key=oper.itemgetter(0)) fileNameStr = os.path.basename(vlsvFile) spectraStr = [] # spectra file contents bulkStr = [] # bulk parameter file contents diff --git a/scripts/magnetopause3d.py b/scripts/magnetopause3d.py index c7463290..13e2a70d 100644 --- a/scripts/magnetopause3d.py +++ b/scripts/magnetopause3d.py @@ -585,10 +585,11 @@ def main(): if plotting[2]: #plot Poynting vetors (not working!) - coords = np.array(coords) - poynting = np.array(poynting) + raise NotImplementedError("Poynting vector plotting not implemented!") + # coords = np.array(coords) + # poynting = np.array(poynting) - ax.quiver(coords[:,0], coords[:,1], coords[:,2], P[:,0], P[:,1], P[:,2]) + # ax.quiver(coords[:,0], coords[:,1], coords[:,2], P[:,0], P[:,1], P[:,2]) if plotting[3]: #plot surface diff --git a/scripts/plot_jet_criteria.py b/scripts/plot_jet_criteria.py index 8b4d384a..37a4e666 100644 --- a/scripts/plot_jet_criteria.py +++ b/scripts/plot_jet_criteria.py @@ -145,7 +145,7 @@ def jetcontours(ax, XmeshXY,YmeshXY, pass_maps): vmin=0.8, vmax=5, external=jetcontours, boxre=[8,16,-6,6], - cbtitle='$n_\mathrm{p}$ [cm$^{-3}$]', + cbtitle=r'$n_\mathrm{p}$ [cm$^{-3}$]', title='', usesci=0, thick=1.2) diff --git a/scripts/ulf_waves_filter.py b/scripts/ulf_waves_filter.py index fe959274..f7db9b15 100644 --- a/scripts/ulf_waves_filter.py +++ b/scripts/ulf_waves_filter.py @@ -101,16 +101,16 @@ def ulf_filter( data_arr, "{:s}_move_ave_{:d}".format(var_to_filter, windowlength), units="T", - latex="$B_{\mathrm{ave}}$", - latexunits="$\mathrm{T}$", + latex=r"$B_{\mathrm{ave}}$", + latexunits=r"$\mathrm{T}$", ) writer.write_variable_info(varinfo, "SpatialGrid", unitConversion=1) varinfo = pt.calculations.VariableInfo( delta_var, "{:s}_move_ave_{:d}_delta".format(var_to_filter, windowlength), units="T", - latex="$\delta{}B_{\mathrm{ave}}$", - latexunits="$\mathrm{T}$", + latex=r"$\delta{}B_{\mathrm{ave}}$", + latexunits=r"$\mathrm{T}$", ) writer.write_variable_info(varinfo, "SpatialGrid", unitConversion=1) # window_pad =50 see above this refers to the target file (centered file) @@ -118,8 +118,8 @@ def ulf_filter( filtered_dataPc2[window_pad, rev_sorti, :], "vg_b_vol_{:s}_{:d}_xyz".format(target_wave, windowlength), units="T^2Hz^-1", - latex="$\delta{}B_{\mathrm{ave}}$", - latexunits="$\mathrm{T}^2\,\mathrm{Hz}^{-1}\mathrm{orsomething}$", + latex=r"$\delta{}B_{\mathrm{ave}}$", + latexunits=r"$\mathrm{T}^2\,\mathrm{Hz}^{-1}\mathrm{orsomething}$", ) writer.write_variable_info(varinfo, "SpatialGrid", unitConversion=1) del reader diff --git a/tools/vlsvintpol.py b/tools/vlsvintpol.py index aaf31c2a..05c068c4 100755 --- a/tools/vlsvintpol.py +++ b/tools/vlsvintpol.py @@ -38,9 +38,10 @@ def extract_file(filename): f.optimize_open_file() t=f.read_parameter("time") if t == None: - t=f.read_parameter("t") - if t == None: - logging.info("Unknown time format in file " + filename) + t=f.read_parameter("t") + if t == None: + logging.info("Unknown time format in file " + filename) + for coord in coords: if(args.re):