Examples of using obsplan observation planning module

obsplan home: github.com/ejeschke/obsplan


In [1]:
%pylab


Using matplotlib backend: TkAgg
Populating the interactive namespace from numpy and matplotlib

In [2]:
# what version are we using?
from obsplan.version import version
version


Out[2]:
'1.0.0'

In [3]:
# boilerplate stuff
from obsplan import entity
from datetime import datetime
import pytz

In [4]:
# convenience function for viewing dates in HST
hst = pytz.timezone('US/Hawaii')
def show_hst(dt):
    return dt.astimezone(hst).strftime("%m/%d %H:%M:%S")

Observation Planning Toolbox


In [5]:
# define an observer
obs = entity.Observer('Subaru Telescope',
                      longitude='-155:28:48.900',
                      latitude='+19:49:42.600',
                      elevation=4163,
                      pressure=615,
                      temperature=0,
                      timezone='US/Hawaii',
                      description="Subaru Telescope on Mauna Kea, Hawaii")

In [6]:
# define a target
s5 = entity.StaticTarget(name='S5', ra='14:20:00.00', dec='48:00:00.00')

In [7]:
# Can I observe this target on the night of May 1, 2015 between 18:30 and 05:30 HST
# for 30 minutes somewhere between 45 degrees and 89 degrees altitude?
t_start = datetime(2015, 05, 01, 18, 30, 0, tzinfo=hst)
t_stop = datetime(2015, 05, 02, 5, 30, 0, tzinfo=hst)
tf, t_rise_utc, t_set_utc = obs.observable(s5, t_start, t_stop, 45.0, 89.0, 30*60)

In [8]:
# can observe under these conditions?
tf


Out[8]:
True

In [21]:
# first time available thusly
t_rise_utc.astimezone(obs.tz_utc).strftime("%m/%d %H:%M:%S")
#t_rise_utc.astimezone(obs.tz_local).strftime("%m/%d %H:%M:%S")
import ephem
datetime(2015, 5, 1, 12, 0, 0, tzinfo=pytz.timezone('US/Eastern'))


Out[21]:
time.struct_time(tm_year=2015, tm_mon=5, tm_mday=1, tm_hour=12, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=121, tm_isdst=0)

In [10]:
# setting time
show_hst(t_set_utc)


Out[10]:
'05/02 02:57:04'

In [11]:
# same question, but specify the lower elevation bound to be the
# telescope minimum and I will specify an airmass of 1.2 for the target
tf, t_rise_utc, t_set_utc = obs.observable(s5, t_start, t_stop, 15.0, 89.0, 30*60, airmass=1.2)

In [12]:
# observable with this airmass
tf


Out[12]:
True

In [13]:
# first time available at airmass 1.2
show_hst(t_rise_utc)


Out[13]:
'05/01 22:37:04'

In [14]:
# set time airmass 1.2
t_set_utc.astimezone(hst).strftime("%m/%d %H:%M:%S")


Out[14]:
'05/02 01:27:54'

In [15]:
# when is sunset on May 1, 2015 at observing position?
day = datetime(2015, 5, 1, tzinfo=hst)
show_hst(obs.sunset(date=day))


Out[15]:
'04/30 18:55:36'

In [16]:
# sunrise the next morning?
day = datetime(2015, 5, 2, tzinfo=hst)
show_hst(obs.sunrise(date=day))


Out[16]:
'05/02 05:41:40'

In [17]:
# what is the moon phase?
# (shows another way of getting the local date/time)
day = obs.get_date("2015-05-01")
obs.moon_phase(date=day)


Out[17]:
0.8257012519316516

In [18]:
# moon rise 
day = obs.get_date("2015-05-01")
show_hst(obs.moon_rise(date=day))


Out[18]:
'04/30 16:02:26'

In [19]:
# moon set 
day = obs.get_date("2015-05-01")
show_hst(obs.moon_set(date=day))


Out[19]:
'05/01 04:33:29'

In [20]:
# define a few more targets
sf = entity.StaticTarget(name='Sf', ra='09:40:00.00', dec='43:00:00.00')
sm = entity.StaticTarget(name='Sm', ra='10:30:00.00', dec='36:00:00.00')
sn = entity.StaticTarget(name='Sn', ra='15:10:00.00', dec='34:00:00.00')

In [21]:
# calculate the distance in alt and az degrees between two targets at
# the given time (e.g. to calculate slew time)
t = obs.get_date("2015-05-01 23:00")
obs.distance(sf, sm, t)


Out[21]:
(-10.255829567097628, 7.780678294911695)

In [22]:
# tell me about object sm in relation to observer obs at time t
t = obs.get_date("2015-05-01 23:00")
cr = obs.calc(sm, t)
cr


Out[22]:
<obsplan.entity.CalculationResult at 0x7f97c68bded0>

In [23]:
# Note use of CalculationResult object--many computations are
# lazily delayed until they are asked for.  This saves a lot of
# time if many objects are evaluated wrt a given time and we only
# need some of the calculation results (e.g. for scheduling)

# airmass, parallactic angle, hour angle
cr.airmass, cr.pang, cr.ha


Out[23]:
(1.4351779979843513, 1.689906368200397, 0.860122261760718)

In [24]:
# ut, gmst, lmst
cr.ut, cr.gmst, cr.lmst


Out[24]:
(datetime.datetime(2015, 5, 2, 9, 30, tzinfo=<UTC>),
 35286.41202526165,
 3.6128831639467975)

In [25]:
# moon altitude, moon separation from target, moon illumination
cr.moon_alt, cr.moon_sep, cr.moon_pct


Out[25]:
(1.074031114578247, 1.0362542976692015, 0.9702902593876648)

In [26]:
# we can also ask for a calculation via the target (same result)
cr = sm.calc(obs, t)

Plots


In [27]:
# boilerplate
from matplotlib.backends.backend_agg import FigureCanvasAgg as fc

targets = [s5, sf, sm, sn]
day = obs.get_date("2015-05-01")
obs.set_date(day)

In [28]:
# make an airmass plot of our targets for the night of May 1, 2015
from obsplan.plots import airmass
plot = airmass.AirMassPlot(10, 6)
canvas = fc(plot.fig)

plot.plot_targets(obs, targets, hst)
plot.fig


Out[28]:

In [29]:
# show our targets sky position relative to our telescope 
# on May 1, 2015 at 22:30 HST
from obsplan.plots import polarsky
reload(polarsky)
plot = polarsky.AZELPlot(6, 6)
canvas = fc(plot.fig)

targets = [s5, sf, sm, sn, entity.moon]
t = obs.get_date("2015-05-01 22:30")
plot.setup()
plot.plot_targets(obs, targets, t)
plot.fig


Out[29]:

Tables


In [30]:
# get a brief almanac of the day
day = obs.get_date("2015-05-01")
almanac = obs.get_text_almanac(day)
print(almanac)


Almanac for the night of 2015-05-01

Evening
______________________________
Sunset: 18:55
12d: 19:36
18d: 20:03

Morning
______________________________
18d: 04:34
12d: 05:01
Sunrise: 05:42


In [31]:
t_start = obs.get_date("2015-05-01 18:30")
t_stop = obs.get_date("2015-05-02 05:30")
tbl = obs.get_target_info_table(s5, t_start, t_stop, 10)
print(tbl)


Date                UTC   LMST     HA       PA     AM  MnAlt   MnSep
____________________________________________________________________
01May2015  18:40  04:40   8:57  -5:23   -82.88   2.82  21.05   56.87
01May2015  18:50  04:50   9:07  -5:13   -84.68   2.62  23.24   56.88
01May2015  19:00  05:00   9:17  -5:03   -86.48   2.45  25.41   56.89
01May2015  19:10  05:10   9:27  -4:53   -88.31   2.30  27.57   56.91
01May2015  19:20  05:20   9:37  -4:43   -90.16   2.17  29.71   56.92
01May2015  19:30  05:30   9:47  -4:33   -92.04   2.05  31.84   56.94
01May2015  19:40  05:40   9:57  -4:23   -93.95   1.95  33.94   56.95
01May2015  19:50  05:50  10:07  -4:13   -95.90   1.86  36.02   56.97
01May2015  20:00  06:00  10:17  -4:03   -97.89   1.78  38.07   56.99
01May2015  20:10  06:10  10:27  -3:53   -99.93   1.71  40.09   57.00
01May2015  20:20  06:20  10:37  -3:43  -102.03   1.65  42.08   57.02
01May2015  20:30  06:30  10:47  -3:32  -104.19   1.59  44.03   57.03
01May2015  20:40  06:40  10:57  -3:22  -106.42   1.53  45.93   57.05
01May2015  20:50  06:50  11:07  -3:12  -108.73   1.49  47.79   57.07
01May2015  21:00  07:00  11:17  -3:02  -111.12   1.44  49.58   57.08
01May2015  21:10  07:10  11:27  -2:52  -113.61   1.40  51.31   57.10
01May2015  21:20  07:20  11:37  -2:42  -116.21   1.37  52.96   57.11
01May2015  21:30  07:30  11:47  -2:32  -118.92   1.34  54.53   57.13
01May2015  21:40  07:40  11:57  -2:22  -121.76   1.31  55.99   57.15
01May2015  21:50  07:50  12:07  -2:12  -124.74   1.28  57.34   57.16
01May2015  22:00  08:00  12:17  -2:02  -127.87   1.26  58.56   57.18
01May2015  22:10  08:10  12:27  -1:52  -131.16   1.24  59.64   57.20
01May2015  22:20  08:20  12:37  -1:42  -134.62   1.22  60.56   57.21
01May2015  22:30  08:30  12:47  -1:32  -138.26   1.20  61.30   57.23
01May2015  22:40  08:40  12:57  -1:22  -142.09   1.19  61.86   57.24
01May2015  22:50  08:50  13:07  -1:12  -146.11   1.17  62.21   57.26
01May2015  23:00  09:00  13:18  -1:02  -150.32   1.16  62.36   57.27
01May2015  23:10  09:10  13:28  -0:52  -154.72   1.15  62.29   57.29
01May2015  23:20  09:20  13:38  -0:42  -159.29   1.15  62.01   57.30
01May2015  23:30  09:30  13:48  -0:32  -164.01   1.14  61.53   57.32
01May2015  23:40  09:40  13:58  -0:22  -168.86   1.14  60.86   57.33
01May2015  23:50  09:50  14:08  -0:12  -173.80   1.13  60.00   57.35
02May2015  00:00  10:00  14:18  -0:02  -178.80   1.13  58.98   57.36
02May2015  00:10  10:10  14:28   0:07   176.20   1.13  57.81   57.38
02May2015  00:20  10:20  14:38   0:17   171.23   1.14  56.50   57.39
02May2015  00:30  10:30  14:48   0:27   166.33   1.14  55.08   57.40
02May2015  00:40  10:40  14:58   0:37   161.55   1.14  53.55   57.42
02May2015  00:50  10:50  15:08   0:47   156.90   1.15  51.93   57.43
02May2015  01:00  11:00  15:18   0:57   152.42   1.16  50.23   57.44
02May2015  01:10  11:10  15:28   1:07   148.12   1.17  48.46   57.45
02May2015  01:20  11:20  15:38   1:17   144.00   1.18  46.62   57.46
02May2015  01:30  11:30  15:48   1:27   140.08   1.20  44.74   57.48
02May2015  01:40  11:40  15:58   1:37   136.35   1.21  42.80   57.49
02May2015  01:50  11:50  16:08   1:47   132.80   1.23  40.83   57.50
02May2015  02:00  12:00  16:18   1:57   129.43   1.25  38.82   57.51
02May2015  02:10  12:10  16:28   2:07   126.22   1.27  36.78   57.52
02May2015  02:20  12:20  16:38   2:17   123.18   1.30  34.70   57.53
02May2015  02:30  12:30  16:48   2:27   120.27   1.32  32.61   57.54
02May2015  02:40  12:40  16:58   2:38   117.50   1.35  30.49   57.54
02May2015  02:50  12:50  17:08   2:48   114.85   1.39  28.35   57.55
02May2015  03:00  13:00  17:18   2:58   112.31   1.42  26.20   57.56
02May2015  03:10  13:10  17:28   3:08   109.87   1.47  24.03   57.57
02May2015  03:20  13:20  17:38   3:18   107.52   1.51  21.85   57.58
02May2015  03:30  13:30  17:48   3:28   105.25   1.56  19.66   57.58
02May2015  03:40  13:40  17:58   3:38   103.06   1.62  17.45   57.59
02May2015  03:50  13:50  18:08   3:48   100.93   1.68  15.24   57.60
02May2015  04:00  14:00  18:18   3:58    98.87   1.75  13.02   57.60
02May2015  04:10  14:10  18:28   4:08    96.85   1.82  10.79   57.61
02May2015  04:20  14:20  18:38   4:18    94.88   1.91   8.57   57.61
02May2015  04:30  14:30  18:48   4:28    92.95   2.00   6.34   57.62
02May2015  04:40  14:40  18:58   4:38    91.06   2.11   4.13   57.62
02May2015  04:50  14:50  19:08   4:48    89.19   2.23   1.94   57.63
02May2015  05:00  15:00  19:18   4:58    87.36   2.37  -0.13   57.63
02May2015  05:10  15:10  19:29   5:08    85.54   2.53  -1.96   57.64
02May2015  05:20  15:20  19:39   5:18    83.75   2.72  -4.74   57.64
02May2015  05:30  15:30  19:49   5:28    81.96   2.93  -7.28   57.64
02May2015  05:40  15:40  19:59   5:38    80.19   3.19  -9.57   57.65
02May2015  05:50  15:50  20:09   5:48    78.43   3.49 -11.85   57.65
02May2015  06:00  16:00  20:19   5:58    76.67   3.85 -14.12   57.65

In [ ]: