# Path: rvic/core/share.py
# FILLVALUE_F = default_fillvals[NC_DOUBLE]
# 
# Path: rvic/core/variables.py
# class Point(object):
#     '''
#     Creates a point class for intellegently storing coordinate information
#     '''
# 
#     def __init__(self, lat=-9999.9, lon=-9999.9, domx=-9999, domy=-9999,
#                  routx=-9999, routy=-9999, name=None, cell_id=-9999):
#         '''Defines x and y variables'''
#         self.lat = lat
#         self.lon = lon
#         self.domx = domx
#         self.domy = domy
#         self.routx = routx
#         self.routy = routy
#         self.cell_id = cell_id
# 
#         if name:
#             self.name = name
#         else:
#             self.name = 'outlet_{0:3.4f}_{1:3.4f}'.format(self.lat, self.lon)
# 
#         return
# 
#     def __str__(self):
#         return ('Point({0}, lat:{1:3.4f}, lon:{2:3.4f}, y:{3:d}, '
#                 'x:{4:d})'.format(self.name, self.lat, self.lon, self.domy,
#                                   self.domx))
# 
#     def __repr__(self):
#         return ('    -- Point --    \n'
#                 'name:\t{0}\n'
#                 'lat:\t{1:3.4f}\n'
#                 'lon:\t{2:3.4f}\n'
#                 'domy:\t{3:d}\n'
#                 'domx:\t{4:d}\n'
#                 'routy:\t{5:d}\n'
#                 'routx:\t{6:d}\n'.format(self.name, self.lat, self.lon,
#                                          self.domy, self.domx,
#                                          self.routy, self.routx))
# 
# Path: rvic/core/log.py
# LOG_NAME = 'rvic'
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
# def itervalues(d):
# def iteritems(d):
# def itervalues(d):


import numpy as np
from .share import FILLVALUE_F
from .utilities import find_nearest, latlon2yx
from .variables import Point
from logging import getLogger
from .log import LOG_NAME
from .pycompat import OrderedDict, iteritems, pyzip

    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Place data
    fraction[ilat_min_ind:ilat_max_ind,
             ilon_min_ind:ilon_max_ind] += in_data['fraction']
    unit_hydrograph[:,
                    ilat_min_ind:ilat_max_ind,
                    ilon_min_ind:ilon_max_ind] += in_data['unit_hydrograph']

    if agg_data:
        fraction[alat_min_ind:alat_max_ind,
                 alon_min_ind:alon_max_ind] += agg_data['fraction']
        unit_hydrograph[:, alat_min_ind:alat_max_ind,
                        alon_min_ind:alon_max_ind] += \
            agg_data['unit_hydrograph']
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Mask and Normalize the unit unit_hydrograph
    if (maskandnorm):
        # Normalize the unit_hydrograph (each cell should sum to 1)

        yv, xv = np.nonzero(fraction > 0.0)
        unit_hydrograph[:, yv, xv] /= unit_hydrograph[:, yv, xv].sum(axis=0)

        # Mask the unit_hydrograph and make sure they sum to 1 at each grid
        # cell
        ym, xm = np.nonzero(fraction <= 0.0)

# Path: rvic/core/share.py
# FILLVALUE_F = default_fillvals[NC_DOUBLE]
# 
# Path: rvic/core/variables.py
# class Point(object):
#     '''
#     Creates a point class for intellegently storing coordinate information
#     '''
# 
#     def __init__(self, lat=-9999.9, lon=-9999.9, domx=-9999, domy=-9999,
#                  routx=-9999, routy=-9999, name=None, cell_id=-9999):
#         '''Defines x and y variables'''
#         self.lat = lat
#         self.lon = lon
#         self.domx = domx
#         self.domy = domy
#         self.routx = routx
#         self.routy = routy
#         self.cell_id = cell_id
# 
#         if name:
#             self.name = name
#         else:
#             self.name = 'outlet_{0:3.4f}_{1:3.4f}'.format(self.lat, self.lon)
# 
#         return
# 
#     def __str__(self):
#         return ('Point({0}, lat:{1:3.4f}, lon:{2:3.4f}, y:{3:d}, '
#                 'x:{4:d})'.format(self.name, self.lat, self.lon, self.domy,
#                                   self.domx))
# 
#     def __repr__(self):
#         return ('    -- Point --    \n'
#                 'name:\t{0}\n'
#                 'lat:\t{1:3.4f}\n'
#                 'lon:\t{2:3.4f}\n'
#                 'domy:\t{3:d}\n'
#                 'domx:\t{4:d}\n'
#                 'routy:\t{5:d}\n'
#                 'routx:\t{6:d}\n'.format(self.name, self.lat, self.lon,
#                                          self.domy, self.domx,
#                                          self.routy, self.routx))
# 
# Path: rvic/core/log.py
# LOG_NAME = 'rvic'
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
# def itervalues(d):
# def iteritems(d):
# def itervalues(d):


# Path: rvic/core/aggregate.py
import numpy as np
from .share import FILLVALUE_F
from .utilities import find_nearest, latlon2yx
from .variables import Point
from logging import getLogger
from .log import LOG_NAME
from .pycompat import OrderedDict, iteritems, pyzip


    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Place data
    fraction[ilat_min_ind:ilat_max_ind,
             ilon_min_ind:ilon_max_ind] += in_data['fraction']
    unit_hydrograph[:,
                    ilat_min_ind:ilat_max_ind,
                    ilon_min_ind:ilon_max_ind] += in_data['unit_hydrograph']

    if agg_data:
        fraction[alat_min_ind:alat_max_ind,
                 alon_min_ind:alon_max_ind] += agg_data['fraction']
        unit_hydrograph[:, alat_min_ind:alat_max_ind,
                        alon_min_ind:alon_max_ind] += \
            agg_data['unit_hydrograph']
    # ---------------------------------------------------------------- #

    # ---------------------------------------------------------------- #
    # Mask and Normalize the unit unit_hydrograph
    if (maskandnorm):
        # Normalize the unit_hydrograph (each cell should sum to 1)

        yv, xv = np.nonzero(fraction > 0.0)
        unit_hydrograph[:, yv, xv] /= unit_hydrograph[:, yv, xv].sum(axis=0)

        # Mask the unit_hydrograph and make sure they sum to 1 at each grid
        # cell
        ym, xm = np.nonzero(fraction <= 0.0)

        unit_hydrograph[:, ym, xm] = FILLVALUE_F