Loading openflexure_microscope/utilities.py +12 −1 Original line number Diff line number Diff line import copy import operator from functools import reduce def axes_to_array(coordinate_dictionary, axis_keys=['x', 'y', 'z'], base_array=None): """Takes key-value pairs of a JSON value, and maps onto an array""" Loading @@ -16,3 +18,12 @@ def axes_to_array(coordinate_dictionary, axis_keys=['x', 'y', 'z'], base_array=N base_array[axis] = coordinate_dictionary[key] return base_array def filter_dict(dictionary: dict, keys: list): # Get value by recursively applying getitem val = reduce(operator.getitem, keys, dictionary) # Create new dictionary by running reduce on key, val pairs out = reduce(lambda x, y: {y: x}, reversed(keys), val) return out No newline at end of file Loading
openflexure_microscope/utilities.py +12 −1 Original line number Diff line number Diff line import copy import operator from functools import reduce def axes_to_array(coordinate_dictionary, axis_keys=['x', 'y', 'z'], base_array=None): """Takes key-value pairs of a JSON value, and maps onto an array""" Loading @@ -16,3 +18,12 @@ def axes_to_array(coordinate_dictionary, axis_keys=['x', 'y', 'z'], base_array=N base_array[axis] = coordinate_dictionary[key] return base_array def filter_dict(dictionary: dict, keys: list): # Get value by recursively applying getitem val = reduce(operator.getitem, keys, dictionary) # Create new dictionary by running reduce on key, val pairs out = reduce(lambda x, y: {y: x}, reversed(keys), val) return out No newline at end of file