-
Notifications
You must be signed in to change notification settings - Fork 39
pyCalculations/derivatives, VlsvWriter updates #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alhom
wants to merge
30
commits into
fmihpc:master
Choose a base branch
from
alhom:divPoynting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 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 2370fc2
Reduced dimension handling
alhom 893d0c2
Note for using reconstructions
alhom 617573b
an initial, dysfunctional divS function and derivatives.py file for f…
alhom cdb3ad2
ElementTree.SubElement not accepting kwords, only arguments. Added vl…
alhom e0ab425
Merge branch 'master' of github.com:fmihpc/analysator into divPoynting
alhom 6fdc55e
Merge branch 'plot_threeslice_interp_syntax' into divPoynting
alhom 16ef537
Functional fg to vg upsampling, todo: diffs beyond eyeballing, downsa…
alhom 0b110fe
fg to vg writer function in VlsvWriter, testing and upsampling-downsa…
alhom 9323843
Derivatives who may not be correct yet, bounding box reader functions…
alhom cc788a3
pyVlsv.VlsvWriter updates: no empty mesh attributes, pretty printed f…
alhom 9386f1d
Added some of Jonas' helpers and ballooning criterion.
alhom c927cae
a merge
alhom 2743746
Merge branch 'master' into divPoynting
alhom 345ccbf
curvature exposed, streamlined
alhom 91e3a7f
Merge branch 'divPoynting' of github.com:alhom/analysator into divPoy…
alhom 049e6e4
Requested changes
alhom 31c21d7
Requested changes 2: errant plot_helpers.PLANE change
alhom d7979c0
Default centering to None, allowed manual centering
alhom 9f64b6f
Last missing requests
alhom 9b957fa
A vlsvwriter.write wrapper to explicitly require necessary variable m…
alhom c9b0263
Utilities
alhom 38b5f17
Guarding against missing paths
alhom 10e4636
Commented out unused import, essentially dummy commit
alhom 659da76
Much faster implementation of read_variable_as_fg
ykempf 3600ce1
Fix copy-paste error.
ykempf f493473
renamed derivatives.py
alhom 9ecc815
A guard against files with zero populations
alhom 9948b48
Merge pull request #1 from ykempf/divPoynting
alhom 9c76555
cleaning up a bit
alhom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| # | ||
| # 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(bulkReader): | ||
| b = bulkReader.read_fg_variable_as_volumetric('fg_b') | ||
| print('b.shape=',b.shape) | ||
| e = bulkReader.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(bulkReader, dx=1e6): | ||
| S = fg_PoyntingFlux(bulkReader) | ||
|
|
||
| divS = (np.roll(S[:,:,:,0],-1, 0) - np.roll(S[:,:,:,0], 1, 0) + | ||
| np.roll(S[:,:,:,1],-1, 1) - np.roll(S[:,:,:,1], 1, 1) + | ||
| np.roll(S[:,:,:,2],-1, 2) - np.roll(S[:,:,:,2], 1, 2))/(2*dx) | ||
| print('divS.shape', divS.shape) | ||
|
|
||
| return divS | ||
|
|
||
| def fg_vol_jacobian(b, dx=1e6): | ||
| dFx_dx, dFx_dy, dFx_dz = np.gradient(b[:,:,:,0], dx) | ||
| dFy_dx, dFy_dy, dFy_dz = np.gradient(b[:,:,:,1], dx) | ||
| dFz_dx, dFz_dy, dFz_dz = np.gradient(b[:,:,:,2], dx) | ||
|
|
||
| return np.stack() | ||
markusbattarbee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def fg_vol_curl(array, dx=1e6): | ||
| 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(array, dx=1e6): | ||
| dFx_dx, dummy, dummy = np.gradient(array[:,:,:,0], dx) | ||
markusbattarbee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| dummy, dFy_dy, dummy = np.gradient(array[:,:,:,1], dx) | ||
| dummy, dummy, dFz_dz = np.gradient(array[:,:,:,2], dx) | ||
|
|
||
| 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 np.sum(np.multiply(a,b), axis=-1) | ||
markusbattarbee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #return ( | ||
| # a[:, :, :, 0] * b[:, :, :, 0] | ||
| # + a[:, :, :, 1] * b[:, :, :, 1] | ||
| # + a[:, :, :, 2] * b[:, :, :, 2] | ||
| #) | ||
|
|
||
| def vfield3_matder(a, b, dr): | ||
| """Calculates material derivative of 3D vector fields a and b""" | ||
|
|
||
| bx = b[:, :, :, 0] | ||
| by = b[:, :, :, 1] | ||
| bz = b[:, :, :, 2] | ||
|
|
||
| grad_bx = np.gradient(bx, dr) | ||
| grad_by = np.gradient(by, dr) | ||
| grad_bz = np.gradient(bz, dr) | ||
|
|
||
| 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(a, dr=1000e3): | ||
| a = vfield3_normalise(a) | ||
| return vfield3_matder(a, a, dr) | ||
|
|
||
| def ballooning_crit(B, P, beta, dr=1000e3): | ||
|
|
||
| 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) | ||
|
|
||
| balloon = (2 + beta) / 4.0 * kappaP / (kappaC + 1e-27) | ||
|
|
||
| return (balloon, kappaC, gradP) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.