.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/1D_1_examples/plot_0_gmsl.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_1D_1_examples_plot_0_gmsl.py: Global Mean Sea Level rise dataset ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. GENERATED FROM PYTHON SOURCE LINES 6-12 The following dataset is the Global Mean Sea Level (GMSL) rise from the late 19th to the Early 21st Century [#f0]_. The `original dataset `_ was downloaded as a CSV file and subsequently converted to the CSD model format. Let's import this file. .. GENERATED FROM PYTHON SOURCE LINES 12-17 .. code-block:: Python import csdmpy as cp filename = "https://www.ssnmr.org/sites/default/files/CSDM/gmsl/GMSL.csdf" sea_level = cp.load(filename) .. GENERATED FROM PYTHON SOURCE LINES 18-24 The variable `filename` is a string with the address to the `.csdf` file. The :meth:`~csdmpy.load` method of the `csdmpy` module reads the file and returns an instance of the :ref:`csdm_api` class, in this case, as a variable ``sea_level``. For a quick preview of the data structure, use the :attr:`~csdmpy.CSDM.data_structure` attribute of this instance. .. GENERATED FROM PYTHON SOURCE LINES 24-27 .. code-block:: Python print(sea_level.data_structure) .. rst-class:: sphx-glr-script-out .. code-block:: none { "csdm": { "version": "1.0", "read_only": true, "timestamp": "2019-05-21T13:43:00Z", "tags": [ "Jason-2", "satellite altimetry", "mean sea level", "climate" ], "description": "Global Mean Sea Level (GMSL) rise from the late 19th to the Early 21st Century.", "dimensions": [ { "type": "linear", "count": 1608, "increment": "0.08333333333 yr", "coordinates_offset": "1880.0416666667 yr", "quantity_name": "time", "reciprocal": { "quantity_name": "frequency" } } ], "dependent_variables": [ { "type": "internal", "name": "Global Mean Sea Level", "unit": "mm", "quantity_name": "length", "numeric_type": "float32", "quantity_type": "scalar", "component_labels": [ "GMSL" ], "components": [ [ "-183.0, -171.125, ..., 59.6875, 58.5" ] ] } ] } } .. GENERATED FROM PYTHON SOURCE LINES 28-36 .. warning:: The serialized string from the :attr:`~csdmpy.CSDM.data_structure` attribute is not the same as the JSON serialization on the file. This attribute is only intended for a quick preview of the data structure and avoids displaying large datasets. Do not use the value of this attribute to save the data to the file. Instead, use the :meth:`~csdmpy.CSDM.save` method of the :ref:`CSDM ` class. .. GENERATED FROM PYTHON SOURCE LINES 38-39 The tuple of the dimensions and dependent variables, from this example, are .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python x = sea_level.dimensions y = sea_level.dependent_variables .. GENERATED FROM PYTHON SOURCE LINES 44-46 respectively. The coordinates along the dimension and the component of the dependent variable are .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python print(x[0].coordinates) .. rst-class:: sphx-glr-script-out .. code-block:: none [1880.04166667 1880.125 1880.20833333 ... 2013.79166666 2013.87499999 2013.95833333] yr .. GENERATED FROM PYTHON SOURCE LINES 49-50 and .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: Python print(y[0].components[0]) .. rst-class:: sphx-glr-script-out .. code-block:: none [-183. -171.125 -164.25 ... 66.375 59.6875 58.5 ] .. GENERATED FROM PYTHON SOURCE LINES 53-54 respectively. .. GENERATED FROM PYTHON SOURCE LINES 56-61 **Plotting the data** .. note:: The following code is only for illustrative purposes. The users may use any plotting library to visualize their datasets. .. GENERATED FROM PYTHON SOURCE LINES 61-72 .. code-block:: Python import matplotlib.pyplot as plt plt.figure(figsize=(5, 3.5)) ax = plt.subplot(projection="csdm") # csdmpy is compatible with matplotlib function. Use the csdm object as the argument # of the matplotlib function. ax.plot(sea_level) plt.tight_layout() plt.show() .. image-sg:: /auto_examples/1D_1_examples/images/sphx_glr_plot_0_gmsl_001.png :alt: plot 0 gmsl :srcset: /auto_examples/1D_1_examples/images/sphx_glr_plot_0_gmsl_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 73-85 The following is a quick description of the above code. Within the code, we make use of the csdm instance's attributes in addition to the matplotlib functions. The first line is an import call for the matplotlib functions. The following line generates a plot of the coordinates along the dimension verse the component of the dependent variable. The next line sets the x-range. For labeling the axes, use the :attr:`~csdmpy.Dimension.axis_label` attribute of both dimension and dependent variable instances. For the figure title, use the :attr:`~csdmpy.DependentVariable.name` attribute of the dependent variable instance. The next statement adds the grid lines. For additional information, refer to `Matplotlib `_ documentation. .. GENERATED FROM PYTHON SOURCE LINES 87-90 .. seealso:: :ref:`getting_started` .. GENERATED FROM PYTHON SOURCE LINES 92-96 .. rubric:: Citation .. [#f0] Church JA, White NJ. Sea-Level Rise from the Late 19th to the Early 21st Century. Surveys in Geophysics. 2011;32:585–602. DOI:10.1007/s10712-011-9119-1. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.647 seconds) .. _sphx_glr_download_auto_examples_1D_1_examples_plot_0_gmsl.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_gmsl.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_0_gmsl.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_