# Path: nansat/utils.py
# def get_random_color(c0=None, minDist=100, low=0, high=255):
#     """Create random color which is far enough from the input color
# 
#     Parameters
#     ----------
#         c0 : str
#             hexademical representation of the color (e.g. '#ff0000' for red)
#         minDist : int
#             minimal distance to input color
# 
#     Returns
#     -------
#         c0 : str
#             hexademical representation of the new random color
#     """
#     if not MATPLOTLIB_IS_INSTALLED:
#         raise ImportError('Matplotlib is not installed')
# 
#     # check inputs
#     if c0 is None:
#         c0 = '#000000'
#     # convert input color to tuple of R,G,B
#     c0rgb = np.array(hex2color(c0))
# 
#     # create new random color
#     c1rgb = np.array([np.random.randint(low, high),
#                       np.random.randint(low, high),
#                       np.random.randint(low, high)])
# 
#     # calculate distance
#     d = np.sum((c0rgb - c1rgb)**2)**0.5
# 
#     # if distance is small, create new random color
#     if d < minDist:
#         c1 = get_random_color(c0, minDist)
#     else:
#         # convert to HEX code
#         c1 = '#%02x%02x%02x' % tuple(c1rgb)
# 
#     return c1
# 
# def parse_time(time_string):
#     ''' Parse time string accounting for possible wrong formatting
#     Parameters
#     ----------
#     time_string : str
#         string with date and time
#     Returns
#     -------
#         time_value : datetime object
# 
#     '''
#     time_string = time_string.strip()
#     # To account for datasets on the format YYYY-MM-DDZ which is
#     # invalid since it has no time, but a timezone
#     try:
#         time_value = parse(time_string)
#     except ValueError:
#         if (len(time_string) == 11 and
#                 time_string.endswith('Z')):
#             time_value = parse(time_string[:10])
# 
#     return time_value
# 
# def register_colormaps():
#     ''' Create custom colormaps and register them '''
#     obpg = {'red': [(0.00, 0.56, 0.56),
#                     (0.19, 0.00, 0.00),
#                     (0.38, 0.00, 0.00),
#                     (0.50, 0.00, 0.00),
#                     (0.63, 1.00, 1.00),
#                     (0.88, 1.00, 1.00),
#                     (1.00, 0.40, 0.40)],
# 
#             'green': [(0.00, 0.00, 0.00),
#                       (0.19, 0.00, 0.00),
#                       (0.38, 1.00, 1.00),
#                       (0.50, 1.00, 1.00),
#                       (0.63, 1.00, 1.00),
#                       (0.88, 0.00, 0.00),
#                       (1.00, 0.00, 0.00)],
# 
#             'blue': [(0.00, 0.43, 0.43),
#                      (0.19, 1.00, 1.00),
#                      (0.38, 1.00, 1.00),
#                      (0.50, 0.00, 0.00),
#                      (0.63, 0.00, 0.00),
#                      (0.88, 0.00, 0.00),
#                      (1.00, 0.00, 0.00)],
#             }
# 
# 
#     ak01 = {'red': [(0, 0.1, 0.1,),
#                     (0.1, 0.56, 0.56,),
#                     (0.22, 0, 0,),
#                     (0.27, 0, 0,),
#                     (0.37, 0.3, 0.3,),
#                     (0.47, 0, 0,),
#                     (0.52, 0, 0,),
#                     (0.64, 1, 1,),
#                     (0.76, 1, 1,),
#                     (0.88, 0.4, 0.4,),
#                     (1, 1, 1,)],
# 
#             'green': [(0, 0, 0,),
#                       (0.1, 0, 0,),
#                       (0.22, 0, 0,),
#                       (0.27, 0, 0,),
#                       (0.37, 0.6, 0.6,),
#                       (0.47, 0.6, 0.6,),
#                       (0.52, 1, 1,),
#                       (0.64, 1, 1,),
#                       (0.76, 0, 0,),
#                       (0.88, 0, 0,),
#                       (1, 0.5, 0.5,)],
# 
#             'blue': [(0, 0.1, 0.1,),
#                      (0.1, 0.5, 0.5,),
#                      (0.22, 0.5, 0.5,),
#                      (0.27, 1, 1,),
#                      (0.37, 1, 1,),
#                      (0.47, 0, 0,),
#                      (0.52, 0, 0,),
#                      (0.64, 0, 0,),
#                      (0.76, 0, 0,),
#                      (0.88, 0, 0,),
#                      (1, 0.5, 0.5,)],
#             }
# 
#     if MATPLOTLIB_IS_INSTALLED:
#         cm.register_cmap(cmap=LinearSegmentedColormap('obpg', obpg, 256))
#         cm.register_cmap(cmap=LinearSegmentedColormap('ak01', ak01, 256))
# 
# Path: nansat/tests/nansat_test_data.py



import os
import unittest
import datetime
import warnings
    import matplotlib
    import matplotlib.pyplot as plt
from mock import patch
    from matplotlib.colors import hex2color
from nansat.utils import get_random_color, parse_time, register_colormaps
from nansat.tests import nansat_test_data as ntd
#------------------------------------------------------------------------------
# Name:         test_nansat.py
# Purpose:      Test the Nansat class
#
# Author:       Morten Wergeland Hansen, Asuka Yamakawa
# Modified: Morten Wergeland Hansen
#
# Created:      18.06.2014
# Last modified:16.04.2015 10:48
# Copyright:    (c) NERSC
# Licence:      This file is part of NANSAT. You can redistribute it or modify
#               under the terms of GNU General Public License, v.3
#               http://www.gnu.org/licenses/gpl-3.0.html
#------------------------------------------------------------------------------
from __future__ import unicode_literals, absolute_import


try:
except ImportError:

# Path: nansat/utils.py
# def get_random_color(c0=None, minDist=100, low=0, high=255):
#     """Create random color which is far enough from the input color
# 
#     Parameters
#     ----------
#         c0 : str
#             hexademical representation of the color (e.g. '#ff0000' for red)
#         minDist : int
#             minimal distance to input color
# 
#     Returns
#     -------
#         c0 : str
#             hexademical representation of the new random color
#     """
#     if not MATPLOTLIB_IS_INSTALLED:
#         raise ImportError('Matplotlib is not installed')
# 
#     # check inputs
#     if c0 is None:
#         c0 = '#000000'
#     # convert input color to tuple of R,G,B
#     c0rgb = np.array(hex2color(c0))
# 
#     # create new random color
#     c1rgb = np.array([np.random.randint(low, high),
#                       np.random.randint(low, high),
#                       np.random.randint(low, high)])
# 
#     # calculate distance
#     d = np.sum((c0rgb - c1rgb)**2)**0.5
# 
#     # if distance is small, create new random color
#     if d < minDist:
#         c1 = get_random_color(c0, minDist)
#     else:
#         # convert to HEX code
#         c1 = '#%02x%02x%02x' % tuple(c1rgb)
# 
#     return c1
# 
# def parse_time(time_string):
#     ''' Parse time string accounting for possible wrong formatting
#     Parameters
#     ----------
#     time_string : str
#         string with date and time
#     Returns
#     -------
#         time_value : datetime object
# 
#     '''
#     time_string = time_string.strip()
#     # To account for datasets on the format YYYY-MM-DDZ which is
#     # invalid since it has no time, but a timezone
#     try:
#         time_value = parse(time_string)
#     except ValueError:
#         if (len(time_string) == 11 and
#                 time_string.endswith('Z')):
#             time_value = parse(time_string[:10])
# 
#     return time_value
# 
# def register_colormaps():
#     ''' Create custom colormaps and register them '''
#     obpg = {'red': [(0.00, 0.56, 0.56),
#                     (0.19, 0.00, 0.00),
#                     (0.38, 0.00, 0.00),
#                     (0.50, 0.00, 0.00),
#                     (0.63, 1.00, 1.00),
#                     (0.88, 1.00, 1.00),
#                     (1.00, 0.40, 0.40)],
# 
#             'green': [(0.00, 0.00, 0.00),
#                       (0.19, 0.00, 0.00),
#                       (0.38, 1.00, 1.00),
#                       (0.50, 1.00, 1.00),
#                       (0.63, 1.00, 1.00),
#                       (0.88, 0.00, 0.00),
#                       (1.00, 0.00, 0.00)],
# 
#             'blue': [(0.00, 0.43, 0.43),
#                      (0.19, 1.00, 1.00),
#                      (0.38, 1.00, 1.00),
#                      (0.50, 0.00, 0.00),
#                      (0.63, 0.00, 0.00),
#                      (0.88, 0.00, 0.00),
#                      (1.00, 0.00, 0.00)],
#             }
# 
# 
#     ak01 = {'red': [(0, 0.1, 0.1,),
#                     (0.1, 0.56, 0.56,),
#                     (0.22, 0, 0,),
#                     (0.27, 0, 0,),
#                     (0.37, 0.3, 0.3,),
#                     (0.47, 0, 0,),
#                     (0.52, 0, 0,),
#                     (0.64, 1, 1,),
#                     (0.76, 1, 1,),
#                     (0.88, 0.4, 0.4,),
#                     (1, 1, 1,)],
# 
#             'green': [(0, 0, 0,),
#                       (0.1, 0, 0,),
#                       (0.22, 0, 0,),
#                       (0.27, 0, 0,),
#                       (0.37, 0.6, 0.6,),
#                       (0.47, 0.6, 0.6,),
#                       (0.52, 1, 1,),
#                       (0.64, 1, 1,),
#                       (0.76, 0, 0,),
#                       (0.88, 0, 0,),
#                       (1, 0.5, 0.5,)],
# 
#             'blue': [(0, 0.1, 0.1,),
#                      (0.1, 0.5, 0.5,),
#                      (0.22, 0.5, 0.5,),
#                      (0.27, 1, 1,),
#                      (0.37, 1, 1,),
#                      (0.47, 0, 0,),
#                      (0.52, 0, 0,),
#                      (0.64, 0, 0,),
#                      (0.76, 0, 0,),
#                      (0.88, 0, 0,),
#                      (1, 0.5, 0.5,)],
#             }
# 
#     if MATPLOTLIB_IS_INSTALLED:
#         cm.register_cmap(cmap=LinearSegmentedColormap('obpg', obpg, 256))
#         cm.register_cmap(cmap=LinearSegmentedColormap('ak01', ak01, 256))
# 
# Path: nansat/tests/nansat_test_data.py



# Path: nansat/tests/test_utils.py
import os
import unittest
import datetime
import warnings
    import matplotlib
    import matplotlib.pyplot as plt
from mock import patch
    from matplotlib.colors import hex2color
from nansat.utils import get_random_color, parse_time, register_colormaps
from nansat.tests import nansat_test_data as ntd

#------------------------------------------------------------------------------
# Name:         test_nansat.py
# Purpose:      Test the Nansat class
#
# Author:       Morten Wergeland Hansen, Asuka Yamakawa
# Modified: Morten Wergeland Hansen
#
# Created:      18.06.2014
# Last modified:16.04.2015 10:48
# Copyright:    (c) NERSC
# Licence:      This file is part of NANSAT. You can redistribute it or modify
#               under the terms of GNU General Public License, v.3
#               http://www.gnu.org/licenses/gpl-3.0.html
#------------------------------------------------------------------------------
from __future__ import unicode_literals, absolute_import


try:
except ImportError:

    MATPLOTLIB_IS_INSTALLED = False