Skip to content

Commit

Permalink
Merge branch 'NSLS-II:main' into propagation-parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
rlb131 authored Jul 19, 2023
2 parents a64bceb + 23fd00e commit ef2e342
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ repos:
rev: 23.3.0
hooks:
- id: black
language_version: python3.10
- id: black-jupyter
language_version: python3.10
exclude: ^(.*\.py)
args: [--line-length=88]
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
Expand Down
33 changes: 18 additions & 15 deletions docs/source/notebooks/elements.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"connection = SirepoBluesky(\"http://localhost:8000\")\n",
"\n",
"data, schema = connection.auth(\"srw\", \"00000002\")\n",
"classes, objects = create_classes(connection.data,\n",
" connection=connection)\n",
"classes, objects = create_classes(connection.data, connection=connection)\n",
"globals().update(**objects)\n",
"\n",
"aperture.horizontalSize.kind = \"hinted\"\n",
Expand Down Expand Up @@ -71,10 +70,13 @@
"nrows = int(np.ceil(num_frames / ncols))\n",
"\n",
"fig = plt.figure()\n",
"grid = ImageGrid(fig, (1, 2, ncols, nrows),\n",
" nrows_ncols=(nrows, ncols),\n",
" axes_pad=0.5,\n",
" aspect=False)\n",
"grid = ImageGrid(\n",
" fig,\n",
" (1, 2, ncols, nrows),\n",
" nrows_ncols=(nrows, ncols),\n",
" axes_pad=0.5,\n",
" aspect=False,\n",
")\n",
"\n",
"for ax, im in zip(grid, w9_image[:, ...]):\n",
" ax.imshow(im, aspect=\"auto\")"
Expand Down Expand Up @@ -103,12 +105,11 @@
"connection = SirepoBluesky(\"http://localhost:8000\")\n",
"\n",
"data, schema = connection.auth(\"shadow\", \"00000002\")\n",
"classes, objects = create_classes(connection.data,\n",
" connection=connection)\n",
"classes, objects = create_classes(connection.data, connection=connection)\n",
"globals().update(**objects)\n",
"\n",
"print(f\"Number of points before change: {data['models']['simulation']['npoint']}\")\n",
"data['models']['simulation']['npoint'] = 1000000\n",
"data[\"models\"][\"simulation\"][\"npoint\"] = 1000000\n",
"print(f\"Number of points after change: {data['models']['simulation']['npoint']}\")\n",
"aperture.horizontalSize.kind = \"hinted\"\n",
"w9.duration.kind = \"hinted\"\n",
Expand Down Expand Up @@ -136,10 +137,13 @@
"nrows = int(np.ceil(num_frames / ncols))\n",
"\n",
"fig = plt.figure()\n",
"grid = ImageGrid(fig, (1, 2, ncols, nrows),\n",
" nrows_ncols=(nrows, ncols),\n",
" axes_pad=0.5,\n",
" aspect=False)\n",
"grid = ImageGrid(\n",
" fig,\n",
" (1, 2, ncols, nrows),\n",
" nrows_ncols=(nrows, ncols),\n",
" axes_pad=0.5,\n",
" aspect=False,\n",
")\n",
"\n",
"for ax, im in zip(grid, w9_image[:, ...]):\n",
" ax.imshow(im, aspect=\"auto\")"
Expand Down Expand Up @@ -169,8 +173,7 @@
"\n",
"data, schema = connection.auth(\"shadow\", \"00000002\")\n",
"\n",
"classes, objects = create_classes(connection.data,\n",
" connection=connection)\n",
"classes, objects = create_classes(connection.data, connection=connection)\n",
"globals().update(**objects)\n",
"\n",
"bsr = BeamStatisticsReport(name=\"bsr\", connection=connection)\n",
Expand Down
17 changes: 11 additions & 6 deletions docs/source/notebooks/madx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@
"connection = SirepoBluesky(\"http://localhost:8000\")\n",
"\n",
"data, schema = connection.auth(\"madx\", \"00000002\")\n",
"classes, objects = create_classes(connection.data,\n",
" connection=connection,\n",
" extra_model_fields=[\"rpnVariables\", \"commands\"])\n",
"classes, objects = create_classes(\n",
" connection.data,\n",
" connection=connection,\n",
" extra_model_fields=[\"rpnVariables\", \"commands\"],\n",
")\n",
"globals().update(**objects)\n",
"\n",
"madx_flyer = MADXFlyer(connection=connection,\n",
" root_dir=\"/tmp/sirepo-bluesky-data\",\n",
" report=\"elementAnimation250-20\")\n",
"madx_flyer = MADXFlyer(\n",
" connection=connection,\n",
" root_dir=\"/tmp/sirepo-bluesky-data\",\n",
" report=\"elementAnimation250-20\",\n",
")\n",
"\n",
"(uid1,) = RE(bp.fly([madx_flyer]))\n",
"hdr1 = db[uid1]\n",
Expand All @@ -68,6 +72,7 @@
" yield from bps.mv(parameter.value, value)\n",
" return (yield from bp.fly([madx_flyer]))\n",
"\n",
"\n",
"(uid2,) = RE(madx_plan())\n",
"hdr2 = db[uid2]\n",
"tbl2 = hdr2.table(stream_name=\"madx_flyer\", fill=True)\n",
Expand Down
21 changes: 14 additions & 7 deletions sirepo_bluesky/shadow_handler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import contextlib
import os

import numpy as np
import Shadow.ShadowLibExtensions as sd
import Shadow.ShadowTools
Expand Down Expand Up @@ -49,7 +52,9 @@ def read_shadow_file_col(filename, parameter=30):
32 S2-stokes = 2 |Es| |Ep| cos(phase_s-phase_p)
33 S3-stokes = 2 |Es| |Ep| sin(phase_s-phase_p)
"""
data = Shadow.ShadowTools.getshcol(filename, col=parameter)
with open(os.devnull, "w") as devnull:
with contextlib.redirect_stdout(devnull):
data = Shadow.ShadowTools.getshcol(filename, col=parameter)

mean_value = np.mean(data)

Expand All @@ -73,12 +78,14 @@ def read_shadow_file(filename, histogram_bins=None):
beam.load(filename)

# 1=X spatial coordinate; 3=Z spatial coordinate
data_dict = beam.histo2(1, 3, nolost=1, nbins=histogram_bins)
data = data_dict["histogram"]

# This returns a list of N values (N=number of rays)
photon_energy_list = Shadow.ShadowTools.getshcol(filename, col=11) # 11=Energy [eV]
photon_energy = np.mean(photon_energy_list)
with open(os.devnull, "w") as devnull:
with contextlib.redirect_stdout(devnull):
data_dict = beam.histo2(1, 3, nolost=1, nbins=histogram_bins)
data = data_dict["histogram"]

# This returns a list of N values (N=number of rays)
photon_energy_list = Shadow.ShadowTools.getshcol(filename, col=11) # 11=Energy [eV]
photon_energy = np.mean(photon_energy_list)

return {
"data": data,
Expand Down
2 changes: 1 addition & 1 deletion sirepo_bluesky/sirepo_ophyd.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def create_classes(sirepo_data, connection, create_objects=True, extra_model_fie

components[k] = Cpt(
cpt_class,
value=v,
value=(float(v) if type(v) is int else v),
sirepo_dict=sirepo_dict,
sirepo_param=k,
)
Expand Down

0 comments on commit ef2e342

Please sign in to comment.