Skip to content

Commit

Permalink
[#6] plot_as_profile1d() almost operational
Browse files Browse the repository at this point in the history
  • Loading branch information
Didou09 committed Apr 25, 2022
1 parent 2c6e1fd commit f1c09e1
Showing 1 changed file with 49 additions and 19 deletions.
68 changes: 49 additions & 19 deletions datastock/_plot_as_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,46 @@ def plot_as_array(
# #############################################################################


def _check_keyXYZ(coll=None, refs=None, keyX=None, ndim=None, dimlim=None):
""" """
def _check_uniform(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,
)
)
)
)
return c0


def _check_keyXYZ(
coll=None,
refs=None,
keyX=None,
ndim=None,
dimlim=None,
uniform=None,
):
""" Ensure keyX refers to a monotonic and (optionally) uniform data
"""

if uniform is None:
uniform = True

refX = None
islog = False
Expand All @@ -266,30 +304,22 @@ def _check_keyXYZ(coll=None, refs=None, keyX=None, ndim=None, dimlim=None):
and v0['ref'][0] in refs
and (
v0['data'].dtype.type == np.str_
or (
v0['monot'] == (True,)
and np.allclose(
np.diff(v0['data']),
v0['data'][1] - v0['data'][0],
equal_nan=False,
)
)
or (
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,
)
)
or v0['monot'] == (True,)
)
]

# optional uniformity
if uniform:
lok = [
k0 for k0 in lok
if _check_uniform(k0=k0, ddata=coll._ddata)
]

keyX = _generic_check._check_var(
keyX, 'keyX',
allowed=lok,
)

refX = coll._ddata[keyX]['ref'][0]

# islog
Expand Down

0 comments on commit f1c09e1

Please sign in to comment.