TimeRange

class sunpy.time.TimeRange(a, b=None, format=None)[source] [edit on github]

Bases: object

A class to create and handle time ranges.

Note

Regardless of how a sunpy.time.TimeRange is constructed it will always provide a positive time range where the start time is before the end time.

Parameters

Examples

>>> from sunpy.time import TimeRange
>>> time_range = TimeRange('2010/03/04 00:10', '2010/03/04 00:20')
>>> time_range = TimeRange(('2010/03/04 00:10', '2010/03/04 00:20'))
>>> import astropy.units as u
>>> time_range = TimeRange('2010/03/04 00:10', 400 * u.s)
>>> TimeRange('2010/03/04 00:10', 400 * u.day)
   <sunpy.time.timerange.TimeRange object at ...>
    Start: 2010-03-04 00:10:00
    End:   2011-04-08 00:10:00
    Center:2010-09-20 00:10:00
    Duration:400.0 days or
           9600.0 hours or
           576000.0 minutes or
           34560000.0 seconds

Attributes Summary

center

Gets the center of the time range.

days

Gets the number of days elapsed.

dt

Get the length of the time range.

end

Get the end time.

hours

Get the number of hours elapsed.

minutes

Gets the number of minutes elapsed.

seconds

Gets the number of seconds elapsed.

start

Get the start time.

Methods Summary

extend(dt_start, dt_end)

Extend the time range forwards and backwards.

get_dates()

Return all partial days contained within the time range.

next()

Shift the time range forward by the amount of time elapsed.

previous()

Shift the time range backward by the amount of time elapsed.

split([n])

Splits the time range into multiple equally sized parts.

window(cadence, window)

Split the time range up into a series of TimeRange that are window long, with a cadence of cadence.

Attributes Documentation

center

Gets the center of the time range.

Returns

astropy.time.Time – The center time.

days

Gets the number of days elapsed.

Returns

astropy.units.Quantity – The amount of days between the start and end time.

dt

Get the length of the time range. Always a positive value.

Returns

astropy.time.TimeDelta – The difference between the start and the end time.

end

Get the end time.

Returns

astropy.time.Time – The end time.

hours

Get the number of hours elapsed.

Returns

astropy.units.Quantity – The amount of hours between the start and end time.

minutes

Gets the number of minutes elapsed.

Returns

astropy.units.Quantity – The amount of minutes between the start and end time.

seconds

Gets the number of seconds elapsed.

Returns

astropy.units.Quantity – The amount of seconds between the start and end time.

start

Get the start time.

Returns

astropy.time.Time – The start time.

Methods Documentation

extend(dt_start, dt_end)[source] [edit on github]

Extend the time range forwards and backwards.

Parameters
get_dates()[source] [edit on github]

Return all partial days contained within the time range.

next()[source] [edit on github]

Shift the time range forward by the amount of time elapsed.

previous()[source] [edit on github]

Shift the time range backward by the amount of time elapsed.

split(n=2)[source] [edit on github]

Splits the time range into multiple equally sized parts.

Parameters

n (int, optional) – The number of times to split the time range (must >= 1). Defaults to 2.

Returns

list – A list of equally sized sunpy.time.TimeRange between the start and end times.

window(cadence, window)[source] [edit on github]

Split the time range up into a series of TimeRange that are window long, with a cadence of cadence.

Parameters
Returns

list – A list of TimeRange, that are window long and separated by cadence.

Examples

>>> import astropy.units as u
>>> from sunpy.time import TimeRange
>>> time_range = TimeRange('2010/03/04 00:10', '2010/03/04 01:20')
>>> time_range.window(60*60*u.s, window=12*u.s)   
[   <sunpy.time.timerange.TimeRange object at 0x7f0214bfc208>
    Start: 2010-03-04 00:10:00
    End:   2010-03-04 00:10:12
    Center:2010-03-04 00:10:06
    Duration:0.0001388888888888889 days or
            0.003333333333333333 hours or
            0.2 minutes or
            12.0 seconds,
    <sunpy.time.timerange.TimeRange object at 0x7f01fe43ac50>
    Start: 2010-03-04 01:10:00
    End:   2010-03-04 01:10:12
    Center:2010-03-04 01:10:06
    Duration:0.0001388888888888889 days or
            0.003333333333333333 hours or
            0.2 minutes or
            12.0 seconds,
    <sunpy.time.timerange.TimeRange object at 0x7f01fb90b898>
    Start: 2010-03-04 02:10:00
    End:   2010-03-04 02:10:12
    Center:2010-03-04 02:10:06
    Duration:0.0001388888888888889 days or
            0.003333333333333333 hours or
            0.2 minutes or
            12.0 seconds]