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

Feature/post processing #21

Merged
merged 30 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1ecc1ac
Added pycharm folders to gitignore
Sep 6, 2021
cd63f7c
Completed install_requires list with missing entries:
Sep 6, 2021
d7aaf27
Extracted main.py from pymepix.py
Sep 6, 2021
91663d3
Multi processing logging issue resolved:
Sep 6, 2021
5c731c6
Rename pymepix class to solve name conflict with pymepix package.
Sep 6, 2021
f2bd824
#15 Implementation of post processing
Sep 6, 2021
19e4970
Fix constructor call for pipeline objects
Sep 6, 2021
dbba6f7
Fix and enhance pipeline packet processor implementation
Sep 7, 2021
b808a2d
Fix pipeline centroid calculator implementation
Sep 7, 2021
7ec765e
#15 Fix centroiding parameters
Sep 8, 2021
de2c427
#14 Fix event_window and handle_events konfiguration. See also Change…
Sep 9, 2021
be69b8f
#14 Fix initialization of event_window, initialize with smaller min_s…
Sep 9, 2021
72ef531
Implement changes to show a progressbar in pymepix_viewer
Sep 13, 2021
5316461
Extract wrapper class to support multiprocesing in pipeline and post …
Sep 13, 2021
5c2215f
Use wrapper for the settings to enable parameters to work with online…
Sep 13, 2021
166dce5
Activating TOA processing again
Sep 14, 2021
ac253d6
#15 Fix save timestamps
Sep 16, 2021
42d6463
#18 Progress bar for CLI post processing implemented
Sep 20, 2021
daeabec
Fix start time not being calculated correctly
Sep 21, 2021
646955e
#19 Fix post-processing test and use git lfs for storage of example f…
Sep 27, 2021
1f447a8
removed .raw and .hdf5 files from gitignore to use git lfs for this t…
Sep 27, 2021
ff043f6
#19 include large datasets raw files and the expected results generat…
Sep 27, 2021
2da5c22
#17 Update documentation for the pymepix CLI
Sep 27, 2021
080cf63
Add tqdm as a dependency
Sep 27, 2021
965586d
Adjust dependencies in requirements file
Sep 27, 2021
e2b47d0
Fix import in test file
Sep 27, 2021
e2311dc
Typo
BenMoon Sep 29, 2021
52e1aa4
Fix typo
BenMoon Sep 29, 2021
8818bce
Include changes suggested in pull-request
Sep 30, 2021
526a7f1
Merge branch 'feature/post_processing' of https://github.com/CFEL-CMI…
Sep 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.raw filter=lfs diff=lfs merge=lfs -text
*.hdf5 filter=lfs diff=lfs merge=lfs -text
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
*.raw
*.hdf5
*.dat
*.egg
*.egg-info/
Expand All @@ -11,3 +9,6 @@
.DS_Store
.vscode/settings.json
build/
venv
.idea

31 changes: 13 additions & 18 deletions doc/users/pymepixacq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,27 @@ PymepixAcq - Command line
===========================


Included with pymepix is a command line code using the pymepix library to acquire from timepix. It is run using::

pymepix-acq --time 10 --output my_file
Included with pymepix is a command line code using the pymepix library to acquire from timepix. The command line interface includes two different commands:
- "connect": to connect to a running timepix camera and record data
- "post-process": to post-process recorded raw data files into easier usable hdf5 files containing raw and centroided data

Doing::

pymepix-acq --help


Outputs the help::

usage: pymepix-acq [-h] [-i IP] [-p PORT] [-s SPX] [-v BIAS] -t TIME -o OUTPUT
[-d DECODE] [-T TOF]
usage: pymepix-acq [-h] {connect,post-process} ...

Timepix acquisition script

positional arguments:
{connect,post-process}
connect Connect to TimePix camera and acquire data.
post-process Perform post-processing for an acquired raw data file.

optional arguments:
-h, --help show this help message and exit
-i IP, --ip IP IP address of Timepix
-p PORT, --port PORT TCP port to use for the connection
-s SPX, --spx SPX Sophy config file to load
-v BIAS, --bias BIAS Bias voltage in Volts
-t TIME, --time TIME Acquisition time in seconds
-o OUTPUT, --output OUTPUT output filename prefix
-d DECODE, --decode DECODE Store decoded values instead
-T TOF, --tof TOF Compute TOF if decode is enabled


TODO: MORE DOCS
-h, --help show this help message and exit


You can access the documentation for both commands by executing "pymepix-acq connect -h" or "pymepix-acq post-process -h" respectively.
3 changes: 2 additions & 1 deletion pymepix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
# see <https://www.gnu.org/licenses/>.

from pymepix.processing import MessageType
from pymepix.pymepix import PollBufferEmpty, Pymepix
from pymepix.pymepix_connection import PollBufferEmpty, PymepixConnection
from pymepix.timepixdef import *
from pymepix.post_processing import run_post_processing
118 changes: 20 additions & 98 deletions pymepix/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
# see <https://www.gnu.org/licenses/>.


from abc import abstractmethod
import logging
import threading
from multiprocessing import Queue
import multiprocessing as mp

__all__ = ["Logger", "ProcessLogger"]


class PymepixLogger(object):
"""Base class for logging in pymepix

Expand All @@ -41,91 +40,19 @@ class PymepixLogger(object):

"""

_proc_log_queue = Queue()

_init = False

@classmethod
def getLogQueue(cls):
"""Provides logging queue for multiprocessing logging

Returns
--------
:obj:`multiprocessing.Queue`
Queue where logs should go

"""
return cls._proc_log_queue

@classmethod
def _logging_thread(cls):
"""This thread collects logs from Processes and writes them to stream"""

thread_log = PymepixLogger.getLogger("log_thread")
log_queue = cls.getLogQueue()

thread_log.info("Starting Multiprocess logging")
while True:
name, log_level, message, args, kwargs = log_queue.get()
_log = logging.getLogger(name)
_log.log(log_level, message, *args, **kwargs)

@classmethod
def getRootLogger(cls):
return cls._root_logger

@classmethod
def getLogger(cls, name):
return logging.getLogger("pymepix.{}".format(name))

@classmethod
def reInit(cls):
if cls._init is False:
cls._root_logger = logging.getLogger("pymepix")

cls._root_logger.info("Reinitializing PymepixLogger")
cls._log_thread = threading.Thread(target=cls._logging_thread)
cls._log_thread.daemon = True
cls._log_thread.start()
cls._init = True


def __init__(self, name):
self._logger = self.getLogger(name)
self._log_name = "pymepix.{}".format(name)
PymepixLogger.reInit()

@property
def logName(self):
return self._log_name

def info(self, message, *args, **kwargs):
pass

def warning(self, message, *args, **kwargs):
pass

def debug(self, message, *args, **kwargs):
pass

def error(self, message, *args, **kwargs):
pass

def critical(self, message, *args, **kwargs):
pass


class Logger(PymepixLogger):
"""Standard logging using logger library

Parameters
-----------
name : str
Name used for logging

"""

def __init__(self, name):
PymepixLogger.__init__(self, name)
self._logger = logging.getLogger(self.logName)
@abstractmethod
def getLogger(cls, name):
pass

def info(self, message, *args, **kwargs):
""" See :class:`logging.Logger` """
Expand All @@ -148,8 +75,8 @@ def critical(self, message, *args, **kwargs):
self._logger.critical(message, *args, **kwargs)


class ProcessLogger(PymepixLogger):
"""Sends logs to queue to be processed by logging thread
class Logger(PymepixLogger):
"""Standard logging using logger library

Parameters
-----------
Expand All @@ -161,27 +88,22 @@ class ProcessLogger(PymepixLogger):
def __init__(self, name):
PymepixLogger.__init__(self, name)
self._logger = logging.getLogger(self.logName)
self._log_queue = PymepixLogger.getLogQueue()

def info(self, message, *args, **kwargs):
""" See :class:`logging.Logger` """
self._log_queue.put((self._log_name, logging.INFO, message, args, kwargs))
def getLogger(cls, name):
return logging.getLogger("pymepix.{}".format(name))

def warning(self, message, *args, **kwargs):
""" See :class:`logging.Logger` """
self._log_queue.put((self._log_name, logging.WARNING, message, args, kwargs))

def debug(self, message, *args, **kwargs):
""" See :class:`logging.Logger` """
self._log_queue.put((self._log_name, logging.DEBUG, message, args, kwargs))
class ProcessLogger(PymepixLogger):
"""Sends logs to queue to be processed by logging thread

def error(self, message, *args, **kwargs):
""" See :class:`logging.Logger` """
self._log_queue.put((self._log_name, logging.ERROR, message, args, kwargs))
Parameters
-----------
name : str
Name used for logging

def critical(self, message, *args, **kwargs):
""" See :class:`logging.Logger` """
self._log_queue.put((self._log_name, logging.CRITICAL, message, args, kwargs))
"""
def getLogger(self, name):
return mp.get_logger()


def main():
Expand Down
Loading