PK F+XwNt t 1D_1_examples/plot_0_gmsl.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Global Mean Sea Level rise dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following dataset is the Global Mean Sea Level (GMSL) rise from the late\n19th to the Early 21st Century [#f0]_. The\n[original dataset](http://www.cmar.csiro.au/sealevel/sl_data_cmar.html) was\ndownloaded as a CSV file and subsequently converted to the CSD model format.\n\nLet's import this file.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/gmsl/GMSL.csdf\"\nsea_level = cp.load(filename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The variable `filename` is a string with the address to the `.csdf` file.\nThe :meth:`~csdmpy.load` method of the `csdmpy` module reads the\nfile and returns an instance of the `csdm_api` class, in\nthis case, as a variable ``sea_level``. For a quick preview of the data\nstructure, use the :attr:`~csdmpy.CSDM.data_structure` attribute of this\ninstance.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(sea_level.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
Warning
The serialized string from the :attr:`~csdmpy.CSDM.data_structure`\n attribute is not the same as the JSON serialization on the file.\n This attribute is only intended for a quick preview of the data\n structure and avoids displaying large datasets. Do not use\n the value of this attribute to save the data to the file. Instead, use the\n :meth:`~csdmpy.CSDM.save` method of the `CSDM `\n class.
\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The tuple of the dimensions and dependent variables, from this example, are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = sea_level.dimensions\ny = sea_level.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"respectively. The coordinates along the dimension and the\ncomponent of the dependent variable are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].coordinates)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[0].components[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"respectively.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Plotting the data**\n\nNote
The following code is only for illustrative purposes. The users may use\n any plotting library to visualize their datasets.
\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nplt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\n\n# csdmpy is compatible with matplotlib function. Use the csdm object as the argument\n# of the matplotlib function.\nax.plot(sea_level)\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following is a quick description of the above code. Within the code, we\nmake use of the csdm instance's attributes in addition to the matplotlib\nfunctions. The first line is an import call for the matplotlib functions.\nThe following line generates a plot of the coordinates along the\ndimension verse the component of the dependent variable.\nThe next line sets the x-range. For labeling the axes,\nuse the :attr:`~csdmpy.Dimension.axis_label` attribute\nof both dimension and dependent variable instances. For the figure title,\nuse the :attr:`~csdmpy.DependentVariable.name` attribute\nof the dependent variable instance. The next statement adds the grid lines.\nFor additional information, refer to [Matplotlib](https://matplotlib.org)\ndocumentation.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. seealso::\n `getting_started`\n\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. rubric:: Citation\n\n.. [#f0] Church JA, White NJ. Sea-Level Rise from the Late 19th to the Early 21st\n Century. Surveys in Geophysics. 2011;32:585\u2013602. DOI:10.1007/s10712-011-9119-1.\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+XYPSi
1D_1_examples/plot_6_Mass.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Mass spectrometry (sparse) dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following mass spectrometry data of acetone is an example of a sparse dataset.\nHere, the CSDM data file holds a sparse dependent variable. Upon import, the\ncomponents of the dependent variable sparsely populates the coordinate grid. The\nremaining unpopulated coordinates are assigned a zero value.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nimport csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/MassSpec/acetone.csdf\"\nmass_spec = cp.load(filename)\nprint(mass_spec.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here, the coordinates along the dimension are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(mass_spec.dimensions[0].coordinates)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and the corresponding components of the dependent variable,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(mass_spec.dependent_variables[0].components[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note, only eight values were listed in the dependent variable's `components`\nattribute in the `.csdf` file. The remaining component values were set to zero.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\nax.plot(mass_spec)\nplt.tight_layout()\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+X=
1D_1_examples/plot_3_GS.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Gas Chromatography dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following\n[Gas Chromatography dataset](http://wwwchem.uwimona.edu.jm/spectra/index.html)\nwas obtained as a JCAMP-DX file, and subsequently converted to the CSD model\nfile-format. The data structure of the gas chromatography dataset follows,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nimport csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/GC/cinnamon_base64.csdf\"\nGCData = cp.load(filename)\nprint(GCData.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and the corresponding plot\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\nax.plot(GCData)\nplt.tight_layout()\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+XE $ 1D_1_examples/plot_1_NMR_bloch.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Nuclear Magnetic Resonance (NMR) dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following dataset is a $^{13}\\mathrm{C}$ time-domain NMR Bloch decay\nsignal of ethanol.\nLet's load this data file and take a quick look at its data\nstructure. We follow the steps described in the previous example.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nimport csdmpy as cp\n\ndomain = \"https://www.ssnmr.org/sites/default/files/CSDM\"\nfilename = f\"{domain}/NMR/blochDecay/blochDecay.csdf\"\nNMR_data = cp.load(filename)\nprint(NMR_data.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This particular example illustrates two additional attributes of the CSD model,\nnamely, the :attr:`~csdmpy.CSDM.geographic_coordinate` and\n:attr:`~csdmpy.CSDM.tags`. The `geographic_coordinate` described the\nlocation where the CSDM file was last serialized. You may access this\nattribute through,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(NMR_data.geographic_coordinate)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `tags` attribute is a list of keywords that best describe the dataset.\nThe `tags` attribute is accessed through,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(NMR_data.tags)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You may add additional tags, if so desired, using the `append`\nmethod of python's list class, for example,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"NMR_data.tags.append(\"Bloch decay\")\nprint(NMR_data.tags)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The coordinates along the dimension are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = NMR_data.dimensions\nx0 = x[0].coordinates\nprint(x0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Unlike the previous example, the data structure of an NMR measurement is\na complex-valued dependent variable. The numeric type of the components from\na dependent variable is accessed through the\n:attr:`~csdmpy.DependentVariable.numeric_type` attribute.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"y = NMR_data.dependent_variables\nprint(y[0].numeric_type)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualizing the dataset\n\nIn the previous example, we illustrated a matplotlib script for plotting 1D data.\nHere, we use the csdmpy :meth:`~csdmpy.plot` method, which is a supplementary method\nfor plotting 1D and 2D datasets only.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\nax.plot(NMR_data.real, label=\"real\")\nax.plot(NMR_data.imag, label=\"imag\")\nplt.grid()\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reciprocal dimension object\n\nWhen observing the dimension instance of `NMR_data`,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"notice, the reciprocal keyword. The :attr:`~csdmpy.Dimension.reciprocal`\nattribute is useful for datasets that frequently transform to a reciprocal domain,\nsuch as the NMR dataset. The value of the reciprocal attribute is the reciprocal\nobject, which contains metadata for describing the reciprocal coordinates, such as\nthe `coordinates_offset`, `origin_offset` of the reciprocal dimension.\n\nYou may perform a fourier transform to visualize the NMR spectrum. Use the\n:meth:`~csdmpy.CSDM.fft` method on the csdm object ``NMR_data`` as follows\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fft_NMR_data = NMR_data.fft()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"By default, the unit associated with a dimension after FFT is the reciprocal of the\nunit associated with the dimension before FFT. In this case, the dimension unit after\nFFT is Hz. NMR datasets are often visualized as a dimension frequency scale. To\nconvert the dimension\u2019s unit to ppm use,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fft_NMR_data.dimensions[0].to(\"ppm\", \"nmr_frequency_ratio\")\n\n# plot of the frequency domain data after FFT.\nfig, ax = plt.subplots(1, 2, figsize=(8, 3), subplot_kw={\"projection\": \"csdm\"})\nax[0].plot(fft_NMR_data.real, label=\"real\")\nplt.grid()\nax[1].plot(fft_NMR_data.imag, label=\"imag\")\nplt.grid()\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the above plot, the plot metadata is taken from the reciprocal object such as\nthe x-axis label.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To return to time domain signal, once again use the :meth:`~csdmpy.CSDM.fft` method\non the ``fft_NMR_data`` object. We use the CSDM object's\n:attr:`~csdmpy.CSDM.complex_fft` attribute to determine the FFT ot iFFT operation.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"NMR_data_2 = fft_NMR_data.fft()\n\n# plot of the frequency domain data.\nfig, ax = plt.subplots(1, 2, figsize=(8, 3), subplot_kw={\"projection\": \"csdm\"})\nax[0].plot(NMR_data_2.real, label=\"real\")\nplt.grid()\nax[1].plot(NMR_data_2.imag, label=\"imag\")\nplt.grid()\nplt.tight_layout()\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+X(y 1D_1_examples/plot_4_FTIR.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Fourier Transform Infrared Spectroscopy (FTIR) dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following\n[FTIR dataset](http://wwwchem.uwimona.edu.jm/spectra/index.html),\nwas obtained as a JCAMP-DX file, and subsequently converted to the CSD model\nfile-format. The data structure of the FTIR dataset follows,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nimport csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/ir/caffeine_base64.csdf\"\nFTIR_data = cp.load(filename)\nprint(FTIR_data.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and the corresponding plot.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\nax.plot(FTIR_data)\nax.invert_xaxis()\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Because, FTIR spectrum is conventionally displayed on a reverse axis, an\noptional `reverse_axis` argument is provided to the :meth:`~csdmpy.plot` method.\nIts value is an order list of boolean, corresponding to the order of the\ndimensions.\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+XA!( ( ! 1D_1_examples/plot_5_UV-vis.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Ultraviolet\u2013visible (UV-vis) dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following\n[UV-vis dataset](http://wwwchem.uwimona.edu.jm/spectra/index.html)\nwas obtained as a JCAMP-DX file, and subsequently converted to the CSD model\nfile-format. The data structure of the UV-vis dataset follows,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nimport csdmpy as cp\n\ndomain = \"https://www.ssnmr.org/sites/default/files/CSDM\"\nfilename = f\"{domain}/UV-vis/benzeneVapour_base64.csdf\"\nUV_data = cp.load(filename)\nprint(UV_data.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and the corresponding plot\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\nax.plot(UV_data)\nplt.tight_layout()\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+X^=E E 1D_1_examples/plot_2_EPR.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Electron Paramagnetic Resonance (EPR) dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following is a simulation of the\n[EPR dataset](http://wwwchem.uwimona.edu.jm/spectra/index.html),\noriginally obtained as a JCAMP-DX file, and subsequently converted to the\nCSD model file-format. The data structure of this dataset follows,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nimport csdmpy as cp\n\ndomain = \"https://www.ssnmr.org/sites/default/files/CSDM\"\nfilename = f\"{domain}/EPR/AmanitaMuscaria_base64.csdf\"\nEPR_data = cp.load(filename)\nprint(EPR_data.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and the corresponding plot.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\nax.plot(EPR_data)\nplt.tight_layout()\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+Xj/ / 2D_1_examples/plot_2_TEM.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Transmission Electron Microscopy (TEM) dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following [TEM dataset](https://doi.org/10.1371/journal.pbio.1000502) is\na section of an early larval brain of *Drosophila melanogaster* used in the\nanalysis of neuronal microcircuitry. The dataset was obtained\nfrom the [TrakEM2 tutorial](http://www.ini.uzh.ch/~acardona/data.html) and\nsubsequently converted to the CSD model file-format.\n\nLet's import the CSD model data-file and look at its data structure.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nimport csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/TEM/TEM.csdf\"\nTEM = cp.load(filename)\nprint(TEM.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This dataset consists of two linear dimensions and one single-component\ndependent variable. The tuple of the dimension and the dependent variable\ninstances from this example are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = TEM.dimensions\ny = TEM.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and the respective coordinates (viewed only for the first ten coordinates),\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].coordinates[:10])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].coordinates[:10])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For convenience, let's convert the coordinates from `nm` to `\u00b5m` using the\n:meth:`~csdmpy.Dimension.to` method of the respective `dim_api` instance,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x[0].to(\"\u00b5m\")\nx[1].to(\"\u00b5m\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and plot the data.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\ncb = ax.imshow(TEM, aspect=\"auto\")\nplt.colorbar(cb, ax=ax)\nplt.tight_layout()\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+Xτ#3 $ 2D_1_examples/plot_0_astronomy.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Astronomy dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following dataset is a new observation of the Bubble Nebula\nacquired by [The Hubble Heritage Team](https://archive.stsci.edu/prepds/heritage/bubble/introduction.html),\nin February 2016. The original dataset was obtained in the FITS format\nand subsequently converted to the CSD model file-format. For the convenience of\nillustration, we have downsampled the original dataset.\n\nLet's load the `.csdfe` file and look at its data structure.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nimport csdmpy as cp\n\ndomain = \"https://www.ssnmr.org/sites/default/files/CSDM\"\nfilename = f\"{domain}/BubbleNebula/Bubble_nebula.csdf\"\nbubble_nebula = cp.load(filename)\nprint(bubble_nebula.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here, the variable ``bubble_nebula`` is an instance of the `csdm_api`\nclass. From the data structure, one finds two dimensions, labeled as\n*Right Ascension* and *Declination*, and one single-component dependent\nvariable named *Bubble Nebula, 656nm*.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's get the tuple of the dimension and dependent variable instances from\nthe ``bubble_nebula`` instance following,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = bubble_nebula.dimensions\ny = bubble_nebula.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are two dimension instances in ``x``. Let's look\nat the coordinates along each dimension, using the\n:attr:`~csdmpy.Dimension.coordinates` attribute of the\nrespective instances.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].coordinates[:10])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].coordinates[:10])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here, we only print the first ten coordinates along the respective dimensions.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The component of the dependent variable is accessed through the\n:attr:`~csdmpy.DependentVariable.components` attribute.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"y00 = y[0].components[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Visualize the dataset**\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from matplotlib.colors import LogNorm\n\nplt.figure(figsize=(6, 4.5))\nax = plt.subplot(projection=\"csdm\")\nax.imshow(bubble_nebula, norm=LogNorm(vmin=7.5e-3, clip=True), aspect=\"auto\")\nplt.tight_layout()\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+Xv % 2D_1_examples/plot_1_NMR_satrec.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Nuclear Magnetic Resonance (NMR) dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following example is a $^{29}\\mathrm{Si}$ NMR time-domain\nsaturation recovery measurement of a highly siliceous zeolite ZSM-12.\nUsually, the spin recovery measurements are acquired over a rectilinear grid\nwhere the measurements along one of the dimensions are non-uniform and span several\norders of magnitude. In this example, we illustrate the use of `monotonic`\ndimensions for describing such datasets.\n\nLet's load the file.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/NMR/satrec/satRec.csdf\"\nNMR_2D_data = cp.load(filename)\nprint(NMR_2D_data.description)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The tuples of the dimension and dependent variable instances from the\n``NMR_2D_data`` instance are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = NMR_2D_data.dimensions\ny = NMR_2D_data.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"respectively. There are two dimension instances in this example with respective\ndimension data structures as\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"respectively. The first dimension is uniformly spaced, as indicated by the\n`linear` subtype, while the second dimension is non-linear and monotonically\nsampled. The coordinates along the respective dimensions are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x0 = x[0].coordinates\nprint(x0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x1 = x[1].coordinates\nprint(x1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice, the unit of ``x0`` is in microseconds. It might be convenient to\nconvert the unit to milliseconds. To do so, use the\n:meth:`~csdmpy.Dimension.to` method of the respective\n`dim_api` instance as follows,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x[0].to(\"ms\")\nx0 = x[0].coordinates\nprint(x0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As before, the components of the dependent variable are accessed using the\n:attr:`~csdmpy.DependentVariable.components` attribute.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"y00 = y[0].components[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Visualize the dataset**\n\nThe :meth:`~csdmpy.plot` method is a very basic supplementary function for\nquick visualization of 1D and 2D datasets. You may use this function to plot\nthe data from this example, however, we use the following script to\nvisualize the data with projections onto the respective dimensions.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nfrom matplotlib.image import NonUniformImage\nimport numpy as np\n\n# Set the extents of the image.\n# To set the independent variable coordinates at the center of each image\n# pixel, subtract and add half the sampling interval from the first\n# and the last coordinate, respectively, of the linearly sampled\n# dimension, i.e., x0.\nsi = x[0].increment\nextent = (\n (x0[0] - 0.5 * si).to(\"ms\").value,\n (x0[-1] + 0.5 * si).to(\"ms\").value,\n x1[0].value,\n x1[-1].value,\n)\n\n# Create a 2x2 subplot grid. The subplot at the lower-left corner is for\n# the image intensity plot. The subplots at the top-left and bottom-right\n# are for the data slice at the horizontal and vertical cross-section,\n# respectively. The subplot at the top-right corner is empty.\nfig, axi = plt.subplots(\n 2, 2, gridspec_kw={\"width_ratios\": [4, 1], \"height_ratios\": [1, 4]}\n)\n\n# The image subplot quadrant.\n# Add an image over a rectilinear grid. Here, only the real part of the\n# data values is used.\nax = axi[1, 0]\nim = NonUniformImage(ax, interpolation=\"nearest\", extent=extent, cmap=\"bone_r\")\nim.set_data(x0, x1, y00.real / y00.real.max())\n\n# Set up the grid lines.\nax.add_artist(im)\nfor i in range(x1.size):\n ax.plot(x0, np.ones(x0.size) * x1[i], \"k--\", linewidth=0.5)\nax.grid(axis=\"x\", color=\"k\", linestyle=\"--\", linewidth=0.5, which=\"both\")\n\n# Setup the axes, add the axes labels, and the figure title.\nax.set_xlim([extent[0], extent[1]])\nax.set_ylim([extent[2], extent[3]])\nax.set_xlabel(x[0].axis_label)\nax.set_ylabel(x[1].axis_label)\nax.set_title(y[0].name)\n\n# Add the horizontal data slice to the top-left subplot.\nax0 = axi[0, 0]\ntop = y00[-1].real\nax0.plot(x0, top, \"k\", linewidth=0.5)\nax0.set_xlim([extent[0], extent[1]])\nax0.set_ylim([top.min(), top.max()])\nax0.axis(\"off\")\n\n# Add the vertical data slice to the bottom-right subplot.\nax1 = axi[1, 1]\nright = y00[:, 513].real\nax1.plot(right, x1, \"k\", linewidth=0.5)\nax1.set_ylim([extent[2], extent[3]])\nax1.set_xlim([right.min(), right.max()])\nax1.axis(\"off\")\n\n# Add the colorbar and the component label.\ncbar = fig.colorbar(im, ax=ax1)\ncbar.ax.set_ylabel(y[0].axis_label[0])\n\n# Turn off the axis system for the top-right subplot.\naxi[0, 1].axis(\"off\")\n\nplt.tight_layout(pad=0.0, w_pad=0.0, h_pad=0.0)\nplt.subplots_adjust(wspace=0.025, hspace=0.05)\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+XUek k " 2D_1_examples/plot_3_labeled.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Labeled Dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The CSD model also supports labeled dimensions. In the following example, we\npresent a mixed `linear` and `labeled` two-dimensional dataset representing\nthe population of the country as a function of time. The dataset is obtained from\n[The World Bank](https://data.worldbank.org/indicator/SP.POP.TOTL?view=chart).\n\nImport the `csdmpy` model and load the dataset.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/labeled/population.csdf\"\nlabeled_data = cp.load(filename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The tuple of dimension and dependent variable objects from ``labeled_data`` instance\nare\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = labeled_data.dimensions\ny = labeled_data.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since one of the dimensions is a `labeled` dimension, let's make use of the\n:attr:`~csdmpy.Dimension.type` attribute of the dimension instances\nto find out which dimension is `labeled`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].type)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].type)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here, the second dimension is the `labeled` dimension with [#f1]_\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].count)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"labels, where the first five labels are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].labels[:5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note
For labeled dimensions, the :attr:`~csdmpy.Dimension.coordinates`\n attribute is an alias of the :attr:`~csdmpy.Dimension.labels`\n attribute.
\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].coordinates[:5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The coordinates along the first dimension, viewed up to the first ten\npoints, are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].coordinates[:10])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Plotting the dataset**\n\nYou may plot this dataset however you like. Here, we use a bar graph to\nrepresent the population of countries in the year 2017. The data\ncorresponding to this year is a cross-section of the dependent variable\nat index 57 along the ``x[0]`` dimension.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].coordinates[57])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To keep the plot simple, we only plot the first 20 country labels along\nthe ``x[1]`` dimension.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nimport numpy as np\n\nx_data = x[1].coordinates[:20]\nx_pos = np.arange(20)\ny_data = y[0].components[0][:20, 57]\n\nplt.bar(x_data, y_data, align=\"center\", alpha=0.5)\nplt.xticks(x_pos, x_data, rotation=90)\nplt.ylabel(y[0].axis_label[0])\nplt.yscale(\"log\")\nplt.title(y[0].name)\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. rubric:: Footnotes\n\n.. [#f1] In the CSD model, the attribute count is only valid for the\n `linearDimension_uml`. In `csdmpy`, however, the\n :attr:`~csdmpy.Dimension.count` attribute is valid for all\n dimension objects and returns an integer with the number of grid\n points along the dimension.\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+XT# # , correlated_examples/plot_1_meteorology.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Meteorological, 2D{1,1,2,1,1} dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following dataset is obtained from [NOAA/NCEP Global Forecast System (GFS)\nAtmospheric Model](https://coastwatch.pfeg.noaa.gov/erddap/griddap/NCEP_Global_Best.graph?ugrd10m[(2017-09-17T12:00:00Z)][(-4.5):(52.0)][(275.0):(331.5)]&.draw=surface&.vars=longitude%7Clatitude%7Cugrd10m&.colorBar=%7C%7C%7C%7C%7C&.bgColor=0xffccccff)\nand subsequently converted to the CSD model file-format.\nThe dataset consists of two spatial dimensions describing the geographical\ncoordinates of the earth surface and five dependent variables with\n1) surface temperature, 2) air temperature at 2 m, 3) relative humidity,\n4) air pressure at sea level as the four `scalar` quantity_type dependent\nvariables, and 5) wind velocity as the two-component `vector`, quantity_type\ndependent variable.\n\nLet's import the `csdmpy` module and load this dataset.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import csdmpy as cp\n\ndomain = \"https://www.ssnmr.org/sites/default/files/CSDM\"\nfilename = f\"{domain}/correlatedDataset/forecast/NCEI.csdf\"\nmulti_dataset = cp.load(filename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The tuple of dimension and dependent variable objects from\n``multi_dataset`` instance are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = multi_dataset.dimensions\ny = multi_dataset.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The dataset contains two dimension objects representing the `longitude` and\n`latitude` of the earth's surface. The labels along thee respective dimensions are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].label)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].label)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are a total of five dependent variables stored in this dataset. The first\ndependent variable is the surface air temperature. The data structure of this\ndependent variable is\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[0].data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you have followed all previous examples, the above data structure should\nbe self-explanatory.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will use the following snippet to plot the dependent variables of scalar\n`quantity_type`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1 import make_axes_locatable\n\n\ndef plot_scalar(yx):\n fig, ax = plt.subplots(1, 1, figsize=(6, 3))\n\n # Set the extents of the image plot.\n extent = [\n x[0].coordinates[0].value,\n x[0].coordinates[-1].value,\n x[1].coordinates[0].value,\n x[1].coordinates[-1].value,\n ]\n\n # Add the image plot.\n im = ax.imshow(yx.components[0], origin=\"lower\", extent=extent, cmap=\"coolwarm\")\n\n # Add a colorbar.\n divider = make_axes_locatable(ax)\n cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n cbar = fig.colorbar(im, cax)\n cbar.ax.set_ylabel(yx.axis_label[0])\n\n # Set up the axes label and figure title.\n ax.set_xlabel(x[0].axis_label)\n ax.set_ylabel(x[1].axis_label)\n ax.set_title(yx.name)\n\n # Set up the grid lines.\n ax.grid(color=\"k\", linestyle=\"--\", linewidth=0.5)\n\n plt.tight_layout()\n plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now to plot the data from the dependent variable.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plot_scalar(y[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Similarly, other dependent variables with their respective plots are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[1].name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plot_scalar(y[1])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[3].name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plot_scalar(y[3])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[4].name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plot_scalar(y[4])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice, we skipped the dependent variable at index two. The reason is that\nthis particular dependent variable is a vector dataset,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[2].quantity_type)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[2].name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"which represents the wind velocity, and requires a vector visualization\nroutine. To visualize the vector data, we use the matplotlib quiver plot.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def plot_vector(yx):\n fig, ax = plt.subplots(1, 1, figsize=(6, 3))\n magnitude = np.sqrt(yx.components[0] ** 2 + yx.components[1] ** 2)\n\n cf = ax.quiver(\n x[0].coordinates,\n x[1].coordinates,\n yx.components[0],\n yx.components[1],\n magnitude,\n pivot=\"middle\",\n cmap=\"inferno\",\n )\n divider = make_axes_locatable(ax)\n cax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n cbar = fig.colorbar(cf, cax)\n cbar.ax.set_ylabel(yx.name + \" / \" + str(yx.unit))\n\n ax.set_xlim([x[0].coordinates[0].value, x[0].coordinates[-1].value])\n ax.set_ylim([x[1].coordinates[0].value, x[1].coordinates[-1].value])\n\n # Set axes labels and figure title.\n ax.set_xlabel(x[0].axis_label)\n ax.set_ylabel(x[1].axis_label)\n ax.set_title(yx.name)\n\n # Set grid lines.\n ax.grid(color=\"gray\", linestyle=\"--\", linewidth=0.5)\n\n plt.tight_layout()\n plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"plot_vector(y[2])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+Xuv - correlated_examples/plot_0_0D11_dataset.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Scatter, 0D{1,1} dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We start with a 0D{1,1} correlated dataset, that is, a dataset\nwithout a coordinate grid. A 0D{1,1} dataset has no dimensions, d = 0, and\ntwo single-component dependent variables.\nIn the following example [#f3]_, the two `correlated` dependent variables are\nthe $^{29}\\text{Si}$ - $^{29}\\text{Si}$ nuclear spin couplings,\n$^2J$, across a Si-O-Si linkage, and the `s`-character product on the\nO and two Si along the Si-O bond across the Si-O-Si linkage.\n\nLet's import the dataset.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import csdmpy as cp\n\ndomain = \"https://www.ssnmr.org/sites/default/files/CSDM\"\nfilename = f\"{domain}/correlatedDataset/0D_dataset/J_vs_s.csdf\"\nzero_d_dataset = cp.load(filename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since the dataset has no dimensions, the value of the\n:attr:`~csdmpy.CSDM.dimensions` attribute of the :attr:`~csdmpy.CSDM`\nclass is an empty tuple,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(zero_d_dataset.dimensions)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The :attr:`~csdmpy.CSDM.dependent_variables` attribute, however, holds\ntwo dependent-variable objects. The data structure from the two dependent\nvariables is\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(zero_d_dataset.dependent_variables[0].data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(zero_d_dataset.dependent_variables[1].data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"respectively.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Visualizing the dataset**\n\nThe correlation plot of the dependent-variables from the dataset is\nshown below.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\ny0 = zero_d_dataset.dependent_variables[0]\ny1 = zero_d_dataset.dependent_variables[1]\n\nplt.scatter(y1.components[0], y0.components[0], s=2, c=\"k\")\nplt.xlabel(y1.axis_label[0])\nplt.ylabel(y0.axis_label[0])\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. rubric:: Citation\n\n.. [#f3] Srivastava DJ, Florian P, Baltisberger JH, Grandinetti PJ. Correlating\n geminal couplings to structure in framework silicates. Phys Chem Chem Phys.\n 2018;20:562\u2013571. DOI:10.1039/C7CP06486A\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+X^v * correlated_examples/plot_2_astronomy.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Astronomy, 2D{1,1,1} dataset (Creating image composition)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"More often, the images in astronomy are a composition of datasets measured\nat different wavelengths over an area of the sky. In this example, we\nillustrate the use of the CSDM file-format, and `csdmpy` module, beyond just\nreading a CSDM-compliant file. We'll use these datasets, and compose an image,\nusing Numpy arrays.\nThe following example is the data from the `Eagle Nebula` acquired at three\ndifferent wavelengths and serialized as a CSDM compliant file.\n\nImport the `csdmpy` model and load the dataset.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import csdmpy as cp\n\ndomain = \"https://www.ssnmr.org/sites/default/files/CSDM\"\nfilename = f\"{domain}/EagleNebula/eagleNebula_base64.csdf\"\neagle_nebula = cp.load(filename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's get the tuple of dimension and dependent variable objects from\nthe ``eagle_nebula`` instance.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = eagle_nebula.dimensions\ny = eagle_nebula.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before we compose an image, let's take a look at the individual\ndependent variables from the dataset. The three dependent variables correspond\nto signal acquisition at 502 nm, 656 nm, and 673 nm, respectively. This\ninformation is also listed in the\n:attr:`~csdmpy.DependentVariable.name` attribute of the\nrespective dependent variable instances,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[0].name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[1].name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[2].name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data Visualization\n\nFor convince, let\u2019s view this CSDM object with three dependent-variables as three\nCSDM objects, each with a single dependent variable. We use the split() method.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"data0, data1, data2 = eagle_nebula.split()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here, ``data0``, ``data1``, and ``data2`` contain the dependent-variable at index\n0, 1, 2 of the ``eagle_nebula`` object. Let's plot the data from these dependent\nvariables.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\n_, ax = plt.subplots(3, 1, figsize=(6, 14), subplot_kw={\"projection\": \"csdm\"})\n\nax[0].imshow(data0 / data0.max(), cmap=\"bone\", vmax=0.1, aspect=\"auto\")\nax[1].imshow(data1 / data1.max(), cmap=\"bone\", vmax=0.1, aspect=\"auto\")\nax[2].imshow(data2 / data1.max(), cmap=\"bone\", vmax=0.1, aspect=\"auto\")\n\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Image composition\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the image composition, we assign the dependent variable at index zero as\nthe blue channel, index one as the green channel, and index two as the red\nchannel of an RGB image. Start with creating an empty array to hold the RGB\ndataset.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"shape = y[0].components[0].shape + (3,)\nimage = np.empty(shape, dtype=np.float64)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here, ``image`` is the variable we use for storing the composition. Add\nthe respective dependent variables to the designated color channel in the\n``image`` array,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"image[..., 0] = y[2].components[0] / y[2].components[0].max() # red channel\nimage[..., 1] = y[1].components[0] / y[1].components[0].max() # green channel\nimage[..., 2] = y[0].components[0] / y[0].components[0].max() # blue channel"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Following the intensity plot of the individual dependent variables, see the\nabove figures, it is evident that the component intensity from ``y[1]`` and,\ntherefore, the green channel dominates the other two. If we\nplot the ``image`` data, the image will be saturated with green intensity. To\nattain a color-balanced image, we arbitrarily scale the intensities from the\nthree channels. You may choose any scaling factor. Each scaling factor will\nproduce a different composition. In this example, we use the following,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"image[..., 0] = np.clip(image[..., 0] * 65.0, 0, 1) # red channel\nimage[..., 1] = np.clip(image[..., 1] * 7.50, 0, 1) # green channel\nimage[..., 2] = np.clip(image[..., 2] * 75.0, 0, 1) # blue channel"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now to plot this composition.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Set the extents of the image plot.\nextent = [\n x[0].coordinates[0].value,\n x[0].coordinates[-1].value,\n x[1].coordinates[0].value,\n x[1].coordinates[-1].value,\n]\n\n# add figure\nplt.imshow(image, origin=\"lower\", extent=extent)\n\nplt.xlabel(x[0].axis_label)\nplt.ylabel(x[1].axis_label)\nplt.title(\"composition\")\n\nplt.tight_layout()\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+XB pixel/plot_0_image.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Image, 2D{3} datasets\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The 2D{3} dataset is two dimensional, $d=2$, with\na single three-component dependent variable, $p=3$.\nA common example from this subset is perhaps the RGB image dataset.\nAn RGB image dataset has two spatial dimensions and one dependent\nvariable with three components corresponding to the red, green, and blue color\nintensities.\n\nThe following is an example of an RGB image dataset.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/image/raccoon_image.csdf\"\nImageData = cp.load(filename)\nprint(ImageData.data_structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The tuple of the dimension and dependent variable instances from\n``ImageData`` instance are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = ImageData.dimensions\ny = ImageData.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"respectively. There are two dimensions, and the coordinates along each\ndimension are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(\"x0 =\", x[0].coordinates[:10])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(\"x1 =\", x[1].coordinates[:10])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"respectively, where only first ten coordinates along each dimension is displayed.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The dependent variable is the image data, as also seen from the\n:attr:`~csdmpy.DependentVariable.quantity_type` attribute\nof the corresponding `dv_api` instance.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[0].quantity_type)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"From the value `pixel_3`, `pixel` indicates a pixel data, while `3`\nindicates the number of pixel components.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As usual, the components of the dependent variable are accessed through\nthe :attr:`~csdmpy.DependentVariable.components` attribute.\nTo access the individual components, use the appropriate array indexing.\nFor example,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[0].components[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"will return an array with the first component of all data values. In this case,\nthe components correspond to the red color intensity, also indicated by the\ncorresponding component label. The label corresponding to\nthe component array is accessed through the\n:attr:`~csdmpy.DependentVariable.component_labels`\nattribute with appropriate indexing, that is\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[0].component_labels[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To avoid displaying larger output, as an example, we print the shape of\neach component array (using Numpy array's `shape` attribute) for the three\ncomponents along with their respective labels.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[0].component_labels[0], y[0].components[0].shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[0].component_labels[1], y[0].components[1].shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(y[0].component_labels[2], y[0].components[2].shape)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The shape (768, 1024) corresponds to the number of points from the each\ndimension instances.\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note
In this example, since there is only one dependent variable, the index\n of `y` is set to zero, which is ``y[0]``. The indices for the\n :attr:`~csdmpy.DependentVariable.components` and the\n :attr:`~csdmpy.DependentVariable.component_labels`,\n on the other hand, spans through the number of components.
\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, to visualize the dataset as an RGB image,\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nax = plt.subplot(projection=\"csdm\")\nax.imshow(ImageData, origin=\"upper\")\nplt.tight_layout()\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+Xd sparse/plot_1_2D_sparse.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Sparse along two dimensions, 2D{1,1} dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following is an example [#f2]_ of a 2D{1,1} sparse dataset with two-dimensions,\n$d=2$, and two, $p=2$, sparse single-component dependent-variables,\nwhere the component is sparsely sampled along two dimensions. The following is an\nexample of a hypercomplex acquisition of the NMR dataset.\n\nLet's import the CSD model data-file and look at its data structure.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/sparse/iglu_2d.csdf\"\nsparse_2d = cp.load(filename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are two linear dimensions and two single-component sparse dependent variables.\nThe tuple of the dimension and the dependent variable instances are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = sparse_2d.dimensions\ny = sparse_2d.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The coordinates, viewed only for the first ten coordinates, are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].coordinates[:10])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].coordinates[:10])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Converting the coordinates to `ms`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x[0].to(\"ms\")\nx[1].to(\"ms\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Visualize the dataset**\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\n# split the CSDM object with two dependent variables into two CSDM objects with single\n# dependent variables.\n\ncos, sin = sparse_2d.split()\n\n# cosine data\nplt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\ncb = ax.contourf(cos.real)\nplt.colorbar(cb, ax=ax)\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# sine data\nplt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\ncb = ax.contourf(sin.real)\nplt.colorbar(cb, ax=ax)\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. rubric:: Citation\n\n.. [#f2] Balsgart NM, Vosegaard T., Fast Forward Maximum entropy reconstruction\n of sparsely sampled data., J Magn Reson. 2012, 223, 164-169.\n doi: 10.1016/j.jmr.2012.07.002\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK
F+X Jo o sparse/plot_0_1D_sparse.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Sparse along one dimension, 2D{1,1} dataset\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following is an example [#f2]_ of a 2D{1,1} sparse dataset with two-dimensions,\n$d=2$, and two, $p=2$, sparse single-component dependent-variables,\nwhere the component is sparsely sampled along one dimension. The following is an\nexample of a hypercomplex acquisition of the NMR dataset.\n\nLet's import the CSD model data-file.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import csdmpy as cp\n\nfilename = \"https://www.ssnmr.org/sites/default/files/CSDM/sparse/iglu_1d.csdf\"\nsparse_1d = cp.load(filename)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are two linear dimensions and two single-component sparse dependent variables.\nThe tuple of the dimension and the dependent variable instances are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x = sparse_1d.dimensions\ny = sparse_1d.dependent_variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The coordinates, viewed only for the first ten coordinates, are\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[0].coordinates[:10])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(x[1].coordinates[:10])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Converting the coordinates to `ms`.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"x[0].to(\"ms\")\nx[1].to(\"ms\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Visualizing the dataset**\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\n# split the CSDM object with two dependent variables into two CSDM objects with single\n# dependent variables.\n\ncos, sin = sparse_1d.split()\n\n# cosine data\nplt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\ncb = ax.contourf(cos.real)\nplt.colorbar(cb, ax=ax)\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# sine data\nplt.figure(figsize=(5, 3.5))\nax = plt.subplot(projection=\"csdm\")\ncb = ax.contourf(sin.real)\nplt.colorbar(cb, ax=ax)\nplt.tight_layout()\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. rubric:: Citation\n\n.. [#f2] Balsgart NM, Vosegaard T., Fast Forward Maximum entropy reconstruction\n of sparsely sampled data., J Magn Reson. 2012, 223, 164-169.\n doi: 10.1016/j.jmr.2012.07.002\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK F+X8ȡL L &