Timespans (simply a start time to end time) are integral to astro planning. But I don't see such in astroplan, other than the Slot class which doesn't strike me as overly developed or much used.
[EDIT: I see now that a lot of the Slot functionality is actually over in class Schedule. Maybe this proposal should reduce to an extension and refactoring of Slot.]
I'm now converting my existing astro planning code to be more astropy- and astroplan-based, and I realized that my (currently in-revision) Timespan class would be a natural fit with astroplan. As synopsis, I propose something like this:
class Timespan(start_time, end_time) # parms as py datetime in UTC, or scalar astropy Time
Properties or attributes:
start, end (as Time)
duration (as TimeDelta)
seconds (duration as float)
midpoint (as Time)
Methods:
.copy() # perhaps not needed, as Timespan objects should be treated as immutable
.__eq__(other_timespan) # for timespan1 == timespan2
.delay_by(TimeDelta) # new timespan, shifted by a timedelta, positive or negative
.expand_by(TimeDelta) # new timespan, extended or shortened at each end by a timedelta
.intersect(other_timespan) # new timespan, including only times common to both timespans
.remove(other_timespan) # new timespan(s), with other_timespan removed
.contains(other_timespan or time) # True iff this timespan contains other timespan or time
.split_at(time) # 2 new timespans, split at time (return same timespan, if time not wholly contained)
.longer(timespan1, timespan2) # returns longer of two timespans (class method)
.periodic_events(ref_time, period, max_events) # returns array Time object with all event times within timespan, the series passing through ref_time (which need not be within the timespan), and spaced by exactly period (a DeltaTime). For variable star ephemerides and the like.
The method syntax is designed to support method chaining, e.g., ts.split_at(t)[0].remove(ts2).duration where convenient.
Similar code has worked for me for some years. But this would be my first pull request (anywhere), so it could take a while for me to get that part right. I'm willing to give it a go if you're interested.
Timespans (simply a start time to end time) are integral to astro planning. But I don't see such in astroplan, other than the
Slot
class which doesn't strike me as overly developed or much used.[EDIT: I see now that a lot of the
Slot
functionality is actually over in classSchedule
. Maybe this proposal should reduce to an extension and refactoring ofSlot
.]I'm now converting my existing astro planning code to be more astropy- and astroplan-based, and I realized that my (currently in-revision)
Timespan
class would be a natural fit with astroplan. As synopsis, I propose something like this:class Timespan(start_time, end_time)
# parms as pydatetime
in UTC, or scalar astropyTime
Properties or attributes:
start, end
(as Time)duration
(as TimeDelta)seconds
(duration as float)midpoint
(as Time)Methods:
.copy()
# perhaps not needed, as Timespan objects should be treated as immutable.__eq__(other_timespan)
# for timespan1 == timespan2.delay_by(TimeDelta)
# new timespan, shifted by a timedelta, positive or negative.expand_by(TimeDelta)
# new timespan, extended or shortened at each end by a timedelta.intersect(other_timespan)
# new timespan, including only times common to both timespans.remove(other_timespan)
# new timespan(s), with other_timespan removed.contains(other_timespan or time)
# True iff this timespan contains other timespan or time.split_at(time)
# 2 new timespans, split at time (return same timespan, if time not wholly contained).longer(timespan1, timespan2)
# returns longer of two timespans (class method).periodic_events(ref_time, period, max_events)
# returns array Time object with all event times within timespan, the series passing through ref_time (which need not be within the timespan), and spaced by exactly period (a DeltaTime). For variable star ephemerides and the like.The method syntax is designed to support method chaining, e.g.,
ts.split_at(t)[0].remove(ts2).duration
where convenient.Similar code has worked for me for some years. But this would be my first pull request (anywhere), so it could take a while for me to get that part right. I'm willing to give it a go if you're interested.