Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customize calc namespace to have most used function at the top level #375

Merged
2 commits merged into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
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
14 changes: 14 additions & 0 deletions hutch_python/calc_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
vespos marked this conversation as resolved.
Show resolved Hide resolved

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'])
)