From 9db64a3c0697b189f8e714e9500b6dd9e5d71256 Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Wed, 28 Aug 2024 12:45:10 +0300 Subject: [PATCH 1/9] Patch to read_velocity_cells to make return types consistent and to raise errors instead of returning None --- pyVlsv/vlsvreader.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pyVlsv/vlsvreader.py b/pyVlsv/vlsvreader.py index b1bd8a0c..004738ce 100644 --- a/pyVlsv/vlsvreader.py +++ b/pyVlsv/vlsvreader.py @@ -3017,8 +3017,8 @@ def read_velocity_cells(self, cellid, pop="proton"): self.__set_cell_offset_and_blocks(pop) # Check that cells has vspace if not cellid in self.__fileindex_for_cellid_blocks[pop]: - print("Cell does not have velocity distribution") - return [] + warnings.warn("Cell(s) does not have velocity distribution") + return {} # Navigate to the correct position: offset = self.__fileindex_for_cellid_blocks[pop][cellid][0] num_of_blocks = self.__fileindex_for_cellid_blocks[pop][cellid][1] @@ -3030,8 +3030,8 @@ def read_velocity_cells(self, cellid, pop="proton"): try: cells_with_blocks_index = self.__order_for_cellid_blocks[pop][cellid] except: - print("Cell does not have velocity distribution") - return [] + warnings.warn("Cell(s) does not have velocity distribution") + return {} # Navigate to the correct position: offset = self.__blocks_per_cell_offsets[pop][cells_with_blocks_index] num_of_blocks = self.__blocks_per_cell[pop][cells_with_blocks_index] @@ -3074,8 +3074,7 @@ def read_velocity_cells(self, cellid, pop="proton"): elif datatype == "uint" and element_size == 8: data_block_ids = np.fromfile(fptr, dtype = np.uint64, count = vector_size*num_of_blocks) else: - print("Error! Bad data type in blocks!") - return + raise TypeError("Error! Bad data type in blocks! datatype found was "+datatype) if (pop=="avgs") and (child.tag == "BLOCKIDS"): # Old avgs files did not have the name set for BLOCKIDS vector_size = ast.literal_eval(child.attrib["vectorsize"]) @@ -3091,8 +3090,7 @@ def read_velocity_cells(self, cellid, pop="proton"): elif datatype == "uint" and element_size == 8: data_block_ids = np.fromfile(fptr, dtype = np.uint64, count = vector_size*num_of_blocks) else: - print("Error! Bad data type in blocks!") - return + raise TypeError("Error! Bad data type in blocks! datatype found was "+datatype) data_block_ids = data_block_ids.reshape(num_of_blocks, vector_size) @@ -3100,7 +3098,7 @@ def read_velocity_cells(self, cellid, pop="proton"): # Check to make sure the sizes match (just some extra debugging) if len(data_avgs) != len(data_block_ids): - print("BAD DATA SIZES") + raise ValueError("BAD DATA SIZES") # Make a dictionary (hash map) out of velocity cell ids and avgs: velocity_cells = {} array_size = len(data_avgs) From 1191f6db9f3f98cfe466b85b578ce666db2c2729 Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Wed, 28 Aug 2024 14:05:07 +0300 Subject: [PATCH 2/9] A bunch of linter error fixes. --- examples/generate_panel.py | 6 +++--- examples/multi_panel_plot.py | 2 +- pyCalculations/cut3d.py | 4 ++-- pyCalculations/find_x_and_o.py | 2 +- pyCalculations/themis_observation.py | 4 ++-- pyPlots/plot_helpers.py | 8 ++++++-- pyPlots/plot_isosurface.py | 6 +++--- pyPlots/plot_vdf.py | 2 +- pyPlots/plot_vdf_profiles.py | 2 +- pyPlots/plot_vdfdiff.py | 2 +- pyVlsv/reduction.py | 19 ++++++++++--------- pyVlsv/vlsvwriter.py | 2 +- scripts/create_time_energy_spectrogram.py | 2 +- scripts/magnetopause3d.py | 7 ++++--- scripts/plot_jet_criteria.py | 2 +- scripts/ulf_waves_filter.py | 12 ++++++------ testpackage/testpackage_colormap.py | 4 ++-- testpackage/testpackage_vdf.py | 2 +- tools/vlsvintpol.py | 6 +++--- 19 files changed, 50 insertions(+), 44 deletions(-) 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 b39f2d74..691ca181 100644 --- a/pyCalculations/cut3d.py +++ b/pyCalculations/cut3d.py @@ -62,8 +62,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 be782a78..5a51fb39 100755 --- a/pyCalculations/find_x_and_o.py +++ b/pyCalculations/find_x_and_o.py @@ -62,7 +62,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 fae379c7..a8d832de 100644 --- a/pyCalculations/themis_observation.py +++ b/pyCalculations/themis_observation.py @@ -104,7 +104,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` @@ -133,7 +133,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 8c4d7be1..87b3333a 100644 --- a/pyPlots/plot_helpers.py +++ b/pyPlots/plot_helpers.py @@ -25,6 +25,7 @@ import numpy as np import sys from rotation import rotateTensorToVector +import warnings PLANE = 'XY' # or alternatively, 'XZ' @@ -1197,8 +1198,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 862c8ba5..4872c39d 100644 --- a/pyPlots/plot_isosurface.py +++ b/pyPlots/plot_isosurface.py @@ -589,14 +589,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 7eebc929..aec6a1b4 100644 --- a/pyPlots/plot_vdf.py +++ b/pyPlots/plot_vdf.py @@ -658,7 +658,7 @@ def plot_vdf(filename=None, pass if not os.access(savefigdir, os.W_OK): - print("No write access for directory "+outputdir2+"! Exiting.") + print("No write access for directory "+savefigdir+"! Exiting.") return diff --git a/pyPlots/plot_vdf_profiles.py b/pyPlots/plot_vdf_profiles.py index 0ecb19e7..b16719c9 100644 --- a/pyPlots/plot_vdf_profiles.py +++ b/pyPlots/plot_vdf_profiles.py @@ -434,7 +434,7 @@ def plot_vdf_profiles(filename=None, pass if not os.access(savefigdir, os.W_OK): - print("No write access for directory "+outputdir2+"! Exiting.") + print("No write access for directory "+savefigdir+"! Exiting.") return diff --git a/pyPlots/plot_vdfdiff.py b/pyPlots/plot_vdfdiff.py index daf61ac2..b17e377c 100644 --- a/pyPlots/plot_vdfdiff.py +++ b/pyPlots/plot_vdfdiff.py @@ -288,7 +288,7 @@ def plot_vdfdiff(filename1=None, filename2=None, pass if not os.access(savefigdir, os.W_OK): - print("No write access for directory "+outputdir2+"! Exiting.") + print("No write access for directory "+savefigdir+"! Exiting.") return diff --git a/pyVlsv/reduction.py b/pyVlsv/reduction.py index 7ee6d9ab..4a72379d 100644 --- a/pyVlsv/reduction.py +++ b/pyVlsv/reduction.py @@ -636,15 +636,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 2ce2c0c6..e0d929bf 100644 --- a/pyVlsv/vlsvwriter.py +++ b/pyVlsv/vlsvwriter.py @@ -209,7 +209,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']: print('MESH required') return mesh = None diff --git a/scripts/create_time_energy_spectrogram.py b/scripts/create_time_energy_spectrogram.py index e81a3f70..25dba426 100644 --- a/scripts/create_time_energy_spectrogram.py +++ b/scripts/create_time_energy_spectrogram.py @@ -257,7 +257,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 1724c43d..98961e56 100644 --- a/scripts/magnetopause3d.py +++ b/scripts/magnetopause3d.py @@ -584,10 +584,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 4875cf52..1adedeab 100644 --- a/scripts/plot_jet_criteria.py +++ b/scripts/plot_jet_criteria.py @@ -144,7 +144,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 3c504158..c188864c 100644 --- a/scripts/ulf_waves_filter.py +++ b/scripts/ulf_waves_filter.py @@ -100,16 +100,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) @@ -117,8 +117,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/testpackage/testpackage_colormap.py b/testpackage/testpackage_colormap.py index 46033dde..397f8a27 100644 --- a/testpackage/testpackage_colormap.py +++ b/testpackage/testpackage_colormap.py @@ -303,7 +303,7 @@ def extcontour(ax, XmeshXY,YmeshXY, extmaps, requestvariables=False): "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, Earth=True)", # title, axes, noborders -"pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$')", +r"pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$')", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='')", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noborder=1)", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noxlabels=1)", @@ -558,7 +558,7 @@ def extcontour(ax, XmeshXY,YmeshXY, extmaps, requestvariables=False): "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, Earth=True)", # title, axes, noborders -"pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$')", +r"pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$')", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='')", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noborder=1)", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noxlabels=1)", diff --git a/testpackage/testpackage_vdf.py b/testpackage/testpackage_vdf.py index c14305fd..b3f86cc7 100644 --- a/testpackage/testpackage_vdf.py +++ b/testpackage/testpackage_vdf.py @@ -96,7 +96,7 @@ "pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, biglabel='E', biglabloc=3, coordre=REPLACECOORDRE)", # title, axes, noborders -"pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$', coordre=REPLACECOORDRE)", +r"pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$', coordre=REPLACECOORDRE)", "pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='', coordre=REPLACECOORDRE)", "pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noborder=1, coordre=REPLACECOORDRE)", "pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noxlabels=1, coordre=REPLACECOORDRE)", diff --git a/tools/vlsvintpol.py b/tools/vlsvintpol.py index 084bf344..88d05467 100755 --- a/tools/vlsvintpol.py +++ b/tools/vlsvintpol.py @@ -37,9 +37,9 @@ def extract_file(filename): f.optimize_open_file() t=f.read_parameter("time") if t == None: - t=f.read_parameter("t") - if t == None: - print("Unknown time format in file " + filename) + t=f.read_parameter("t") + if t == None: + print("Unknown time format in file " + filename) for coord in coords: if(args.re): From 7388fa0d20fbcd84fde3299ecb764bedc7ba2366 Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Wed, 28 Aug 2024 16:55:11 +0300 Subject: [PATCH 3/9] Bunch of linter errors averted with None defaults --- scripts/create_time_energy_spectrogram.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/create_time_energy_spectrogram.py b/scripts/create_time_energy_spectrogram.py index 25dba426..c64da646 100644 --- a/scripts/create_time_energy_spectrogram.py +++ b/scripts/create_time_energy_spectrogram.py @@ -91,6 +91,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) @@ -152,7 +157,7 @@ cidsTemp = [] if 'cids' not in locals(): print('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): print('ERROR: cids or (xReq,yReq,zReq) coordinates must be given') quit() if xReq.shape == yReq.shape == zReq.shape: From 33a96ea5da0df60f2166489cdc9378af35b01b7c Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Wed, 28 Aug 2024 17:03:20 +0300 Subject: [PATCH 4/9] Exclude stale folders from linting --- .github/workflows/test_python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From e1d2dd8ecaa7a0444ce56215f795a5237f792b1e Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Wed, 28 Aug 2024 17:21:46 +0300 Subject: [PATCH 5/9] Somewhat more uncertain fixes. To be reviewed. --- pyPlots/plot_helpers.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pyPlots/plot_helpers.py b/pyPlots/plot_helpers.py index 87b3333a..da6bffe1 100644 --- a/pyPlots/plot_helpers.py +++ b/pyPlots/plot_helpers.py @@ -486,7 +486,7 @@ def expr_timeavg(pass_maps, requestvariables=False): var = next(listofkeys) if var!="dstep": break ntimes = len(pass_maps) - thismap = thesemaps[var] + 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 +1135,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 +1149,9 @@ 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 + 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 +1185,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. 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] From 45e8495aa345729d7a8af94965feed3663d75612 Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Wed, 28 Aug 2024 17:26:22 +0300 Subject: [PATCH 6/9] reverting few questionable raw string edits from testpackage, those dont seem to trip the CI --- testpackage/testpackage_colormap.py | 4 ++-- testpackage/testpackage_vdf.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/testpackage/testpackage_colormap.py b/testpackage/testpackage_colormap.py index 397f8a27..46033dde 100644 --- a/testpackage/testpackage_colormap.py +++ b/testpackage/testpackage_colormap.py @@ -303,7 +303,7 @@ def extcontour(ax, XmeshXY,YmeshXY, extmaps, requestvariables=False): "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, Earth=True)", # title, axes, noborders -r"pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$')", +"pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$')", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='')", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noborder=1)", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noxlabels=1)", @@ -558,7 +558,7 @@ def extcontour(ax, XmeshXY,YmeshXY, extmaps, requestvariables=False): "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, Earth=True)", # title, axes, noborders -r"pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$')", +"pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$')", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='')", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noborder=1)", "pt.plot.plot_colormap(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noxlabels=1)", diff --git a/testpackage/testpackage_vdf.py b/testpackage/testpackage_vdf.py index b3f86cc7..c14305fd 100644 --- a/testpackage/testpackage_vdf.py +++ b/testpackage/testpackage_vdf.py @@ -96,7 +96,7 @@ "pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, biglabel='E', biglabloc=3, coordre=REPLACECOORDRE)", # title, axes, noborders -r"pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$', coordre=REPLACECOORDRE)", +"pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title=r'$\mathcal{Title}$ and so forth $\odot$', cbtitle=r'$\mathcal{Color}$', coordre=REPLACECOORDRE)", "pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='', coordre=REPLACECOORDRE)", "pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noborder=1, coordre=REPLACECOORDRE)", "pt.plot.plot_vdf(vlsvobj=f, run=verifydir+REPLACEINDEX, title='',cbtitle='',noxlabels=1, coordre=REPLACECOORDRE)", From 5f1b9a79d769e74e5d4cad920281ad2b94d45400 Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Wed, 28 Aug 2024 17:33:13 +0300 Subject: [PATCH 7/9] Added warnings for edits --- pyPlots/plot_helpers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyPlots/plot_helpers.py b/pyPlots/plot_helpers.py index da6bffe1..27490f1e 100644 --- a/pyPlots/plot_helpers.py +++ b/pyPlots/plot_helpers.py @@ -486,6 +486,8 @@ def expr_timeavg(pass_maps, requestvariables=False): var = next(listofkeys) if var!="dstep": break ntimes = len(pass_maps) + + 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): @@ -1149,6 +1151,7 @@ def expr_dLstardt(pass_maps, requestvariables=False): thesemaps = pass_maps[curri] pastmaps = pass_maps[previ] + 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 From a378a501090a294b983e4b7fc8eadad0dfd693dd Mon Sep 17 00:00:00 2001 From: Alho Markku J Date: Wed, 28 Aug 2024 17:35:09 +0300 Subject: [PATCH 8/9] Added commit reference to one more tentative fix --- pyPlots/plot_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyPlots/plot_helpers.py b/pyPlots/plot_helpers.py index 27490f1e..337cd762 100644 --- a/pyPlots/plot_helpers.py +++ b/pyPlots/plot_helpers.py @@ -1188,7 +1188,7 @@ def overplotvectors(ax, XmeshXY,YmeshXY, pass_maps): step = int(np.sqrt(colors.shape[0] * colors.shape[1]/100.)) # inplane unit length vectors - warnings.warn("usage of inplanevec(vf) is unverified! Used to be inplanevec(vectmap), with vectmap undefined. Check if results are as expected!") + 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] From 3e7f37668b186b995073f1bfe27d32f74c26189b Mon Sep 17 00:00:00 2001 From: Markku Alho Date: Wed, 28 Aug 2024 22:06:59 +0300 Subject: [PATCH 9/9] Update test_python.yml - fail on linter errors Enforcing linter error checking for CI --- .github/workflows/test_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_python.yml b/.github/workflows/test_python.yml index 9a1c8928..6db2d816 100644 --- a/.github/workflows/test_python.yml +++ b/.github/workflows/test_python.yml @@ -61,7 +61,7 @@ jobs: lint: runs-on: ubuntu-latest - continue-on-error: true + #continue-on-error: true strategy: fail-fast: false