Moved axes_to_array into general utilities
This commit is contained in:
parent
504c9b48a1
commit
55c3014d26
3 changed files with 20 additions and 19 deletions
|
|
@ -3,3 +3,4 @@ __version__ = "0.1.0"
|
||||||
|
|
||||||
from .microscope import Microscope
|
from .microscope import Microscope
|
||||||
from . import config
|
from . import config
|
||||||
|
from . import utilities
|
||||||
|
|
@ -43,24 +43,6 @@ class JsonPayload:
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
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"""
|
|
||||||
# If no base array is given
|
|
||||||
if not base_array:
|
|
||||||
# Create an array of zeros
|
|
||||||
base_array = [0]*len(axis_keys)
|
|
||||||
else:
|
|
||||||
# Create a copy of the passed base_array
|
|
||||||
base_array = copy.copy(base_array)
|
|
||||||
|
|
||||||
# Do the mapping
|
|
||||||
for axis, key in enumerate(axis_keys):
|
|
||||||
if key in coordinate_dictionary:
|
|
||||||
base_array[axis] = coordinate_dictionary[key]
|
|
||||||
|
|
||||||
return base_array
|
|
||||||
|
|
||||||
|
|
||||||
def gen(camera):
|
def gen(camera):
|
||||||
"""Video streaming generator function."""
|
"""Video streaming generator function."""
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
18
openflexure_microscope/utilities.py
Normal file
18
openflexure_microscope/utilities.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import copy
|
||||||
|
|
||||||
|
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"""
|
||||||
|
# If no base array is given
|
||||||
|
if not base_array:
|
||||||
|
# Create an array of zeros
|
||||||
|
base_array = [0]*len(axis_keys)
|
||||||
|
else:
|
||||||
|
# Create a copy of the passed base_array
|
||||||
|
base_array = copy.copy(base_array)
|
||||||
|
|
||||||
|
# Do the mapping
|
||||||
|
for axis, key in enumerate(axis_keys):
|
||||||
|
if key in coordinate_dictionary:
|
||||||
|
base_array[axis] = coordinate_dictionary[key]
|
||||||
|
|
||||||
|
return base_array
|
||||||
Loading…
Add table
Add a link
Reference in a new issue