From 810dea0c4167ed02e039e95147f9676dc6505185 Mon Sep 17 00:00:00 2001 From: rettigl Date: Fri, 8 Mar 2024 17:19:53 +0100 Subject: [PATCH] update notebook and example config --- sed/config/flash_example_config.yaml | 2 - tutorial/4_hextof_workflow.ipynb | 98 ++++++++++++++++++--- tutorial/hextof_config.yaml | 122 --------------------------- 3 files changed, 84 insertions(+), 138 deletions(-) delete mode 100644 tutorial/hextof_config.yaml diff --git a/sed/config/flash_example_config.yaml b/sed/config/flash_example_config.yaml index 25f46ef1..89021864 100644 --- a/sed/config/flash_example_config.yaml +++ b/sed/config/flash_example_config.yaml @@ -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 diff --git a/tutorial/4_hextof_workflow.ipynb b/tutorial/4_hextof_workflow.ipynb index dcda5d45..9da996e3 100644 --- a/tutorial/4_hextof_workflow.ipynb +++ b/tutorial/4_hextof_workflow.ipynb @@ -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\")" ] }, { @@ -102,7 +102,7 @@ " \"data_parquet_dir\": \"/asap3/flash/gpfs/pg2/2023/data/11019101/parquet\"\n", " },\n", " },\n", - "}\n" + "}" ] }, { @@ -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": {}, @@ -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)" ] }, { @@ -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": {}, @@ -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, @@ -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", @@ -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", ")" ] }, @@ -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])" @@ -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)" ] }, @@ -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])" ] }, @@ -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\")" ] }, { @@ -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])" ] }, diff --git a/tutorial/hextof_config.yaml b/tutorial/hextof_config.yaml deleted file mode 100644 index 1bf7b481..00000000 --- a/tutorial/hextof_config.yaml +++ /dev/null @@ -1,122 +0,0 @@ -core: - loader: flash - beamtime_id: 11013410 - year: 2023 - beamline: pg2 - instrument: hextof - paths: - data_raw_dir: "/path/to/data" - # change this to a local directory where you want to store the parquet files - data_parquet_dir: "/path/to/parquet" - -binning: - num_cores: 50 - -dataframe: - ubid_offset: 5 - daq: fl1user3 - forward_fill_iterations: 2 - split_sector_id_from_dld_time: True - sector_id_reserved_bits: 3 - x_column: dldPosX - corrected_x_column: "X" - kx_column: "kx" - y_column: dldPosY - corrected_y_column: "Y" - ky_column: "ky" - tof_column: dldTimeSteps - tof_ns_column: dldTime - corrected_tof_column: "tm" - bias_column: "sampleBias" - tof_binwidth: 2.0576131995767355E-11 # in seconds - tof_binning: 3 - sector_id_column: dldSectorID - sector_delays: [0., 0., 0., 0., 0., 0., 0., 0.] - jitter_cols: ["dldPosX", "dldPosY", "dldTimeSteps"] - delay_column: delayStage - - units: - dldPosX: 'step' - dldPosY: 'step' - dldTimeSteps: 'step' - tof_voltage: 'V' - extractorVoltage: 'V' - extractorCurrent: 'A' - cryoTemperature: 'K' - sampleTemperature: 'K' - dldTime: 'ns' - # delay: 'ps' - timeStamp: 's' - # energy: 'eV' - # E: 'eV' - kx: '1/A' - ky: '1/A' - - channels: - timeStamp: - format: per_train - group_name: "/uncategorised/FLASH.DIAG/TIMINGINFO/TIME1.BUNCH_FIRST_INDEX.1/" - pulseId: - format: per_electron - group_name: "/uncategorised/FLASH.EXP/HEXTOF.DAQ/DLD1/" - slice: 2 - dldPosX: - format: per_electron - group_name: "/uncategorised/FLASH.EXP/HEXTOF.DAQ/DLD1/" - slice: 1 - dldPosY: - format: per_electron - group_name: "/uncategorised/FLASH.EXP/HEXTOF.DAQ/DLD1/" - slice: 0 - dldTimeSteps: - format: per_electron - group_name: "/uncategorised/FLASH.EXP/HEXTOF.DAQ/DLD1/" - slice: 3 - dldAux: - format: per_pulse - group_name : "/uncategorised/FLASH.EXP/HEXTOF.DAQ/DLD1/" - slice: 4 - dldAuxChannels: - sampleBias: 0 - tofVoltage: 1 - extractorVoltage: 2 - extractorCurrent: 3 - cryoTemperature: 4 - sampleTemperature: 5 - crystalVoltage: 6 - dldTimeBinSize: 15 - pulserSignAdc: # ADC containing the pulser sign (1: value approx. 35000, 0: 33000) - format: per_pulse - group_name: "/FL1/Experiment/PG/SIS8300 100MHz ADC/CH6/TD/" - #slice: 0 - monochromatorPhotonEnergy: - format: per_train - group_name: "/FL1/Beamlines/PG/Monochromator/monochromator photon energy/" - gmdBda: # The GMDs can not be read yet... - format: per_train - group_name: "/FL1/Photon Diagnostic/GMD/Average energy/energy BDA/" - # slice: ":" - #gmdTunnel: # The GMDs can not be read yet... - # format: per_pulse - # group_name: "/FL1/Photon Diagnostic/GMD/Pulse resolved energy/energy tunnel/" - # slice: ":" - bam: # Here we use the DBC2 BAM as the "normal" one is broken. - format: per_pulse - group_name: "/uncategorised/FLASH.SDIAG/BAM.DAQ/FL0.DBC2.ARRIVAL_TIME.ABSOLUTE.SA1.COMP/" - delayStage: - format: per_train - group_name: "/zraw/FLASH.SYNC/LASER.LOCK.EXP/F1.PG.OSC/FMC0.MD22.1.ENCODER_POSITION.RD/dGroup/" - - stream_name_prefixes: - pbd: "GMD_DATA_gmd_data" - pbd2: "FL2PhotDiag_pbd2_gmd_data" - fl1user1: "FLASH1_USER1_stream_2" - fl1user2: "FLASH1_USER2_stream_2" - fl1user3: "FLASH1_USER3_stream_2" - fl2user1: "FLASH2_USER1_stream_2" - fl2user2: "FLASH2_USER2_stream_2" - - beamtime_dir: - pg2: "/asap3/flash/gpfs/pg2/" - hextof: "/asap3/fs-flash-o/gpfs/hextof/" - wespe: "/asap3/fs-flash-o/gpfs/wespe/"