# Path: hftools/py3compat.py
# DEFAULT_ENCODING = "cp1252"
#     PY3 = True
#     PY3 = False
# def no_code(x, encoding=None):
# def decode(s, encoding=None):
# def encode(u, encoding=None):
# def cast_unicode(s, encoding=None):
# def cast_bytes(s, encoding=None):
#     def reraise(tp, value, tb=None):
#     def popen(command):
#     def popen(command):
#     def print(*k, **kw):
# def cast_str(s, encoding=None):
# 
# Path: hftools/constants/si_units.py
# def unit_to_multiplier(unit):
# def string_number_with_unit_to_value(string_number):
# def convert_with_unit(unit, value):
# def _help_format_sci(value, digs):
# def mantissa(x):
# def format_number(number, fmt="%(num)s %(unit)s",
#                   unit="", digs=3, greek=False):
#     def __init__(self, fmt="%(num)s %(unit)s", unit="", digs=3, greek=False):
#     def __mod__(self, value):
# class SIFormat(object):
# 
# Path: hftools/dataset/arrayobj.py
# class hfarray(_hfarray):
#     def __new__(subtype, data, dims=None, dtype=None, copy=True, order=None,
#                 subok=False, ndmin=0, unit=None, outputformat=None, info=None):
#         if hasattr(data, "__hfarray__"):
#             data, dims = data.__hfarray__()
#             if unit is None and len(dims) == 1:
#                 unit = dims[0].unit
#             if outputformat is None and len(dims) == 1:
#                 outputformat = dims[0].outputformat
#         return _hfarray.__new__(subtype, data, dims=dims, dtype=dtype,
#                                 copy=copy, order=order, subok=subok,
#                                 ndmin=ndmin, unit=unit,
#                                 outputformat=outputformat, info=info)
# 
# def remove_tail(x):
#     u"""Collapse all dimensions except first and matrix dimensions"""
# 
#     a = np.array(x)
#     shape = x.shape
#     if ismatrix(x):
#         newshape = (shape[0], int(np.multiply.reduce(shape[1:-2])))
#         newshape = newshape + shape[-2:]
#     else:
#         newshape = (shape[0], int(np.multiply.reduce(shape[1:])))
#     outa = a.reshape(newshape)
#     if isinstance(x, hfarray):
#         dim = DimRep("Tail", np.arange(outa.shape[1]))
#         dims = (x.dims[0], dim)
#         if ismatrix(x):
#             dims = dims + x.dims[-2:]
#         outa = hfarray(outa, dims=dims, unit=x.unit)
#     return outa
# 
# Path: hftools/math.py
# def delay(freq, var):
#     r"""Berakna grupploptid :math:`\tau=-\frac{d\varphi}{d\omega}` for data
# 
#     Invariabler
# 
#         *freq*
#             frekvenser som *var* galler for
# 
#         *var*
#             komplexa data som skall anvandas i berakningen
# 
#     Resultat (f,tau)
# 
#         *f*
#             frekvenserna som motsvarar mittpunkter i *freq*
# 
#         *tau*
#             beraknad grupploptid med hjalp av mittpunkts approximation for
#             derivatan
# 
#    >>> x=hfarray(np.arange(0,10.))
#    >>> y=hfarray(np.exp(-2j*np.pi*x/10))
#    >>> f,tau=delay(x,y)
#    >>> f
#    hfarray([ 0.5,  1.5,  2.5,  3.5,  4.5,  5.5,  6.5,  7.5,  8.5])
#    >>> tau
#    hfarray([ 0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1])
# 
#     """
#     freq, var = make_same_dims(freq, var)
#     f_mean = (freq[:-1] + freq[1:]) / 2
#     domega = (2 * pi * (freq[:-1] - freq[1:]))
#     dfi = angle(var[1:] / var[:-1])
#     return (f_mean, dfi / domega)
# 
# def unwrap_phase(data, deg=False):
#     a1 = _unwrap_phase(data, deg=deg)
#     return a1


import itertools
import re
import sys
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import pylab
import hftools.math
from matplotlib.axes import Axes
from matplotlib.projections.polar import PolarAxes
from matplotlib.ticker import FormatStrFormatter, EngFormatter
from matplotlib._pylab_helpers import Gcf
from matplotlib.backends.backend_pdf import PdfPages
from hftools.py3compat import text_type
from hftools.constants.si_units import si_exp_to_prefixes, _help_format_sci
from hftools.dataset import hfarray, remove_tail
from hftools.math import delay, unwrap_phase
    from win32api import GetSystemMetrics
    from hftools import path
    from hftools.file_formats import read_data

class WrapUnwrapDegAxes(DegAxes):
    name = "wrapunwrapeddeg"
matplotlib.projections.register_projection(WrapUnwrapDegAxes)


class RadAxes(MagAxes):
    name = "rad"

    def __init__(self, *args, **kwargs):
        MagAxes.__init__(self, *args, **kwargs)
        self.set_ylabel_fmt(u"[]")

    def set_ylabel_fmt(self, fmt, unit=u"rad"):
        MagAxes.set_ylabel_fmt(self, fmt, unit)
matplotlib.projections.register_projection(RadAxes)


class UnwrapRadAxes(RadAxes):
    name = "unwraprad"
matplotlib.projections.register_projection(UnwrapRadAxes)


class ComplexPolarAxes(PolarAxes):
    name = "cplxpolar"

    def plot(self, *args, **kwargs):
        projection = self.name
        vars = args[:2]
        args = args[2:]

# Path: hftools/py3compat.py
# DEFAULT_ENCODING = "cp1252"
#     PY3 = True
#     PY3 = False
# def no_code(x, encoding=None):
# def decode(s, encoding=None):
# def encode(u, encoding=None):
# def cast_unicode(s, encoding=None):
# def cast_bytes(s, encoding=None):
#     def reraise(tp, value, tb=None):
#     def popen(command):
#     def popen(command):
#     def print(*k, **kw):
# def cast_str(s, encoding=None):
# 
# Path: hftools/constants/si_units.py
# def unit_to_multiplier(unit):
# def string_number_with_unit_to_value(string_number):
# def convert_with_unit(unit, value):
# def _help_format_sci(value, digs):
# def mantissa(x):
# def format_number(number, fmt="%(num)s %(unit)s",
#                   unit="", digs=3, greek=False):
#     def __init__(self, fmt="%(num)s %(unit)s", unit="", digs=3, greek=False):
#     def __mod__(self, value):
# class SIFormat(object):
# 
# Path: hftools/dataset/arrayobj.py
# class hfarray(_hfarray):
#     def __new__(subtype, data, dims=None, dtype=None, copy=True, order=None,
#                 subok=False, ndmin=0, unit=None, outputformat=None, info=None):
#         if hasattr(data, "__hfarray__"):
#             data, dims = data.__hfarray__()
#             if unit is None and len(dims) == 1:
#                 unit = dims[0].unit
#             if outputformat is None and len(dims) == 1:
#                 outputformat = dims[0].outputformat
#         return _hfarray.__new__(subtype, data, dims=dims, dtype=dtype,
#                                 copy=copy, order=order, subok=subok,
#                                 ndmin=ndmin, unit=unit,
#                                 outputformat=outputformat, info=info)
# 
# def remove_tail(x):
#     u"""Collapse all dimensions except first and matrix dimensions"""
# 
#     a = np.array(x)
#     shape = x.shape
#     if ismatrix(x):
#         newshape = (shape[0], int(np.multiply.reduce(shape[1:-2])))
#         newshape = newshape + shape[-2:]
#     else:
#         newshape = (shape[0], int(np.multiply.reduce(shape[1:])))
#     outa = a.reshape(newshape)
#     if isinstance(x, hfarray):
#         dim = DimRep("Tail", np.arange(outa.shape[1]))
#         dims = (x.dims[0], dim)
#         if ismatrix(x):
#             dims = dims + x.dims[-2:]
#         outa = hfarray(outa, dims=dims, unit=x.unit)
#     return outa
# 
# Path: hftools/math.py
# def delay(freq, var):
#     r"""Berakna grupploptid :math:`\tau=-\frac{d\varphi}{d\omega}` for data
# 
#     Invariabler
# 
#         *freq*
#             frekvenser som *var* galler for
# 
#         *var*
#             komplexa data som skall anvandas i berakningen
# 
#     Resultat (f,tau)
# 
#         *f*
#             frekvenserna som motsvarar mittpunkter i *freq*
# 
#         *tau*
#             beraknad grupploptid med hjalp av mittpunkts approximation for
#             derivatan
# 
#    >>> x=hfarray(np.arange(0,10.))
#    >>> y=hfarray(np.exp(-2j*np.pi*x/10))
#    >>> f,tau=delay(x,y)
#    >>> f
#    hfarray([ 0.5,  1.5,  2.5,  3.5,  4.5,  5.5,  6.5,  7.5,  8.5])
#    >>> tau
#    hfarray([ 0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1])
# 
#     """
#     freq, var = make_same_dims(freq, var)
#     f_mean = (freq[:-1] + freq[1:]) / 2
#     domega = (2 * pi * (freq[:-1] - freq[1:]))
#     dfi = angle(var[1:] / var[:-1])
#     return (f_mean, dfi / domega)
# 
# def unwrap_phase(data, deg=False):
#     a1 = _unwrap_phase(data, deg=deg)
#     return a1


# Path: hftools/plotting/helper.py
import itertools
import re
import sys
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import pylab
import hftools.math
from matplotlib.axes import Axes
from matplotlib.projections.polar import PolarAxes
from matplotlib.ticker import FormatStrFormatter, EngFormatter
from matplotlib._pylab_helpers import Gcf
from matplotlib.backends.backend_pdf import PdfPages
from hftools.py3compat import text_type
from hftools.constants.si_units import si_exp_to_prefixes, _help_format_sci
from hftools.dataset import hfarray, remove_tail
from hftools.math import delay, unwrap_phase
    from win32api import GetSystemMetrics
    from hftools import path
    from hftools.file_formats import read_data


class WrapUnwrapDegAxes(DegAxes):
    name = "wrapunwrapeddeg"
matplotlib.projections.register_projection(WrapUnwrapDegAxes)


class RadAxes(MagAxes):
    name = "rad"

    def __init__(self, *args, **kwargs):
        MagAxes.__init__(self, *args, **kwargs)
        self.set_ylabel_fmt(u"[]")

    def set_ylabel_fmt(self, fmt, unit=u"rad"):
        MagAxes.set_ylabel_fmt(self, fmt, unit)
matplotlib.projections.register_projection(RadAxes)


class UnwrapRadAxes(RadAxes):
    name = "unwraprad"
matplotlib.projections.register_projection(UnwrapRadAxes)


class ComplexPolarAxes(PolarAxes):
    name = "cplxpolar"

    def plot(self, *args, **kwargs):
        projection = self.name
        vars = args[:2]
        args = args[2:]

        if len(vars) == 2 and isinstance(vars[1], text_type):