Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
26ce835
Initial commit of divS helpers. Introduced fsgrid reader that crudely…
alhom May 28, 2021
2370fc2
Reduced dimension handling
alhom Jun 1, 2021
893d0c2
Note for using reconstructions
alhom Jun 4, 2021
617573b
an initial, dysfunctional divS function and derivatives.py file for f…
alhom Jun 22, 2021
cdb3ad2
ElementTree.SubElement not accepting kwords, only arguments. Added vl…
alhom Aug 19, 2021
e0ab425
Merge branch 'master' of github.com:fmihpc/analysator into divPoynting
alhom Aug 19, 2021
6fdc55e
Merge branch 'plot_threeslice_interp_syntax' into divPoynting
alhom Aug 19, 2021
16ef537
Functional fg to vg upsampling, todo: diffs beyond eyeballing, downsa…
alhom Aug 23, 2021
0b110fe
fg to vg writer function in VlsvWriter, testing and upsampling-downsa…
alhom Aug 25, 2021
9323843
Derivatives who may not be correct yet, bounding box reader functions…
alhom Sep 7, 2021
cc788a3
pyVlsv.VlsvWriter updates: no empty mesh attributes, pretty printed f…
alhom Sep 7, 2021
9386f1d
Added some of Jonas' helpers and ballooning criterion.
alhom Sep 8, 2021
c927cae
a merge
alhom Sep 9, 2021
2743746
Merge branch 'master' into divPoynting
alhom Sep 16, 2021
345ccbf
curvature exposed, streamlined
alhom Sep 23, 2021
91e3a7f
Merge branch 'divPoynting' of github.com:alhom/analysator into divPoy…
alhom Sep 23, 2021
049e6e4
Requested changes
alhom Sep 28, 2021
31c21d7
Requested changes 2: errant plot_helpers.PLANE change
alhom Sep 28, 2021
d7979c0
Default centering to None, allowed manual centering
alhom Sep 28, 2021
9f64b6f
Last missing requests
alhom Sep 28, 2021
9b957fa
A vlsvwriter.write wrapper to explicitly require necessary variable m…
alhom Sep 29, 2021
c9b0263
Utilities
alhom Jan 26, 2022
38b5f17
Guarding against missing paths
alhom May 19, 2022
10e4636
Commented out unused import, essentially dummy commit
alhom May 19, 2022
659da76
Much faster implementation of read_variable_as_fg
ykempf May 30, 2022
3600ce1
Fix copy-paste error.
ykempf May 30, 2022
f493473
renamed derivatives.py
alhom Jun 1, 2022
9ecc815
A guard against files with zero populations
alhom Sep 27, 2022
9948b48
Merge pull request #1 from ykempf/divPoynting
alhom Dec 16, 2022
9c76555
cleaning up a bit
alhom Nov 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyCalculations/calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
import fit
from fieldtracer import static_field_tracer
from fieldtracer import dynamic_field_tracer

from differentialops import fg_divPoynting, fg_PoyntingFlux, fg_vol_curl, ballooning_crit,vfield3_curvature
144 changes: 144 additions & 0 deletions pyCalculations/differentialops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#
# This file is part of Analysator.
# Copyright 2013-2016 Finnish Meteorological Institute
# Copyright 2017-2018 University of Helsinki
#
# For details of usage, see the COPYING file and read the "Rules of the Road"
# at http://www.physics.helsinki.fi/vlasiator/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

import numpy as np
import scipy as sp
import pytools as pt
import warnings
#from scipy import interpolate

def fg_PoyntingFlux(reader):
b = reader.read_fg_variable_as_volumetric('fg_b')
print('b.shape=',b.shape)
e = reader.read_fg_variable_as_volumetric('fg_e')
print('e.shape=',e.shape)

mu_0 = 1.25663706144e-6
S = np.cross(e,b)/mu_0
return S


def fg_divPoynting(reader):
S = fg_PoyntingFlux(reader)
dx = reader.get_fsgrid_cell_size()
divS = ((np.roll(S[:,:,:,0],-1, 0) - np.roll(S[:,:,:,0], 1, 0))/(2*dx[0]) +
(np.roll(S[:,:,:,1],-1, 1) - np.roll(S[:,:,:,1], 1, 1))/(2*dx[1]) +
(np.roll(S[:,:,:,2],-1, 2) - np.roll(S[:,:,:,2], 1, 2))/(2*dx[2])
)
print('divS.shape', divS.shape)

return divS

def fg_vol_jacobian(reader, b):
# Return the jacobian of an fsgrid volumetric variable
# result is a 3x3 array for each cell
# Last index of output gives the vector component,
# second-to-last the direction of derivative
dx = reader.get_fsgrid_cell_size()
dFx_dx, dFx_dy, dFx_dz = np.gradient(b[:,:,:,0], dx[0])
dFy_dx, dFy_dy, dFy_dz = np.gradient(b[:,:,:,1], dx[1])
dFz_dx, dFz_dy, dFz_dz = np.gradient(b[:,:,:,2], dx[2])

dFx = np.stack([dFx_dx, dFx_dy, dFx_dz], axis=-1)
dFy = np.stack([dFy_dx, dFy_dy, dFy_dz], axis=-1)
dFz = np.stack([dFz_dx, dFz_dy, dFz_dz], axis=-1)

return np.stack([dFx,dFy,dFz], axis=-1)

def fg_vol_curl(reader, array):
dx = reader.get_fsgrid_cell_size()
dummy, dFx_dy, dFx_dz = np.gradient(array[:,:,:,0], *dx)
dFy_dx, dummy, dFy_dz = np.gradient(array[:,:,:,1], *dx)
dFz_dx, dFz_dy, dummy = np.gradient(array[:,:,:,2], *dx)

rotx = dFz_dy - dFy_dz
roty = dFx_dz - dFz_dx
rotz = dFy_dx - dFx_dy

return np.stack([rotx, roty, rotz], axis=-1)

def fg_vol_div(reader, array):
dx = reader.get_fsgrid_cell_size()
dFx_dx = np.gradient(array[:,:,:,0], dx[0], axis=0)
dFy_dy = np.gradient(array[:,:,:,1], dx[1], axis=1)
dFz_dz = np.gradient(array[:,:,:,2], dx[2], axis=2)

return dFx_dx+dFy_dy+dFz_dz

def vfield3_dot(a, b):
"""Calculates dot product of vectors a and b in 3D vector field"""

return (a*b).sum(-1)
#return (
# a[:, :, :, 0] * b[:, :, :, 0]
# + a[:, :, :, 1] * b[:, :, :, 1]
# + a[:, :, :, 2] * b[:, :, :, 2]
#)

def vfield3_matder(reader, a, b):
"""Calculates material derivative of 3D vector fields a and b"""
dr = reader.get_fsgrid_cell_size()
bx = b[:, :, :, 0]
by = b[:, :, :, 1]
bz = b[:, :, :, 2]

grad_bx = np.gradient(bx, dr[0])
grad_by = np.gradient(by, dr[1])
grad_bz = np.gradient(bz, dr[2])

resx = vfield3_dot(a, grad_bx)
resy = vfield3_dot(a, grad_by)
resz = vfield3_dot(a, grad_bz)

return np.stack((resx, resy, resz), axis=-1)

def vfield3_normalise(a):

amag = np.linalg.norm(a, axis=-1)

res=a/amag
return res
#resx = a[:, :, :, 0] / amag
#resy = a[:, :, :, 1] / amag
#resz = a[:, :, :, 2] / amag

#return np.stack((resx, resy, resz), axis=-1)

def vfield3_curvature(reader, a):
dr = reader.get_fsgrid_cell_size()
a = vfield3_normalise(a)
return vfield3_matder(a, a, dr)

def ballooning_crit(reader, B, P, beta):
dr = reader.get_fsgrid_cell_size()
n = vfield3_curvature(B, dr)

nnorm = vfield3_normalise(n)

gradP = np.gradient(P,dr)

kappaP = vfield3_dot(nnorm, gradP) / P

kappaC = vfield3_dot(nnorm, n)

return (kappaC, gradP)
8 changes: 6 additions & 2 deletions pyPlots/plot_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ def exprMA_cust(exprmaps, requestvariables=False):
if filename:
f=pt.vlsvfile.VlsvReader(filename)
elif (filedir and step is not None):
filename = glob.glob(filedir+'bulk*'+str(step).rjust(7,'0')+'.vlsv')[0]
try:
filename = glob.glob(filedir+'bulk*'+str(step).rjust(7,'0')+'.vlsv')[0]
except IndexError as err:
print("IndexError for filedir =", filedir, ", step = ", step)
return
#filename = filedir+'bulk.'+str(step).rjust(7,'0')+'.vlsv'
f=pt.vlsvfile.VlsvReader(filename)
elif vlsvobj:
Expand Down Expand Up @@ -816,7 +820,7 @@ def exprMA_cust(exprmaps, requestvariables=False):
if lin is None:
# Special SymLogNorm case
if symlog is not None:
if LooseVersion(matplotlib.__version__) < LooseVersion("3.3.0"):
if LooseVersion(matplotlib.__version__) < LooseVersion("3.2.0"):
norm = SymLogNorm(linthresh=linthresh, linscale = 1.0, vmin=vminuse, vmax=vmaxuse, clip=True)
print("WARNING: colormap SymLogNorm uses base-e but ticks are calculated with base-10.")
#TODO: copy over matplotlib 3.3.0 implementation of SymLogNorm into pytools/analysator
Expand Down
6 changes: 6 additions & 0 deletions pyPlots/plot_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ def expr_flowcompression(pass_maps, requestvariables=False):
return ['V']
Vmap = TransposeVectorArray(pass_maps['V']) # Bulk flow
return numdiv(Vmap).T

def expr_divPoynting(pass_maps, requestvariables=False):
if requestvariables==True:
return ['poynting']
dSmap = TransposeVectorArray(pass_maps['poynting']) # Bulk flow
return numdiv(dSmap).T

# def expr_gradB_aniso(pass_maps):
# Bmap = TransposeVectorArray(pass_maps['B']) # Magnetic field
Expand Down
Loading