
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/Interacting_With_GS_Files/xarray_methods.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_Interacting_With_GS_Files_xarray_methods.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_Interacting_With_GS_Files_xarray_methods.py:


Basic Class Structure and Xarray Methods
----------------------------------------

The three primary classes (Survey, Tabular, and Raster) all contain data and metadata within `Xarray <https://docs.xarray.dev/en/stable/>`_ Datasets. This example demonstrates how to access the xarray object for each class, and methods for exploring the data and metadata.

This example uses ASEG-formatted raw AEM data from the Tempest system, and a 2-D GeoTiFF of magnetic data.

Dataset Reference:
Minsley, B.J., James, S.R., Bedrosian, P.A., Pace, M.D., Hoogenboom, B.E., and Burton, B.L., 2021, Airborne electromagnetic, magnetic, and radiometric survey of the Mississippi Alluvial Plain, November 2019 - March 2020: U.S. Geological Survey data release, https://doi.org/10.5066/P9E44CTQ.

.. GENERATED FROM PYTHON SOURCE LINES 14-18

.. code-block:: default

    import matplotlib.pyplot as plt
    from os.path import join
    from gspy import Survey


.. GENERATED FROM PYTHON SOURCE LINES 19-20

First Create the Survey & Data Objects

.. GENERATED FROM PYTHON SOURCE LINES 20-33

.. code-block:: default


    # Initialize the Survey
    data_path = '..//..//supplemental//region//MAP'
    metadata = join(data_path, "data//Tempest_survey_md.json")
    survey = Survey(metadata)

    # Add Tabular and Raster Datasets
    t_data = join(data_path, 'data//Tempest.dat')
    t_supp = join(data_path, 'data//Tempest_data_md.json')
    survey.add_tabular(type='aseg', data_filename=t_data, metadata_file=t_supp)
    r_supp = join(data_path, 'data//Tempest_raster_md.json')
    survey.add_raster(metadata_file = r_supp)


.. GENERATED FROM PYTHON SOURCE LINES 34-36

Accessing the Xarray object
+++++++++++++++++++++++++++

.. GENERATED FROM PYTHON SOURCE LINES 36-69

.. code-block:: default


    # Survey
    # The Survey's metadata is accessed through the xarray property
    print(survey.xarray)

    # To look just at the attributes
    print(survey.xarray.attrs)

    # Or expand a specific variable
    print(survey.xarray['survey_information'])

    # Tabular & Raster
    # Datasets are attached to the Survey as lists, however if only one Dataset of a given 
    # type is present then the xarray object is returned simply by the name of the group

    # tabular
    print(survey.tabular)

    # raster
    print(survey.raster)

    # If more than one Dataset is present under the group, then the list begins indexing
    # For example, let's add a second Tabular Dataset
    m_data = join(data_path, 'model//Tempest_model.dat')
    m_supp = join(data_path, 'model//Tempest_model_md.json')
    survey.add_tabular(type='aseg', data_filename=m_data, metadata_file=m_supp)

    # Now the first dataset is accessed at index 0
    print(survey.tabular[0])

    # and the second is located at index 1
    print(survey.tabular[1])


.. GENERATED FROM PYTHON SOURCE LINES 70-72

Coordinates, Dimensions, and Attributes
+++++++++++++++++++++++++++++++++++++++


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  0.000 seconds)


.. _sphx_glr_download_examples_Interacting_With_GS_Files_xarray_methods.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example




    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: xarray_methods.py <xarray_methods.py>`

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: xarray_methods.ipynb <xarray_methods.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
