From a47223e7b64ec61aa980af37a8e487f21534ce39 Mon Sep 17 00:00:00 2001 From: Rafael Gort <rafael.gort@xfel.eu> Date: Mon, 27 Apr 2020 16:17:50 +0200 Subject: [PATCH] test packaging --- README.rst | 14 ++ __init__.py | 10 -- setup.py | 23 +++ toolbox/__init__.py | 10 ++ DSSC.py => toolbox/detectors/DSSC.py | 0 .../detectors/DSSC1module.py | 0 FastCCD.py => toolbox/detectors/FastCCD.py | 0 toolbox/detectors/__init__.py | 11 ++ Load.py => toolbox/load.py | 0 toolbox/misc/__init__.py | 31 ++++ .../misc/azimuthal_integrator.py | 2 +- .../misc/bunch_pattern.py | 0 .../misc/bunch_pattern_external.py | 0 Laser_utils.py => toolbox/misc/laser_utils.py | 0 toolbox/plot/plot_dssc.py | 0 XAS.py => toolbox/routines/XAS.py | 0 .../routines/knife_edge.py | 0 xgm.py => toolbox/routines/xgm.py | 0 .../test_package_demo-checkpoint.ipynb | 151 ++++++++++++++++++ toolbox/test/__init__.py | 1 + toolbox/test/test_top_level.py | 79 +++++++++ 21 files changed, 321 insertions(+), 11 deletions(-) create mode 100644 README.rst delete mode 100644 __init__.py create mode 100644 setup.py create mode 100644 toolbox/__init__.py rename DSSC.py => toolbox/detectors/DSSC.py (100%) rename DSSC1module.py => toolbox/detectors/DSSC1module.py (100%) rename FastCCD.py => toolbox/detectors/FastCCD.py (100%) create mode 100644 toolbox/detectors/__init__.py rename Load.py => toolbox/load.py (100%) create mode 100644 toolbox/misc/__init__.py rename azimuthal_integrator.py => toolbox/misc/azimuthal_integrator.py (98%) rename bunch_pattern.py => toolbox/misc/bunch_pattern.py (100%) rename bunch_pattern_external.py => toolbox/misc/bunch_pattern_external.py (100%) rename Laser_utils.py => toolbox/misc/laser_utils.py (100%) create mode 100644 toolbox/plot/plot_dssc.py rename XAS.py => toolbox/routines/XAS.py (100%) rename knife_edge.py => toolbox/routines/knife_edge.py (100%) rename xgm.py => toolbox/routines/xgm.py (100%) create mode 100644 toolbox/test/.ipynb_checkpoints/test_package_demo-checkpoint.ipynb create mode 100644 toolbox/test/__init__.py create mode 100644 toolbox/test/test_top_level.py diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..1db37f5 --- /dev/null +++ b/README.rst @@ -0,0 +1,14 @@ +########### +SCS ToolBox +########### + +Kernel +###### + +The SCS ToolBox is design to work in the exfel_anaconda3 environement. This can +be selected on the online cluster by: + +`module load exfel exfel_anaconda3` + +before launching the jupyter-notebook or on max-jhub by selecting the 'xfel' +kernel instead of the 'Python 3' anaconda environement maintained by DESY. \ No newline at end of file diff --git a/__init__.py b/__init__.py deleted file mode 100644 index ee34d75..0000000 --- a/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -from ToolBox.Load import * -from ToolBox.xgm import * -from ToolBox.XAS import * -from ToolBox.knife_edge import * -from ToolBox.Laser_utils import * -from ToolBox.DSSC import DSSC -from ToolBox.azimuthal_integrator import * -from ToolBox.DSSC1module import * -from ToolBox.bunch_pattern import * -from ToolBox.FastCCD import * diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..34a3af7 --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +from setuptools import setup, find_packages + +with open('README.rst') as f: + readme = f.read() + +# _get_version() # get current version from release tag +# ...... + +setup(name='toolbox_scs', + # to be replaced by _get_version() + version='1.0.0-a1', + description="A collection of code, often used at the SCS beamline", + long_description=readme, + author='Loic Le Guyader, Laurent Mercadier, ....', + url="https://git.xfel.eu/gitlab/SCS/ToolBox.git", + keywords='XAS, xgm, DSSC, FCCD, PPL', + packages=['toolbox'], + install_requires=[ + 'xarray', 'numpy', 'matplotlib', + 'pandas', 'bisect', 'scipy', 'h5py', + 'extra_data', 'euxfel_bunch_pattern', + ], + ) diff --git a/toolbox/__init__.py b/toolbox/__init__.py new file mode 100644 index 0000000..b27904a --- /dev/null +++ b/toolbox/__init__.py @@ -0,0 +1,10 @@ +from .load import mnemonics, load, concatenateRuns + +__all__ = ( + # Top level functions + "load", + "concatenateRuns", + # Classes + # Variables + "mnemonics", +) diff --git a/DSSC.py b/toolbox/detectors/DSSC.py similarity index 100% rename from DSSC.py rename to toolbox/detectors/DSSC.py diff --git a/DSSC1module.py b/toolbox/detectors/DSSC1module.py similarity index 100% rename from DSSC1module.py rename to toolbox/detectors/DSSC1module.py diff --git a/FastCCD.py b/toolbox/detectors/FastCCD.py similarity index 100% rename from FastCCD.py rename to toolbox/detectors/FastCCD.py diff --git a/toolbox/detectors/__init__.py b/toolbox/detectors/__init__.py new file mode 100644 index 0000000..e0f177e --- /dev/null +++ b/toolbox/detectors/__init__.py @@ -0,0 +1,11 @@ +from .detectors import ( + DSSC, process_one_module, + ) + +__all__ = ( + # Functions + "process_one_module", + # Classes + "DSSC", + # Variables +) diff --git a/Load.py b/toolbox/load.py similarity index 100% rename from Load.py rename to toolbox/load.py diff --git a/toolbox/misc/__init__.py b/toolbox/misc/__init__.py new file mode 100644 index 0000000..7ed9d39 --- /dev/null +++ b/toolbox/misc/__init__.py @@ -0,0 +1,31 @@ +from .bunch_pattern import ( + extractBunchPattern, pulsePatternInfo, repRate, sortBAMdata, + ) +from .bunch_pattern_external import ( + is_sase_3, is_sase_1, is_ppl, get_index_ppl, get_index_sase1, + get_index_sase3, + ) +from .laser_utils import ( + positionToDelay, degToRelPower, + ) +from . azimuthal_integrator import ( + AzimutalIntegrator, + +__all__ = ( + # Functions + "extractBunchPattern", + "pulsePatternInfo", + "repRate", + "sortBAMdata", + "is_sase_3", + "is_sase_1", + "is_ppl", + "get_index_ppl", + "get_index_sase1", + "get_index_sase3", + "positionToDelay", + "degToRelPower", + # Classes + "AzimutalIntegrator", + # Variables +) diff --git a/azimuthal_integrator.py b/toolbox/misc/azimuthal_integrator.py similarity index 98% rename from azimuthal_integrator.py rename to toolbox/misc/azimuthal_integrator.py index b84df6c..e682281 100644 --- a/azimuthal_integrator.py +++ b/toolbox/misc/azimuthal_integrator.py @@ -1,6 +1,6 @@ import numpy as np -class azimuthal_integrator(object): +class AzimutalIntegrator(object): def __init__(self, imageshape, center, polar_range, dr=2, aspect=204/236): ''' Create a reusable integrator for repeated azimuthal integration of similar diff --git a/bunch_pattern.py b/toolbox/misc/bunch_pattern.py similarity index 100% rename from bunch_pattern.py rename to toolbox/misc/bunch_pattern.py diff --git a/bunch_pattern_external.py b/toolbox/misc/bunch_pattern_external.py similarity index 100% rename from bunch_pattern_external.py rename to toolbox/misc/bunch_pattern_external.py diff --git a/Laser_utils.py b/toolbox/misc/laser_utils.py similarity index 100% rename from Laser_utils.py rename to toolbox/misc/laser_utils.py diff --git a/toolbox/plot/plot_dssc.py b/toolbox/plot/plot_dssc.py new file mode 100644 index 0000000..e69de29 diff --git a/XAS.py b/toolbox/routines/XAS.py similarity index 100% rename from XAS.py rename to toolbox/routines/XAS.py diff --git a/knife_edge.py b/toolbox/routines/knife_edge.py similarity index 100% rename from knife_edge.py rename to toolbox/routines/knife_edge.py diff --git a/xgm.py b/toolbox/routines/xgm.py similarity index 100% rename from xgm.py rename to toolbox/routines/xgm.py diff --git a/toolbox/test/.ipynb_checkpoints/test_package_demo-checkpoint.ipynb b/toolbox/test/.ipynb_checkpoints/test_package_demo-checkpoint.ipynb new file mode 100644 index 0000000..da2d5f2 --- /dev/null +++ b/toolbox/test/.ipynb_checkpoints/test_package_demo-checkpoint.ipynb @@ -0,0 +1,151 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Boltzmann Modules\n", + "\n", + "### This notebook is part of the repository for demonstration purposes." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The code below should be run from the command line in the directory: scs_simulations/test.\n", + "\n", + "The test suites directly import the scs_simulation package. The idea is to notice problems related to packaging immediately (changing folder structure, breaking relative dependencies between the subpackages ....).\n", + "\n", + "During development, use the -e flag when installing the module via pip. This makes changes effective immediately, without having to reinstall the package." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "usage: test_boltzmann_simulation.py [-h] [--list-suites]\n", + " [--test-suites S [S ...]]\n", + "\n", + "optional arguments:\n", + " -h, --help show this help message and exit\n", + " --list-suites list possible test suites\n", + " --test-suites S [S ...]\n", + " a list of valid test suites\n" + ] + } + ], + "source": [ + "%run test_boltzmann_simulation.py --help" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Possible test suites:\n", + "-------------------------\n", + "boltzmann-imports\n", + "boltzmann-manipulations\n", + "-------------------------\n", + "\n" + ] + } + ], + "source": [ + "%run test_boltzmann_simulation.py --list-suites" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "test_adddos (__main__.BoltzmannData) ... DEBUG:scs_simulations.boltzmann_data.data_manipulation:Try to append parabolic bs at high-energy DOS.\n", + "DEBUG:scs_simulations.boltzmann_data.data_manipulation:dataframe has been extended\n", + "ok\n", + "test_electronsholes (__main__.BoltzmannData) ... DEBUG:scs_simulations.boltzmann_data.data_manipulation:Try to add electrons and holes\n", + "DEBUG:scs_simulations.boltzmann_data.data_manipulation:Added columns for electrons and holes\n", + "ok\n", + "\n", + "----------------------------------------------------------------------\n", + "Ran 2 tests in 0.068s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "%run test_boltzmann_simulation.py --test-suites boltzmann-manipulations" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "py38-scs", + "language": "python", + "name": "py38-scs" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.0" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/toolbox/test/__init__.py b/toolbox/test/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/toolbox/test/__init__.py @@ -0,0 +1 @@ + diff --git a/toolbox/test/test_top_level.py b/toolbox/test/test_top_level.py new file mode 100644 index 0000000..5703c30 --- /dev/null +++ b/toolbox/test/test_top_level.py @@ -0,0 +1,79 @@ +import unittest +import logging +import os +import sys +import argparse + + +import toolbox_scs as tb + +suites = {"suite-1": ( + "test_load", + "test_load" + ) + } + + +def list_suites(): + print("""\nPossible test suites:\n-------------------------""") + for key in suites: + print(key) + print("-------------------------\n") + + +class TemplateTest(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + + def test_load(self): + #tb.load(....) + pass + + +def suite(*tests): + suite = unittest.TestSuite() + for test in tests: + suite.addTest(TemplateTest(test)) + return suite + + +def main(*cliargs): + logging.basicConfig(level=logging.DEBUG) + log_root = logging.getLogger(__name__) + try: + for test_suite in cliargs: + if test_suite in suites: + runner = unittest.TextTestRunner(verbosity=2) + runner.run(suite(*suites[test_suite])) + else: + log_root.warning( + "Unknown suite: '{}'".format(test_suite)) + pass + except Exception as err: + log_root.error("Unecpected error: {}".format(err), + exc_info=True) + pass + + + + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--list-suites', + action='store_true', + help='list possible test suites') + parser.add_argument('--test-suites', metavar='S', + nargs='+', action='store', + help='a list of valid test suites') + args = parser.parse_args() + + if args.list_suites: + list_suites() + + if args.test_suites: + main(*args.test_suites) -- GitLab