Skip to content

Commit

Permalink
Merge pull request #221 from markusbattarbee/fix_plot_vdf_centering
Browse files Browse the repository at this point in the history
Fix plot vdf centering
  • Loading branch information
markusbattarbee authored Jun 11, 2024
2 parents 339e768 + e240eb0 commit 33ce88b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions pyPlots/plot_vdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,15 @@ def vSpaceReducer(vlsvReader, cid, slicetype, normvect, VXBins, VYBins, pop="pro
print("Found "+str(len(V))+" v-space cells")

# center on highest f-value
if center == "peak":
if str(center) == "peak":
peakindex = np.argmax(f)
Vpeak = V[peakindex,:]
V = V - Vpeak
print(peakindex)
#print(peakindex)
print("Transforming to frame of peak f-value, travelling at speed "+str(Vpeak))
elif not center is None:
if len(center)==3: # assumes it's a vector
# assumes it's a vector, either provided or extracted from bulk velocity
if len(center)==3:
print("Transforming to frame travelling at speed "+str(center))
V = V - center
else:
Expand Down Expand Up @@ -414,7 +415,7 @@ def plot_vdf(filename=None,
bpara=None, bpara1=None, bperp=None,
coordswap=None,
bvector=None,bvectorscale=0.2,
cbulk=None, center=None, wflux=None, setThreshold=None,
cbulk=None, cpeak=None,center=None, wflux=None, setThreshold=None,
noborder=None, scale=1.0, scale_text=8.0, scale_title=10.0,scale_cb=5.0,scale_label=12.0,
biglabel=None, biglabloc=None,
noxlabels=None, noylabels=None,
Expand Down Expand Up @@ -473,6 +474,8 @@ def plot_vdf(filename=None,
:kword cbulk: Center plot on position of total bulk velocity (or if not available,
bulk velocity for this population)
:kword cpeak: Center plot on velocity associated with highest (peak) phase-space density for
this population)
:kword center: Center plot on provided 3-element velocity vector position (in m/s)
If set instead to "bulk" will center on bulk velocity
If set instead to "peak" will center on velocity with highest phase-space density
Expand Down Expand Up @@ -960,17 +963,19 @@ def plot_vdf(filename=None,
normvectX = np.array(normvectX)
normvectX = normvectX/np.linalg.norm(normvectX)


if cbulk is not None or center=='bulk':
center=None # Finds the bulk velocity and places it in the center vector
if (cpeak is not None):
center='peak'
if (cbulk is not None) or (str(center)=='bulk'):
center = None # Fallthrough handling
# Finds the bulk velocity and places it in the center vector
print("Transforming to plasma frame")
if type(cbulk) is str:
if vlsvReader.check_variable(cbulk):
center = vlsvReader.read_variable(cbulk,cellid)
print("Found bulk frame from variable "+cbulk)
else:
center = Vbulk

# Note: center can still be equal to vector, or to the string "peak" and be valid

# Geometric magic to stretch the grid to assure that each cell has some velocity grid points inside it.
# Might still be incorrect, erring on the side of caution.
Expand Down

0 comments on commit 33ce88b

Please sign in to comment.