Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
refactoring, new functions for restapi
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Samartsev committed Jan 23, 2024
1 parent 0672060 commit 1d7bdb6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pymepix/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ def get(self):
class TPXpropertyHandler(RequestHandler):
def get(self):

global pymepix_connection_obj
global timepix_obj

arguments = self.get_arguments('param_name')

tkns = re.findall(r"[\w']+|\[\d+\]", arguments[0])

ref = pymepix_connection_obj
ref = timepix_obj
ref = get_path(ref, tkns)

if is_jsonable(ref):
Expand All @@ -139,15 +139,15 @@ def get(self):


def post(self):
global pymepix_connection_obj
global timepix_obj

try:
data = json.loads(self.request.body)
except:
raise HTTPError(400, u"Bad request")

for key, val in data.items():
ref = pymepix_connection_obj
ref = timepix_obj
tkns = re.findall(r"[\w']+|\[\d+\]", key)
ref = get_path(ref, tkns[:-1])
if tkns[-1][0] != '[':
Expand All @@ -159,7 +159,7 @@ def post(self):

class TPXmethodHandler(RequestHandler):
def post(self):
global pymepix_connection_obj
global timepix_obj
try:
data = json.loads(self.request.body)
except:
Expand All @@ -170,7 +170,7 @@ def post(self):

tkns = re.findall(r"[\w']+|\[\d+\]", func_name)

ref = pymepix_connection_obj
ref = timepix_obj
ref = get_path(ref, tkns)

data.pop('func_name')
Expand Down Expand Up @@ -208,28 +208,28 @@ def make_app():


def start_api(args):
global pymepix_connection_obj
global timepix_obj

pymepix_connection_obj = PymepixConnection(spidr_address=(args.ip, args.port),\
timepix_obj = PymepixConnection(spidr_address=(args.ip, args.port),\
camera_generation=args.cam_gen,
pipeline_class=CentroidPipeline)


if len(pymepix_connection_obj) == 0:
if len(timepix_obj) == 0:
logging.error(
"-------ERROR: SPIDR FOUND BUT NO VALID TIMEPIX DEVICE DETECTED ---------- "
)
quit()
if args.spx:
logging.info(f"Opening Sophy file {args.spx}")
pymepix_connection_obj[0].loadConfig(args.spx)
timepix_obj[0].loadConfig(args.spx)

# Switch to TOF mode if set
if args.decode and args.tof:
pymepix_connection_obj[0].acquisition.enableEvents = True
timepix_obj[0].acquisition.enableEvents = True

# Set the bias voltage
pymepix_connection_obj.biasVoltage = args.bias
timepix_obj.biasVoltage = args.bias

app = make_app()
app.listen(args.api_port)
Expand Down
2 changes: 2 additions & 0 deletions pymepix/pymepix_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def __init__(self,

self._running = False

self.cfg = cfg

@property
def biasVoltage(self):
"""Bias voltage in volts"""
Expand Down
10 changes: 10 additions & 0 deletions pymepix/timepixdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# from .config.sophyconfig import SophyConfig
from .core.log import Logger
from .timepixdef import *
import numpy as np



Expand Down Expand Up @@ -98,6 +99,15 @@ def __init__(self, spidr_device, data_queue, pipeline_class=PixelPipeline):
def config(self):
return self.__config

@property
def maskPixelsJsonable(self):
return [list(i) for i in self.__config.maskPixels.astype(str)]

@maskPixelsJsonable.setter
def maskPixelsJsonable(self, value):
self.__config.maskPixels = np.asarray(value, dtype=np.uint8)


def setupAcquisition(self, acquisition_klass, *args, **kwargs):
self.info("Setting up acquisition class")
self._acquisition_pipeline = acquisition_klass(
Expand Down

0 comments on commit 1d7bdb6

Please sign in to comment.