From fc21f2fe729d5775802d2da842093983d3814cce Mon Sep 17 00:00:00 2001 From: Vincent Esposito Date: Fri, 15 Sep 2023 15:39:50 -0700 Subject: [PATCH 1/9] customize calc namespace to have most used function at the top level --- hutch_python/calc_defaults.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hutch_python/calc_defaults.py b/hutch_python/calc_defaults.py index 36838924..b576ea9a 100644 --- a/hutch_python/calc_defaults.py +++ b/hutch_python/calc_defaults.py @@ -31,9 +31,23 @@ def collect_functions(modules): pass return HelpfulNamespace(**functions) +# import specific function to have at the top level of the namespace +try: + from pcdscalc.diffraction import (bragg_angle, darwin_width) +except ImportError: + print("Failed to import functions from pcdscalc.diffraction") + +try: + from pcdscalc.xray import transmission +except ImportError: + print("Failed to import functions from pcdscalc.xray") calc_namespace = HelpfulNamespace( + darwin_width=darwin_width, + bragg_angle=bragg_angle, + transmission=transmission, be_lens=collect_functions(['pcdscalc.be_lens_calcs']), common=collect_functions(['pcdscalc.common']), diffraction=collect_functions(['pcdscalc.diffraction']), + xray=collect_functions(['pcdscalc.xray']) ) From c5b3b45f42a3aeb8fd03fdab13fb3a7b0d6da733 Mon Sep 17 00:00:00 2001 From: Vincent Esposito Date: Thu, 21 Sep 2023 17:24:32 -0700 Subject: [PATCH 2/9] fix try/except for function import --- hutch_python/calc_defaults.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hutch_python/calc_defaults.py b/hutch_python/calc_defaults.py index b576ea9a..b41521f2 100644 --- a/hutch_python/calc_defaults.py +++ b/hutch_python/calc_defaults.py @@ -31,23 +31,27 @@ def collect_functions(modules): pass return HelpfulNamespace(**functions) + # import specific function to have at the top level of the namespace +funcs = {} try: - from pcdscalc.diffraction import (bragg_angle, darwin_width) + from pcdscalc.diffraction import bragg_angle, darwin_width + funcs['bragg_angle'] = bragg_angle + funcs['darwin_width'] = darwin_width except ImportError: print("Failed to import functions from pcdscalc.diffraction") try: from pcdscalc.xray import transmission + funcs['transmission'] = transmission except ImportError: print("Failed to import functions from pcdscalc.xray") calc_namespace = HelpfulNamespace( - darwin_width=darwin_width, - bragg_angle=bragg_angle, - transmission=transmission, be_lens=collect_functions(['pcdscalc.be_lens_calcs']), common=collect_functions(['pcdscalc.common']), diffraction=collect_functions(['pcdscalc.diffraction']), - xray=collect_functions(['pcdscalc.xray']) + xray=collect_functions(['pcdscalc.xray']), + **funcs + ) From 1942b02d433121eefd68bb2a202e348dd8ac9a60 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Mon, 14 Oct 2024 18:08:30 -0700 Subject: [PATCH 3/9] ENH: include two functions added in xpp3 dev --- hutch_python/calc_defaults.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hutch_python/calc_defaults.py b/hutch_python/calc_defaults.py index b41521f2..3e4bbc0e 100644 --- a/hutch_python/calc_defaults.py +++ b/hutch_python/calc_defaults.py @@ -46,8 +46,12 @@ def collect_functions(modules): funcs['transmission'] = transmission except ImportError: print("Failed to import functions from pcdscalc.xray") +from pcdscalc.common import energy_to_wavelength as E2lam +from pcdscalc.common import wavelength_to_energy as lam2E calc_namespace = HelpfulNamespace( + lam2E=lam2E, + E2lam=E2lam, be_lens=collect_functions(['pcdscalc.be_lens_calcs']), common=collect_functions(['pcdscalc.common']), diffraction=collect_functions(['pcdscalc.diffraction']), From d6d4296ab2de9b4c0ca4a2b75caf5188005ef111 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Mon, 14 Oct 2024 18:10:17 -0700 Subject: [PATCH 4/9] ENH: simplify- just make sure we have a new enough pcdscalc installed --- hutch_python/calc_defaults.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/hutch_python/calc_defaults.py b/hutch_python/calc_defaults.py index 3e4bbc0e..943cf954 100644 --- a/hutch_python/calc_defaults.py +++ b/hutch_python/calc_defaults.py @@ -1,5 +1,10 @@ from importlib import import_module +from pcdscalc.common import energy_to_wavelength as E2lam +from pcdscalc.common import wavelength_to_energy as lam2E +from pcdscalc.diffraction import bragg_angle, darwin_width +from pcdscalc.xray import transmission + from .utils import HelpfulNamespace @@ -32,30 +37,14 @@ def collect_functions(modules): return HelpfulNamespace(**functions) -# import specific function to have at the top level of the namespace -funcs = {} -try: - from pcdscalc.diffraction import bragg_angle, darwin_width - funcs['bragg_angle'] = bragg_angle - funcs['darwin_width'] = darwin_width -except ImportError: - print("Failed to import functions from pcdscalc.diffraction") - -try: - from pcdscalc.xray import transmission - funcs['transmission'] = transmission -except ImportError: - print("Failed to import functions from pcdscalc.xray") -from pcdscalc.common import energy_to_wavelength as E2lam -from pcdscalc.common import wavelength_to_energy as lam2E - calc_namespace = HelpfulNamespace( + darwin_width=darwin_width, + bragg_angle=bragg_angle, + transmission=transmission, lam2E=lam2E, E2lam=E2lam, be_lens=collect_functions(['pcdscalc.be_lens_calcs']), common=collect_functions(['pcdscalc.common']), diffraction=collect_functions(['pcdscalc.diffraction']), xray=collect_functions(['pcdscalc.xray']), - **funcs - ) From d523edc5670cc30182566c8a70a1a37aea7e44bb Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Mon, 14 Oct 2024 18:11:25 -0700 Subject: [PATCH 5/9] STY: rearrange top-level functions to match isort order --- hutch_python/calc_defaults.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hutch_python/calc_defaults.py b/hutch_python/calc_defaults.py index 943cf954..ef110891 100644 --- a/hutch_python/calc_defaults.py +++ b/hutch_python/calc_defaults.py @@ -38,11 +38,11 @@ def collect_functions(modules): calc_namespace = HelpfulNamespace( - darwin_width=darwin_width, + E2lam=E2lam, + lam2E=lam2E, bragg_angle=bragg_angle, + darwin_width=darwin_width, transmission=transmission, - lam2E=lam2E, - E2lam=E2lam, be_lens=collect_functions(['pcdscalc.be_lens_calcs']), common=collect_functions(['pcdscalc.common']), diffraction=collect_functions(['pcdscalc.diffraction']), From a79815a9b375286640ad6fa0acff8a2ed721f7e9 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Mon, 14 Oct 2024 18:14:01 -0700 Subject: [PATCH 6/9] BLD: pin pcdscalc to latest to ensure calc availability --- conda-recipe/meta.yaml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index 52fb9ed2..3437b400 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -32,7 +32,7 @@ requirements: - lightpath >=1.0.1 - matplotlib-base >=3.4.0 - nabs >=1.5.0 - - pcdscalc >=0.3.0 + - pcdscalc >=0.6.0 - pcdsdaq >=2.3.0 - pcdsdevices >=7.0.0 - pcdsutils >=0.6.0 diff --git a/requirements.txt b/requirements.txt index 78485a31..9655e7d2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ jinja2>=2.11.0 lightpath>=1.0.1 matplotlib>=3.4.0 nabs>=1.5.0 -pcdscalc>=0.3.0 +pcdscalc>=0.6.0 pcdsdaq>=2.3.0 pcdsdevices>=7.0.0 pcdsutils>=0.5.0 From 41e2ae1351e3814c9705cba66eb8c75434127666 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Mon, 14 Oct 2024 18:20:03 -0700 Subject: [PATCH 7/9] DOC: add pre-release notes for 390 --- .../390-enh_xpp_calc_ns.rst | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 docs/source/upcoming_release_notes/390-enh_xpp_calc_ns.rst diff --git a/docs/source/upcoming_release_notes/390-enh_xpp_calc_ns.rst b/docs/source/upcoming_release_notes/390-enh_xpp_calc_ns.rst new file mode 100644 index 00000000..f3113c79 --- /dev/null +++ b/docs/source/upcoming_release_notes/390-enh_xpp_calc_ns.rst @@ -0,0 +1,25 @@ +390 enh_xpp_calc_ns +################### + +API Changes +----------- +- N/A + +Features +-------- +- Add ``pcdscalc.xray`` to the calc namespace. +- Add top-level shortcuts to some of the most used calcs, + ``E2lam``, ``lam2E``, ``bragg_angle``, ``darwin_width``, and ``transmission``. + +Bugfixes +-------- +- N/A + +Maintenance +----------- +- N/A + +Contributors +------------ +- vespos +- zllentz From 404dbd705a23243382e7897aa9f1c12d662709f1 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Mon, 14 Oct 2024 18:21:05 -0700 Subject: [PATCH 8/9] MNT: shed unneeded as imports --- hutch_python/calc_defaults.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hutch_python/calc_defaults.py b/hutch_python/calc_defaults.py index ef110891..cf6f9d43 100644 --- a/hutch_python/calc_defaults.py +++ b/hutch_python/calc_defaults.py @@ -1,7 +1,6 @@ from importlib import import_module -from pcdscalc.common import energy_to_wavelength as E2lam -from pcdscalc.common import wavelength_to_energy as lam2E +from pcdscalc.common import energy_to_wavelength, wavelength_to_energy from pcdscalc.diffraction import bragg_angle, darwin_width from pcdscalc.xray import transmission @@ -38,8 +37,8 @@ def collect_functions(modules): calc_namespace = HelpfulNamespace( - E2lam=E2lam, - lam2E=lam2E, + E2lam=energy_to_wavelength, + lam2E=wavelength_to_energy, bragg_angle=bragg_angle, darwin_width=darwin_width, transmission=transmission, From b57ca20d0e3d2d9856985dfa86eb3002df07142e Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Mon, 14 Oct 2024 18:22:15 -0700 Subject: [PATCH 9/9] DOC: improve pre-release notes --- docs/source/upcoming_release_notes/390-enh_xpp_calc_ns.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/source/upcoming_release_notes/390-enh_xpp_calc_ns.rst b/docs/source/upcoming_release_notes/390-enh_xpp_calc_ns.rst index f3113c79..5f4b60a2 100644 --- a/docs/source/upcoming_release_notes/390-enh_xpp_calc_ns.rst +++ b/docs/source/upcoming_release_notes/390-enh_xpp_calc_ns.rst @@ -9,7 +9,11 @@ Features -------- - Add ``pcdscalc.xray`` to the calc namespace. - Add top-level shortcuts to some of the most used calcs, - ``E2lam``, ``lam2E``, ``bragg_angle``, ``darwin_width``, and ``transmission``. + ``E2lam``, ``lam2E``, ``bragg_angle``, ``darwin_width``, + and ``transmission``. + ``E2lam`` is an alias for ``energy_to_wavelength`` and + ``lam2E`` is an alias for ``wavelength_to_energy`` + to match scientist expectations. Bugfixes --------