.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/tutorial_messpy.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_tutorial_messpy.py: Messpy v1 Example ================= This example shows how to load files from MessPy v1, hence it is only of interested for people working with files produced by it. Here we loading a datafile, which used our infrared detection setup. MessPy v1 files are .npz files, which consists of zipped npy (numpy) files. Under the module messpy we a helper class to work with it. We will start with importing the module and the standard tools. .. GENERATED FROM PYTHON SOURCE LINES 14-23 .. code-block:: Python from skultrafast import messpy, dataset, data_io import matplotlib.pyplot as plt import skultrafast print(skultrafast.__version__) plt.rcParams['figure.dpi'] = 130 plt.rcParams['figure.figsize'] = (3.2, 2) plt.rcParams['figure.autolayout'] = True .. rst-class:: sphx-glr-script-out .. code-block:: none 6.0 .. GENERATED FROM PYTHON SOURCE LINES 24-28 The main tool is the `MessPyFile` class. Note the constructor takes all the neccesary information to do the processing. Here I will pass all parameters explictily for documentation proposes. Some of the parameters are infered automatically. .. GENERATED FROM PYTHON SOURCE LINES 28-43 .. code-block:: Python # Get the file location first fname = data_io.get_example_path('messpy') print("Tutorial MessPy-file located at %s" % fname) mpf = messpy.MessPyFile( fname, invert_data=True, # Changes the sign of the data is_pol_resolved=True, # If the data was recored polarization resolved. pol_first_scan='perp', # Polarisation of the first scan valid_channel=1, # Which channel to use, recent IR data always uses 1 # Recent visible data uses 0 ) print(mpf.data.shape) .. rst-class:: sphx-glr-script-out .. code-block:: none Tutorial MessPy-file located at /home/docs/checkouts/readthedocs.org/user_builds/skultrafast/envs/latest/lib/python3.11/site-packages/skultrafast/examples/data/messpyv1_data.npz /home/docs/checkouts/readthedocs.org/user_builds/skultrafast/envs/latest/lib/python3.11/site-packages/skultrafast/messpy.py:174: RuntimeWarning: overflow encountered in cast self.wavenumbers = 1e7 / self.wl (3, 150, 32, 2, 15) .. GENERATED FROM PYTHON SOURCE LINES 44-47 Simlar to TimeResSpec the MessPyFile class has a plotter subclass with various plot methods. For example, the `compare_spec` method plots a averaged spectrum for each central channel recored. .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: Python mpf.plot.compare_spec() .. image-sg:: /auto_examples/images/sphx_glr_tutorial_messpy_001.png :alt: tutorial messpy :srcset: /auto_examples/images/sphx_glr_tutorial_messpy_001.png, /auto_examples/images/sphx_glr_tutorial_messpy_001_1_50x.png 1.50x, /auto_examples/images/sphx_glr_tutorial_messpy_001_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/skultrafast/envs/latest/lib/python3.11/site-packages/numpy/ma/core.py:4450: RuntimeWarning: overflow encountered in multiply self._data.__imul__(other_data) /home/docs/checkouts/readthedocs.org/user_builds/skultrafast/envs/latest/lib/python3.11/site-packages/skultrafast/dataset.py:174: RuntimeWarning: overflow encountered in cast self._wavenumbers = 1e7 / wl .. GENERATED FROM PYTHON SOURCE LINES 51-53 As we can see, the applied wavelength calibration used by messpy was not correct. Let's change that. .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python mpf.recalculate_wavelengths(8.8) mpf.plot.compare_spec() .. image-sg:: /auto_examples/images/sphx_glr_tutorial_messpy_002.png :alt: tutorial messpy :srcset: /auto_examples/images/sphx_glr_tutorial_messpy_002.png, /auto_examples/images/sphx_glr_tutorial_messpy_002_1_50x.png 1.50x, /auto_examples/images/sphx_glr_tutorial_messpy_002_2_00x.png 2.00x :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 58-61 Note that `MessPyFile` uses sigma clipping when averaging the scans. If you want more control over the process, use the `average_scans` method. For example here we change the clipping range and use only the first 5 scans. .. GENERATED FROM PYTHON SOURCE LINES 61-63 .. code-block:: Python mpf.average_scans(sigma=2, max_scan=20); .. rst-class:: sphx-glr-script-out .. code-block:: none {'para0': , 'perp0': , 'iso0': , 'para1': , 'perp1': , 'iso1': , 'para2': , 'perp2': , 'iso2': } .. GENERATED FROM PYTHON SOURCE LINES 64-66 The indivudal datasets, for each polarization and each spectral window can be found in a dict belonging to the class. .. GENERATED FROM PYTHON SOURCE LINES 66-70 .. code-block:: Python for key, ds in mpf.av_scans_.items(): print(key, ds) .. rst-class:: sphx-glr-script-out .. code-block:: none para0 perp0 iso0 para1 perp1 iso1 para2 perp2 iso2 .. GENERATED FROM PYTHON SOURCE LINES 71-72 Now we can work with them directly. For example datasets can be combined manually .. GENERATED FROM PYTHON SOURCE LINES 72-76 .. code-block:: Python iso_merge = mpf.av_scans_['iso0'].concat_datasets(mpf.av_scans_['iso1']) all_iso = iso_merge.concat_datasets(mpf.av_scans_['iso2']) .. GENERATED FROM PYTHON SOURCE LINES 77-79 Since this is quite common, this is also automated by the `avg_and_concat` method. .. GENERATED FROM PYTHON SOURCE LINES 79-83 .. code-block:: Python para, perp, iso = mpf.avg_and_concat() iso.plot.spec(1, 3, 10, n_average=5); .. image-sg:: /auto_examples/images/sphx_glr_tutorial_messpy_003.png :alt: tutorial messpy :srcset: /auto_examples/images/sphx_glr_tutorial_messpy_003.png, /auto_examples/images/sphx_glr_tutorial_messpy_003_1_50x.png 1.50x, /auto_examples/images/sphx_glr_tutorial_messpy_003_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none [, , ] .. GENERATED FROM PYTHON SOURCE LINES 84-92 The spectrum looks a little bit janky now, since after merging the datasets the points in the overlapping regions were seperataly recorded and the noise within a recording is correlated. Hence, while the spectrum looks kind of smooth within a window, the noise difference between the windows makes it unsmooth. There is also a second issue with the merged spectrum: The point density suggests a larger spectral resolution than available. To mitigate both issues, we have to bin down the spectrum. We can either bin uniformly or only merge channels that are too close together. .. GENERATED FROM PYTHON SOURCE LINES 92-107 .. code-block:: Python fig, (ax0, ax1) = plt.subplots(2, figsize=(3, 4), sharex=True) bin_iso = iso.bin_freqs(30) bin_iso.plot.spec(1, 3, 10, n_average=5, marker='o', ax=ax0, ms=3) merge_iso = iso.merge_nearby_channels(8) merge_iso.plot.spec(1, 3, 10, n_average=5, marker='o', ax=ax1, ms=3) # Remove Legend and correct ylabel ax0.legend_ = None ax0.yaxis.label.set_position((0, 0.0)) ax1.legend_ = None ax1.set_ylabel(''); .. image-sg:: /auto_examples/images/sphx_glr_tutorial_messpy_004.png :alt: tutorial messpy :srcset: /auto_examples/images/sphx_glr_tutorial_messpy_004.png, /auto_examples/images/sphx_glr_tutorial_messpy_004_1_50x.png 1.50x, /auto_examples/images/sphx_glr_tutorial_messpy_004_2_00x.png 2.00x :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(73.00000000000001, 0.5, '') .. GENERATED FROM PYTHON SOURCE LINES 108-110 The prefered way to work with are polarisation resolved transient spectra is to use `PolTRSpec`, which takes the two datasets we get from avg_and_concat. .. GENERATED FROM PYTHON SOURCE LINES 110-117 .. code-block:: Python pol_ds = dataset.PolTRSpec(para, perp) merged_ds = pol_ds.merge_nearby_channels(8) merged_ds.plot.spec(1, n_average=4); .. rst-class:: sphx-glr-script-out .. code-block:: pytb Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/skultrafast/checkouts/latest/skultrafast/examples/tutorial_messpy.py", line 113, in merged_ds.plot.spec(1, n_average=4); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docs/checkouts/readthedocs.org/user_builds/skultrafast/envs/latest/lib/python3.11/site-packages/skultrafast/dataset.py", line 1887, in spec l1 = pa.plot.spec(*times, ^^^^^^^^^^^^^^^^^^^^ File "/home/docs/checkouts/readthedocs.org/user_builds/skultrafast/envs/latest/lib/python3.11/site-packages/skultrafast/dataset.py", line 1415, in spec dat = filter.uniform_filter(ds, (2*n_average + 1, 1)).data[idx, :] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docs/checkouts/readthedocs.org/user_builds/skultrafast/envs/latest/lib/python3.11/site-packages/skultrafast/filter.py", line 39, in uniform_filter f = nd.uniform_filter(d, size=sigma, mode="nearest") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/docs/checkouts/readthedocs.org/user_builds/skultrafast/envs/latest/lib/python3.11/site-packages/scipy/ndimage/_filters.py", line 1613, in uniform_filter uniform_filter1d(input, int(size), axis, output, mode, File "/home/docs/checkouts/readthedocs.org/user_builds/skultrafast/envs/latest/lib/python3.11/site-packages/scipy/ndimage/_filters.py", line 1539, in uniform_filter1d _nd_image.uniform_filter1d(input, size, axis, output, mode, cval, RuntimeError: array type dtype('float16') not supported .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.226 seconds) .. _sphx_glr_download_auto_examples_tutorial_messpy.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tutorial_messpy.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tutorial_messpy.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: tutorial_messpy.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_