.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_auto_tutorials_1D_datasets_plot_1_1D.py:
1D{1,1} datasets
----------------
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.
.. code-block:: default
import matplotlib.pyplot as plt
import numpy as np
import csdmpy as cp
Let's generate two 1D NumPy arrays as the dependent variables of as our dataset.
.. code-block:: default
test_data1 = np.zeros(500)
test_data1[250] = 1
test_data2 = np.zeros(500)
test_data2[150] = 1
Create the two DependentVariable objects from the numpy objects.
.. code-block:: default
dv1 = cp.as_dependent_variable(test_data1, unit="%")
dv2 = cp.as_dependent_variable(test_data2, unit="J")
Create the corresponding dimension object. Here, we create a LinearDimension object.
.. code-block:: default
dim = cp.LinearDimension(count=500, increment="43 cm", coordinates_offset="-0.1 km")
Creating the CSDM object.
.. code-block:: default
csdm_object = cp.CSDM(dependent_variables=[dv1, dv2], dimensions=[dim])
Plot of the dataset.
.. code-block:: default
plt.figure(figsize=(5, 3.5))
ax = plt.gca(projection="csdm")
ax.plot(csdm_object)
plt.tight_layout()
plt.show()
.. image:: /auto_tutorials/1D_datasets/images/sphx_glr_plot_1_1D_001.png
:alt: plot 1 1D
:class: sphx-glr-single-img
To serialize the file, use the save method.
.. code-block:: default
csdm_object.save("1D_11_dataset.csdf")
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 0.183 seconds)
.. _sphx_glr_download_auto_tutorials_1D_datasets_plot_1_1D.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: plot_1_1D.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_1_1D.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_