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
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Branches
* ``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
=======
Expand Down
Binary file added data/continuous_spectra.h5
Binary file not shown.
Binary file added data/scan_photodiode.h5
Binary file not shown.
Binary file added data/spectrum_naverage200.h5
Binary file not shown.
287 changes: 287 additions & 0 deletions notebooks/01_data_objects.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Module C, sequence 1: the data objects (exercises)\n",
"\n",
"Replace each `...` by what its comment asks, then run the cell. The steps follow the TP 1 of the handout of the module C. The corrected notebook is in the branch `correction-module-c`."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"import numpy as np\n",
"from pymodaq_utils.math_utils import gauss1D\n",
"from pymodaq_data import Q_\n",
"from pymodaq_data.data import Axis, DataRaw, DataToExport"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 0. A minimal example\n",
"\n",
"A data object holds a **list** of NumPy arrays of the same shape (one per channel), their axes, their labels and\n",
"their units. Here, five values of one detector measured at five positions of an actuator. Read it, run it, then\n",
"build your own data in the next cells."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
"position = Axis('position', 'mm', data=np.array([0., 1., 2., 3., 4.]), index=0) # index: the dimension of the array\n",
"minimal = DataRaw('minimal', data=[np.array([0.1, 0.4, 1.0, 0.4, 0.1])], axes=[position],\n",
" labels=['detector'], units='V')\n",
"print(minimal)\n",
"print(minimal.axes[0].label, minimal.axes[0].units, minimal.axes[0].get_data())\n",
"print(minimal.labels, minimal.units, minimal.data[0])"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Build the line\n",
"\n",
"The profile of a spectral line seen by the photodiode: 121 points from 500 to 560 nm, a gaussian centred at 528 nm,\n",
"4 nm wide at half maximum (`gauss1D(x, x0, fwhm)`), 3 V high, on a background of 0.1 V."
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"exercise"
]
},
"source": [
"wavelength = Axis('wavelength', ..., data=..., index=0) # units 'nm', 121 points from 500 to 560 nm (hint: np.linspace)\n",
"signal = 3 * gauss1D(..., 528, 4) + 0.1 # computed on the values of the axis (hint: get_data())\n",
"line = DataRaw('line', data=..., axes=..., labels=['photodiode'], units=...) # data and axes are lists\n",
"print(line)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. A linear axis does not store its array"
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"exercise"
]
},
"source": [
"print(...) # the `data` attribute of `wavelength`: why is it None?\n",
"print(...) # the first three values of the array of `wavelength`"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Navigation and signal axes"
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"exercise"
]
},
"source": [
"print(line.dim, ..., ..., ...) # the shape, the navigation indexes and the signal indexes of `line`\n",
"assert len(...) == 0 # `line` has no navigation axis"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Plot with the PyMoDAQ viewer (needs a display)\n",
"\n",
"Find the centre of the line with the mouse."
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"exercise"
]
},
"source": [
"%gui qt\n",
"line.plot(...) # plot `line` in the PyMoDAQ viewer (Qt)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Slicing by values and by indices"
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"exercise"
]
},
"source": [
"by_value = line.vsig[...] # keep the points from 515 nm to 540 nm (vsig: by axis values, on the signal axis)\n",
"by_index = line.isig[...] # keep the ten first points (isig: by indices, on the signal axis)\n",
"print(by_value.shape, by_value.axes[0].get_data()[[0, -1]])\n",
"print(by_index.shape)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Units: remove the background"
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"exercise"
]
},
"source": [
"try:\n",
" ... # subtract the bare number 0.1 from `line`\n",
"except Exception as e:\n",
" print(type(e).__name__, e) # read the error\n",
"no_bkg = line - ... # subtract a background of 0.1 V (hint: Q_)\n",
"no_bkg.name = 'line_no_bkg'\n",
"print(no_bkg.units, no_bkg.data[0].max())"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7. The axis in eV (on a copy)"
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"exercise"
]
},
"source": [
"line_ev = ... # an independent copy of `line` (hint: deepcopy)\n",
"line_ev.axes[0] = line.axes[0].units_as(..., inplace=..., context=...) # in eV, without modifying `line`\n",
"print(line.axes[0].units, line.axes[0].get_data()[[0, -1]])\n",
"print(line_ev.axes[0].units, line_ev.axes[0].get_data()[[0, -1]])"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 8. Errors follow the slicing"
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"exercise"
]
},
"source": [
"line.errors = [...] # an uncertainty of 0.05 V on each of the 121 points (a list of arrays, like `data`)\n",
"cropped = line.vsig[515.:540.]\n",
"print(cropped.errors[0].shape == ...) # the errors have the same shape as the data"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 9. Gather in a DataToExport"
]
},
{
"cell_type": "code",
"metadata": {
"tags": [
"exercise"
]
},
"source": [
"mesure = DataToExport('mesure', data=...) # holding `line` and `no_bkg`\n",
"print(...) # get back `line` from `mesure` by its name (hint: get_data_from_name)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Control question 1\n",
"\n",
"What is the difference between `line.vsig[515.:540.]` and `line.isig[10:60]` for this axis from 500 to 560 nm with\n",
"a step of 0.5 nm? Check your answer in a cell below."
]
},
{
"cell_type": "code",
"metadata": {},
"source": [
""
],
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading