diff --git a/notebooks/01_data_objects.ipynb b/notebooks/01_data_objects.ipynb index 99b49f0..0469732 100644 --- a/notebooks/01_data_objects.ipynb +++ b/notebooks/01_data_objects.ipynb @@ -232,6 +232,28 @@ "execution_count": null, "outputs": [] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Plot `cropped` in the PyMoDAQ viewer (needs a display): the errors are drawn as a band around the line, and the\n", + "**Errors** button of the toolbar shows or hides it." + ] + }, + { + "cell_type": "code", + "metadata": { + "tags": [ + "exercise" + ] + }, + "source": [ + "%gui qt\n", + "... # plot `cropped` in the PyMoDAQ viewer" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/notebooks/02_saving_loading.ipynb b/notebooks/02_saving_loading.ipynb index 5580087..c9c91f3 100644 --- a/notebooks/02_saving_loading.ipynb +++ b/notebooks/02_saving_loading.ipynb @@ -17,8 +17,7 @@ "from pathlib import Path\n", "from pymodaq_utils.math_utils import gauss1D\n", "from pymodaq_data.data import Axis, DataRaw, DataToExport\n", - "from pymodaq_data.h5modules.saving import H5SaverLowLevel\n", - "from pymodaq_data.h5modules.data_saving import DataToExportSaver, DataLoader\n", + "from pymodaq_data.h5modules.data_saving import DataToExportSaver, DataSaverLoader, DataLoader\n", "\n", "DATA = Path('../data')\n", "\n", @@ -50,15 +49,11 @@ }, "source": [ "path = Path('line.h5')\n", - "path.unlink(missing_ok=True) # init_file appends to an existing file\n", - "\n", - "h5saver = H5SaverLowLevel()\n", - "... # create the file at `path`\n", - "... # add a detector group under '/RawData', titled 'Photodiode line'\n", - "... # save `mesure` in the group '/RawData/Detector000' (hint: DataToExportSaver)\n", - "for node in ...: # walk all the nodes of the file, from '/'\n", - " print(node)\n", - "h5saver.close_file()" + "with DataToExportSaver(..., new_file=...) as saver: # the path of the file; overwrite it if it exists\n", + " ... # save `mesure` in the group '/RawData' (hint: add_data)\n", + " for node in saver.h5saver.walk_nodes('/'): # all the nodes of the file: where are the data, the axis, the errors?\n", + " print(node)\n", + "# the file is closed when leaving the `with` block" ], "execution_count": null, "outputs": [] @@ -79,7 +74,7 @@ }, "source": [ "loader = ... # open the file for reading\n", - "loaded = ... # load everything under '/RawData/Detector000' (a DataToExport)\n", + "loaded = ... # load everything under '/RawData' (a DataToExport)\n", "loader.close_file()\n", "back = ... # the data named 'line'\n", "print(...) # is it equal to `line`? Print also its axes and its errors" @@ -87,6 +82,37 @@ "execution_count": null, "outputs": [] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 2 bis. One data alone\n", + "\n", + "`DataSaverLoader` saves one data object (a `DataWithAxes`), `DataToExportSaver` a whole `DataToExport`. Compare the\n", + "nodes with the ones of the part 1." + ] + }, + { + "cell_type": "code", + "metadata": { + "tags": [ + "exercise" + ] + }, + "source": [ + "path_one = Path('line_alone.h5')\n", + "with DataSaverLoader(path_one, new_file=True) as saver:\n", + " ... # save `line` in the group '/RawData'\n", + "loader = DataLoader(path_one)\n", + "for node in loader.walk_nodes('/'):\n", + " print(node)\n", + "alone = ... # load the data node '/RawData/Data00'\n", + "loader.close_file()\n", + "print(alone == line)" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/notebooks/03_analysis.ipynb b/notebooks/03_analysis.ipynb index 5559b1d..2a1e053 100644 --- a/notebooks/03_analysis.ipynb +++ b/notebooks/03_analysis.ipynb @@ -191,6 +191,30 @@ "execution_count": null, "outputs": [] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Plot the averaged data with its error bars and the weighted fit: are the residuals inside the error bars?" + ] + }, + { + "cell_type": "code", + "metadata": { + "tags": [ + "exercise" + ] + }, + "source": [ + "fig, ax = plt.subplots()\n", + "ax.errorbar(x, window.data[0], yerr=..., fmt='.', label='mean of 8 scans') # the errors of `window`\n", + "ax.plot(x, model(x, *popt_w), '-', label='weighted fit')\n", + "ax.set_xlabel('wavelength (nm)')\n", + "ax.legend()" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -241,6 +265,28 @@ "execution_count": null, "outputs": [] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Plot the spectrum with its errors in the PyMoDAQ viewer (needs a display): where is the band the widest?" + ] + }, + { + "cell_type": "code", + "metadata": { + "tags": [ + "exercise" + ] + }, + "source": [ + "%gui qt\n", + "import pymodaq_gui # registers the Qt plotter\n", + "... # plot `spectrum` in the PyMoDAQ viewer" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "markdown", "metadata": {},