Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
alhom authored Aug 28, 2024
2 parents 0da5563 + a5654c0 commit 04606c0
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions examples/generate_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_panel_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
4 changes: 2 additions & 2 deletions pyCalculations/cut3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pyCalculations/find_x_and_o.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <index>\n")
sys.stderr.write("or: size.py <starting_index> <final_index+1>\n")
Expand Down
4 changes: 2 additions & 2 deletions pyCalculations/themis_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
24 changes: 16 additions & 8 deletions pyPlots/plot_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import numpy as np
import sys
from rotation import rotateTensorToVector
import warnings

PLANE = 'XY'
# or alternatively, 'XZ'
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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]
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions pyPlots/plot_isosurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyPlots/plot_vdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion pyPlots/plot_vdf_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion pyPlots/plot_vdfdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
19 changes: 10 additions & 9 deletions pyVlsv/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pyVlsv/vlsvwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions scripts/create_time_energy_spectrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions scripts/magnetopause3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion scripts/plot_jet_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
12 changes: 6 additions & 6 deletions scripts/ulf_waves_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ 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)
varinfo = pt.calculations.VariableInfo(
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
Expand Down
7 changes: 4 additions & 3 deletions tools/vlsvintpol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 04606c0

Please sign in to comment.