Skip to content
Snippets Groups Projects

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

2 unresolved threads
2 files
+ 56
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 28
0
@@ -389,3 +389,31 @@ def full_sc(shape, fill_value, *args, **kwargs):
else:
shape = (3, *shape)
return np.full(shape, fill_value, *args, **kwargs)
def dict2mosa(dictionary):
"""Return a new MOSA array with values given in `dictionary`.
Args:
dictionary: dictionary with MOSA indices as keys
"""
dict_str = {str(key): dictionary[key] for key in dictionary}
try:
values = [dict_str[mosa] for mosa in MOSAS]
except KeyError as error:
raise ValueError(f"incomplete dictionary '{dictionary}', must contain '{MOSAS}' as keys") from error
return np.stack(values, axis=0)
def dict2sc(dictionary):
"""Return a new SC array with values given in `dictionary`.
Args:
dictionary: dictionary with SC indices as keys
"""
dict_str = {str(key): dictionary[key] for key in dictionary}
try:
values = [dict_str[sc] for sc in SC]
except KeyError as error:
raise ValueError(f"incomplete dictionary '{dictionary}', must contain '{SC}' as keys") from error
return np.stack(values, axis=0)
Loading