ocw/utils.py
def decode_time_values(dataset, time_var_name):
    ''' Decode NetCDF time values into Python datetime objects.

    :param dataset: The dataset from which time values should be extracted.
    :type dataset: netCDF4.Dataset
    :param time_var_name: The name of the time variable in dataset.
    :type time_var_name: :mod:`string`

    :returns: The list of converted datetime values.

    :raises ValueError: If the time units value couldn't be parsed, if the
        base time value couldn't be parsed, or if the time_var_name could not
        be found in the dataset.
    '''
    time_data = dataset.variables[time_var_name]
    time_format = time_data.units
    if time_format[-1].lower() == 'z':
        time_format = time_format[:-1]
    if time_format[-3:].lower() == 'utc':
        time_format = time_format[:-3]

    time_units = parse_time_units(time_format)

    times = []
    if time_units == 'months':
        # datetime.timedelta doesn't support a 'months' option. To remedy
        # this, a month == 30 days for our purposes.
        time_base = parse_time_base(time_format)
        for time_val in time_data:
            times.append(time_base + relativedelta(months=int(time_val)))
    else:
        try:
            times_calendar = time_data.calendar
        except:
            times_calendar = 'standard'

        times = num2date(
            time_data[:], units=time_format, calendar=times_calendar)
        if times_calendar == '360_day':
            for it, t in enumerate(times):
                times[it] = dt.datetime.strptime(str(t), '%Y-%m-%d 00:00:00')
    return times
 Decode NetCDF time values into Python datetime objects.

    :param dataset: The dataset from which time values should be extracted.
    :type dataset: netCDF4.Dataset
    :param time_var_name: The name of the time variable in dataset.
    :type time_var_name: :mod:`string`

    :returns: The list of converted datetime values.

    :raises ValueError: If the time units value couldn't be parsed, if the
        base time value couldn't be parsed, or if the time_var_name could not
        be found in the dataset.
    
Decode NetCDF time values into Python datetime objects.
Decode NetCDF time values into Python datetime objects .
def decode_time_values(dataset, time_var_name):
    time_data = dataset.variables[time_var_name]
    time_format = time_data.units
    if time_format[-1].lower() == 'z':
        time_format = time_format[:-1]
    if time_format[-3:].lower() == 'utc':
        time_format = time_format[:-3]
    time_units = parse_time_units(time_format)
    times = []
    if time_units == 'months':
        time_base = parse_time_base(time_format)
        for time_val in time_data:
            times.append(time_base + relativedelta(months=int(time_val)))
    else:
        try:
            times_calendar = time_data.calendar
        except:
            times_calendar = 'standard'
        times = num2date(
            time_data[:], units=time_format, calendar=times_calendar)
        if times_calendar == '360_day':
            for it, t in enumerate(times):
                times[it] = dt.datetime.strptime(str(t), '%Y-%m-%d 00:00:00')
    return times
def decode_time_values ( dataset , time_var_name ) : time_data = dataset . variables [ time_var_name ] time_format = time_data . units if time_format [ - 1 ] . lower ( ) == 'z' : time_format = time_format [ : - 1 ] if time_format [ - 3 : ] . lower ( ) == 'utc' : time_format = time_format [ : - 3 ] time_units = parse_time_units ( time_format ) times = [ ] if time_units == 'months' : time_base = parse_time_base ( time_format ) for time_val in time_data : times . append ( time_base + relativedelta ( months = int ( time_val ) ) ) else : try : times_calendar = time_data . calendar except : times_calendar = 'standard' times = num2date ( time_data [ : ] , units = time_format , calendar = times_calendar ) if times_calendar == '360_day' : for it , t in enumerate ( times ) : times [ it ] = dt . datetime . strptime ( str ( t ) , '%Y-%m-%d 00:00:00' ) return times
Decode NetCDF time values into Python datetime objects.
Decode NetCDF time values into Python datetime objects .
''' Decode NetCDF time values into Python datetime objects.

    :param dataset: The dataset from which time values should be extracted.
    :type dataset: netCDF4.Dataset
    :param time_var_name: The name of the time variable in dataset.
    :type time_var_name: :mod:`string`

    :returns: The list of converted datetime values.

    :raises ValueError: If the time units value couldn't be parsed, if the
        base time value couldn't be parsed, or if the time_var_name could not
        be found in the dataset.
    ''' # datetime.timedelta doesn't support a 'months' option. To remedy # this, a month == 30 days for our purposes.
The list of converted datetime values.
The list of converted datetime values .
If the time units value couldn't be parsed, if the
base time value couldn't be parsed, or if the time_var_name could not
be found in the dataset.
If the time units value couldn ' t be parsed if the base time value couldn ' t be parsed or if the time_var_name could not be found in the dataset .
ValueError
dataset
The dataset from which time values should be extracted.
The dataset from which time values should be extracted .
time_var_name
The name of the time variable in dataset.
The name of the time variable in dataset .