
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/Interacting_With_GS_Files/plot_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_plot_xarray_methods.py>`
        to download the full example code.

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

.. _sphx_glr_examples_Interacting_With_GS_Files_plot_xarray_methods.py:


Basic Class Structure
---------------------

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-20

.. code-block:: Python

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








.. GENERATED FROM PYTHON SOURCE LINES 21-22

First open the netcdf GS standard survey file.

.. GENERATED FROM PYTHON SOURCE LINES 22-25

.. code-block:: Python


    survey = gspy.open_datatree("..//data_files//tempest_aseg//Tempest.nc")['survey']








.. GENERATED FROM PYTHON SOURCE LINES 26-28

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

.. GENERATED FROM PYTHON SOURCE LINES 30-31

Survey

.. GENERATED FROM PYTHON SOURCE LINES 31-36

.. code-block:: Python


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





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Survey:
    <xarray.DataTree 'survey'>
    Group: /survey
    │   Dimensions:                 ()
    │   Coordinates:
    │       spatial_ref             float64 8B ...
    │   Data variables:
    │       survey_information      float64 8B ...
    │       survey_units            float64 8B ...
    │       flightline_information  float64 8B ...
    │       survey_equipment        float64 8B ...
    │   Attributes:
    │       uuid:         6475fff9-4236-4c02-897a-df0cc69e4a2a
    │       title:        Example Tempest Airborne Electromagnetic (AEM) Dataset
    │       institution:  USGS Geology, Geophysics, & Geochemistry Science Center
    │       source:       Contractor provided ASEG-formatted data
    │       history:      <date and time when the data were produced and/or modified>
    │       references:   <data release reference>
    │       comment:      <additional details or ancillary information>
    │       content:      <summary list of file contents, e.g. raw data (/survey/tabu...
    │       conventions:  CF-1.8, GS-0.0
    │       created_by:   gspy==0.0.1
    │       type:         survey
    ├── Group: /survey/data
    │   │   Dimensions:      ()
    │   │   Data variables:
    │   │       spatial_ref  float64 8B ...
    │   │   Attributes:
    │   │       content:  raw and processed data
    │   │       type:     container
    │   ├── Group: /survey/data/raw_data
    │   │   │   Dimensions:          (index: 2001, gate_times: 15)
    │   │   │   Coordinates:
    │   │   │     * index            (index) int32 8kB 0 1 2 3 4 5 ... 1996 1997 1998 1999 2000
    │   │   │     * gate_times       (gate_times) float64 120B 1.085e-05 3.255e-05 ... 0.01338
    │   │   │       spatial_ref      float64 8B ...
    │   │   │       x                (index) float64 16kB ...
    │   │   │       y                (index) float64 16kB ...
    │   │   │       z                (index) float64 16kB ...
    │   │   │   Data variables: (12/61)
    │   │   │       line             (index) int32 8kB ...
    │   │   │       flight           (index) int32 8kB ...
    │   │   │       fiducial         (index) float64 16kB ...
    │   │   │       proj_cgg         (index) int32 8kB ...
    │   │   │       proj_client      (index) int32 8kB ...
    │   │   │       date             (index) int32 8kB ...
    │   │   │       ...               ...
    │   │   │       z_primaryfield   (index) float64 16kB ...
    │   │   │       z_vlf1           (index) float64 16kB ...
    │   │   │       z_vlf2           (index) float64 16kB ...
    │   │   │       z_vlf3           (index) float64 16kB ...
    │   │   │       z_vlf4           (index) float64 16kB ...
    │   │   │       z_geofact        (index) float64 16kB ...
    │   │   │   Attributes:
    │   │   │       uuid:     fcc5f052-ddc6-4bc9-a6d4-f5dd27e22eae
    │   │   │       content:  raw data
    │   │   │       comment:  This dataset includes minimally processed (raw) AEM data
    │   │   ├── Group: /survey/data/raw_data/tempest_system
    │   │   │       Dimensions:                       (gate_times: 15, nv: 2, n_transmitter: 1,
    │   │   │                                          waveform_time: 7, n_receiver: 2,
    │   │   │                                          n_component: 2)
    │   │   │       Coordinates:
    │   │   │         * nv                            (nv) int64 16B 0 1
    │   │   │         * n_transmitter                 (n_transmitter) int64 8B 0
    │   │   │         * waveform_time                 (waveform_time) float64 56B -0.01667 ... 0....
    │   │   │         * n_receiver                    (n_receiver) int64 16B 0 1
    │   │   │         * n_component                   (n_component) int64 16B 0 1
    │   │   │       Data variables: (12/21)
    │   │   │           gate_times_bnds               (gate_times, nv) float64 240B ...
    │   │   │           transmitter_label             (n_transmitter) <U1 4B ...
    │   │   │           transmitter_area              (n_transmitter) int64 8B ...
    │   │   │           transmitter_waveform_type     (n_transmitter) <U6 24B ...
    │   │   │           transmitter_waveform_current  (waveform_time) float64 56B ...
    │   │   │           transmitter_scale_factor      (n_transmitter) float64 8B ...
    │   │   │           ...                            ...
    │   │   │           component_label               (n_component) <U3 24B ...
    │   │   │           component_transmitters        (n_component) <U1 8B ...
    │   │   │           component_receivers           (n_component) <U1 8B ...
    │   │   │           component_txrx_dx             (n_component) int64 16B ...
    │   │   │           component_txrx_dy             (n_component) int64 16B ...
    │   │   │           component_txrx_dz             (n_component) int64 16B ...
    │   │   │       Attributes: (12/13)
    │   │   │           type:                     system
    │   │   │           mode:                     airborne
    │   │   │           method:                   electromagnetic
    │   │   │           submethod:                time domain
    │   │   │           instrument:               tempest
    │   │   │           uuid:                     51b3d522-c7af-4c64-867b-65b1bc14358d
    │   │   │           ...                       ...
    │   │   │           structure:                tabular
    │   │   │           data_normalized:          True
    │   │   │           output_data_type:         B
    │   │   │           reference_frame:          right-handed positive up
    │   │   │           output_sample_frequency:  5
    │   │   │           digitization_frequency:   92160
    │   │   ├── Group: /survey/data/raw_data/magnetic_system
    │   │   │       Attributes:
    │   │   │           type:              system
    │   │   │           mode:              airborne
    │   │   │           method:            magnetic
    │   │   │           submethod:         not_defined
    │   │   │           instrument:        not_defiend
    │   │   │           name:              magnetic_system
    │   │   │           sample_frequency:  1.0
    │   │   │           resolution:        0.001
    │   │   └── Group: /survey/data/raw_data/radiometric_system
    │   │           Attributes:
    │   │               type:              system
    │   │               mode:              airborne
    │   │               method:            radiometric
    │   │               submethod:         not_defined
    │   │               instrument:        not_defined
    │   │               name:              radiometric_system
    │   │               sample_frequency:  1.0
    │   └── Group: /survey/data/derived_maps
    │       │   Dimensions:      ()
    │       │   Data variables:
    │       │       spatial_ref  float64 8B ...
    │       │   Attributes:
    │       │       content:  derived maps
    │       │       type:     container
    │       └── Group: /survey/data/derived_maps/maps
    │               Dimensions:       (x: 599, nv: 2, y: 1212)
    │               Coordinates:
    │                 * x             (x) float64 5kB 2.928e+05 2.934e+05 ... 6.51e+05 6.516e+05
    │                 * nv            (nv) int64 16B 0 1
    │                 * y             (y) float64 10kB 1.607e+06 1.606e+06 ... 8.808e+05 8.802e+05
    │                   spatial_ref   float64 8B ...
    │               Data variables:
    │                   x_bnds        (x, nv) float64 10kB ...
    │                   y_bnds        (y, nv) float64 19kB ...
    │                   magnetic_tmi  (y, x) float64 6MB ...
    │               Attributes:
    │                   uuid:     497f4feb-ff9f-4a4c-9a2c-3a23b65bef62
    │                   comment:  <additional details or ancillary information>
    │                   content:  gridded magnetic map
    └── Group: /survey/models
        │   Dimensions:      ()
        │   Data variables:
        │       spatial_ref  float64 8B ...
        │   Attributes:
        │       content:  inverted models
        │       type:     container
        └── Group: /survey/models/inverted_models
                Dimensions:                  (layer_depth: 30, nv: 2, gate_times: 15,
                                              index: 2001)
                Coordinates:
                  * layer_depth              (layer_depth) float64 240B 1.5 4.65 ... 424.2 467.5
                  * nv                       (nv) int64 16B 0 1
                  * gate_times               (gate_times) float64 120B 1.085e-05 ... 0.01338
                  * index                    (index) int32 8kB 0 1 2 3 4 ... 1997 1998 1999 2000
                    spatial_ref              float64 8B ...
                    x                        (index) float64 16kB ...
                    y                        (index) float64 16kB ...
                    z                        (index) float64 16kB ...
                Data variables: (12/49)
                    layer_depth_bnds         (layer_depth, nv) float64 480B ...
                    gate_times_bnds          (gate_times, nv) float64 240B ...
                    uniqueid                 (index) int32 8kB ...
                    survey                   (index) int32 8kB ...
                    date                     (index) int32 8kB ...
                    flight                   (index) int32 8kB ...
                    ...                       ...
                    phic                     (index) float64 16kB ...
                    phit                     (index) float64 16kB ...
                    phig                     (index) float64 16kB ...
                    phis                     (index) float64 16kB ...
                    lambda                   (index) float64 16kB ...
                    iterations               (index) int32 8kB ...
                Attributes:
                    uuid:     b41252cd-a11d-4d2e-acc5-dffd2b18c237
                    content:  inverted resistivity models
                    comment:  This dataset includes inverted resistivity models derived from ...




.. GENERATED FROM PYTHON SOURCE LINES 37-38

To look just at the attributes

.. GENERATED FROM PYTHON SOURCE LINES 38-41

.. code-block:: Python

    print('Survey Attributes:\n')
    pprint(survey.attrs)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Survey Attributes:

    {'comment': '<additional details or ancillary information>',
     'content': '<summary list of file contents, e.g. raw data '
                '(/survey/tabular/0), processed data (/survey/tabular/1)>',
     'conventions': 'CF-1.8, GS-0.0',
     'created_by': 'gspy==0.0.1',
     'history': '<date and time when the data were produced and/or modified>',
     'institution': 'USGS Geology, Geophysics, & Geochemistry Science Center',
     'references': '<data release reference>',
     'source': 'Contractor provided ASEG-formatted data',
     'title': 'Example Tempest Airborne Electromagnetic (AEM) Dataset',
     'type': 'survey',
     'uuid': '6475fff9-4236-4c02-897a-df0cc69e4a2a'}




.. GENERATED FROM PYTHON SOURCE LINES 42-43

Or expand a specific variable

.. GENERATED FROM PYTHON SOURCE LINES 43-46

.. code-block:: Python

    print('Survey Information:\n')
    print(survey['survey_information'])





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Survey Information:

    <xarray.DataArray 'survey_information' ()> Size: 8B
    [1 values with dtype=float64]
    Coordinates:
        spatial_ref  float64 8B ...
    Attributes:
        contractor_project_number:  603756FWA
        contractor:                 CGG Canada Services Ltd.
        client:                     U.S. Geological Survey
        survey_type:                electromagneticmagneticradiometric
        survey_area_name:           Mississippi Alluvial Plain (MAP)
        state:                      MOARTNMSLAILKY
        country:                    USA
        acquisition_start:          20191120
        acquisition_end:            20200307
        dataset_created:            20200420




.. GENERATED FROM PYTHON SOURCE LINES 47-49

Datasets
Get the list of datasets attached to the survey

.. GENERATED FROM PYTHON SOURCE LINES 49-51

.. code-block:: Python

    print(survey.items)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    <bound method Mapping.items of <xarray.DataTree 'survey'>
    Group: /survey
    │   Dimensions:                 ()
    │   Coordinates:
    │       spatial_ref             float64 8B ...
    │   Data variables:
    │       survey_information      float64 8B ...
    │       survey_units            float64 8B ...
    │       flightline_information  float64 8B ...
    │       survey_equipment        float64 8B ...
    │   Attributes:
    │       uuid:         6475fff9-4236-4c02-897a-df0cc69e4a2a
    │       title:        Example Tempest Airborne Electromagnetic (AEM) Dataset
    │       institution:  USGS Geology, Geophysics, & Geochemistry Science Center
    │       source:       Contractor provided ASEG-formatted data
    │       history:      <date and time when the data were produced and/or modified>
    │       references:   <data release reference>
    │       comment:      <additional details or ancillary information>
    │       content:      <summary list of file contents, e.g. raw data (/survey/tabu...
    │       conventions:  CF-1.8, GS-0.0
    │       created_by:   gspy==0.0.1
    │       type:         survey
    ├── Group: /survey/data
    │   │   Dimensions:      ()
    │   │   Data variables:
    │   │       spatial_ref  float64 8B ...
    │   │   Attributes:
    │   │       content:  raw and processed data
    │   │       type:     container
    │   ├── Group: /survey/data/raw_data
    │   │   │   Dimensions:          (index: 2001, gate_times: 15)
    │   │   │   Coordinates:
    │   │   │     * index            (index) int32 8kB 0 1 2 3 4 5 ... 1996 1997 1998 1999 2000
    │   │   │     * gate_times       (gate_times) float64 120B 1.085e-05 3.255e-05 ... 0.01338
    │   │   │       spatial_ref      float64 8B ...
    │   │   │       x                (index) float64 16kB ...
    │   │   │       y                (index) float64 16kB ...
    │   │   │       z                (index) float64 16kB ...
    │   │   │   Data variables: (12/61)
    │   │   │       line             (index) int32 8kB ...
    │   │   │       flight           (index) int32 8kB ...
    │   │   │       fiducial         (index) float64 16kB ...
    │   │   │       proj_cgg         (index) int32 8kB ...
    │   │   │       proj_client      (index) int32 8kB ...
    │   │   │       date             (index) int32 8kB ...
    │   │   │       ...               ...
    │   │   │       z_primaryfield   (index) float64 16kB ...
    │   │   │       z_vlf1           (index) float64 16kB ...
    │   │   │       z_vlf2           (index) float64 16kB ...
    │   │   │       z_vlf3           (index) float64 16kB ...
    │   │   │       z_vlf4           (index) float64 16kB ...
    │   │   │       z_geofact        (index) float64 16kB ...
    │   │   │   Attributes:
    │   │   │       uuid:     fcc5f052-ddc6-4bc9-a6d4-f5dd27e22eae
    │   │   │       content:  raw data
    │   │   │       comment:  This dataset includes minimally processed (raw) AEM data
    │   │   ├── Group: /survey/data/raw_data/tempest_system
    │   │   │       Dimensions:                       (gate_times: 15, nv: 2, n_transmitter: 1,
    │   │   │                                          waveform_time: 7, n_receiver: 2,
    │   │   │                                          n_component: 2)
    │   │   │       Coordinates:
    │   │   │         * nv                            (nv) int64 16B 0 1
    │   │   │         * n_transmitter                 (n_transmitter) int64 8B 0
    │   │   │         * waveform_time                 (waveform_time) float64 56B -0.01667 ... 0....
    │   │   │         * n_receiver                    (n_receiver) int64 16B 0 1
    │   │   │         * n_component                   (n_component) int64 16B 0 1
    │   │   │       Data variables: (12/21)
    │   │   │           gate_times_bnds               (gate_times, nv) float64 240B ...
    │   │   │           transmitter_label             (n_transmitter) <U1 4B ...
    │   │   │           transmitter_area              (n_transmitter) int64 8B ...
    │   │   │           transmitter_waveform_type     (n_transmitter) <U6 24B ...
    │   │   │           transmitter_waveform_current  (waveform_time) float64 56B ...
    │   │   │           transmitter_scale_factor      (n_transmitter) float64 8B ...
    │   │   │           ...                            ...
    │   │   │           component_label               (n_component) <U3 24B ...
    │   │   │           component_transmitters        (n_component) <U1 8B ...
    │   │   │           component_receivers           (n_component) <U1 8B ...
    │   │   │           component_txrx_dx             (n_component) int64 16B ...
    │   │   │           component_txrx_dy             (n_component) int64 16B ...
    │   │   │           component_txrx_dz             (n_component) int64 16B ...
    │   │   │       Attributes: (12/13)
    │   │   │           type:                     system
    │   │   │           mode:                     airborne
    │   │   │           method:                   electromagnetic
    │   │   │           submethod:                time domain
    │   │   │           instrument:               tempest
    │   │   │           uuid:                     51b3d522-c7af-4c64-867b-65b1bc14358d
    │   │   │           ...                       ...
    │   │   │           structure:                tabular
    │   │   │           data_normalized:          True
    │   │   │           output_data_type:         B
    │   │   │           reference_frame:          right-handed positive up
    │   │   │           output_sample_frequency:  5
    │   │   │           digitization_frequency:   92160
    │   │   ├── Group: /survey/data/raw_data/magnetic_system
    │   │   │       Attributes:
    │   │   │           type:              system
    │   │   │           mode:              airborne
    │   │   │           method:            magnetic
    │   │   │           submethod:         not_defined
    │   │   │           instrument:        not_defiend
    │   │   │           name:              magnetic_system
    │   │   │           sample_frequency:  1.0
    │   │   │           resolution:        0.001
    │   │   └── Group: /survey/data/raw_data/radiometric_system
    │   │           Attributes:
    │   │               type:              system
    │   │               mode:              airborne
    │   │               method:            radiometric
    │   │               submethod:         not_defined
    │   │               instrument:        not_defined
    │   │               name:              radiometric_system
    │   │               sample_frequency:  1.0
    │   └── Group: /survey/data/derived_maps
    │       │   Dimensions:      ()
    │       │   Data variables:
    │       │       spatial_ref  float64 8B ...
    │       │   Attributes:
    │       │       content:  derived maps
    │       │       type:     container
    │       └── Group: /survey/data/derived_maps/maps
    │               Dimensions:       (x: 599, nv: 2, y: 1212)
    │               Coordinates:
    │                 * x             (x) float64 5kB 2.928e+05 2.934e+05 ... 6.51e+05 6.516e+05
    │                 * nv            (nv) int64 16B 0 1
    │                 * y             (y) float64 10kB 1.607e+06 1.606e+06 ... 8.808e+05 8.802e+05
    │                   spatial_ref   float64 8B ...
    │               Data variables:
    │                   x_bnds        (x, nv) float64 10kB ...
    │                   y_bnds        (y, nv) float64 19kB ...
    │                   magnetic_tmi  (y, x) float64 6MB ...
    │               Attributes:
    │                   uuid:     497f4feb-ff9f-4a4c-9a2c-3a23b65bef62
    │                   comment:  <additional details or ancillary information>
    │                   content:  gridded magnetic map
    └── Group: /survey/models
        │   Dimensions:      ()
        │   Data variables:
        │       spatial_ref  float64 8B ...
        │   Attributes:
        │       content:  inverted models
        │       type:     container
        └── Group: /survey/models/inverted_models
                Dimensions:                  (layer_depth: 30, nv: 2, gate_times: 15,
                                              index: 2001)
                Coordinates:
                  * layer_depth              (layer_depth) float64 240B 1.5 4.65 ... 424.2 467.5
                  * nv                       (nv) int64 16B 0 1
                  * gate_times               (gate_times) float64 120B 1.085e-05 ... 0.01338
                  * index                    (index) int32 8kB 0 1 2 3 4 ... 1997 1998 1999 2000
                    spatial_ref              float64 8B ...
                    x                        (index) float64 16kB ...
                    y                        (index) float64 16kB ...
                    z                        (index) float64 16kB ...
                Data variables: (12/49)
                    layer_depth_bnds         (layer_depth, nv) float64 480B ...
                    gate_times_bnds          (gate_times, nv) float64 240B ...
                    uniqueid                 (index) int32 8kB ...
                    survey                   (index) int32 8kB ...
                    date                     (index) int32 8kB ...
                    flight                   (index) int32 8kB ...
                    ...                       ...
                    phic                     (index) float64 16kB ...
                    phit                     (index) float64 16kB ...
                    phig                     (index) float64 16kB ...
                    phis                     (index) float64 16kB ...
                    lambda                   (index) float64 16kB ...
                    iterations               (index) int32 8kB ...
                Attributes:
                    uuid:     b41252cd-a11d-4d2e-acc5-dffd2b18c237
                    content:  inverted resistivity models
                    comment:  This dataset includes inverted resistivity models derived from ...>




.. GENERATED FROM PYTHON SOURCE LINES 52-54

Datasets are attached to the Survey regardless of their format whether unstructured tabular data or
image-type raster data

.. GENERATED FROM PYTHON SOURCE LINES 54-63

.. code-block:: Python


    # Tabular
    print('Tabular:\n')
    print(survey['data'])

    # Raster
    print('\nRaster:\n')
    print(survey['data/derived_maps/maps'])





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Tabular:

    <xarray.DataTree 'data'>
    Group: /survey/data
    │   Dimensions:      ()
    │   Data variables:
    │       spatial_ref  float64 8B ...
    │   Attributes:
    │       content:  raw and processed data
    │       type:     container
    ├── Group: /survey/data/raw_data
    │   │   Dimensions:          (index: 2001, gate_times: 15)
    │   │   Coordinates:
    │   │     * index            (index) int32 8kB 0 1 2 3 4 5 ... 1996 1997 1998 1999 2000
    │   │     * gate_times       (gate_times) float64 120B 1.085e-05 3.255e-05 ... 0.01338
    │   │       spatial_ref      float64 8B ...
    │   │       x                (index) float64 16kB ...
    │   │       y                (index) float64 16kB ...
    │   │       z                (index) float64 16kB ...
    │   │   Data variables: (12/61)
    │   │       line             (index) int32 8kB ...
    │   │       flight           (index) int32 8kB ...
    │   │       fiducial         (index) float64 16kB ...
    │   │       proj_cgg         (index) int32 8kB ...
    │   │       proj_client      (index) int32 8kB ...
    │   │       date             (index) int32 8kB ...
    │   │       ...               ...
    │   │       z_primaryfield   (index) float64 16kB ...
    │   │       z_vlf1           (index) float64 16kB ...
    │   │       z_vlf2           (index) float64 16kB ...
    │   │       z_vlf3           (index) float64 16kB ...
    │   │       z_vlf4           (index) float64 16kB ...
    │   │       z_geofact        (index) float64 16kB ...
    │   │   Attributes:
    │   │       uuid:     fcc5f052-ddc6-4bc9-a6d4-f5dd27e22eae
    │   │       content:  raw data
    │   │       comment:  This dataset includes minimally processed (raw) AEM data
    │   ├── Group: /survey/data/raw_data/tempest_system
    │   │       Dimensions:                       (gate_times: 15, nv: 2, n_transmitter: 1,
    │   │                                          waveform_time: 7, n_receiver: 2,
    │   │                                          n_component: 2)
    │   │       Coordinates:
    │   │         * nv                            (nv) int64 16B 0 1
    │   │         * n_transmitter                 (n_transmitter) int64 8B 0
    │   │         * waveform_time                 (waveform_time) float64 56B -0.01667 ... 0....
    │   │         * n_receiver                    (n_receiver) int64 16B 0 1
    │   │         * n_component                   (n_component) int64 16B 0 1
    │   │       Data variables: (12/21)
    │   │           gate_times_bnds               (gate_times, nv) float64 240B ...
    │   │           transmitter_label             (n_transmitter) <U1 4B ...
    │   │           transmitter_area              (n_transmitter) int64 8B ...
    │   │           transmitter_waveform_type     (n_transmitter) <U6 24B ...
    │   │           transmitter_waveform_current  (waveform_time) float64 56B ...
    │   │           transmitter_scale_factor      (n_transmitter) float64 8B ...
    │   │           ...                            ...
    │   │           component_label               (n_component) <U3 24B ...
    │   │           component_transmitters        (n_component) <U1 8B ...
    │   │           component_receivers           (n_component) <U1 8B ...
    │   │           component_txrx_dx             (n_component) int64 16B ...
    │   │           component_txrx_dy             (n_component) int64 16B ...
    │   │           component_txrx_dz             (n_component) int64 16B ...
    │   │       Attributes: (12/13)
    │   │           type:                     system
    │   │           mode:                     airborne
    │   │           method:                   electromagnetic
    │   │           submethod:                time domain
    │   │           instrument:               tempest
    │   │           uuid:                     51b3d522-c7af-4c64-867b-65b1bc14358d
    │   │           ...                       ...
    │   │           structure:                tabular
    │   │           data_normalized:          True
    │   │           output_data_type:         B
    │   │           reference_frame:          right-handed positive up
    │   │           output_sample_frequency:  5
    │   │           digitization_frequency:   92160
    │   ├── Group: /survey/data/raw_data/magnetic_system
    │   │       Attributes:
    │   │           type:              system
    │   │           mode:              airborne
    │   │           method:            magnetic
    │   │           submethod:         not_defined
    │   │           instrument:        not_defiend
    │   │           name:              magnetic_system
    │   │           sample_frequency:  1.0
    │   │           resolution:        0.001
    │   └── Group: /survey/data/raw_data/radiometric_system
    │           Attributes:
    │               type:              system
    │               mode:              airborne
    │               method:            radiometric
    │               submethod:         not_defined
    │               instrument:        not_defined
    │               name:              radiometric_system
    │               sample_frequency:  1.0
    └── Group: /survey/data/derived_maps
        │   Dimensions:      ()
        │   Data variables:
        │       spatial_ref  float64 8B ...
        │   Attributes:
        │       content:  derived maps
        │       type:     container
        └── Group: /survey/data/derived_maps/maps
                Dimensions:       (x: 599, nv: 2, y: 1212)
                Coordinates:
                  * x             (x) float64 5kB 2.928e+05 2.934e+05 ... 6.51e+05 6.516e+05
                  * nv            (nv) int64 16B 0 1
                  * y             (y) float64 10kB 1.607e+06 1.606e+06 ... 8.808e+05 8.802e+05
                    spatial_ref   float64 8B ...
                Data variables:
                    x_bnds        (x, nv) float64 10kB ...
                    y_bnds        (y, nv) float64 19kB ...
                    magnetic_tmi  (y, x) float64 6MB ...
                Attributes:
                    uuid:     497f4feb-ff9f-4a4c-9a2c-3a23b65bef62
                    comment:  <additional details or ancillary information>
                    content:  gridded magnetic map

    Raster:

    <xarray.DataTree 'maps'>
    Group: /survey/data/derived_maps/maps
        Dimensions:       (x: 599, nv: 2, y: 1212)
        Coordinates:
          * x             (x) float64 5kB 2.928e+05 2.934e+05 ... 6.51e+05 6.516e+05
          * nv            (nv) int64 16B 0 1
          * y             (y) float64 10kB 1.607e+06 1.606e+06 ... 8.808e+05 8.802e+05
            spatial_ref   float64 8B ...
        Data variables:
            x_bnds        (x, nv) float64 10kB ...
            y_bnds        (y, nv) float64 19kB ...
            magnetic_tmi  (y, x) float64 6MB ...
        Attributes:
            uuid:     497f4feb-ff9f-4a4c-9a2c-3a23b65bef62
            comment:  <additional details or ancillary information>
            content:  gridded magnetic map




.. GENERATED FROM PYTHON SOURCE LINES 64-65

and the second is located at index 1

.. GENERATED FROM PYTHON SOURCE LINES 65-68

.. code-block:: Python

    print('Second Tabular Group:\n')
    print(survey['models/inverted_models'])





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Second Tabular Group:

    <xarray.DataTree 'inverted_models'>
    Group: /survey/models/inverted_models
        Dimensions:                  (layer_depth: 30, nv: 2, gate_times: 15,
                                      index: 2001)
        Coordinates:
          * layer_depth              (layer_depth) float64 240B 1.5 4.65 ... 424.2 467.5
          * nv                       (nv) int64 16B 0 1
          * gate_times               (gate_times) float64 120B 1.085e-05 ... 0.01338
          * index                    (index) int32 8kB 0 1 2 3 4 ... 1997 1998 1999 2000
            spatial_ref              float64 8B ...
            x                        (index) float64 16kB ...
            y                        (index) float64 16kB ...
            z                        (index) float64 16kB ...
        Data variables: (12/49)
            layer_depth_bnds         (layer_depth, nv) float64 480B ...
            gate_times_bnds          (gate_times, nv) float64 240B ...
            uniqueid                 (index) int32 8kB ...
            survey                   (index) int32 8kB ...
            date                     (index) int32 8kB ...
            flight                   (index) int32 8kB ...
            ...                       ...
            phic                     (index) float64 16kB ...
            phit                     (index) float64 16kB ...
            phig                     (index) float64 16kB ...
            phis                     (index) float64 16kB ...
            lambda                   (index) float64 16kB ...
            iterations               (index) int32 8kB ...
        Attributes:
            uuid:     b41252cd-a11d-4d2e-acc5-dffd2b18c237
            content:  inverted resistivity models
            comment:  This dataset includes inverted resistivity models derived from ...




.. GENERATED FROM PYTHON SOURCE LINES 69-71

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

.. GENERATED FROM PYTHON SOURCE LINES 73-74

All data variables must have dimensions, coordinate, and attributes

.. GENERATED FROM PYTHON SOURCE LINES 76-78

Dimensions
^^^^^^^^^^

.. GENERATED FROM PYTHON SOURCE LINES 80-82

Tabular data are typicaly 1-D or 2-D variables with the primary dimension being ``index``, which
corresponds to the rows of the input text file representing individual measurements.

.. GENERATED FROM PYTHON SOURCE LINES 82-84

.. code-block:: Python

    print(survey['models/inverted_models']['index'])





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    <xarray.DataArray 'index' (index: 2001)> Size: 8kB
    array([   0,    1,    2, ..., 1998, 1999, 2000], shape=(2001,), dtype=int32)
    Coordinates:
      * index        (index) int32 8kB 0 1 2 3 4 5 ... 1995 1996 1997 1998 1999 2000
        spatial_ref  float64 8B ...
        x            (index) float64 16kB ...
        y            (index) float64 16kB ...
        z            (index) float64 16kB ...
    Attributes:
        standard_name:  index
        long_name:      Index of individual data points
        units:          not_defined
        null_value:     not_defined
        valid_range:    [   0. 2000.]
        grid_mapping:   spatial_ref




.. GENERATED FROM PYTHON SOURCE LINES 85-88

If a dimension is not discrete, meaning it represents ranges (such as depth layers),
then the bounds on each dimension value also need to be defined, and are linked
to the dimension through the "bounds" attribute.

.. GENERATED FROM PYTHON SOURCE LINES 88-92

.. code-block:: Python

    print('example non-discrete dimension:\n')
    print(survey['models/inverted_models']['gate_times'])
    print('\n\ncorresponding bounds on non-discrete dimension:\n')
    print(survey['models/inverted_models']['gate_times_bnds'])




.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    example non-discrete dimension:

    <xarray.DataArray 'gate_times' (gate_times: 15)> Size: 120B
    array([1.085000e-05, 3.255000e-05, 5.426000e-05, 8.681000e-05, 1.410600e-04,
           2.278700e-04, 3.689300e-04, 5.859500e-04, 9.114800e-04, 1.410630e-03,
           2.191900e-03, 3.418070e-03, 5.338690e-03, 8.301020e-03, 1.337928e-02])
    Coordinates:
      * gate_times   (gate_times) float64 120B 1.085e-05 3.255e-05 ... 0.01338
        spatial_ref  float64 8B ...
    Attributes:
        standard_name:  gate_times
        long_name:      receiver gate times
        units:          seconds
        null_value:     not_defined
        valid_range:    [1.085000e-05 1.337928e-02]
        grid_mapping:   spatial_ref
        bounds:         gate_times_bnds


    corresponding bounds on non-discrete dimension:

    <xarray.DataArray 'gate_times_bnds' (gate_times: 15, nv: 2)> Size: 240B
    [30 values with dtype=float64]
    Coordinates:
      * gate_times   (gate_times) float64 120B 1.085e-05 3.255e-05 ... 0.01338
      * nv           (nv) int64 16B 0 1
        spatial_ref  float64 8B ...
    Attributes:
        standard_name:  gate_times_bounds
        long_name:      receiver gate times cell boundaries
        null_value:     not_defined
        valid_range:    [-0.00012479  0.01351492]
        grid_mapping:   spatial_ref




.. GENERATED FROM PYTHON SOURCE LINES 93-95

Coordinates
^^^^^^^^^^^

.. GENERATED FROM PYTHON SOURCE LINES 97-102

Coordinates define the spatial and temporal positioning of the data (X Y Z T).
Additionally, all dimensions are by default classified as a coordinate.
This means a dataset can have both dimensional and non-dimensional coordinates.
Dimensional coordinates are noted with a * (or bold text) in printed output of the xarray,
such as ``index``, ``gate_times``, ``nv`` in this example:

.. GENERATED FROM PYTHON SOURCE LINES 102-104

.. code-block:: Python

    print(survey['data'].dataset.coords)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Coordinates:
        *empty*




.. GENERATED FROM PYTHON SOURCE LINES 105-106

Tabular Coordinates

.. GENERATED FROM PYTHON SOURCE LINES 108-113

In Tabular data, coordinates are typically non-dimensional, since the primary dataset
dimension is ``index``. By default, we define the spatial coordinates, ``x`` and ``y``,
based on the longitude and latitude (or easting/northing) data variables. If relevant,
``z`` and ``t`` coordinate variables can also be defined, representing the vertical and
temporal coordinates of the data points.

.. GENERATED FROM PYTHON SOURCE LINES 115-116

Note: All coordinates must match the coordinate reference system defined in the Survey.

.. GENERATED FROM PYTHON SOURCE LINES 118-119

Raster Coordinates

.. GENERATED FROM PYTHON SOURCE LINES 121-124

Raster data are gridded, typically representing maps or multi-dimensional models.
Therefore, Raster data almost always have dimensional coordinates, i.e., the
data dimensions correspond directly to either spatial or temporal coordinates (``x``, ``y``, ``z``, ``t``).

.. GENERATED FROM PYTHON SOURCE LINES 124-126

.. code-block:: Python

    print(survey['data/derived_maps/maps'].coords)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Coordinates:
      * x            (x) float64 5kB 2.928e+05 2.934e+05 ... 6.51e+05 6.516e+05
      * nv           (nv) int64 16B 0 1
      * y            (y) float64 10kB 1.607e+06 1.606e+06 ... 8.808e+05 8.802e+05
        spatial_ref  float64 8B ...




.. GENERATED FROM PYTHON SOURCE LINES 127-128

The Spatial Reference Coordinate

.. GENERATED FROM PYTHON SOURCE LINES 130-133

the ``spatial_ref`` coordinate variable is a non-dimensional coordinate that
contains information on the coordinate reference system. For more information,
see :ref:`Coordinate Reference Systems <coordinate reference systems>`.

.. GENERATED FROM PYTHON SOURCE LINES 135-137

Attributes
^^^^^^^^^^

.. GENERATED FROM PYTHON SOURCE LINES 139-142

Both datasets and data variables have attributes (metadata fields). Certain
attributes are required, see our documentation on :ref:`the GS standard <GS Convention Requirements>`.
for more details.

.. GENERATED FROM PYTHON SOURCE LINES 144-145

Dataset attributes

.. GENERATED FROM PYTHON SOURCE LINES 147-151

Dataset attributes provide users a way to document and describe supplementary
information about a dataset group as a whole, such as model inversion parameters
or other processing descriptions. At a minimum, a ``content`` attribute should
contain a brief summary of the contents of the dataset.

.. GENERATED FROM PYTHON SOURCE LINES 151-153

.. code-block:: Python

    pprint(survey['models/inverted_models'].attrs)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    {'comment': 'This dataset includes inverted resistivity models derived from '
                'processed AEM data produced by USGS',
     'content': 'inverted resistivity models',
     'uuid': 'b41252cd-a11d-4d2e-acc5-dffd2b18c237'}




.. GENERATED FROM PYTHON SOURCE LINES 154-155

Variable attributes

.. GENERATED FROM PYTHON SOURCE LINES 157-159

Each data variable must contain attributes detailing the metadata
of that individual variable. These follow the `Climate and Forecast (CF) metadata conventions <http://cfconventions.org/>`_.

.. GENERATED FROM PYTHON SOURCE LINES 159-159

.. code-block:: Python

    pprint(survey['models/inverted_models']['conductivity'].attrs)



.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    {'format': '30e15.6',
     'grid_mapping': 'spatial_ref',
     'long_name': 'Layer conductivity',
     'null_value': 'not_defined',
     'standard_name': 'conductivity',
     'units': 'S/m',
     'valid_range': array([1.456164e-04, 1.000000e+01])}





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

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


.. _sphx_glr_download_examples_Interacting_With_GS_Files_plot_xarray_methods.py:

.. only:: html

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

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_xarray_methods.zip <plot_xarray_methods.zip>`


.. only:: html

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

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