Skip to content

Commit

Permalink
fix new notebooks and merging bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rettigl committed Nov 30, 2024
1 parent f4350d8 commit 02d8a71
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 80 deletions.
2 changes: 1 addition & 1 deletion docs/sed/config.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Config
***************************************************
.. automobile:: sed.core.config
.. automodule:: sed.core.config
:members:
:undoc-members:

Expand Down
8 changes: 4 additions & 4 deletions src/sed/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,10 +1380,10 @@ def calibrate_energy_axis(
backend="matplotlib",
title="Quality of Calibration",
)
plt.xlabel("Energy (eV)")
plt.ylabel("Intensity")
plt.tight_layout()
plt.show()
plt.xlabel("Energy (eV)")
plt.ylabel("Intensity")
plt.tight_layout()
plt.show()
if energy_scale == "kinetic":
self.ec.view(
traces=self.ec.calibration["axis"][None, :] + self.ec.biases[0],
Expand Down
52 changes: 29 additions & 23 deletions tutorial/10_hextof_workflow_trXPS_bam_correction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"outputs": [],
"source": [
"# pick the default configuration file for hextof@FLASH\n",
"config_file = Path('../sed/config/flash_example_config.yaml')\n",
"config_file = Path('../config/flash_example_config.yaml')\n",
"assert config_file.exists()"
]
},
Expand All @@ -112,8 +112,8 @@
" \"core\": {\n",
" \"beamtime_id\": 11019101,\n",
" \"paths\": {\n",
" \"data_raw_dir\": path,\n",
" \"data_parquet_dir\": buffer_path\n",
" \"raw\": path,\n",
" \"processed\": buffer_path\n",
" },\n",
" },\n",
"}"
Expand All @@ -129,26 +129,24 @@
"energy_cal = {\n",
" \"energy\": {\n",
" \"calibration\": {\n",
" \"E0\": -53.96145014592986,\n",
" \"creation_date\": 1732056868.029444,\n",
" \"d\": 0.8096677233434938,\n",
" \"E0\": -132.47100427179566,\n",
" \"creation_date\": '2024-11-30T20:47:03.305244',\n",
" \"d\": 0.8096677238144319,\n",
" \"energy_scale\": \"kinetic\",\n",
" \"t0\": 4.0148196718030886e-07,\n",
" \"t0\": 4.0148196706891397e-07,\n",
" },\n",
" \"offsets\":{\n",
" \"constant\": -77.5,\n",
" \"creation_date\": 1732056874.060922,\n",
" \"monochromatorPhotonEnergy\": {\n",
" \"preserve_mean\": True,\n",
" \"weight\": -1,\n",
" },\n",
" \"sampleBias\": {\n",
" \"preserve_mean\": False,\n",
" \"weight\": 1,\n",
" },\n",
" \"tofVoltage\": {\n",
" \"preserve_mean\": True,\n",
" \"weight\": -1,\n",
" \"constant\": 1,\n",
" \"creation_date\": '2024-11-30T21:17:07.762199',\n",
" \"columns\": {\n",
" \"monochromatorPhotonEnergy\": {\n",
" \"preserve_mean\": True,\n",
" \"weight\": -1,\n",
" },\n",
" \"tofVoltage\": {\n",
" \"preserve_mean\": True,\n",
" \"weight\": -1,\n",
" },\n",
" },\n",
" },\n",
" },\n",
Expand Down Expand Up @@ -230,7 +228,7 @@
"axes = ['energy', 'delayStage']\n",
"ranges = [[-37.5,-27.5], [1446.75,1449.15]]\n",
"bins = [200,40]\n",
"res = sp_44498.compute(bins=bins, axes=axes, ranges=ranges, normalize_to_acquisition_time=\"delayStage\")"
"res = sp_44498.compute(bins=bins, axes=axes, ranges=ranges)"
]
},
{
Expand Down Expand Up @@ -396,7 +394,7 @@
"axes = ['energy', 'delayStage']\n",
"ranges = [[-37.5,-27.5], [-1.5,1.5]]\n",
"bins = [200,60]\n",
"res_corr = sp_44498.compute(bins=bins, axes=axes, ranges=ranges, normalize_to_acquisition_time=\"delayStage\")"
"res_corr = sp_44498.compute(bins=bins, axes=axes, ranges=ranges)"
]
},
{
Expand Down Expand Up @@ -535,11 +533,19 @@
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e2e6e852",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "python3",
"display_name": "sed-processor-7Jy-bAA8-py3.9",
"language": "python",
"name": "python3"
},
Expand Down
59 changes: 30 additions & 29 deletions tutorial/11_hextof_workflow_trXPS_energy_calibration_using_SB.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"outputs": [],
"source": [
"# pick the default configuration file for hextof@FLASH\n",
"config_file = Path('../sed/config/flash_example_config.yaml')\n",
"config_file = Path('../config/flash_example_config.yaml')\n",
"assert config_file.exists()"
]
},
Expand All @@ -113,8 +113,8 @@
" \"core\": {\n",
" \"beamtime_id\": 11019101,\n",
" \"paths\": {\n",
" \"data_raw_dir\": path,\n",
" \"data_parquet_dir\": buffer_path\n",
" \"raw\": path,\n",
" \"processed\": buffer_path\n",
" },\n",
" },\n",
"}"
Expand Down Expand Up @@ -175,14 +175,6 @@
"sp_44455.find_bias_peaks(ranges=ranges, ref_id=ref_id, apply=True)"
]
},
{
"cell_type": "markdown",
"id": "d3e4f30d",
"metadata": {},
"source": [
"We offset the reference energy by the different in bias voltages between this run and run 44498"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -191,14 +183,12 @@
"outputs": [],
"source": [
"sp_44455.calibrate_energy_axis(\n",
" ref_id=0,\n",
" ref_energy=-34.9,\n",
" ref_energy=-31.4,\n",
" method=\"lmfit\",\n",
" energy_scale='kinetic',\n",
" d={'value':1.0,'min': .7, 'max':1.0, 'vary':True},\n",
" t0={'value':5e-7, 'min': 1e-7, 'max': 1e-6, 'vary':True},\n",
" E0={'value': 0., 'min': -200, 'max': 100, 'vary': True},\n",
" verbose=True,\n",
")"
]
},
Expand All @@ -225,7 +215,8 @@
"id": "98266c62-ab48-4746-96c8-2d47cf92c0e9",
"metadata": {},
"source": [
"### Now we can use those parameters and load our trXPS data using the additional config file"
"### Now we can use those parameters and load our trXPS data using the additional config file\n",
"To obtain a correct energy axis, we offset the energy axis by the difference of photon energy between this run and the energy calibration runs"
]
},
{
Expand All @@ -238,7 +229,13 @@
"run_number = 44498\n",
"sp_44498 = SedProcessor(runs=[run_number], config=config_override, folder_config=\"reference_calib.yaml\", system_config=config_file, verbose=True)\n",
"sp_44498.add_jitter()\n",
"sp_44498.append_energy_axis()"
"sp_44498.append_energy_axis()\n",
"sp_44498.add_energy_offset(\n",
" constant=1,\n",
" columns=['monochromatorPhotonEnergy','tofVoltage'],\n",
" weights=[-1,-1],\n",
" preserve_mean=[True, True],\n",
")"
]
},
{
Expand Down Expand Up @@ -328,14 +325,14 @@
"axes = ['dldTimeSteps', 'delayStage']\n",
"ranges = [[3900,4200], [-1.5,1.5]]\n",
"bins = [100,60]\n",
"res_corr = sp_44498.compute(bins=bins, axes=axes, ranges=ranges, normalize_to_acquisition_time=\"delayStage\")\n",
"res_corr = sp_44498.compute(bins=bins, axes=axes, ranges=ranges)\n",
"\n",
"fig,ax = plt.subplots(1,2,figsize=(8,3), layout='constrained')\n",
"fig.suptitle(f\"Run {run_number}: W 4f, side bands\")\n",
"res_corr.plot(robust=True, ax=ax[0], cmap='terrain')\n",
"res_corr.plot(ax=ax[0], cmap='terrain')\n",
"ax[0].set_title('raw')\n",
"bg = res_corr.sel(delayStage=slice(-1.3,-1.0)).mean('delayStage')\n",
"(res_corr-bg).plot(robust=True, ax=ax[1])\n",
"(res_corr-bg).plot(ax=ax[1])\n",
"ax[1].set_title('difference')"
]
},
Expand Down Expand Up @@ -395,29 +392,27 @@
"outputs": [],
"source": [
"### Kinetic energy of w4f peaks and their SB\n",
"ref_energy = -31.4\n",
"ref_id = 1\n",
"ref_energy = -30.2\n",
"sp_44498.ec.biases = -1*np.array([-30.2,-31.4,-32.6,-33.6,-34.8])\n",
"sp_44498.ec.peaks = np.expand_dims(data[peaks]['dldTimeSteps'].data,1)\n",
"sp_44498.ec.tof = res_corr.dldTimeSteps.data\n",
"\n",
"sp_44498.calibrate_energy_axis(\n",
" ref_id=ref_id,\n",
" ref_energy=ref_energy,\n",
" method=\"lmfit\",\n",
" d={'value':1.0,'min': .8, 'max':1.0, 'vary':True},\n",
" t0={'value':5e-7, 'min': 1e-7, 'max': 1e-6, 'vary':True},\n",
" E0={'value': -100., 'min': -200, 'max': 15, 'vary': True},\n",
" labels=\"\",\n",
" verbose=True)"
")"
]
},
{
"cell_type": "markdown",
"id": "4052d629-1178-4248-a945-d60a6ff34bf3",
"metadata": {},
"source": [
"### Append energy axis into a data frame, bin and visualize data in the calibrated energy and corrected delay axis "
"### Append energy axis into a data frame, bin and visualize data in the calibrated energy and corrected delay axis\n",
"To get a correct energy axis, we undo the shifts imposed by the calibration function"
]
},
{
Expand All @@ -427,7 +422,13 @@
"metadata": {},
"outputs": [],
"source": [
"sp_44498.append_energy_axis()"
"sp_44498.append_energy_axis()\n",
"sp_44498.add_energy_offset(\n",
" constant=30.2,\n",
" columns=['monochromatorPhotonEnergy','tofVoltage','sampleBias'],\n",
" weights=[-1,-1,-1],\n",
" preserve_mean=[True, True,False],\n",
")"
]
},
{
Expand All @@ -440,14 +441,14 @@
"axes = ['energy', 'delayStage']\n",
"ranges = [[-37.5,-27.5], [-1.5,1.5]]\n",
"bins = [200,60]\n",
"res_corr = sp_44498.compute(bins=bins, axes=axes, ranges=ranges, normalize_to_acquisition_time=\"delayStage\")\n",
"res_corr = sp_44498.compute(bins=bins, axes=axes, ranges=ranges)\n",
"\n",
"fig,ax = plt.subplots(1,2,figsize=(8,3), layout='constrained')\n",
"fig.suptitle(f\"Run {run_number}: W 4f, side bands\")\n",
"res_corr.plot(robust=True, ax=ax[0], cmap='terrain')\n",
"res_corr.plot(ax=ax[0], cmap='terrain')\n",
"ax[0].set_title('raw')\n",
"bg = res_corr.sel(delayStage=slice(-1.3,-1.0)).mean('delayStage')\n",
"(res_corr-bg).plot(robust=True, ax=ax[1])\n",
"(res_corr-bg).plot(ax=ax[1])\n",
"ax[1].set_title('difference')"
]
},
Expand Down
52 changes: 29 additions & 23 deletions tutorial/9_hextof_workflow_trXPD.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"outputs": [],
"source": [
"# pick the default configuration file for hextof@FLASH\n",
"config_file = Path('../sed/config/flash_example_config.yaml')\n",
"config_file = Path('../config/flash_example_config.yaml')\n",
"assert config_file.exists()"
]
},
Expand All @@ -111,8 +111,8 @@
" \"core\": {\n",
" \"beamtime_id\": 11019101,\n",
" \"paths\": {\n",
" \"data_raw_dir\": path,\n",
" \"data_parquet_dir\": buffer_path\n",
" \"raw\": path,\n",
" \"processed\": buffer_path\n",
" },\n",
" },\n",
"}"
Expand Down Expand Up @@ -142,25 +142,31 @@
"metadata": {},
"outputs": [],
"source": [
"en_cal_config = {\n",
" 'energy': {\n",
" 'calibration': {\n",
" 'E0': -54.971004271795664,\n",
" 'creation_date': 1718801358.232129,\n",
" 'd': 0.8096677238144319,\n",
" 'energy_scale': 'kinetic',\n",
" 't0': 4.0148196706891397e-07,\n",
" 'calib_type': 'fit',\n",
" 'fit_function': '(a0/(x0-a1))**2 + a2',\n",
" 'coefficients': ([ 8.09667724e-01, 4.01481967e-07, -5.49710043e+01]),\n",
" 'axis': 0},\n",
" 'tof': None,\n",
" 'offsets': {\n",
" 'constant': -76.5,\n",
" 'creation_date': 1718801360.817963,\n",
" 'monochromatorPhotonEnergy': {'preserve_mean': True,'reduction': None,'weight': -1},\n",
" 'sampleBias': {'preserve_mean': False, 'reduction': None, 'weight': 1},\n",
" 'tofVoltage': {'preserve_mean': True, 'reduction': None, 'weight': -1}}}}"
"energy_cal = {\n",
" \"energy\": {\n",
" \"calibration\": {\n",
" \"E0\": -132.47100427179566,\n",
" \"creation_date\": '2024-11-30T20:47:03.305244',\n",
" \"d\": 0.8096677238144319,\n",
" \"energy_scale\": \"kinetic\",\n",
" \"t0\": 4.0148196706891397e-07,\n",
" },\n",
" \"offsets\":{\n",
" \"constant\": 1,\n",
" \"creation_date\": '2024-11-30T21:17:07.762199',\n",
" \"columns\": {\n",
" \"monochromatorPhotonEnergy\": {\n",
" \"preserve_mean\": True,\n",
" \"weight\": -1,\n",
" },\n",
" \"tofVoltage\": {\n",
" \"preserve_mean\": True,\n",
" \"weight\": -1,\n",
" },\n",
" },\n",
" },\n",
" },\n",
"}"
]
},
{
Expand Down Expand Up @@ -275,7 +281,7 @@
"axes = ['energy', 'delayStage']\n",
"ranges = [[-37.5,-27.5], [-1.5,1.5]]\n",
"bins = [200,60]\n",
"res_corr = sp_44498.compute(bins=bins, axes=axes, ranges=ranges, normalize_to_acquisition_time=\"delayStage\")"
"res_corr = sp_44498.compute(bins=bins, axes=axes, ranges=ranges)"
]
},
{
Expand Down

0 comments on commit 02d8a71

Please sign in to comment.