.. 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_examples_sparse_plot_1_2D_sparse.py:
Sparse along two dimensions, 2D{1,1} dataset
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The following is an example [#f2]_ of a 2D{1,1} sparse dataset with two-dimensions,
:math:`d=2`, and two, :math:`p=2`, sparse single-component dependent-variables,
where the component is sparsely sampled along two dimensions. The following is an
example of a hypercomplex acquisition of the NMR dataset.
Let's import the CSD model data-file and look at its data structure.
.. code-block:: default
import csdmpy as cp
filename = "https://osu.box.com/shared/static/kaos28g47brtswi6mgsgaap5qlahp1zo.csdf"
sparse_2d = cp.load(filename)
There are two linear dimensions and two single-component sparse dependent variables.
The tuple of the dimension and the dependent variable instances are
.. code-block:: default
x = sparse_2d.dimensions
y = sparse_2d.dependent_variables
The coordinates, viewed only for the first ten coordinates, are
.. code-block:: default
print(x[0].coordinates[:10])
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[ 0. 192. 384. 576. 768. 960. 1152. 1344. 1536. 1728.] us
.. code-block:: default
print(x[1].coordinates[:10])
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
[ 0. 192. 384. 576. 768. 960. 1152. 1344. 1536. 1728.] us
Converting the coordinates to `ms`.
.. code-block:: default
x[0].to("ms")
x[1].to("ms")
**Visualize the dataset**
.. code-block:: default
import matplotlib.pyplot as plt
# split the CSDM object with two dependent variables into two CSDM objects with single
# dependent variables.
cos, sin = sparse_2d.split()
# cosine data
plt.figure(figsize=(5, 3.5))
ax = plt.subplot(projection="csdm")
ax.contourf(cos.real)
plt.tight_layout()
plt.show()
.. image:: /auto_examples/sparse/images/sphx_glr_plot_1_2D_sparse_001.png
:alt: cos
:class: sphx-glr-single-img
.. code-block:: default
# sine data
plt.figure(figsize=(5, 3.5))
ax = plt.subplot(projection="csdm")
ax.contourf(sin.real)
plt.tight_layout()
plt.show()
.. image:: /auto_examples/sparse/images/sphx_glr_plot_1_2D_sparse_002.png
:alt: sin
:class: sphx-glr-single-img
.. rubric:: Citation
.. [#f2] Balsgart NM, Vosegaard T., Fast Forward Maximum entropy reconstruction
of sparsely sampled data., J Magn Reson. 2012, 223, 164-169.
doi: 10.1016/j.jmr.2012.07.002
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 0 minutes 2.012 seconds)
.. _sphx_glr_download_auto_examples_sparse_plot_1_2D_sparse.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_2D_sparse.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_1_2D_sparse.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_