Skip to content

Commit

Permalink
[#6] Implemented _check_uniform_lin() and _check_uniform_log() => cle…
Browse files Browse the repository at this point in the history
…aner code
  • Loading branch information
Didou09 committed Apr 25, 2022
1 parent f1c09e1 commit 13b60a8
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions datastock/_plot_as_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# library-specific
from . import _generic_check
from . import _plot_text
from . import _class2_interactivity
from . import _class1_compute


__all__ = ['plot_as_array']
Expand Down Expand Up @@ -252,27 +252,34 @@ def plot_as_array(
# #############################################################################


def _check_uniform(k0=None, ddata=None):
def _check_uniform_lin(k0=None, ddata=None):

v0 = ddata[k0]

c0 = (
v0['data'].dtype.type != np.str_
and v0['monot'] == (True,)
and (
np.allclose(
np.diff(v0['data']),
v0['data'][1] - v0['data'][0],
equal_nan=False,
)
or (
np.all(v0['data'] > 0.)
and np.allclose(
np.diff(np.log(v0['data'])),
np.log(v0['data'][1]) - np.log(v0['data'][0]),
equal_nan=False,
)
)
and np.allclose(
np.diff(v0['data']),
v0['data'][1] - v0['data'][0],
equal_nan=False,
)
)
return c0


def _check_uniform_log(k0=None, ddata=None):

v0 = ddata[k0]

c0 = (
v0['data'].dtype.type != np.str_
and v0['monot'] == (True,)
and np.all(v0['data'] > 0.)
and np.allclose(
np.diff(np.log(v0['data'])),
np.log(v0['data'][1]) - np.log(v0['data'][0]),
equal_nan=False,
)
)
return c0
Expand Down Expand Up @@ -312,7 +319,8 @@ def _check_keyXYZ(
if uniform:
lok = [
k0 for k0 in lok
if _check_uniform(k0=k0, ddata=coll._ddata)
if _check_uniform_lin(k0=k0, ddata=coll._ddata)
or _check_uniform_log(k0=k0, ddata=coll._ddata)
]

keyX = _generic_check._check_var(
Expand All @@ -323,17 +331,7 @@ def _check_keyXYZ(
refX = coll._ddata[keyX]['ref'][0]

# islog
c0 = (
np.all(coll._ddata[keyX]['data'] > 0.)
and np.allclose(
np.diff(np.log(coll._ddata[keyX]['data'])),
np.log(coll._ddata[keyX]['data'][1])
- np.log(coll._ddata[keyX]['data'][0]),
equal_nan=False,
)
)
if c0:
islog = True
islog = _check_uniform_log(k0=keyX, ddata=coll._ddata)

elif keyX in refs:
keyX, refX = 'index', keyX
Expand Down Expand Up @@ -851,8 +849,8 @@ def plot_as_array_2d(
# prepare slicing

# here slice X => slice in dim Y and vice-versa
sliX = _class2_interactivity._get_slice(laxis=[1-axisX], ndim=2)
sliY = _class2_interactivity._get_slice(laxis=[1-axisY], ndim=2)
sliX = _class1_compute._get_slice(laxis=[1-axisX], ndim=2)
sliY = _class1_compute._get_slice(laxis=[1-axisY], ndim=2)

# ----------------------
# labels and data
Expand Down Expand Up @@ -1267,10 +1265,10 @@ def plot_as_array_3d(
# prepare slicing

# here slice X => slice in dim Y and vice-versa
sliX = _class2_interactivity._get_slice(laxis=[axY, axZ], ndim=3)
sliY = _class2_interactivity._get_slice(laxis=[axX, axZ], ndim=3)
sliZ = _class2_interactivity._get_slice(laxis=[axX, axY], ndim=3)
sliZ2 = _class2_interactivity._get_slice(laxis=[axZ], ndim=3)
sliX = _class1_compute._get_slice(laxis=[axY, axZ], ndim=3)
sliY = _class1_compute._get_slice(laxis=[axX, axZ], ndim=3)
sliZ = _class1_compute._get_slice(laxis=[axX, axY], ndim=3)
sliZ2 = _class1_compute._get_slice(laxis=[axZ], ndim=3)

if axX < axY:
datatype = 'data.T'
Expand Down

0 comments on commit 13b60a8

Please sign in to comment.