Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions notebooks/01_data_objects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
]
},
"source": [
"print(...) # the `data` attribute of `wavelength`: why is it None?\n",
"print(...) # the first three values of the array of `wavelength`"
"print(...) # the `data` attribute of `wavelength`: why is it None? (hint: wavelength.data)\n",
"print(...) # the first three values of the array of `wavelength` (hint: get_data())"
],
"execution_count": null,
"outputs": []
Expand All @@ -109,8 +109,8 @@
]
},
"source": [
"print(line.dim, ..., ..., ...) # the shape, the navigation indexes and the signal indexes of `line`\n",
"assert len(...) == 0 # `line` has no navigation axis"
"print(line.dim, ..., ..., ...) # the shape, the navigation indexes and the signal indexes of `line` (hint: shape, nav_indexes, sig_indexes)\n",
"assert len(...) == 0 # `line` has no navigation axis (hint: nav_indexes)"
],
"execution_count": null,
"outputs": []
Expand All @@ -133,7 +133,7 @@
},
"source": [
"%gui qt\n",
"line.plot(...) # plot `line` in the PyMoDAQ viewer (Qt)"
"line.plot(...) # plot `line` in the PyMoDAQ viewer (hint: the backend 'qt')"
],
"execution_count": null,
"outputs": []
Expand Down Expand Up @@ -249,7 +249,7 @@
},
"source": [
"%gui qt\n",
"... # plot `cropped` in the PyMoDAQ viewer"
"... # plot `cropped` in the PyMoDAQ viewer (hint: plot with the backend 'qt')"
],
"execution_count": null,
"outputs": []
Expand Down
20 changes: 10 additions & 10 deletions notebooks/02_saving_loading.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"source": [
"path = Path('line.h5')\n",
"with DataToExportSaver(..., new_file=...) as saver: # the path of the file; overwrite it if it exists\n",
"with DataToExportSaver(..., new_file=...) as saver: # the path of the file; True to 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",
Expand All @@ -73,11 +73,11 @@
]
},
"source": [
"loader = ... # open the file for reading\n",
"loaded = ... # load everything under '/RawData' (a DataToExport)\n",
"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",
"back = ... # the data named 'line'\n",
"print(...) # is it equal to `line`? Print also its axes and its errors"
"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"
],
"execution_count": null,
"outputs": []
Expand All @@ -102,11 +102,11 @@
"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",
" ... # 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'\n",
"alone = ... # load the data node '/RawData/Data00' (hint: loader.load_data)\n",
"loader.close_file()\n",
"print(alone == line)"
],
Expand All @@ -131,7 +131,7 @@
},
"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)\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",
"print(spectra.shape[0], 'spectra recorded, shape', spectra.shape)\n",
Expand All @@ -156,9 +156,9 @@
]
},
"source": [
"mean_spectrum = ... # the mean over the navigation axis (the acquisitions), as a data object\n",
"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",
"wavelength = ... # the values of the signal axis (the wavelengths)\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])"
],
Expand Down
42 changes: 21 additions & 21 deletions notebooks/03_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
},
"source": [
"loader = DataLoader(DATA / 'scan_photodiode.h5')\n",
"scan = ... # the data of SCAN, with its navigation axes\n",
"scan8 = ... # the data of SCAN8, with its navigation axes\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",
"print(scan, scan.axes) # compare the shapes and the axes: the Average axis is only in the second one\n",
"print(scan8, scan8.axes)"
Expand All @@ -72,8 +72,8 @@
]
},
"source": [
"mean8 = ... # the mean over the first navigation axis (the repetitions)\n",
"wavelength = ... # the values of the wavelength axis of mean8\n",
"mean8 = ... # the mean over the first navigation axis, the repetitions (hint: scan8.mean)\n",
"wavelength = ... # the values of the wavelength axis of mean8 (hint: get_axis_from_index, get_data)\n",
"fig, ax = plt.subplots()\n",
"ax.plot(wavelength, scan.data[0], '.', label='one scan')\n",
"ax.plot(wavelength, mean8.data[0], '-', label='mean of 8 scans')\n",
Expand All @@ -100,13 +100,13 @@
]
},
"source": [
"window = ... # mean8 between 505 and 555 nm (by values, on the navigation axis)\n",
"... # declare the navigation axis as a signal axis: `window` becomes a 1D data\n",
"window = ... # mean8 between 505 and 555 nm (hint: vnav: by values, on the navigation axis)\n",
"... # declare the navigation axis as a signal axis: `window` becomes a 1D data (hint: nav_indexes)\n",
"x = window.get_axis_from_index(0)[0].get_data()\n",
"y = window.data[0]\n",
"p0 = [y.max() - y.min(), x[np.argmax(y)], 5., y.min()]\n",
"popt, pcov = ... # fit `model` to (x, y) starting from p0\n",
"perr = ... # the uncertainties of the parameters, from pcov\n",
"popt, pcov = ... # fit `model` to (x, y) starting from p0 (hint: curve_fit)\n",
"perr = ... # the uncertainties of the parameters: square root of the diagonal of pcov\n",
"for name, value, error in zip(['amplitude', 'center (nm)', 'FWHM (nm)', 'offset'], popt, perr):\n",
" print(f'{name}: {value:.3f} +/- {error:.3f}')"
],
Expand All @@ -128,7 +128,7 @@
]
},
"source": [
"fit = ... # fit `window` with `model`, starting from p0, with the method of the data object\n",
"fit = ... # fit `window` with `model`, starting from p0, with the method of the data object (hint: window.fit)\n",
"print(fit.fit_coeffs[0])\n",
"assert np.allclose(fit.fit_coeffs[0], popt, rtol=1e-3) # what is missing compared to curve_fit?"
],
Expand All @@ -153,11 +153,11 @@
]
},
"source": [
"full = ... # a copy of mean8...\n",
"... # ...whose navigation axis is declared as a signal axis\n",
"full = ... # a copy of mean8... (hint: deepcopy)\n",
"... # ...whose navigation axis is declared as a signal axis (hint: nav_indexes)\n",
"x_full = full.get_axis_from_index(0)[0].get_data()\n",
"y_full = full.data[0]\n",
"finite = ... # mask of the finite values: curve_fit refuses NaN (look at np.isnan(scan8.data[0]): what happened?)\n",
"finite = ... # mask of the finite values, curve_fit refuses NaN (hint: np.isfinite; look at np.isnan(scan8.data[0]): what happened?)\n",
"popt_full, pcov_full = curve_fit(model, x_full[finite], y_full[finite], p0=p0)\n",
"print('offset, cropped:', popt[3], ' whole scan:', popt_full[3])"
],
Expand All @@ -180,10 +180,10 @@
},
"source": [
"n_repeat = scan8.shape[0]\n",
"mean8.errors = ... # the standard error of the mean of the 8 repetitions (std with ddof=1, divided by sqrt(8))\n",
"window = ... # crop again between 505 and 555 nm: the errors follow the slicing\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",
"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: sigma from the errors of `window`, absolute_sigma=True\n",
"popt_w, pcov_w = ... # weighted fit (hint: curve_fit with sigma=window.errors[0] and absolute_sigma=True)\n",
"chi2_red = np.sum(((window.data[0] - model(x, *popt_w)) / window.errors[0]) ** 2) / (len(x) - len(popt_w))\n",
"print(popt_w, np.sqrt(np.diag(pcov_w)))\n",
"print('reduced chi2:', chi2_red) # larger than 1: why?"
Expand All @@ -207,7 +207,7 @@
},
"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.errorbar(x, window.data[0], yerr=..., fmt='.', label='mean of 8 scans') # the errors of `window` (hint: window.errors)\n",
"ax.plot(x, model(x, *popt_w), '-', label='weighted fit')\n",
"ax.set_xlabel('wavelength (nm)')\n",
"ax.legend()"
Expand All @@ -230,7 +230,7 @@
]
},
"source": [
"axis_ev = ... # the axis of `window` converted to eV, without modifying it (context 'spectroscopy')\n",
"axis_ev = ... # the axis of `window` converted to eV, without modifying it (hint: units_as, context 'spectroscopy')\n",
"window_ev = window.deepcopy()\n",
"window_ev.axes[0] = axis_ev\n",
"x_ev = axis_ev.get_data()\n",
Expand Down Expand Up @@ -258,7 +258,7 @@
},
"source": [
"loader = DataLoader(DATA / 'spectrum_naverage200.h5')\n",
"spectrum = ... # load everything under '/RawData/Detector000' and keep the data named 'Spectrum'\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",
"print(spectrum.errors[0][:3])"
],
Expand All @@ -282,7 +282,7 @@
"source": [
"%gui qt\n",
"import pymodaq_gui # registers the Qt plotter\n",
"... # plot `spectrum` in the PyMoDAQ viewer"
"... # plot `spectrum` in the PyMoDAQ viewer (hint: plot with the backend 'qt')"
],
"execution_count": null,
"outputs": []
Expand All @@ -303,10 +303,10 @@
},
"source": [
"loader = DataLoader(DATA / 'continuous_spectra.h5')\n",
"series = ... # the enlargeable array '/RawData/Detector000/Data1D/CH00/EnlData00', with its navigation axis\n",
"series = ... # the enlargeable array '/RawData/Detector000/Data1D/CH00/EnlData00', with its navigation axis (hint: load_data)\n",
"loader.close_file()\n",
"n_spectra = series.shape[0]\n",
"sem_series = ... # the standard deviation of the series over the acquisitions, divided by sqrt(n_spectra)\n",
"sem_series = ... # the standard deviation of the series over the acquisitions, divided by sqrt(n_spectra) (hint: series.data[0].std)\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",
Expand Down
Loading