.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/2D_datasets/plot_0_2D.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_tutorials_2D_datasets_plot_0_2D.py: 2D{1} dataset with two linear dimensions ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 6-8 In the following example, we illustrate how one can covert a Numpy array into a CSDM object. Start by importing the Numpy and csdmpy libraries. .. GENERATED FROM PYTHON SOURCE LINES 8-13 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import csdmpy as cp .. GENERATED FROM PYTHON SOURCE LINES 14-15 Let's generate a 2D NumPy array of random numbers as our dataset. .. GENERATED FROM PYTHON SOURCE LINES 15-17 .. code-block:: Python data = np.random.rand(65536).reshape(256, 256) .. GENERATED FROM PYTHON SOURCE LINES 18-19 Create the DependentVariable object from the numpy object. .. GENERATED FROM PYTHON SOURCE LINES 19-21 .. code-block:: Python dv = cp.as_dependent_variable(data, unit="Pa") .. GENERATED FROM PYTHON SOURCE LINES 22-23 Create the two Dimension objects .. GENERATED FROM PYTHON SOURCE LINES 23-31 .. code-block:: Python d0 = cp.LinearDimension( count=256, increment="15.23 µs", coordinates_offset="-1.95 ms", label="t1" ) d1 = cp.LinearDimension( count=256, increment="10 cm", coordinates_offset="-5 m", label="x2" ) .. GENERATED FROM PYTHON SOURCE LINES 32-34 Here, ``d0`` and ``d1`` are LinearDimension objects with 256 points and 15.23 µs and 10 cm as increment. .. GENERATED FROM PYTHON SOURCE LINES 36-37 Creating the CSDM object. .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python csdm_object = cp.CSDM(dependent_variables=[dv], dimensions=[d0, d1]) print(csdm_object.dimensions) .. rst-class:: sphx-glr-script-out .. code-block:: none [LinearDimension(count=256, increment=15.23 µs, coordinates_offset=-1.95 ms, quantity_name=time, label=t1, reciprocal={'quantity_name': 'frequency'}), LinearDimension(count=256, increment=10.0 cm, coordinates_offset=-5.0 m, quantity_name=length, label=x2, reciprocal={'quantity_name': 'wavenumber'})] .. GENERATED FROM PYTHON SOURCE LINES 41-42 Plot of the dataset. .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. code-block:: Python plt.figure(figsize=(5, 3.5)) ax = plt.subplot(projection="csdm") cb = ax.imshow(csdm_object, aspect="auto") plt.colorbar(cb, ax=ax) plt.tight_layout() plt.show() .. image-sg:: /auto_tutorials/2D_datasets/images/sphx_glr_plot_0_2D_001.png :alt: plot 0 2D :srcset: /auto_tutorials/2D_datasets/images/sphx_glr_plot_0_2D_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 50-51 To serialize the file, use the save method. .. GENERATED FROM PYTHON SOURCE LINES 51-52 .. code-block:: Python csdm_object.save("2D_1_dataset.csdf") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.286 seconds) .. _sphx_glr_download_auto_tutorials_2D_datasets_plot_0_2D.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_0_2D.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_0_2D.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_