Skip to content

Commit

Permalink
update notebook and example config
Browse files Browse the repository at this point in the history
  • Loading branch information
rettigl committed Mar 8, 2024
1 parent 99ea5e4 commit 810dea0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 138 deletions.
2 changes: 0 additions & 2 deletions sed/config/flash_example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ core:
loader: flash
# the beamline where experiment took place
beamline: pg2
# the instrument used
instrument: hextof
# the ID number of the beamtimme
beamtime_id: 11013410
# the year of the beamtime
Expand Down
98 changes: 84 additions & 14 deletions tutorial/4_hextof_workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"\n",
" os.system(f\"mkdir {data_path}/flash_data\")\n",
" os.system(f\"mv {data_path}/analysis_data/*/*.h5 {data_path}/flash_data\")\n",
" os.system(f\"mv {data_path}/calibration_data/*/*.h5 {data_path}/flash_data\")\n"
" os.system(f\"mv {data_path}/calibration_data/*/*.h5 {data_path}/flash_data\")"
]
},
{
Expand Down Expand Up @@ -102,7 +102,7 @@
" \"data_parquet_dir\": \"/asap3/flash/gpfs/pg2/2023/data/11019101/parquet\"\n",
" },\n",
" },\n",
"}\n"
"}"
]
},
{
Expand Down Expand Up @@ -219,6 +219,23 @@
"sp.dataframe.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Visualizing event histograms\n",
"For getting a first impression of the data, and to determine binning ranges, the method sp.`view_even_histogram()` allows visualizing the events in one dataframe partition as histograms. Default axes and ranges are defined in the config, and show the dldPosX, dldPosY, and dldTimeStep columns:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sp.view_event_histogram(dfpid=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -310,7 +327,7 @@
"fig,ax = plt.subplots(1,3,figsize=(8,2), layout='tight')\n",
"res_chessy.plot(ax=ax[0], robust=True)\n",
"res_t05.plot(ax=ax[1], robust=True)\n",
"res_t10.plot(ax=ax[2], robust=True)\n"
"res_t10.plot(ax=ax[2], robust=True)"
]
},
{
Expand Down Expand Up @@ -338,6 +355,22 @@
"sp.add_jitter()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use the `view_event_histogram()` function also to e.g. visualize the events per microbunch along the train, or hit multiplicity per microbunch:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sp.view_event_histogram(dfpid=0, axes=[\"pulseId\", \"electronId\"], ranges=[[0, 600], [0,10]], bins=[100, 10])"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -383,6 +416,22 @@
"sp.append_tof_ns_axis()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, to determine propper binning ranges, let's have again a look at the event histograms:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sp.view_event_histogram(dfpid=0, axes=[\"sampleBias\", \"dldTime\"], ranges=[[27, 33], [650,1050]], bins=[50, 100])"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -459,8 +508,8 @@
"outputs": [],
"source": [
"sp.calibrate_energy_axis(\n",
" ref_id=2,\n",
" ref_energy=-1,\n",
" ref_id=4,\n",
" ref_energy=-.55,\n",
" method=\"lmfit\",\n",
" energy_scale='kinetic',\n",
" d={'value':1.0,'min': .2, 'max':1.0, 'vary':False},\n",
Expand Down Expand Up @@ -549,10 +598,10 @@
"outputs": [],
"source": [
"sp.add_energy_offset(\n",
" constant=0,\n",
" constant=-32, # Sample bias used as reference for energy calibration\n",
" columns=['sampleBias','monochromatorPhotonEnergy','tofVoltage'],\n",
" weights=[1,-1,-1],\n",
" preserve_mean=True,\n",
" preserve_mean=[False, True, True],\n",
")"
]
},
Expand Down Expand Up @@ -701,7 +750,7 @@
"metadata": {},
"outputs": [],
"source": [
"fig,ax = plt.subplots(1,2,figsize=(6,3), layout='constrained')\n",
"fig,ax = plt.subplots(1,2,figsize=(8,3), layout='constrained')\n",
"res.plot(robust=True, ax=ax[0])\n",
"bg = res.isel(delayStage=slice(0,10)).mean('delayStage')\n",
"(res-bg).plot(robust=True, ax=ax[1])"
Expand Down Expand Up @@ -755,7 +804,7 @@
"axes = ['energy','delayStage']\n",
"bins = [100,150]\n",
"delay_start,delay_stop=1462.00,1464.85\n",
"ranges = [[-5,2], [-1.15, 1.7]]\n",
"ranges = [[-3,2], [-1.15, 1.7]]\n",
"res = sp.compute(bins=bins, axes=axes, ranges=ranges)"
]
},
Expand All @@ -769,9 +818,30 @@
},
"outputs": [],
"source": [
"fig,ax = plt.subplots(1,2,figsize=(12,5))\n",
"fig,ax = plt.subplots(1,2,figsize=(8,3))\n",
"res.plot(robust=True, ax=ax[0])\n",
"bg = res.isel(delayStage=slice(0,10)).mean('delayStage')\n",
"bg = res.sel(delayStage=slice(-1,-0.2)).mean('delayStage')\n",
"(res-bg).plot(robust=True, ax=ax[1])\n",
"fig.tight_layout()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You may note some intensity variation along the delay axis. This comes mainly from inhomogenous speed of the delay stage, and thus inquivalently time spend on every delay point. This can be corrected for by normalizing the data to the aquisition time per delay point:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"res = sp.compute(bins=bins, axes=axes, ranges=ranges, normalize_to_acquisition_time=\"delayStage\")\n",
"fig,ax = plt.subplots(1,2,figsize=(8,3), layout='constrained')\n",
"res.plot(robust=True, ax=ax[0])\n",
"bg = res.sel(delayStage=slice(-1,-.2)).mean('delayStage')\n",
"(res-bg).plot(robust=True, ax=ax[1])"
]
},
Expand Down Expand Up @@ -857,7 +927,7 @@
"bins = [100,150]\n",
"delay_start,delay_stop=1462.00,1464.85\n",
"ranges = [[-5,2], [-1.15, 1.7]]\n",
"res = sp.compute(bins=bins, axes=axes, ranges=ranges)"
"res = sp.compute(bins=bins, axes=axes, ranges=ranges, normalize_to_acquisition_time=\"delayStage\")"
]
},
{
Expand All @@ -866,9 +936,9 @@
"metadata": {},
"outputs": [],
"source": [
"fig,ax = plt.subplots(1,2,figsize=(12,5))\n",
"fig,ax = plt.subplots(1,2,figsize=(8,3), layout='constrained')\n",
"res.plot(robust=True, ax=ax[0])\n",
"bg = res.isel(delayStage=slice(0,10)).mean('delayStage')\n",
"bg = res.sel(delayStage=slice(-1,-.2)).mean('delayStage')\n",
"(res-bg).plot(robust=True, ax=ax[1])"
]
},
Expand Down
122 changes: 0 additions & 122 deletions tutorial/hextof_config.yaml

This file was deleted.

0 comments on commit 810dea0

Please sign in to comment.