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

.. only:: html

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

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

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

.. _sphx_glr_examples_Creating_GS_Files_help_I_have_no_variable_metadata.py:


Help! I have no metadata
------------------------

Generate Metadata Templates

This example shows how GSPy can help when you are just getting started with no metadata files at all, only partially complete metadata files, or large data files and need to do the tedious task of filling out the variable metadata.

GSPy provides a ``metadata_template`` function to generate a template YAML file either for ``Survey`` for ``Dataset`` metadata. These templates contain placeholder metadata dictionaries with default values of "not_defined" to help users get started filling in their survey or data variable metadata. Below are multiple example scenarios demonstrating how to generate the desired metadata templates. 


.. figure:: /_static/variable_metadata_template_snippet.png
   :width: 50%
   :align: center

   Example snippet of what the output template YAML file contains. For a dataset's metadata template, each variable in the data file (e.g. columns in a CSV file) is given a dictionary of attributes with the default values of "not_defined" that the user can then go through and update.

.. GENERATED FROM PYTHON SOURCE LINES 19-20

.. code-block:: Python
   :dedent: 1



.. GENERATED FROM PYTHON SOURCE LINES 22-28

.. code-block:: Python


    from os.path import join
    from gspy import Survey, Dataset
    import matplotlib.pyplot as plt
    from matplotlib import image as img


.. GENERATED FROM PYTHON SOURCE LINES 29-31

Generate the Survey Metadata Template
+++++++++++++++++++++++++++++++++++++

.. GENERATED FROM PYTHON SOURCE LINES 33-34

No existing Survey metadata, start with making a generic Survey template

.. GENERATED FROM PYTHON SOURCE LINES 34-37

.. code-block:: Python

    template = Survey.metadata_template()
    template.dump("template_survey_empty.yml")


.. GENERATED FROM PYTHON SOURCE LINES 38-39

Partial existing Survey metadata file, generate a combined template to see what might be missing

.. GENERATED FROM PYTHON SOURCE LINES 39-50

.. code-block:: Python


    # Path to example files
    data_path = '..//data_files//resolve'

    # Pre-existing Survey metadata file
    metadata = join(data_path, "data//Resolve_survey_md.yml")

    # Generate the template, passing the pre-existing file
    template = Survey.metadata_template(metadata)
    template.dump("template_md_survey.yml")


.. GENERATED FROM PYTHON SOURCE LINES 51-53

Generate the Variable Metadata Template for My Dataset
++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. GENERATED FROM PYTHON SOURCE LINES 55-56

Zero existing Dataset metadata file, start with making an empty Dataset metadata template

.. GENERATED FROM PYTHON SOURCE LINES 56-63

.. code-block:: Python


    # Pass the data file (in this case a CSV) to make the template variable-specific. 
    # Each column in the CSV file becomes a variable by default. 
    data = join(data_path, 'data//Resolve.csv')
    template = Dataset.metadata_template(data)
    template.dump("template_md_resolve_empty.yml")


.. GENERATED FROM PYTHON SOURCE LINES 64-65

Combine with a partial existing Dataset metadata file

.. GENERATED FROM PYTHON SOURCE LINES 65-74

.. code-block:: Python


    # Here we have a CSV data file and a partial metadata file (missing the variable attributes)
    metadata = join(data_path, 'data//Resolve_data_md_without_variables.yml')

    # Generate the template for this CSV dataset by combining the existing 
    # partial file with an empty template based on the dataset's variables
    template = Dataset.metadata_template(data, metadata)
    template.dump("template_md_resolve.yml")


.. GENERATED FROM PYTHON SOURCE LINES 75-76

Another CSV example ?

.. GENERATED FROM PYTHON SOURCE LINES 76-83

.. code-block:: Python

    data_path = '..//data_files//skytem_csv'

    data = join(data_path, 'data//skytem_contractor_data.csv')
    metadata = join(data_path, 'data//skytem_contractor_data.yml')
    template = Dataset.metadata_template(data, metadata)
    template.dump("template_md_skytem.yml")


.. GENERATED FROM PYTHON SOURCE LINES 84-85

Loupe Data

.. GENERATED FROM PYTHON SOURCE LINES 85-92

.. code-block:: Python


    data_path = '..//data_files//loupe'

    data = join(data_path, 'data//Kankakee.dat')
    metadata = join(data_path, 'data//loupe_data_metadata.yml')

    template = Dataset.metadata_template(data_filename=data, metadata_file=metadata)
    template.dump("template_md_loupe.yml")

.. _sphx_glr_download_examples_Creating_GS_Files_help_I_have_no_variable_metadata.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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