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

guess_signed #1128

Merged
merged 19 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
21 changes: 20 additions & 1 deletion WrightTools/kit/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"valid_index",
"mask_reduce",
"enforce_mask_shape",
"signed",
]


Expand Down Expand Up @@ -202,7 +203,7 @@ def orthogonal(*args) -> bool:
if hasattr(arg, "shape"):
args[i] = arg.shape
for s in zip(*args):
if np.prod(s) != max(s):
if np.product(s) != max(s):
ddkohler marked this conversation as resolved.
Show resolved Hide resolved
return False
return True

Expand Down Expand Up @@ -433,3 +434,21 @@ def enforce_mask_shape(mask, shape):
"""
red = tuple([i for i in range(len(shape)) if shape[i] == 1])
return mask.max(axis=red, keepdims=True)


def signed(d0):
"""Tells bluesky whether to sign data. We have a 7.5 % tolerance right now.%"""
ddkohler marked this conversation as resolved.
Show resolved Hide resolved

maxd0 = np.max(d0)
mind0 = np.min(d0)

tolerance = (maxd0 - np.absolute(mind0)) / (maxd0 + np.absolute(mind0))

if tolerance < 7.5 * 10 ** (-2):
if min(d0) > 0:
return False
else:
return True

else:
return False
ddkohler marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions tests/kit/signed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Test signed data."""


# --- import -------------------------------------------------------------------------------------


import numpy as np

import WrightTools as wt


# --- test ---------------------------------------------------------------------------------------


def test_5():
arr = np.array([-1, 0, 1])
assert wt.kit.signed(arr) == True
ddkohler marked this conversation as resolved.
Show resolved Hide resolved


def test_5_multiple():
arr = np.array([1, 3, 4, 11, 12])
assert wt.kit.signed(arr) == False
ddkohler marked this conversation as resolved.
Show resolved Hide resolved