{ "cells": [ { "cell_type": "markdown", "id": "28d17496", "metadata": {}, "source": [ "# Extracting datasets to do specialised plots\n", "\n", "## Description\n", "giwaxs_toolbox also has functions to extract the 1d or 2d datasets from i07 processed files which can then be used in personalised plots\n", "\n", "first create a data loader using the following syntax:\n", "\n", "```python\n", "from giwaxs_toolbox.processing import data_loader\n", "loader = data_loader(datafolder='path/to/your/data')\n", "```\n", "\n", "Once you have a data loader for your data folder you can extract a series of datasets using the syntax:\n", "\n", "```python\n", "filelist=['file1','file2','file3']\n", "results= loader.loadfiles(filelist)\n", "```\n", "\n", "This will then give you a list of your datasets, each of which will either be of the type result1d or result2d. These result objects have the following attributes:\n", "\n", "result1d\n", "\n", "```python\n", "result1d.data # the one dimensional profile data\n", "result1d.x_axis # the axis data for the x-axis\n", "```\n", "\n", "result2d\n", "\n", "```python\n", "result2d.data # the two dimensional image data\n", "result2d.x_axis # the axis data for the x-axis\n", "result2d.y_axis # the axis data for the y-axis\n", "```" ] }, { "cell_type": "markdown", "id": "53431dfe", "metadata": {}, "source": [ "# Load in 1d datasets" ] }, { "cell_type": "code", "execution_count": null, "id": "88bf6c93", "metadata": {}, "outputs": [], "source": [ "from giwaxs_toolbox.processing import data_loader\n", "from giwaxs_toolbox.plotting import reset_plots\n", "import matplotlib.pyplot as plt\n", "from pprint import pprint\n", "import numpy as np\n", "import os" ] }, { "cell_type": "code", "execution_count": null, "id": "a3471a07", "metadata": {}, "outputs": [], "source": [ "folder1=\"/dls/science/groups/das/ExampleData/i07/fast_rsm_example_data/tests_versioned/v2.4.1_i07_2026-04-14\"\n", "filelist= [file for file in os.listdir(folder1) if file.endswith('.hdf5')]\n", "\n", "#create your data loader for your data directory path\n", "loader=data_loader(datafolder=folder1)\n", "\n", "#choose which datasets you want to load\n", "\n", "example_ivqfiles=['IvsQ_432196_2026-04-14_14h19m06s.hdf5',\n", " 'IvsQ_610009_2026-04-14_14h22m41s.hdf5']\n", "\n", "# load the files into a results object\n", "ivqresults=loader.loadfiles(example_ivqfiles,index1vals= np.arange(0,100,10))" ] }, { "cell_type": "markdown", "id": "e4c71b13", "metadata": {}, "source": [ "You can then use the results objects in your plotting routines, as shown below using the attributes '.x_axis' and '.data'" ] }, { "cell_type": "code", "execution_count": null, "id": "953921a2", "metadata": {}, "outputs": [], "source": [ "#set interactive ipympl\n", "%matplotlib ipympl\n", "\n", "#create your figure\n", "fig,axs=plt.subplots(figsize=(10,4))\n", "\n", "#use the result objects from the results list to plot onto the graph\n", "for num,res in enumerate(ivqresults):\n", " axs.semilogy(res.x_axis,res.data,label=example_ivqfiles[num])\n", "\n", "axs.axvline(2,ls='--')\n", "axs.axvline(6,ls='--',color='red')\n", "plt.legend()\n", "plt.show" ] }, { "cell_type": "markdown", "id": "b6c2d0c6", "metadata": {}, "source": [ "This will give the example plot \n", "\n", "![image2.png](../images/bespoke_ivsq.png)" ] }, { "cell_type": "markdown", "id": "06ceb0e5", "metadata": {}, "source": [ "## loading in 2d datasets\n", "You can do the same process for 2d datasets as well, below is an example using the result2d objects along with extra plotting shapes for customised plots" ] }, { "cell_type": "code", "execution_count": null, "id": "fded56bd", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "from matplotlib.patches import Annulus, Wedge\n", "\n", "\n", "#create your data loader for your data directory path, note if the 2d datasets are in the same folder as the 1d datasets the loader from the previous section can be reused\n", "loader=data_loader(datafolder=folder1)\n", "\n", "\n", "#choose which datasets you want to load\n", "exitmap_filenames=['exitmap_432196_2026-04-14_14h19m03s.hdf5','exitmap_610009_2026-04-14_14h22m49s.hdf5']\n", "\n", "# load the files into a results object\n", "exitmapresults=loader.loadfiles(exitmap_filenames)" ] }, { "cell_type": "code", "execution_count": null, "id": "540adb65", "metadata": {}, "outputs": [], "source": [ "fig,axs=plt.subplots(1,2,figsize=(10,4))\n", "\n", "axlist=axs.flatten()\n", "for i,res in enumerate(exitmapresults):\n", " maplimits=[res.x_axis.min(), res.x_axis.max(), res.y_axis.min(),res.y_axis.max()]\n", " map2d=res.data\n", " axlist[i].imshow(map2d,vmax=map2d.mean()+2*map2d.std(),extent=maplimits,alpha=0.95)\n", " #axlist[i].set_aspect('equal')\n", " axlist[i].set_xlabel('exit_para (deg)')\n", " axlist[i].set_ylabel('exit_perp (deg)')\n", "\n", "selection_ring=Annulus((0,0), 15, 1.25,color='red',alpha=0.55)\n", "selection_wedge = Wedge((0.0),40,40,60,color='red',alpha=0.5)\n", "axlist[0].add_patch(selection_ring)\n", "axlist[1].add_patch(selection_wedge)\n", "plt.tight_layout()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "f7a1422c", "metadata": {}, "source": [ "Similar to the previous example this will output a specialised plot using the loaded data result objects\n", "\n", "![image4.png](../images/bespoke_qmap.png)\n" ] }, { "cell_type": "markdown", "id": "86a55192", "metadata": {}, "source": [ "# Using supplementary data\n", "\n", "If you have supplementary data saved in your output file (e.g. adc1, adc2 values) this will be available in the loaded result object to plot\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "2a37c589", "metadata": {}, "outputs": [], "source": [ "from giwaxs_toolbox.processing import data_loader\n", "from giwaxs_toolbox.plotting import reset_plots, plot_1d_profile\n", "import matplotlib.pyplot as plt\n", "from pprint import pprint\n", "import numpy as np\n", "import os\n" ] }, { "cell_type": "code", "execution_count": null, "id": "78eb80c0", "metadata": {}, "outputs": [], "source": [ "#folder1=\"/dls/science/groups/das/ExampleData/i07/fast_rsm_example_data/tests_versioned/v2.4.1_i07_2026-04-14\"\n", "folder1=\"/dls/science/groups/das/ExampleData/i07/fast_rsm_example_data/tests_local/local_i07_2026-07-10\"\n", "\n", "#create your data loader for your data directory path\n", "loader1=data_loader(datafolder=folder1)\n", "\n", "#choose which datasets you want to load\n", "example_ivqfiles=['IvsQ_652795_2026-07-10_14h59m28s.hdf5']\n", "\n", "#you can select the number of the dataset you want to load from the stack of datasets, if not speficied the loader will load the first dataset in the stack by default.\n", "selection_num = 500\n", "\n", "# load the files into a results object\n", "ivqresult1=loader1.loadfiles([example_ivqfiles[0]], index1vals=[selection_num])" ] }, { "cell_type": "code", "execution_count": null, "id": "7e39994c", "metadata": {}, "outputs": [], "source": [ "fig,ax = plt.subplots(2,1)\n", "for i,res in enumerate([ivqresult1[0]]):\n", " plot_1d_profile(\n", " res.data,\n", " res.x_axis,\n", " example_ivqfiles[i],\n", " fig,\n", " ax[0],\n", " logscale=False,\n", " axlabels=[res.data_name, res.x_axis_name],\n", " label = 'adc1: ' +str(round(ivqresult1[0].supplementary_data['adc1'][selection_num],4))\n", " )\n", "\n", "ax[0].legend()\n", "\n", "#here you can plot supplementary data if it is available, for example the adc1 value \n", "ax[1].plot(ivqresult1[0].supplementary_data['adc1'][:])\n", "ax[1].axvline(selection_num, ls='--')\n", "plt.tight_layout()" ] }, { "cell_type": "markdown", "id": "13d5bc58", "metadata": {}, "source": [ "Similar to the previous example this will output a specialised plot using the loaded data result objects, as well as a second plot showing the supplementary data (in this case the adc1 value) for the selected dataset.\n", "\n", "![image5.png](../images/supplementary_plot.png)" ] }, { "cell_type": "code", "execution_count": null, "id": "d065d938", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "testoolbox (3.12.8.final.0)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.8" } }, "nbformat": 4, "nbformat_minor": 5 }