diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..1aa761d --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,40 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Upload Python Package + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine toml + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* + diff --git a/.gitignore b/.gitignore index 60cbbe7..122f98f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ scripts/results/ Thumbs.db +.idea + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..8458cf8 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include README.md +include LICENSE +include pypret/VERSION + diff --git a/pypret/VERSION b/pypret/VERSION new file mode 100644 index 0000000..8a9ecc2 --- /dev/null +++ b/pypret/VERSION @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file diff --git a/pypret/retrieval/nlo_retriever.py b/pypret/retrieval/nlo_retriever.py index 117a9fd..50e0850 100644 --- a/pypret/retrieval/nlo_retriever.py +++ b/pypret/retrieval/nlo_retriever.py @@ -19,7 +19,7 @@ def _scalar_objective(self, x): R = self._Rr(r) # printing and logging if rs.nfev % 100 == 0 and self.verbose: - print(rs.nfev, R) + self.print(rs.nfev, R) if self.logging: log.trace_error.append(R) rs.nfev += 1 @@ -37,7 +37,7 @@ def _vector_objective(self, x): R = self._Rr(np.sum(diff * diff)) # printing and logging if rs.nfev % 100 == 0 and self.verbose: - print(rs.nfev, R) + self.print(rs.nfev, R) if self.logging: log.trace_error.append(R) rs.nfev += 1 diff --git a/pypret/retrieval/retriever.py b/pypret/retrieval/retriever.py index 701e975..95225c3 100644 --- a/pypret/retrieval/retriever.py +++ b/pypret/retrieval/retriever.py @@ -61,6 +61,21 @@ def __init__(self, pnps, logging=False, verbose=False, **kwargs): self.log = None rs = self._retrieval_state = SimpleNamespace() rs.running = False + if 'status_sig' in kwargs: + self.print = kwargs['status_sig'].emit + else: + self.print = print + + if 'callback' in kwargs: + self.callback = kwargs['callback'] + else: + self.callback = None + + if 'step_command' in kwargs: + self.step_command = kwargs['step_command'] + else: + self.step_command = None + if (self.supported_schemes is not None and pnps.scheme not in self.supported_schemes): raise ValueError("Retriever '%s' does not support scheme '%s'. " @@ -139,12 +154,12 @@ def _retrieve_begin(self, measurement, initial_guess, weights): else: self.log = None if self.verbose: - print("Started retriever '%s'" % self.method) - print("Options:") - print(self.options) - print("Initial trace error R = {:.10e}".format(res.trace_error)) - print("Starting retrieval...") - print() + self.print("Started retriever '%s'" % self.method) + self.print("Options:") + self.print(str(self.options)) + self.print("Initial trace error R = {:.10e}".format(res.trace_error)) + self.print("Starting retrieval...") + self.print("") def _retrieve_end(self): rs = self._retrieval_state diff --git a/pypret/retrieval/step_retriever.py b/pypret/retrieval/step_retriever.py index 19e4bed..830025c 100644 --- a/pypret/retrieval/step_retriever.py +++ b/pypret/retrieval/step_retriever.py @@ -40,8 +40,10 @@ def _retrieve(self): # accept the new spectrum spectrum[:] = new_spectrum if self.verbose: + if self.callback is not None: + self.callback([rs.mu * rs.Tmn - self.Tmn_meas, self.parameter, self.pnps.process_w, new_spectrum]) if i == 0: - print("iteration".ljust(10) + "trace error".ljust(20)) + self.print("iteration".ljust(10) + "trace error".ljust(20)) s = "{:d}".format(i + 1).ljust(10) if rs.approximate_error: s += "~" @@ -50,14 +52,16 @@ def _retrieve(self): s += "{:.10e}".format(R) if R == res.trace_error: s += "*" - print(s) + self.print(s) if not rs.running: break + if self.step_command is not None: + self.step_command() if self.verbose: - print() - print("~ approximate trace error") - print("* accepted as best trace error") - print() + self.print("") + self.print("~ approximate trace error") + self.print("* accepted as best trace error") + self.print("") # return the retrieved spectrum # for a more detailed analysis call self.result() diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..f62a777 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,39 @@ +[metadata] +name = pypret_pymodaq +version = file: pypret/VERSION +description = fork of Python for Pulse Retrieval for PyMoDAQ +long_description = This project aims to provide numerical algorithms for ultrashort laser pulse measurement methods +license = MIT +licence_file = LICENSE +url = https://github.com/PyMoDAQ/pypret_pymodaq +author = S. J. Weber +author_email = sebastien.weber@cemes.fr +classifiers = + Programming Language :: Python :: 3 + Development Status :: 5 - Production/Stable + Environment :: Other Environment + Intended Audience :: Science/Research + Topic :: Scientific/Engineering :: Human Machine Interfaces + Topic :: Scientific/Engineering :: Visualization + License :: OSI Approved :: MIT License + Operating System :: OS Independent + Topic :: Software Development :: Libraries :: Python Modules + Topic :: Software Development :: User Interfaces + +[options] +py_module = pypret +python_requires = >=3.6, <3.9 +install_requires= + h5py + loky + scipy + +package_dir = + =. +packages = find: +include_package_data = True + +[options.packages.find] +where = . + + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8bf1ba9 --- /dev/null +++ b/setup.py @@ -0,0 +1,2 @@ +from setuptools import setup +setup()