Skip to content
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

on-the-fly data reducers #245

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions pyVlsv/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ def makelambda(index):
v5reducers["vg_jacobian_b"] = DataReducerVariable(["vg_dbxvoldx","vg_dbxvoldy","vg_dbxvoldz","vg_dbyvoldx","vg_dbyvoldy","vg_dbyvoldz","vg_dbzvoldx","vg_dbzvoldy","vg_dbzvoldz"], TensorFromScalars, "T/m", 1, latex=r"$\vec{J}$",latexunits=r"$\mathrm{A}\,\mathrm{m}^{-2}$")
v5reducers["vg_jacobian_bper"] = DataReducerVariable(["vg_dperbxvoldx","vg_dperbxvoldy","vg_dperbxvoldz","vg_dperbyvoldx","vg_dperbyvoldy","vg_dperbyvoldz","vg_dperbzvoldx","vg_dperbzvoldy","vg_dperbzvoldz"], TensorFromScalars, "T/m", 1, latex=r"$\vec{J}$",latexunits=r"$\mathrm{A}\,\mathrm{m}^{-2}$")
v5reducers["vg_j"] = DataReducerVariable(["vg_jacobian_bper"], J, "A/m^2", 1, latex=r"$\vec{J}$",latexunits=r"$\mathrm{A}\,\mathrm{m}^{-2}$")
v5reducers["vg_j_parallel"] = DataReducerVariable(["vg_j", "vg_b_vol"], ParallelVectorComponent, "A/m^2", 1, latex=r"$J_\parallel$",latexunits=r"$\mathrm{A}\,\mathrm{m}^{-2}$")


#multipopv5reducers
Expand Down
22 changes: 22 additions & 0 deletions pyVlsv/vlsvreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,28 @@ def read_variable(self, name, cellids=-1,operator="pass"):

.. seealso:: :func:`read` :func:`read_variable_info`
'''

# Handle custom variable names
# ex. (x-component unit vector Bx/|B|): name = '{vg_b_vol.x} / {vg_b_vol.magnitude}'
if '{' in name:
name_split = re.split(r"(\{.*?\})", name)
var_dct = {}
var_count = 0
for i, n in enumerate(name_split):
if '{' in n:
varname_x = 'var_{}'.format(var_count)
var_op = n[1:-1].split('.')
if len(var_op) == 2:
op = var_op[1] # note: overrides operator keyword
else:
op = operator
# Recursion: Evaluate variables in '{}'
var_dct[varname_x] = self.read_variable(var_op[0], cellids = cellids, operator = op)
var_count += 1
name_split[i] = varname_x
expr = ''.join(name_split)
return eval(expr, None, var_dct)

cellids = get_data(cellids)

# Wrapper, check if requesting an fsgrid variable
Expand Down