# Path: rvic/core/time_utility.py
# def ord_to_datetime(time, units, calendar='standard'):
#     '''
#     netCDF4.num2date yields a fake datetime object, this function converts
#     converts that back to a real datetime object
#     '''
#     # this is the netCDF4.datetime object
#     # if the calendar is standard, t is already a real datetime object
#     if type(time) == np.ndarray:
#         if len(time) == 1:
#             time = time[0]
#         else:
#             raise ValueError('time variable is a numpy array with length > 1')
#     t = num2date(time, units, calendar=calendar)
#     if calendar in ['proleptic_gregorian', 'standard', 'gregorian']:
#         return t
#     else:
#         return datetime(t.year, t.month, t.day, t.hour, t.minute, t.second)
# 
# Path: rvic/core/log.py
# LOG_NAME = 'rvic'
# 
# Path: rvic/core/share.py
# SECSPERDAY = HOURSPERDAY * SECSPERHOUR
# 
# HOURSPERDAY = 24.
# 
# TIMEUNITS = 'days since ' + REFERENCE_STRING  # do not change (MUST BE DAYS)!
# 
# Path: rvic/core/share.py
# NC_INT = 'i4'
# 
# NC_FLOAT = 'f4'
# 
# NC_CHAR = 'S1'
# 
# Path: rvic/core/share.py
# NC_DOUBLE = 'f8'
# 
# WATERDENSITY = 1000.
# 
# MONTHSPERYEAR = 12
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
#     return iter(d.items())


import os
import numpy as np
from netCDF4 import Dataset, date2num, num2date, stringtochar
from datetime import datetime
from .time_utility import ord_to_datetime
from logging import getLogger
from .log import LOG_NAME
from .share import SECSPERDAY, HOURSPERDAY, TIMEUNITS
from .share import NC_INT, NC_FLOAT, NC_CHAR
from .share import NC_DOUBLE, WATERDENSITY, MONTHSPERYEAR
from .pycompat import iteritems
from . import share
        self._units = units
        if units in ['kg/m2/s', 'kg m-2 s-1', 'kg m^-2 s^-1',
                     'kg*m-2*s-1', 'kg s-1 m-2']:
            self._units_mult = np.ones_like(self._outlet_y_ind,
                                            dtype=np.float64)
        elif units in ['m3/s', 'm^3/s', 'm3 s-1']:
            # kg/m2/s --> m3/s
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]
            self._units_mult /= WATERDENSITY
        elif units in ['mm/day', 'mm d-1', 'mm d^-1', 'mm/day']:
            # kg/m2/s --> mm/day over basin area
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]
            self._units_mult *= SECSPERDAY
            self._units_mult /= WATERDENSITY
            self._units_mult /= self._outlet_upstream_area
        elif units in ['gal/day', 'gpd', 'gal d-1']:
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]
            self._units_mult /= WATERDENSITY
            self._units_mult *= 2.28E7
        elif units in ['cfs', 'ft^3 s-1', 'f3/s']:
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]
            self._units_mult /= WATERDENSITY
            self._units_mult *= 35.3
        elif units in ['acre-ft/d']:
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]

# Path: rvic/core/time_utility.py
# def ord_to_datetime(time, units, calendar='standard'):
#     '''
#     netCDF4.num2date yields a fake datetime object, this function converts
#     converts that back to a real datetime object
#     '''
#     # this is the netCDF4.datetime object
#     # if the calendar is standard, t is already a real datetime object
#     if type(time) == np.ndarray:
#         if len(time) == 1:
#             time = time[0]
#         else:
#             raise ValueError('time variable is a numpy array with length > 1')
#     t = num2date(time, units, calendar=calendar)
#     if calendar in ['proleptic_gregorian', 'standard', 'gregorian']:
#         return t
#     else:
#         return datetime(t.year, t.month, t.day, t.hour, t.minute, t.second)
# 
# Path: rvic/core/log.py
# LOG_NAME = 'rvic'
# 
# Path: rvic/core/share.py
# SECSPERDAY = HOURSPERDAY * SECSPERHOUR
# 
# HOURSPERDAY = 24.
# 
# TIMEUNITS = 'days since ' + REFERENCE_STRING  # do not change (MUST BE DAYS)!
# 
# Path: rvic/core/share.py
# NC_INT = 'i4'
# 
# NC_FLOAT = 'f4'
# 
# NC_CHAR = 'S1'
# 
# Path: rvic/core/share.py
# NC_DOUBLE = 'f8'
# 
# WATERDENSITY = 1000.
# 
# MONTHSPERYEAR = 12
# 
# Path: rvic/core/pycompat.py
# def iteritems(d):
#     return iter(d.items())


# Path: rvic/core/history.py
import os
import numpy as np
from netCDF4 import Dataset, date2num, num2date, stringtochar
from datetime import datetime
from .time_utility import ord_to_datetime
from logging import getLogger
from .log import LOG_NAME
from .share import SECSPERDAY, HOURSPERDAY, TIMEUNITS
from .share import NC_INT, NC_FLOAT, NC_CHAR
from .share import NC_DOUBLE, WATERDENSITY, MONTHSPERYEAR
from .pycompat import iteritems
from . import share

        self._units = units
        if units in ['kg/m2/s', 'kg m-2 s-1', 'kg m^-2 s^-1',
                     'kg*m-2*s-1', 'kg s-1 m-2']:
            self._units_mult = np.ones_like(self._outlet_y_ind,
                                            dtype=np.float64)
        elif units in ['m3/s', 'm^3/s', 'm3 s-1']:
            # kg/m2/s --> m3/s
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]
            self._units_mult /= WATERDENSITY
        elif units in ['mm/day', 'mm d-1', 'mm d^-1', 'mm/day']:
            # kg/m2/s --> mm/day over basin area
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]
            self._units_mult *= SECSPERDAY
            self._units_mult /= WATERDENSITY
            self._units_mult /= self._outlet_upstream_area
        elif units in ['gal/day', 'gpd', 'gal d-1']:
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]
            self._units_mult /= WATERDENSITY
            self._units_mult *= 2.28E7
        elif units in ['cfs', 'ft^3 s-1', 'f3/s']:
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]
            self._units_mult /= WATERDENSITY
            self._units_mult *= 35.3
        elif units in ['acre-ft/d']:
            self._units_mult = grid_area[self._outlet_y_ind,
                                         self._outlet_x_ind]

            self._units_mult /= WATERDENSITY