Metadata-Version: 2.0
Name: ncflag
Version: 0.0.3
Summary: Utility for interaction with CF compliant NetCDF flag variables.
Home-page: https://ctor.space/gitlab/work/ncflag
Author: Stefan Codrescu
Author-email: stefan.codrescu@noaa.gov
License: UNKNOWN
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.6
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Dist: Click
Requires-Dist: netCDF4
Requires-Dist: numpy

NetCDF Flag Wrapper (ncflag)
============================

So... you want to inspect CF Compliant NetCDF flag variables?

CF Compliant NetCDF Flag variables are integer flags associated with, or
having:

-  flag\_values
-  flag\_meanings
-  flag\_masks (optionally)

Read the `CF Conventions on
flags <http://cfconventions.org/Data/cf-conventions/cf-conventions-1.7/cf-conventions.html#flags>`__
for more information.

TL;DR
-----

Install the utility with with pip:

::

    pip install ncflag

On the command line, use ``ncflag``:

::

    Usage: ncflag [OPTIONS] NCFILE FLAG

    Options:
      -v, --version                   Show the version and exit.
      --show_flags PATH               Print the flags this tool can inspect.
      --use_time_var TEXT
      -l [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                      log level
      --help                          Show this message and exit.

Notes:

Use --show\_flags to discover what flags in a given file can be
inspected.

Limitation: can only inspect flags of at most one dimension. See details
below for dealing with multidimensional flags.

The nominal output with --use\_time\_var specified is shown below.
Without use\_time\_var, the index along the dimension will be printed
instead of a iso 8601 timestamp.

.. code:: text

    2017-11-27T21:07:41.543778: [u'data_quality_error']
    2017-11-27T21:07:42.543812: [u'good_data']
    2017-11-27T21:07:43.543807: [u'good_data']
    2017-11-27T21:07:44.543802: [u'good_data']

Multidimensional Flags
----------------------

Occasionally, by some poor misfortune, you may encounter
multidimensional flag variables. These are currently not supported by
the Command Line Interface (CLI), however, the FlagWrap class can still
be used in code, or through an interactive (IPython) session. The
``FlagWrap.get_flags_set_at_index`` can be passed a tuple of indicies to
get the flags set in a multidimensional flag variable. Below is an
example.

.. code:: python

    from ncflag import FlagWrap
    import netCDF4 as nc

    with nc.Dataset("somenetcdf.nc") as nc_in:
        v = nc_in.variables["mutidim_variable"]
        print(v.shape)  # --> (2, 10), is multidim.
        w = FlagWrap(v)
        print(w.get_flags_set_at_index((0, 0)))  # --> ["good_quality_qf"]

API and Documentation
---------------------

To use the FlagWrap in your own code, see the example above for
multidimensional flags.

For documentation, please read ``flag_wrapper.py``. It is one file and
is documented with comprehensive docstrings. The functions are named
descriptively. A following functions are available:

::

    - init_zeros(cls, nc_var, shape)
    - get_flag(self, flag_meaning)
    - reduce(self, exclude_mask, axis=-1)
    - get_flag_at_index(self, flag_meaning, i)
    - get_flags_set_at_index(self, i, exit_on_good=False)
    - find_flag(self, options)
    - set_flag(self, flag_meaning, flags)
    - set_flag_at_index(self, flag_meaning, i)
    - get_value_for_meaning(self, flag_meaning)
    - sync(self)

Testing
-------

TODO! (tested in production...., good enough right?)

--------------

Deploy to pip, after testing with python2 and python3:

.. code:: bash

    rm -r dist/
    python setup.py bdist_wheel --universal
    twine upload dist/*


