diff --git a/README.rst b/README.rst index 418161c..c5482c2 100644 --- a/README.rst +++ b/README.rst @@ -19,19 +19,6 @@ PyMoDAQ Plugins Teaching PyMoDAQ plugins developed specifically to teach how to create new plugins -Branches -======== - -* ``main``: the skeleton of ``pymodaq_plugins_template`` (plugins to complete) and the wrappers of the ``hardware`` folder - that the trainees use. This is the starting point of the exercises. -* ``correction-module-a``: the solution of the module A (``DAQ_Move_Monochromator``, - ``DAQ_0DViewer_PhotodiodeMonochromator``, ``DAQ_1DViewer_Spectrometer``). -* ``correction-module-b``: the solution of the modules A and B (adds the beam profiler plugin, app and extension). -* ``correction-module-c``: the corrected notebooks of the module C. - -The module C (data and analysis) uses the notebooks of the ``notebooks`` folder (to complete: replace each ``...``) -and the measurement files of the ``data`` folder. - Authors ======= @@ -65,3 +52,17 @@ Viewer2D ViewerND ++++++++ + + +Branches +======== + +* ``main``: the skeleton of ``pymodaq_plugins_template`` (plugins to complete) and the wrappers of the ``hardware`` folder + that the trainees use. This is the starting point of the exercises. +* ``correction-module-a``: the solution of the module A (``DAQ_Move_Monochromator``, + ``DAQ_0DViewer_PhotodiodeMonochromator``, ``DAQ_1DViewer_Spectrometer``). +* ``correction-module-b``: the solution of the modules A and B (adds the beam profiler plugin, app and extension). +* ``correction-module-c``: the corrected notebooks of the module C. + +The module C (data and analysis) uses the notebooks of the ``notebooks`` folder (to complete: replace each ``...``) +and the measurement files of the ``data`` folder. diff --git a/notebooks/02_saving_loading.ipynb b/notebooks/02_saving_loading.ipynb index a52e29f..c93861b 100644 --- a/notebooks/02_saving_loading.ipynb +++ b/notebooks/02_saving_loading.ipynb @@ -73,9 +73,8 @@ ] }, "source": [ - "loader = ... # open the file at `path` for reading (hint: DataLoader, imported above)\n", - "loaded = ... # load everything under '/RawData', as a DataToExport (hint: loader.load_all)\n", - "loader.close_file()\n", + "with ... as loader: # open the file at `path` for reading (hint: DataLoader, imported above; the file is closed at the end of the block)\n", + " loaded = ... # load everything under '/RawData', as a DataToExport (hint: loader.load_all)\n", "back = ... # the data named 'line' (hint: get_data_from_name)\n", "print(...) # is it equal to `line` (hint: ==)? Print also its axes and its errors" ], @@ -103,11 +102,10 @@ "path_one = Path('line_alone.h5')\n", "with DataSaverLoader(path_one, new_file=True) as saver:\n", " ... # save `line` in the group '/RawData' (hint: saver.add_data)\n", - "loader = DataLoader(path_one)\n", - "for node in loader.walk_nodes('/'):\n", - " print(node)\n", - "alone = ... # load the data node '/RawData/Data00' (hint: loader.load_data)\n", - "loader.close_file()\n", + "with DataLoader(path_one) as loader:\n", + " for node in loader.walk_nodes('/'):\n", + " print(node)\n", + " alone = ... # load the data node '/RawData/Data00' (hint: loader.load_data)\n", "print(alone == line)" ], "execution_count": null, @@ -119,7 +117,7 @@ "source": [ "## 3. Read the continuous recording of the DAQ_Viewer (enlargeable arrays)\n", "\n", - "Use your own recording (Do Save in the DAQ_Viewer of the spectrometer), or the file of the `data` folder." + "Use your own recording (the Continuous Save button of the toolbar of the DAQ_Viewer of the spectrometer), or the file of the `data` folder." ] }, { @@ -130,10 +128,9 @@ ] }, "source": [ - "loader = DataLoader(DATA / 'continuous_spectra.h5') # or the path of your own recording\n", - "... # print the nodes of the file and find the enlargeable array, EnlData (hint: loader.walk_nodes('/'))\n", - "spectra = ... # load this array with its navigation axis (hint: load_data, load_all=True)\n", - "loader.close_file()\n", + "with DataLoader(DATA / 'continuous_spectra.h5') as loader: # or the path of your own recording\n", + " ... # print the nodes of the file and find the enlargeable array, EnlData (hint: loader.walk_nodes('/'))\n", + " spectra = ... # load this array with its navigation axis (hint: load_data, load_all=True)\n", "print(spectra.shape[0], 'spectra recorded, shape', spectra.shape)\n", "timestamps = ... # the axis of the dimension 0 (hint: get_axis_from_index)\n", "print(timestamps.label, timestamps.units, timestamps.get_data()[:3])" @@ -145,7 +142,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 4. Mean and standard deviation of the series" + "## 4. Mean and standard error of the series" ] }, { @@ -156,11 +153,10 @@ ] }, "source": [ - "mean_spectrum = ... # the mean over the navigation axis (the acquisitions), as a data object (hint: spectra.mean)\n", - "std_spectrum = spectra.data[0].std(axis=0, ddof=1)\n", + "mean_spectrum = ... # the mean over the acquisitions, with its standard error in `errors` (hint: spectra.mean_with_errors)\n", "wavelength = ... # the values of the signal axis, the dimension 1 (hint: get_axis_from_index, get_data)\n", "i_peak = int(np.argmax(mean_spectrum.data[0]))\n", - "print(wavelength[i_peak], mean_spectrum.data[0][i_peak], std_spectrum[i_peak])" + "print(wavelength[i_peak], mean_spectrum.data[0][i_peak], mean_spectrum.errors[0][i_peak])" ], "execution_count": null, "outputs": [] diff --git a/notebooks/03_analysis.ipynb b/notebooks/03_analysis.ipynb index 509edf0..ac2f7b3 100644 --- a/notebooks/03_analysis.ipynb +++ b/notebooks/03_analysis.ipynb @@ -47,10 +47,9 @@ ] }, "source": [ - "loader = DataLoader(DATA / 'scan_photodiode.h5')\n", - "scan = ... # the data of SCAN, with its navigation axes (hint: loader.load_data(..., load_all=True))\n", - "scan8 = ... # the data of SCAN8, the same way\n", - "loader.close_file()\n", + "with DataLoader(DATA / 'scan_photodiode.h5') as loader:\n", + " scan = ... # the data of SCAN, with its navigation axes (hint: loader.load_data(..., load_all=True))\n", + " scan8 = ... # the data of SCAN8, the same way\n", "print(scan, scan.axes) # compare the shapes and the axes: the Average axis is only in the second one\n", "print(scan8, scan8.axes)" ], @@ -179,8 +178,7 @@ ] }, "source": [ - "n_repeat = scan8.shape[0]\n", - "mean8.errors = ... # the standard error of the mean of the 8 repetitions, a list like `data` (hint: scan8.data[0].std(axis=0, ddof=1))\n", + "mean8 = ... # the mean of the 8 repetitions, with their standard error of the mean in `errors` (hint: scan8.mean_with_errors)\n", "window = ... # crop again between 505 and 555 nm: the errors follow the slicing (hint: vnav)\n", "window.nav_indexes = ()\n", "popt_w, pcov_w = ... # weighted fit (hint: curve_fit with sigma=window.errors[0] and absolute_sigma=True)\n", @@ -257,9 +255,8 @@ ] }, "source": [ - "loader = DataLoader(DATA / 'spectrum_naverage200.h5')\n", - "spectrum = ... # load everything under '/RawData/Detector000' and keep the data named 'Spectrum' (hint: load_all, get_data_from_name)\n", - "loader.close_file()\n", + "with DataLoader(DATA / 'spectrum_naverage200.h5') as loader:\n", + " spectrum = ... # load everything under '/RawData/Detector000' and keep the data named 'Spectrum' (hint: load_all, get_data_from_name)\n", "print(spectrum.errors[0][:3])" ], "execution_count": null, @@ -291,7 +288,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 9. Compare with the standard deviation of the continuous recording" + "## 9. Compare with the standard error of the continuous recording" ] }, { @@ -302,11 +299,10 @@ ] }, "source": [ - "loader = DataLoader(DATA / 'continuous_spectra.h5')\n", - "series = ... # the enlargeable array '/RawData/Detector000/Data1D/CH00/EnlData00', with its navigation axis (hint: load_data)\n", - "loader.close_file()\n", + "with DataLoader(DATA / 'continuous_spectra.h5') as loader:\n", + " series = ... # the enlargeable array '/RawData/Detector000/Data1D/CH00/EnlData00', with its navigation axis (hint: load_data)\n", "n_spectra = series.shape[0]\n", - "sem_series = ... # the standard deviation of the series over the acquisitions, divided by sqrt(n_spectra) (hint: series.data[0].std)\n", + "sem_series = ... # the standard error of the mean of the series over the acquisitions (hint: series.mean_with_errors, then its errors)\n", "i_peak = int(np.argmax(spectrum.data[0]))\n", "print('standard error at the peak, Naverage=200:', spectrum.errors[0][i_peak], ' series:', sem_series[i_peak])\n", "print('standard error far from the peak, Naverage=200:', spectrum.errors[0][:10].mean(), ' series:', sem_series[:10].mean())\n",