Skip to content
Snippets Groups Projects

Draft: Resolve "Use Numpy arrays instead of `ForEachObject` instances"

2 files
+ 47
7
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 17
7
@@ -44,14 +44,19 @@ Note that this uses complex slicing, and therefore copy the data."""
def dict2sc(x, axis=0):
"""Return a new array whose `axis` is for spacecraft with content of `x`.
The keys of `x` should be [1, 2, 3] (or convertible to those), and values array-like.
If `x` is a dictionary, its keys should be [1, 2, 3] (or convertible to those), and values array-like.
Note that all values of `x` should have the same shape, or can be automatically broadcasted.
If they have shape (N), the resulting array will be of shape (3, N) by default (first axis).
If `x` is not a dictionary but array-like (or scalar) of shape (N), we extend its axis so that it
can be automatically broadcasted, i.e. the resulting array will be of shape (1, N) by default (first axis).
Args:
x: input dictionary
x: input
"""
if not isinstance(x, dict):
return np.expand_dims(x, axis)
keys = [1, 2, 3]
x_int = {int(key): x[key] for key in x}
if set(x_int.keys()) != set(keys):
@@ -63,14 +68,19 @@ def dict2sc(x, axis=0):
def dict2mosa(x, axis=0):
"""Return a new array whose `axis` is for spacecraft and `axis + 1` for MOSAs, with content of `x`.
The keys of `x` should be [12, 23, 31, 13, 32, 21] (or convertible to those), and values array-like.
If `x` is a dictionary, its keys should be [12, 23, 31, 13, 32, 21] (or convertible to those),
and values array-like. Note that all values of `x` should have the same shape, or can be automatically
broadcasted. If they have shape (N), the resulting array will be of shape (3, 2, N) by default (first axis).
Note that all values of `x` should have the same shape, or can be automatically broadcasted.
If they have shape (N), the resulting array will be of shape (3, 2, N) by default (first axis).
If `x` is not a dictionary but array-like (or scalar) of shape (N), we extend its axis so that it
can be automatically broadcasted, i.e. the resulting array will be of shape (1, 2, N) by default (first axis).
Args:
x: input dictionary
x: input
"""
if not isinstance(x, dict):
return np.expand_dims(x, (axis, axis + 1))
mosas = [12, 23, 31, 13, 32, 21]
x_int = {int(key): x[key] for key in x}
if set(x_int.keys()) != set(mosas):
Loading