Commit ddb7e70e authored by Clément Haëck's avatar Clément Haëck
Browse files

Exchange var_name arguments

so they are in output string order
parent 04ac6993
......@@ -57,7 +57,7 @@ def get_data(args=None, remove_dims=None, **kwargs):
parallel=False, data_vars='different')
def var_name(var, name='bins'):
def var_name(name, var):
return '{}_{}'.format(name, var)
......@@ -83,7 +83,7 @@ def histogram_da(da: xr.DataArray, bins, density=True, **kwargs):
def get_full_bins(da, bins=None):
"""Get bins with the rightmost edge."""
if bins is None:
bins = da[var_name(da.VAR, 'bins')]
bins = da[var_name('bins', da.VAR)]
if isinstance(bins, str):
bins = da[bins]
return np.append(bins.values, bins.attrs['right_edge'])
......@@ -129,7 +129,7 @@ def variables(name_in='hist', allowconcat=True):
if variables is None:
variables = ds.VARS
# DataArrays names
variables_ext = [var_name(v, name_in) for v in variables]
variables_ext = [var_name(name_in, v) for v in variables]
out_vars = []
for var, var_ext in zip(variables, variables_ext):
......@@ -139,7 +139,7 @@ def variables(name_in='hist', allowconcat=True):
if concat:
out = out.expand_dims(var=[var])
else:
out = out.rename(var_name(var, out.name))
out = out.rename(var_name(out.name, var))
out_vars.append(out)
if concat:
......@@ -155,7 +155,7 @@ def variables(name_in='hist', allowconcat=True):
@variables()
def get_N(hist):
"""Return total number of hits per image."""
return hist.sum(var_name(hist.VAR, 'bins')).rename('N')
return hist.sum(var_name('bins', hist.VAR)).rename('N')
@variables('N')
......@@ -168,7 +168,7 @@ def get_surface_fraction(N):
@variables(allowconcat=False)
def get_pdf(hist):
"""Return histogram normalized to a probability density function."""
bins_name = var_name(hist.VAR, 'bins')
bins_name = var_name('bins', hist.VAR)
# Get frequency (probability to hit a given bin)
freq = hist / hist.sum(bins_name)
......@@ -184,7 +184,7 @@ def get_pdf(hist):
@variables('pdf')
def get_median(pdf):
"""Return median computed from pdf."""
bins_name = var_name(pdf.VAR, 'bins')
bins_name = var_name('bins', pdf.VAR)
bins = get_full_bins(pdf, bins_name)
def uf_med(arr):
......@@ -205,7 +205,7 @@ def get_median(pdf):
@variables()
def get_total(hist):
"""Return total amount of quantity counted in histograms."""
bins_name = var_name(hist.VAR, 'bins')
bins_name = var_name('bins', hist.VAR)
return (hist * hist[bins_name]).sum(bins_name)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment