esmvaltool/preprocessor/_time_area.py
def time_slice(mycube, start_year, start_month, start_day, end_year, end_month,
               end_day):
    """
    Slice cube on time.

    Function that returns a subset of the original cube (slice)
    given two dates of interest start date and end date
    start date and end date should be given in a yr,mo,d (int)format e.g.
    time_slice(cube, 2006, 2, 2, 2010, 1, 1) or
    time_slice(cube, '2006', '2', '2', '2010', '1', '1');

    Returns a cube

    History
    -------
    - 13-Oct-2018: @RCHG added detection of Iris Library
    - 14-Oct-2018: @RCHG added a changes on time-constrain

    """
    from iris.time import PartialDateTime
    import datetime
    time_units = mycube.coord('time').units
    if time_units.calendar == '360_day':
        if start_day > 30:
            start_day = 30
        if end_day > 30:
            end_day = 30
    start_date = datetime.datetime(
        int(start_year), int(start_month), int(start_day))
    end_date = datetime.datetime(int(end_year), int(end_month), int(end_day))

    t_1 = time_units.date2num(start_date)
    t_2 = time_units.date2num(end_date)
    # TODO replace the block below for when using iris 2.0
    # my_constraint = iris.Constraint(time=lambda t: (
    #     t_1 < time_units.date2num(t.point) < t_2))
    if int(iris.__version__.split('.')[0]) >= 2:
        time_constraint = iris.Constraint(time=lambda t: (
          start_date
          < PartialDateTime(year=t.point.year,
                            month=t.point.month,
                            day=t.point.day)
          < end_date))
    else:
        time_constraint = iris.Constraint(time=lambda t: (
                        t_1 < t.point < t_2))
    cube_slice = mycube.extract(time_constraint)
    return cube_slice

    Slice cube on time.

    Function that returns a subset of the original cube (slice)
    given two dates of interest start date and end date
    start date and end date should be given in a yr,mo,d (int)format e.g.
    time_slice(cube, 2006, 2, 2, 2010, 1, 1) or
    time_slice(cube, '2006', '2', '2', '2010', '1', '1');

    Returns a cube

    History
    -------
    - 13-Oct-2018: @RCHG added detection of Iris Library
    - 14-Oct-2018: @RCHG added a changes on time-constrain

    
Slice cube on time.
Function that returns a subset of the original cube (slice)
given two dates of interest start date and end date
start date and end date should be given in a yr,mo,d (int)format e.g.

Returns a cube

History


Slice cube on time . Function that returns a subset of the original cube ( slice ) given two dates of interest start date and end date start date and end date should be given in a yr mo d ( int ) format e . g . Returns a cube History
def time_slice(mycube, start_year, start_month, start_day, end_year, end_month,
               end_day):
    from iris.time import PartialDateTime
    import datetime
    time_units = mycube.coord('time').units
    if time_units.calendar == '360_day':
        if start_day > 30:
            start_day = 30
        if end_day > 30:
            end_day = 30
    start_date = datetime.datetime(
        int(start_year), int(start_month), int(start_day))
    end_date = datetime.datetime(int(end_year), int(end_month), int(end_day))
    t_1 = time_units.date2num(start_date)
    t_2 = time_units.date2num(end_date)
    if int(iris.__version__.split('.')[0]) >= 2:
        time_constraint = iris.Constraint(time=lambda t: (
          start_date
          < PartialDateTime(year=t.point.year,
                            month=t.point.month,
                            day=t.point.day)
          < end_date))
    else:
        time_constraint = iris.Constraint(time=lambda t: (
                        t_1 < t.point < t_2))
    cube_slice = mycube.extract(time_constraint)
    return cube_slice
def time_slice ( mycube , start_year , start_month , start_day , end_year , end_month , end_day ) : from iris . time import PartialDateTime import datetime time_units = mycube . coord ( 'time' ) . units if time_units . calendar == '360_day' : if start_day > 30 : start_day = 30 if end_day > 30 : end_day = 30 start_date = datetime . datetime ( int ( start_year ) , int ( start_month ) , int ( start_day ) ) end_date = datetime . datetime ( int ( end_year ) , int ( end_month ) , int ( end_day ) ) t_1 = time_units . date2num ( start_date ) t_2 = time_units . date2num ( end_date ) if int ( iris . __version__ . split ( '.' ) [ 0 ] ) >= 2 : time_constraint = iris . Constraint ( time = lambda t : ( start_date < PartialDateTime ( year = t . point . year , month = t . point . month , day = t . point . day ) < end_date ) ) else : time_constraint = iris . Constraint ( time = lambda t : ( t_1 < t . point < t_2 ) ) cube_slice = mycube . extract ( time_constraint ) return cube_slice
Slice cube on time.
Slice cube on time .
"""
    Slice cube on time.

    Function that returns a subset of the original cube (slice)
    given two dates of interest start date and end date
    start date and end date should be given in a yr,mo,d (int)format e.g.
    time_slice(cube, 2006, 2, 2, 2010, 1, 1) or
    time_slice(cube, '2006', '2', '2', '2010', '1', '1');

    Returns a cube

    History
    -------
    - 13-Oct-2018: @RCHG added detection of Iris Library
    - 14-Oct-2018: @RCHG added a changes on time-constrain

    """ # TODO replace the block below for when using iris 2.0 # my_constraint = iris.Constraint(time=lambda t: ( #     t_1 < time_units.date2num(t.point) < t_2))
mycube
start_year
start_month
start_day
end_year
end_month
end_day