TimeRange

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

Bases: object

An object to handle time ranges.

Note

Regardless of how a 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)
>>> time_range = TimeRange('2010/03/04 00:10', 400 * u.day)

Creates a new TimeRange instance

Attributes Summary

center Gets the center of the TimeRange instance.
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 timerange
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 TimeRange into multiple equally sized parts.
window(cadence, window) Split the TimeRange up into a series of TimeRange windows, ‘window’ long, between the start and end with a cadence of ‘cadence’.

Attributes Documentation

center

Gets the center of the TimeRange instance.

Returns:value (datetime.datetime)
days

Gets the number of days elapsed.

Returns:value (astropy.units.Quantity)
dt

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

Returns:dt (datetime.timedelta)
end

Get the end time

Returns:end (datetime.datetime)
hours

Get the number of hours elapsed.

Returns:value (astropy.units.Quantity)
minutes

Gets the number of minutes elapsed.

Returns:value (astropy.units.Quantity)
seconds

Gets the number of seconds elapsed.

Returns:value (astropy.units.Quantity)
start

Get the start time

Returns:start (datetime.datetime)

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 timerange

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 TimeRange into multiple equally sized parts.

Parameters:n (int) – The number of times to split the time range (must >= 1)
Returns:time ranges (list) – An list of equally sized TimeRange objects between the start and end times.
Raises:ValueError – If requested amount is less than 1
window(cadence, window)[source] [edit on github]

Split the TimeRange up into a series of TimeRange windows, ‘window’ long, between the start and end with a cadence of ‘cadence’.

Parameters:
Returns:

time ranges (list) – A list of TimeRange objects, 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)   
[    Start: 2010-03-04 00:10:00
    End:   2010-03-04 00:10:12
    Center:2010-03-04 00:10:06
    Duration:0.000138888888889 days or
           0.00333333333333 hours or
           0.2 minutes or
           12.0 seconds
 ,    Start: 2010-03-04 01:10:00
    End:   2010-03-04 01:10:12
    Center:2010-03-04 01:10:06
    Duration:0.000138888888889 days or
           0.00333333333333 hours or
           0.2 minutes or
           12.0 seconds
 ,    Start: 2010-03-04 02:10:00
    End:   2010-03-04 02:10:12
    Center:2010-03-04 02:10:06
    Duration:0.000138888888889 days or
           0.00333333333333 hours or
           0.2 minutes or
           12.0 seconds
  ]