From 38b87a41200d93ead6643468009b98b8984b9283 Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 13:25:06 +0200 Subject: [PATCH 01/17] Using os.path.join instead of concatenation to make life easier with the paths hopefully --- scripts/cutthrough_timeseries.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/cutthrough_timeseries.py b/scripts/cutthrough_timeseries.py index ff9c98ae..0110a8d7 100644 --- a/scripts/cutthrough_timeseries.py +++ b/scripts/cutthrough_timeseries.py @@ -58,11 +58,8 @@ def jplots( fnr_arr = np.arange(fnr1, fnr2 + 0.1, 1, dtype=int) t_arr = np.zeros_like(fnr_arr).astype(float) - if bulkpath[-1] != "/": - bulkpath += "/" - fobj = pt.vlsvfile.VlsvReader( - bulkpath + bulkprefix + ".{}.vlsv".format(str(fnr1).zfill(7)) + os.path.join(bulkpath , bulkprefix , ".{}.vlsv".format(str(fnr1).zfill(7))) ) if re: point1 = [point1[0] * r_e, point1[1] * r_e, point1[2] * r_e] @@ -88,7 +85,7 @@ def jplots( for idx in range(fnr_arr.size): fnr = fnr_arr[idx] vlsvobj = pt.vlsvfile.VlsvReader( - bulkpath + bulkprefix + ".{}.vlsv".format(str(fnr).zfill(7)) + os.path.join(bulkpath , bulkprefix , ".{}.vlsv".format(str(fnr).zfill(7))) ) t_arr[idx] = vlsvobj.read_parameter("time") From 360acc57cb3b080f39d143b14ce1d30f33762a63 Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 13:28:12 +0200 Subject: [PATCH 02/17] ditto earlier for output files --- scripts/cutthrough_timeseries.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/cutthrough_timeseries.py b/scripts/cutthrough_timeseries.py index 0110a8d7..69a02b86 100644 --- a/scripts/cutthrough_timeseries.py +++ b/scripts/cutthrough_timeseries.py @@ -131,10 +131,7 @@ def jplots( except OSError: pass - if outputdir[-1] != "/": - outputdir += "/" - - fig.savefig(outputdir + outputname, dpi=300) + fig.savefig(os.path.join(outputdir,outputname), dpi=300) plt.close(fig) else: return (fig,ax,XmeshXY,YmeshXY,data_arr) From 39d8b851bf7b1b3e9e548f2c2d4092b72e808cbd Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 13:37:12 +0200 Subject: [PATCH 03/17] filename was part of the path name, oops --- scripts/cutthrough_timeseries.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cutthrough_timeseries.py b/scripts/cutthrough_timeseries.py index 69a02b86..2fb278d3 100644 --- a/scripts/cutthrough_timeseries.py +++ b/scripts/cutthrough_timeseries.py @@ -59,7 +59,7 @@ def jplots( t_arr = np.zeros_like(fnr_arr).astype(float) fobj = pt.vlsvfile.VlsvReader( - os.path.join(bulkpath , bulkprefix , ".{}.vlsv".format(str(fnr1).zfill(7))) + os.path.join(bulkpath , bulkprefix + ".{}.vlsv".format(str(fnr1).zfill(7))) ) if re: point1 = [point1[0] * r_e, point1[1] * r_e, point1[2] * r_e] @@ -85,7 +85,7 @@ def jplots( for idx in range(fnr_arr.size): fnr = fnr_arr[idx] vlsvobj = pt.vlsvfile.VlsvReader( - os.path.join(bulkpath , bulkprefix , ".{}.vlsv".format(str(fnr).zfill(7))) + os.path.join(bulkpath , bulkprefix + ".{}.vlsv".format(str(fnr).zfill(7))) ) t_arr[idx] = vlsvobj.read_parameter("time") From 4fbc26b25e68d5924030688985073aa21bc2627d Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 13:54:44 +0200 Subject: [PATCH 04/17] Added jplots to analysator itself, also changed outputfile handling to use one provided by plot submodule --- analysator/plot/plot_cutthrough_timeseries.py | 141 ++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 analysator/plot/plot_cutthrough_timeseries.py diff --git a/analysator/plot/plot_cutthrough_timeseries.py b/analysator/plot/plot_cutthrough_timeseries.py new file mode 100644 index 00000000..c9021863 --- /dev/null +++ b/analysator/plot/plot_cutthrough_timeseries.py @@ -0,0 +1,141 @@ + + + + + + +import analysator as pt +import numpy as np +import matplotlib.pyplot as plt +from scipy.ndimage import uniform_filter1d +import os +from analysator.calculations.lineout import lineout + +r_e = 6.371e6 #Maybe we should add an import that holds all the constants? + +def jplots( + var, + fnr1, + fnr2, + bulkpath, + bulkprefix, + point1, + point2, + outputname, + outputdir, + filt=-1, + op="pass", + cmap="viridis", + re=False, + npoints=100, + interpolation_order=1, + draw=True, + nooverwrite=False +): + ''' + Function for plotting a cut-through timeseries, aka keogram, aka time-elongation map, etc. for a given variable, a given set of coordinates, and a range of times. + + :kwarg var: Variable to plot (e.g. "proton/vg_rho", "vg_b_vol") + :kwarg fnr1: First file number to plot + :kwarg fnr2: Last file number to plot + :kwarg bulkpath: Path to directory containing bulk files + :kwarg bulkprefix: Starting string of bulk file name (e.g. bulk, bulk1, bulk5) + :kwarg point1: First point on the line to plot + :kwarg point2: Last point on the line to plot + :kwarg outputname: Name of output file + :kwarg outputdir: Path to output directory + :kwarg filt: Filter out temporally slowly changing signal? (<=0: no filtering, >0: filter with specified window size), default=-1 + :kwarg op: Variable operator, default="pass" + :kwarg cmap: Colormap, default="viridis" + :kwarg re: Input points given in Earth radii? default=False + :kwarg npoints: Number of points in line, default=100 + :kwarg interpolation_order: Order of interpolation (0 or 1), default=1 + :kward nooverwrite: Whether to overwrite if output file already exists, default=False + + :returns: Outputs an image to a file or to the screen. + + .. code-block:: python + + # Example usage: + jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath='/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1',bulkprefix='bulk1', + point1=[10,-20,0],point2=[20,-20,0],outputdir='./',outputname='test.png',op='x',re=True,npoints=50) + ''' + + + fnr_arr = np.arange(fnr1, fnr2 + 0.1, 1, dtype=int) + t_arr = np.zeros_like(fnr_arr).astype(float) + + fobj = pt.vlsvfile.VlsvReader( + os.path.join(bulkpath , bulkprefix + ".{}.vlsv".format(str(fnr1).zfill(7))) + ) + if re: + point1 = [point1[0] * r_e, point1[1] * r_e, point1[2] * r_e] + point2 = [point2[0] * r_e, point2[1] * r_e, point2[2] * r_e] + + lineout0 = lineout( + fobj, + point1, + point2, + variable=var, + operator=op, + points=npoints, + interpolation_order=interpolation_order, + ) + distances, _, _ = lineout0 + + fobj.optimize_clear_fileindex_for_cellid() + + distances = np.array(distances) / r_e + + data_arr = np.zeros((fnr_arr.size, distances.size), dtype=float) + + for idx in range(fnr_arr.size): + fnr = fnr_arr[idx] + vlsvobj = pt.vlsvfile.VlsvReader( + os.path.join(bulkpath , bulkprefix + ".{}.vlsv".format(str(fnr).zfill(7))) + ) + t_arr[idx] = vlsvobj.read_parameter("time") + + linecut = lineout( + vlsvobj, + point1, + point2, + variable=var, + operator=op, + points=npoints, + interpolation_order=interpolation_order, + ) + data_arr[idx, :] = linecut[2] + vlsvobj.optimize_clear_fileindex_for_cellid() + if filt > 0: + data_arr = data_arr - uniform_filter1d(data_arr, size=filt, axis=0) + + XmeshXY, YmeshXY = np.meshgrid(distances, t_arr) + + fig, ax = plt.subplots(1, 1, figsize=(8, 12), constrained_layout=True) + + im = ax.pcolormesh( + XmeshXY, + YmeshXY, + data_arr, + shading="gouraud", + cmap=cmap, + rasterized=True, + ) + + ax.set_xlim(distances[0], distances[-1]) + ax.set_ylim(t_arr[0], t_arr[-1]) + ax.set_xlabel("Distance along cut [RE]", labelpad=10, fontsize=16) + ax.set_ylabel("Time [s]", labelpad=10, fontsize=16) + ax.set_title(var, pad=10, fontsize=16) + + cb = fig.colorbar(im, ax=ax) + + if not draw: + outputpath=pt.plot.output_path(outputname,None,outputdir,nooverwrite) + fig.savefig(outputpath, dpi=300) + plt.close(fig) + else: + return (fig,ax,XmeshXY,YmeshXY,data_arr) + + From 48185b03387adf58a1dba20b884e12c3957d38b5 Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 13:56:31 +0200 Subject: [PATCH 05/17] Added jplots to init --- analysator/plot/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/analysator/plot/__init__.py b/analysator/plot/__init__.py index 0e71900d..7315091e 100644 --- a/analysator/plot/__init__.py +++ b/analysator/plot/__init__.py @@ -36,7 +36,7 @@ #for usage with "from (package) import *" __all__ = ['plot_colormap', 'plot_vdf', 'plot_vdfdiff', 'plot_vdf_profiles', 'plot_colormap3dslice', 'plot_threeslice', 'plot_ionosphere', 'plot_isosurface', 'plot_neutral_sheet', - 'plot_variables','colormaps', 'plot_helpers'] + 'plot_variables','colormaps', 'plot_helpers','jplots'] from .plot_variables import plot_variables, plot_multiple_variables @@ -49,6 +49,7 @@ from . import plot_helpers from .plot_colormap import plot_colormap +from .plot_cutthrough_timeseries import jplots from .plot_vdf import plot_vdf from .plot_vdfdiff import plot_vdfdiff from .plot_vdf_profiles import plot_vdf_profiles From 1e6eb8afa10bca54a51eab48cdc079b9ef359804 Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 14:05:19 +0200 Subject: [PATCH 06/17] Added draw default to False --- analysator/plot/plot_cutthrough_timeseries.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/analysator/plot/plot_cutthrough_timeseries.py b/analysator/plot/plot_cutthrough_timeseries.py index c9021863..4cbb21f3 100644 --- a/analysator/plot/plot_cutthrough_timeseries.py +++ b/analysator/plot/plot_cutthrough_timeseries.py @@ -29,7 +29,7 @@ def jplots( re=False, npoints=100, interpolation_order=1, - draw=True, + draw=False, nooverwrite=False ): ''' @@ -51,6 +51,7 @@ def jplots( :kwarg npoints: Number of points in line, default=100 :kwarg interpolation_order: Order of interpolation (0 or 1), default=1 :kward nooverwrite: Whether to overwrite if output file already exists, default=False + :kwarg draw: Whether draw on screen or output to file, default=False :returns: Outputs an image to a file or to the screen. From 8db5baa955479eb119a3345ccce57c9997583d8c Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 15:45:20 +0200 Subject: [PATCH 07/17] Added jplots to CI testpackage, made it so the funcs value in runs can take a dict where key tells the filename for the file and plot module import name and the value tells the actual function name. --- testpackage/testpackage_commons.py | 40 +++++++++++++++---- .../testpackage_plot_cutthrough_timeseries.py | 5 +++ 2 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py diff --git a/testpackage/testpackage_commons.py b/testpackage/testpackage_commons.py index 96babdb1..04ef9456 100644 --- a/testpackage/testpackage_commons.py +++ b/testpackage/testpackage_commons.py @@ -70,7 +70,7 @@ def source_file_name(filename,fileLocation,time): 'verifydir': '/FID/', 'fileLocation': datalocation+'/3D/FID/bulk1/', 'fluxLocation': None, - 'funcs': ['plot_colormap3dslice','plot_ionosphere','plot_isosurface'], + 'funcs': ['plot_colormap3dslice','plot_ionosphere','plot_isosurface',{'plot_cutthrough_timeseries':"jplots"}], 'pops': ['avgs'], 'time': 1000, 'skipped_args':{'plot_ionosphere':{"var":["ig_z","ig_p","ig_source","ig_residual"]}, @@ -215,7 +215,13 @@ def source_file_name(filename,fileLocation,time): functions = run['funcs'] else: - functions = sorted(list(set(run['funcs']) & set(funcs_to_use))) + functions=[] + for func in run['funcs']: + func_key=list(func.keys())[0] if type(func) is dict else func + if func_key in funcs_to_use: + functions.append(func) + + # functions = sorted(list(set(run['funcs']) & set(funcs_to_use))) if not functions: continue @@ -223,7 +229,11 @@ def source_file_name(filename,fileLocation,time): for j,func in enumerate(functions): #If one wants to test new calls to be added to the testpackage, they could be added in here after the testpackage_definitions/ lists have been parsed callindex = 0 - + func_dict=None + if type(func) is dict: + func_dict=func + func=list(func_dict.keys())[0] + #try to import the list of calls corresponding to the function to be tested. try: exec(f'import testpackage_definitions.testpackage_{func} as testpackage_{func}') @@ -240,7 +250,6 @@ def source_file_name(filename,fileLocation,time): skipped_args=run['skipped_args'] - if filename is not None: calls_in=v5restartcalls if vlasiator5 else restartcalls list_index=0 @@ -250,6 +259,8 @@ def source_file_name(filename,fileLocation,time): else: call = call.replace("var='V'","var='restart_V'") if skipped_args: + if func_dict: + func=func_dict[func] call=call_replace(call,func,skipped_args,required_args) if call is not None: callrunids.append(i) @@ -287,6 +298,8 @@ def source_file_name(filename,fileLocation,time): elif (("_backstream" in call) or ("_nonbackstream" in call)) and nosubpops: continue if skipped_args: + if func_dict: + func=func_dict[func] call=call_replace(call,func,skipped_args,required_args) if call is not None: list_inidices.append((1,list_index)) @@ -318,6 +331,8 @@ def source_file_name(filename,fileLocation,time): continue call = call.replace('REPLACEPOP',pop) if skipped_args: + if func_dict: + func=func_dict[func] call=call_replace(call,func,skipped_args,required_args) if call is not None: list_inidices.append((2,list_index)) @@ -361,13 +376,24 @@ def source_file_name(filename,fileLocation,time): list_index=list_inidices[j] funcid=funcids[j] - + #This could also be skipped since it's also done earlier but that would mean making new variable, checking it works blabla, im too lazy rn if not funcs_to_use: func = runs[runid]['funcs'][funcid] + if type(func) is dict: + func_dict=func + func=list(func_dict.keys())[0] else: - func = sorted(list(set(runs[runid]['funcs']) & set(funcs_to_use)))[funcid] + functions=[] + for func in runs[runid]['funcs']: + if type(func) is dict: + func=list(func.keys())[0] + if func in funcs_to_use: + functions.append(func) + if functions: + func=functions[funcid] + # func = sorted(list(set(runs[runid]['funcs']) & set(funcs_to_use)))[funcid] if not func: continue @@ -380,7 +406,7 @@ def source_file_name(filename,fileLocation,time): filename = runs[runid]['filename'] vlasiator5 = runs[runid]['vlasiator5'] singletime = runs[runid]['singletime'] - + #set custom expression variables for plot_colormap if 'plot_colormap' in func: exec(f"testpackage_{func}.cexp.level_bow_shock = runs[runid]['cavitonparams'][0]") diff --git a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py new file mode 100644 index 00000000..7ae67a78 --- /dev/null +++ b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py @@ -0,0 +1,5 @@ +v5nonrestartcalls=[ + + 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="./",outputname="test.png",op="x",re=True,npoints=50)', + +] From 9ccd3360d0934af5ebdaddebb899bed772ffd399 Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 15:48:36 +0200 Subject: [PATCH 08/17] Changed the output path for the testpackage_plot_cutthrough --- .../testpackage_plot_cutthrough_timeseries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py index 7ae67a78..78bf05bc 100644 --- a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py +++ b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py @@ -1,5 +1,5 @@ v5nonrestartcalls=[ - 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="./",outputname="test.png",op="x",re=True,npoints=50)', + 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=50)', ] From 6a841941ef2094af39049e80a7299e0050b65c50 Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 16:48:06 +0200 Subject: [PATCH 09/17] Added the datalocation to the call and testing with FID 986-1000 --- testpackage/testpackage_commons.py | 8 ++++++-- .../testpackage_plot_cutthrough_timeseries.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/testpackage/testpackage_commons.py b/testpackage/testpackage_commons.py index 04ef9456..178918ac 100644 --- a/testpackage/testpackage_commons.py +++ b/testpackage/testpackage_commons.py @@ -471,9 +471,13 @@ def source_file_name(filename,fileLocation,time): # Many different plots - print(j, runid, jrun, call,fileLocation+bulkname) - f = pt.vlsvfile.VlsvReader(fileLocation+bulkname) + if "vlsvobj" in call: + f = pt.vlsvfile.VlsvReader(fileLocation+bulkname) + else: + bulkname="" + call=call.replace("DATALOCATION",fileLocation) + print(j, runid, jrun, call,fileLocation+bulkname) try: exec(call) except Exception as e: diff --git a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py index 78bf05bc..0c8fa88b 100644 --- a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py +++ b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py @@ -1,5 +1,5 @@ v5nonrestartcalls=[ - 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=50)', - + # 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=50)', + 'pt.plot.jplots(var="vg_b_vol",fnr1=986,fnr2=1000,bulkpath=DATALOCATION,bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=14)', ] From e1fc2b1f3e8085f67f8be8ddd9c39f9f72f6c45c Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 17:05:26 +0200 Subject: [PATCH 10/17] Added FIF run for jplots --- testpackage/testpackage_commons.py | 16 +++++++++++++++- .../testpackage_plot_cutthrough_timeseries.py | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/testpackage/testpackage_commons.py b/testpackage/testpackage_commons.py index 178918ac..f44658b4 100644 --- a/testpackage/testpackage_commons.py +++ b/testpackage/testpackage_commons.py @@ -65,12 +65,26 @@ def source_file_name(filename,fileLocation,time): 'filename': None , 'cavitonparams': [6.6e6,2.64e6,4.e-9,10] }) +#For now this has just the jplots run, since that uses multiple files a method of forming the call arugments should be made +#since what is defined in the definition file only works for FIF (or runs with 501-531 times) +runs.append( { 'name': 'FIF', + 'verifydir': '/FIF/', + 'fileLocation': "/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1", + 'fluxLocation': None, + 'funcs': [{'plot_cutthrough_timeseries':"jplots"}], + 'pops': ['avgs'], + 'time': 0, + 'singletime': True, + 'filename': None, #restart file + 'nosubpops': True, # backstreaming / non-backstreaming + 'vlasiator5': True, + 'cavitonparams': [6.6e6,2.64e6,4.e-9,10] } ) runs.append( { 'name': 'FID', 'verifydir': '/FID/', 'fileLocation': datalocation+'/3D/FID/bulk1/', 'fluxLocation': None, - 'funcs': ['plot_colormap3dslice','plot_ionosphere','plot_isosurface',{'plot_cutthrough_timeseries':"jplots"}], + 'funcs': ['plot_colormap3dslice','plot_ionosphere','plot_isosurface'], 'pops': ['avgs'], 'time': 1000, 'skipped_args':{'plot_ionosphere':{"var":["ig_z","ig_p","ig_source","ig_residual"]}, diff --git a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py index 0c8fa88b..6026fd9b 100644 --- a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py +++ b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py @@ -1,5 +1,5 @@ v5nonrestartcalls=[ # 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=50)', - 'pt.plot.jplots(var="vg_b_vol",fnr1=986,fnr2=1000,bulkpath=DATALOCATION,bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=14)', + 'pt.plot.jplots(var="vg_b_vol",fnr1=501,fnr2=531,bulkpath=DATALOCATION,bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=30)', ] From 10868e9f8fa684e926b71a6a16ba7b620e65462c Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 17:15:06 +0200 Subject: [PATCH 11/17] Added missing key to run dict for FIF entry --- testpackage/testpackage_commons.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testpackage/testpackage_commons.py b/testpackage/testpackage_commons.py index f44658b4..251af7a5 100644 --- a/testpackage/testpackage_commons.py +++ b/testpackage/testpackage_commons.py @@ -74,6 +74,7 @@ def source_file_name(filename,fileLocation,time): 'funcs': [{'plot_cutthrough_timeseries':"jplots"}], 'pops': ['avgs'], 'time': 0, + 'skipped_args': None, 'singletime': True, 'filename': None, #restart file 'nosubpops': True, # backstreaming / non-backstreaming From f66a0410e1e2147d28231445a67b8a5556215008 Mon Sep 17 00:00:00 2001 From: lassejsc Date: Mon, 9 Mar 2026 17:53:06 +0200 Subject: [PATCH 12/17] Remade if statment so bulkfilename variable doesnt get overwritten on accident --- testpackage/testpackage_commons.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/testpackage/testpackage_commons.py b/testpackage/testpackage_commons.py index 251af7a5..0bd955fd 100644 --- a/testpackage/testpackage_commons.py +++ b/testpackage/testpackage_commons.py @@ -6,6 +6,7 @@ def source_file_name(filename,fileLocation,time): if filename is None: + #This may not produce correct result but works currently if '2D' not in fileLocation: bulkname = "bulk1."+str(time).rjust(7,'0')+".vlsv" @@ -486,12 +487,12 @@ def source_file_name(filename,fileLocation,time): # Many different plots - if "vlsvobj" in call: - f = pt.vlsvfile.VlsvReader(fileLocation+bulkname) - else: + + if "jplots" in call: bulkname="" call=call.replace("DATALOCATION",fileLocation) - + else: + f = pt.vlsvfile.VlsvReader(fileLocation+bulkname) print(j, runid, jrun, call,fileLocation+bulkname) try: exec(call) From 9c51365c733279906f4561a0592970547edd19a1 Mon Sep 17 00:00:00 2001 From: lassjsc Date: Tue, 10 Mar 2026 10:47:40 +0200 Subject: [PATCH 13/17] Fixed error in filename that caused failure due to string delimiters --- .../testpackage_plot_cutthrough_timeseries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py index 6026fd9b..6547f3e2 100644 --- a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py +++ b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py @@ -1,5 +1,5 @@ v5nonrestartcalls=[ # 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=50)', - 'pt.plot.jplots(var="vg_b_vol",fnr1=501,fnr2=531,bulkpath=DATALOCATION,bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=30)', + 'pt.plot.jplots(var="vg_b_vol",fnr1=501,fnr2=531,bulkpath=DATALOCATION,bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots.png",op="x",re=True,npoints=30)', ] From 3b1f85c8c4fb7c690632fd34c882a38dfd6d797b Mon Sep 17 00:00:00 2001 From: lassjsc Date: Tue, 10 Mar 2026 11:15:47 +0200 Subject: [PATCH 14/17] Another issue with strings fixed in the call --- .../testpackage_plot_cutthrough_timeseries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py index 6547f3e2..416097ac 100644 --- a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py +++ b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py @@ -1,5 +1,5 @@ v5nonrestartcalls=[ # 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=50)', - 'pt.plot.jplots(var="vg_b_vol",fnr1=501,fnr2=531,bulkpath=DATALOCATION,bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots.png",op="x",re=True,npoints=30)', + 'pt.plot.jplots(var="vg_b_vol",fnr1=501,fnr2=531,bulkpath=DATALOCATION,bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir=verifydir+REPLACEINDEX,outputname="plot_jplots.png",op="x",re=True,npoints=30)', ] From d88c03f0e7f15cd8ad456ebedfba8da58c4401dd Mon Sep 17 00:00:00 2001 From: lassjsc Date: Tue, 10 Mar 2026 13:09:41 +0200 Subject: [PATCH 15/17] Fixed formatting of the call in plot_cutthrough definition for testpackage --- .../testpackage_plot_cutthrough_timeseries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py index 416097ac..99e17292 100644 --- a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py +++ b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py @@ -1,5 +1,5 @@ v5nonrestartcalls=[ # 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=50)', - 'pt.plot.jplots(var="vg_b_vol",fnr1=501,fnr2=531,bulkpath=DATALOCATION,bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir=verifydir+REPLACEINDEX,outputname="plot_jplots.png",op="x",re=True,npoints=30)', + "pt.plot.jplots(var='vg_b_vol',fnr1=501,fnr2=531,bulkpath='DATALOCATION',bulkprefix='bulk1',point1=[10,-20,0],point2=[20,-20,0],outputdir=verifydir+REPLACEINDEX,outputname='plot_jplots.png',op='x',re=True,npoints=30)", ] From 800eb36a127e32a1b11805119c7adbf785a2d59e Mon Sep 17 00:00:00 2001 From: lassjsc Date: Tue, 10 Mar 2026 16:58:29 +0200 Subject: [PATCH 16/17] Added default outputdir as none to jplots and fixed the output path for testpackage call of it --- analysator/plot/plot_cutthrough_timeseries.py | 2 +- .../testpackage_plot_cutthrough_timeseries.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/analysator/plot/plot_cutthrough_timeseries.py b/analysator/plot/plot_cutthrough_timeseries.py index 4cbb21f3..17f2854c 100644 --- a/analysator/plot/plot_cutthrough_timeseries.py +++ b/analysator/plot/plot_cutthrough_timeseries.py @@ -22,7 +22,7 @@ def jplots( point1, point2, outputname, - outputdir, + outputdir=None, filt=-1, op="pass", cmap="viridis", diff --git a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py index 99e17292..1b1e1fc2 100644 --- a/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py +++ b/testpackage/testpackage_definitions/testpackage_plot_cutthrough_timeseries.py @@ -1,5 +1,5 @@ v5nonrestartcalls=[ # 'pt.plot.jplots(var="vg_b_vol",fnr1=600,fnr2=650,bulkpath="/wrk-vakka/group/spacephysics/vlasiator/3D/FIF/bulk1",bulkprefix="bulk1",point1=[10,-20,0],point2=[20,-20,0],outputdir="verifydir+REPLACEINDEX",outputname="plot_jplots_REPLACEINDEX.png",op="x",re=True,npoints=50)', - "pt.plot.jplots(var='vg_b_vol',fnr1=501,fnr2=531,bulkpath='DATALOCATION',bulkprefix='bulk1',point1=[10,-20,0],point2=[20,-20,0],outputdir=verifydir+REPLACEINDEX,outputname='plot_jplots.png',op='x',re=True,npoints=30)", + "pt.plot.jplots(var='vg_b_vol',fnr1=501,fnr2=531,bulkpath='DATALOCATION',bulkprefix='bulk1',point1=[10,-20,0],point2=[20,-20,0],outputdir=outputLocation,outputname=REPLACEINDEX+'_plot_jplots.png',op='x',re=True,npoints=30)", ] From 184c79be71f02ac83d5b8b6e1728ddcbad4b04cf Mon Sep 17 00:00:00 2001 From: lassjsc Date: Fri, 22 May 2026 17:34:31 +0300 Subject: [PATCH 17/17] hack job of adding vmin,vmax,custom title and log/linear scaling for the colormap --- analysator/plot/plot_cutthrough_timeseries.py | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/analysator/plot/plot_cutthrough_timeseries.py b/analysator/plot/plot_cutthrough_timeseries.py index 17f2854c..cdc4d01a 100644 --- a/analysator/plot/plot_cutthrough_timeseries.py +++ b/analysator/plot/plot_cutthrough_timeseries.py @@ -1,12 +1,10 @@ - - - - - import analysator as pt import numpy as np import matplotlib.pyplot as plt +from matplotlib.colors import BoundaryNorm,LogNorm +from matplotlib.ticker import MaxNLocator +from matplotlib.ticker import LogLocator from scipy.ndimage import uniform_filter1d import os from analysator.calculations.lineout import lineout @@ -23,6 +21,10 @@ def jplots( point2, outputname, outputdir=None, + title=None, + lin=True, + vmin=None, + vmax=None, filt=-1, op="pass", cmap="viridis", @@ -42,6 +44,10 @@ def jplots( :kwarg bulkprefix: Starting string of bulk file name (e.g. bulk, bulk1, bulk5) :kwarg point1: First point on the line to plot :kwarg point2: Last point on the line to plot + :kwarg lin: Whether to use linear or logarithmic scaling? (True: Use linear with 7 ticks, False: Logarithmic, int: Number of ticks for linear case ) + :kwarg vmin: Min value for the colormap scaling. + :kwarg vmax: Max value for the colormap scaling. + :kwarg title: Custom title, default None which then uses title=var. :kwarg outputname: Name of output file :kwarg outputdir: Path to output directory :kwarg filt: Filter out temporally slowly changing signal? (<=0: no filtering, >0: filter with specified window size), default=-1 @@ -115,12 +121,41 @@ def jplots( fig, ax = plt.subplots(1, 1, figsize=(8, 12), constrained_layout=True) + if not lin and lin != 0: + lin = None + if lin is True and lin!=1: + lin = 7 + + if vmin is not None: + vminuse=vmin + else: + vminuse=np.ma.amin(data_arr) + if vmax is not None: + vmaxuse=vmax + else: + vmaxuse=np.ma.amax(data_arr) + + # If both values are zero, we have an empty array + if vmaxuse==vminuse==0: + raise ValueError("requested array is zero everywhere. Exiting.") + + cmapuse = pt.plot.get_cmap(cmap) + + if not lin: + norm = LogNorm(vmin=vminuse,vmax=vmaxuse) + ticks = LogLocator(base=10,subs=list(range(10))) # where to show labels + else: + levels = MaxNLocator(nbins=255).tick_values(vminuse,vmaxuse) + norm = BoundaryNorm(levels, ncolors=cmapuse.N, clip=True) + ticks = np.linspace(vminuse,vmaxuse,num=lin) + im = ax.pcolormesh( XmeshXY, YmeshXY, data_arr, shading="gouraud", cmap=cmap, + norm=norm, rasterized=True, ) @@ -128,9 +163,9 @@ def jplots( ax.set_ylim(t_arr[0], t_arr[-1]) ax.set_xlabel("Distance along cut [RE]", labelpad=10, fontsize=16) ax.set_ylabel("Time [s]", labelpad=10, fontsize=16) - ax.set_title(var, pad=10, fontsize=16) + ax.set_title(title if title else var, pad=10, fontsize=16) - cb = fig.colorbar(im, ax=ax) + cb = fig.colorbar(im, ax=ax,ticks=ticks) if not draw: outputpath=pt.plot.output_path(outputname,None,outputdir,nooverwrite)