Skip to content

Commit

Permalink
* ImageShift
Browse files Browse the repository at this point in the history
* Fixed some Python 2.X imports
  • Loading branch information
niermann committed Jan 20, 2017
1 parent 0e16deb commit 54b8354
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
11 changes: 10 additions & 1 deletion temscript/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
except ImportError:
# Python 2.X
from httplib import HTTPConnection
from urlparse import urlencode
from urllib import urlencode
from cStringIO import StringIO as BytesIO


Expand Down Expand Up @@ -123,6 +123,15 @@ def set_detector_param(self, name, param):
self._request("PUT", "/v1/detector_param/" + name, body=content, accepted_response=[200, 204],
headers={"Content-Type": "application/json"})

def get_image_shift(self):
response, body = self._request("GET", "/v1/image_shift")
return body

def set_image_shift(self, pos):
content = json.dumps(tuple(pos)).encode("utf-8")
self._request("PUT", "/v1/image_shift", body=content, accepted_response=[200, 204],
headers={"Content-Type": "application/json"})

allowed_types = {"INT8", "INT16", "INT32", "INT64", "UINT8", "UINT16", "UINT32", "UINT64", "FLOAT32", "FLOAT64"}
allowed_endianness = {"LITTLE", "BIG"}

Expand Down
8 changes: 7 additions & 1 deletion temscript/enums.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from enum import IntEnum
# Get imports from library
try:
# Python 3.X
from enum import IntEnum
except ImportError:
# Python 2.X
from enum34 import IntEnum

import temscript.constants as const

Expand Down
4 changes: 3 additions & 1 deletion temscript/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Set temscript version string
version = "1.0.5"

# Import COM bridging code
try:
# Where the _temscript module is available and the COM interface works (i.e. the microscope's computer)
# use the real thing
from _temscript import *

except ImportError:
# Have atleast some stubs to develop software also on off-line computers...
def GetInstrument():
"""Returns Instrument instance."""
raise RuntimeError("temscript microscope API is not accessible")
Expand Down
17 changes: 16 additions & 1 deletion temscript/microscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from urllib.parse import quote
except ImportError:
# Python 2.X
from urlparse import quote
from urllib import quote


def _parse_enum(type, item):
Expand Down Expand Up @@ -328,3 +328,18 @@ def acquire(self, *args):
for img in images:
result[quote(img.Name)] = img.Array
return result

def get_image_shift(self):
"""
Return image shift as (x,y) tuple.
The units this is returned in are meters. The accuracy of ths value depends on the accuracy of the
calibration within the microscope and thus is better not to be trusted blindly.
"""
return self._tem_projection.ImageShift

def set_image_shift(self, pos):
"""
Set image shift to position `pos`, which should be an (x, y) tuple, as returned for instance by :meth:`get_image_shift`.
"""
self._tem_projection.ImageShift = pos
4 changes: 4 additions & 0 deletions temscript/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def do_GET_V1(self, endpoint, query):
response = self.server.microscope.get_stage_limits()
elif endpoint == "detectors":
response = self.server.microscope.get_detectors()
elif endpoint == "image_shift":
response = self.server.microscope.get_image_shift()
elif endpoint.startswith("detector_param/"):
try:
name = endpoint[15:]
Expand Down Expand Up @@ -151,6 +153,8 @@ def do_PUT_V1(self, endpoint, query):
method = decoded_content.get("method", "GO")
pos = dict((k, decoded_content[k]) for k in decoded_content.keys() if k in Microscope.STAGE_AXES)
self.server.microscope.set_stage_position(pos, method=method)
elif endpoint == "image_shift":
self.server.microscope.set_image_shift(decoded_content)
elif endpoint.startswith("detector_param/"):
try:
name = endpoint[15:]
Expand Down

0 comments on commit 54b8354

Please sign in to comment.