hcam-widgets 0.2.3__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ from __future__ import print_function, unicode_literals, absolute_import, division
3
+
4
+ __author__ = """Stuart Littlefair"""
5
+ __email__ = 's.littlefair@shef.ac.uk'
6
+ __version__ = '0.2.3'
7
+
8
+
9
+ class DriverError(Exception):
10
+ pass
hcam_widgets/astro.py ADDED
@@ -0,0 +1,281 @@
1
+ # Some utility tools to handle rising and setting etc.
2
+ from __future__ import print_function, unicode_literals, absolute_import, division
3
+ import warnings
4
+ import numpy as np
5
+ from numpy.polynomial.polynomial import polyval
6
+
7
+ # astropy
8
+ from astropy import coordinates as coord
9
+ from astropy.time import Time
10
+ from astropy import units as u
11
+
12
+ MAGIC_TIME = Time(-999, format='jd')
13
+
14
+
15
+ def _equation_of_time(t):
16
+ """
17
+ Find the difference between apparent and mean solar time
18
+
19
+ Parameters
20
+ ----------
21
+ t : `~astropy.time.Time`
22
+ times (array)
23
+
24
+ Returns
25
+ ----------
26
+ ret1 : `~astropy.units.Quantity`
27
+ the equation of time
28
+ """
29
+
30
+ # Julian centuries since J2000.0
31
+ T = (t - Time("J2000")).to(u.year).value / 100
32
+
33
+ # obliquity of ecliptic (Meeus 1998, eq 22.2)
34
+ poly_pars = (84381.448, 46.8150, 0.00059, 0.001813)
35
+ eps = u.Quantity(polyval(T, poly_pars), u.arcsec)
36
+ y = np.tan(eps/2)**2
37
+
38
+ # Sun's mean longitude (Meeus 1998, eq 25.2)
39
+ poly_pars = (280.46646, 36000.76983, 0.0003032)
40
+ L0 = u.Quantity(polyval(T, poly_pars), u.deg)
41
+
42
+ # Sun's mean anomaly (Meeus 1998, eq 25.3)
43
+ poly_pars = (357.52911, 35999.05029, 0.0001537)
44
+ M = u.Quantity(polyval(T, poly_pars), u.deg)
45
+
46
+ # eccentricity of Earth's orbit (Meeus 1998, eq 25.4)
47
+ poly_pars = (0.016708634, -0.000042037, -0.0000001267)
48
+ e = polyval(T, poly_pars)
49
+
50
+ # equation of time, radians (Meeus 1998, eq 28.3)
51
+ eot = (y * np.sin(2*L0) - 2*e*np.sin(M) + 4*e*y*np.sin(M)*np.cos(2*L0) -
52
+ 0.5*y**2 * np.sin(4*L0) - 5*e**2 * np.sin(2*M)/4) * u.rad
53
+ return eot.to(u.hourangle)
54
+
55
+
56
+ def _astropy_time_from_LST(t, LST, location, prev_next):
57
+ """
58
+ Convert a Local Sidereal Time to an astropy Time object.
59
+
60
+ The local time is related to the LST through the RA of the Sun.
61
+ This routine uses this relationship to convert a LST to an astropy
62
+ time object.
63
+
64
+ Returns
65
+ -------
66
+ ret1 : `~astropy.time.Time`
67
+ time corresponding to LST
68
+ """
69
+ # now we need to figure out time to return from LST
70
+ raSun = coord.get_sun(t).ra
71
+
72
+ # calculate Greenwich Apparent Solar Time, which we will use as ~UTC for now
73
+ with warnings.catch_warnings():
74
+ warnings.simplefilter('ignore')
75
+ # ignore astropy deprecation warnings
76
+ lon = location.longitude
77
+ solarTime = LST - raSun + 12*u.hourangle - lon
78
+
79
+ # assume this is on the same day as supplied time, and fix later
80
+ first_guess = Time(
81
+ u.d*int(t.mjd) + u.hour*solarTime.wrap_at('360d').hour,
82
+ format='mjd'
83
+ )
84
+
85
+ # Equation of time is difference between GAST and UTC
86
+ eot = _equation_of_time(first_guess)
87
+ first_guess = first_guess - u.hour * eot.value
88
+
89
+ if prev_next == 'next':
90
+ # if 'next', we want time to be greater than given time
91
+ mask = first_guess < t
92
+ rise_set_time = first_guess + mask * u.sday
93
+ else:
94
+ # if 'previous', we want time to be less than given time
95
+ mask = first_guess > t
96
+ rise_set_time = first_guess - mask * u.sday
97
+ return rise_set_time
98
+
99
+
100
+ def _rise_set_trig(t, target, location, prev_next, rise_set):
101
+ """
102
+ Crude time at next rise/set of ``target`` using spherical trig.
103
+
104
+ This method is ~15 times faster than `_calcriseset`,
105
+ and inherently does *not* take the atmosphere into account.
106
+
107
+ The time returned should not be used in calculations; the purpose
108
+ of this routine is to supply a guess to `_calcriseset`.
109
+
110
+ Parameters
111
+ ----------
112
+ t : `~astropy.time.Time` or other (see below)
113
+ Time of observation. This will be passed in as the first argument to
114
+ the `~astropy.time.Time` initializer, so it can be anything that
115
+ `~astropy.time.Time` will accept (including a `~astropy.time.Time`
116
+ object)
117
+
118
+ target : `~astropy.coordinates.SkyCoord`
119
+ Position of target or multiple positions of that target
120
+ at multiple times (if target moves, like the Sun)
121
+
122
+ location : `~astropy.coordinates.EarthLocation`
123
+ Observatory location
124
+
125
+ prev_next : str - either 'previous' or 'next'
126
+ Test next rise/set or previous rise/set
127
+
128
+ rise_set : str - either 'rising' or 'setting'
129
+ Compute prev/next rise or prev/next set
130
+
131
+ Returns
132
+ -------
133
+ ret1 : `~astropy.time.Time`
134
+ Time of rise/set
135
+ """
136
+ dec = target.transform_to(coord.ICRS).dec
137
+ with warnings.catch_warnings():
138
+ warnings.simplefilter('ignore')
139
+ # ignore astropy deprecation warnings
140
+ lat = location.latitude
141
+ cosHA = -np.tan(dec)*np.tan(lat.radian)
142
+ # find the absolute value of the hour Angle
143
+ HA = coord.Longitude(np.fabs(np.arccos(cosHA)))
144
+ # if rise, HA is -ve and vice versa
145
+ if rise_set == 'rising':
146
+ HA = -HA
147
+ # LST = HA + RA
148
+ LST = HA + target.ra
149
+
150
+ return _astropy_time_from_LST(t, LST, location, prev_next)
151
+
152
+
153
+ def calc_riseset(t, target_name, location, prev_next, rise_set, horizon):
154
+ """
155
+ Time at next rise/set of ``target``.
156
+
157
+ Parameters
158
+ ----------
159
+ t : `~astropy.time.Time` or other (see below)
160
+ Time of observation. This will be passed in as the first argument to
161
+ the `~astropy.time.Time` initializer, so it can be anything that
162
+ `~astropy.time.Time` will accept (including a `~astropy.time.Time`
163
+ object)
164
+
165
+ target_name : str
166
+ 'moon' or 'sun'
167
+
168
+ location : `~astropy.coordinates.EarthLocation`
169
+ Observatory location
170
+
171
+ prev_next : str - either 'previous' or 'next'
172
+ Test next rise/set or previous rise/set
173
+
174
+ rise_set : str - either 'rising' or 'setting'
175
+ Compute prev/next rise or prev/next set
176
+
177
+ location : `~astropy.coordinates.EarthLocation`
178
+ Location of observer
179
+
180
+ horizon : `~astropy.units.Quantity`
181
+ Degrees above/below actual horizon to use
182
+ for calculating rise/set times (i.e.,
183
+ -6 deg horizon = civil twilight, etc.)
184
+
185
+ Returns
186
+ -------
187
+ ret1 : `~astropy.time.Time`
188
+ Time of rise/set
189
+ """
190
+ target = coord.get_body(target_name, t)
191
+ t0 = _rise_set_trig(t, target, location, prev_next, rise_set)
192
+ grid = t0 + np.linspace(-4*u.hour, 4*u.hour, 10)
193
+ altaz_frame = coord.AltAz(obstime=grid, location=location)
194
+ target = coord.get_body(target_name, grid)
195
+ altaz = target.transform_to(altaz_frame)
196
+ time_limits, altitude_limits = _horiz_cross(altaz.obstime, altaz.alt,
197
+ rise_set, horizon)
198
+ return _two_point_interp(time_limits, altitude_limits, horizon)
199
+
200
+
201
+ @u.quantity_input(horizon=u.deg)
202
+ def _horiz_cross(t, alt, rise_set, horizon=0*u.degree):
203
+ """
204
+ Find time ``t`` when values in array ``a`` go from
205
+ negative to positive or positive to negative (exclude endpoints)
206
+
207
+ ``return_limits`` will return nearest times to zero-crossing.
208
+
209
+ Parameters
210
+ ----------
211
+ t : `~astropy.time.Time`
212
+ Grid of times
213
+ alt : `~astropy.units.Quantity`
214
+ Grid of altitudes
215
+ rise_set : {"rising", "setting"}
216
+ Calculate either rising or setting across the horizon
217
+ horizon : float
218
+ Number of degrees above/below actual horizon to use
219
+ for calculating rise/set times (i.e.,
220
+ -6 deg horizon = civil twilight, etc.)
221
+
222
+ Returns
223
+ -------
224
+ Returns the lower and upper limits on the time and altitudes
225
+ of the horizon crossing.
226
+ """
227
+ if rise_set == 'rising':
228
+ # Find index where altitude goes from below to above horizon
229
+ condition = (alt[:-1] < horizon) * (alt[1:] > horizon)
230
+ elif rise_set == 'setting':
231
+ # Find index where altitude goes from above to below horizon
232
+ condition = (alt[:-1] > horizon) * (alt[1:] < horizon)
233
+
234
+ if np.count_nonzero(condition) == 0:
235
+ warnmsg = ('Target does not cross horizon={} within '
236
+ '8 hours of trigonometric estimate'.format(horizon))
237
+ warnings.warn(warnmsg)
238
+
239
+ # Fill in missing time with MAGIC_TIME
240
+ time_inds = np.nan
241
+ times = [np.nan, np.nan]
242
+ altitudes = [np.nan, np.nan]
243
+ else:
244
+ time_inds = np.nonzero(condition)[0][0]
245
+ times = t[time_inds:time_inds+2]
246
+ altitudes = alt[time_inds:time_inds+2]
247
+
248
+ return times, altitudes
249
+
250
+
251
+ @u.quantity_input(horizon=u.deg)
252
+ def _two_point_interp(times, altitudes, horizon=0*u.deg):
253
+ """
254
+ Do linear interpolation between two ``altitudes`` at
255
+ two ``times`` to determine the time where the altitude
256
+ goes through zero.
257
+
258
+ Parameters
259
+ ----------
260
+ times : `~astropy.time.Time`
261
+ Two times for linear interpolation between
262
+
263
+ altitudes : array of `~astropy.units.Quantity`
264
+ Two altitudes for linear interpolation between
265
+
266
+ horizon : `~astropy.units.Quantity`
267
+ Solve for the time when the altitude is equal to
268
+ reference_alt.
269
+
270
+ Returns
271
+ -------
272
+ t : `~astropy.time.Time`
273
+ Time when target crosses the horizon
274
+
275
+ """
276
+ if not isinstance(times, Time):
277
+ return MAGIC_TIME
278
+ else:
279
+ slope = (altitudes[1] - altitudes[0])/(times[1].jd - times[0].jd)
280
+ return Time(times[1].jd - ((altitudes[1] - horizon)/slope).value,
281
+ format='jd')
@@ -0,0 +1,165 @@
1
+ from __future__ import print_function, division, unicode_literals, absolute_import
2
+ from six.moves.queue import Queue
3
+ """
4
+ This module supplies a single class, the Container. The idea is
5
+ that the root widget (the GUI mainwindow) has a single Container
6
+ property. Since all sub-widgets can get a reference to the root
7
+ window, all sub widgets can access the Container and thus communicate,
8
+ hence avoiding the use of globals.
9
+ """
10
+
11
+
12
+ class Container:
13
+ """
14
+ A simple class to hold common attributes for communication between widgets.
15
+
16
+ Those in CAPITALS are meant to be immutable; lowercase ones get
17
+ updated.
18
+
19
+ The meaning of the globals is as follows (uppercase)::
20
+
21
+ COL : colours
22
+ DAY : number of seconds in a day
23
+ EFAC : ratio FWHM/sigma for a gaussian
24
+ EXTINCTION : extinction, mags/airmass
25
+ SKY : sky brightenesses
26
+ TINS : Telescop/instrument data
27
+ DEFAULT_FONT : standard font (set in drivers)
28
+ MENU_FONT : font for menus (set in drivers)
29
+ ENTRY_FONT : font for data entry fields and mutable fields
30
+
31
+ SERVER_POST_PATH : url for posting setups to rack server
32
+
33
+ and lowercase (all set = None to start with)::
34
+
35
+ astro : astronomical information
36
+ clog : command log widget. Used to report actions and results
37
+ count : count & S/N information widget
38
+ cpars : dictionary of configuration parameters
39
+ fpslide : focal plane slide widget
40
+ info : information widget
41
+ ipars : instrument parameters widget (windows sizes etc)
42
+ observe : widget of observing commands
43
+ rlog : response log widget. Used to report server responses
44
+ rpars : run parameter widget
45
+ setup : setup widget
46
+ ccd_hw : CCD hardware (temps, flow rates etc) monitoring widget
47
+ start_filter : filter at last press of 'Start'
48
+ logfile : file to log messages
49
+ """
50
+
51
+ def __init__(self):
52
+ # Ratio of FWHM/sigma for a gaussian
53
+ self.EFAC = 2.3548
54
+
55
+ # FIFO Queue for retrieving exceptions from
56
+ # threaded operations
57
+ self.FIFO = Queue()
58
+
59
+ # Colours
60
+ self.COL = {
61
+ 'main': '#d0d0ff', # Colour for the surrounds
62
+ 'text': '#000050', # Text colour
63
+ 'debug': '#a0a0ff', # Text background for debug messages
64
+ 'warn': '#f0c050', # Text background for warnings
65
+ 'error': '#ffa0a0', # Text background for errors
66
+ 'critical': '#ff0000', # Text background for disasters
67
+ 'start': '#00e000', # Start / Success button colour when enabled
68
+ 'stop': '#ff5050', # Stop / Failure button colour when enabled
69
+ 'startD': '#d0e0d0', # Start / Success button colour when disabled
70
+ 'stopD': '#ffe0e0', # Stop / Failure button colour when disabled
71
+ 'log': '#e0d4ff', # Logger windows
72
+ }
73
+
74
+ # Telescope / instrument info. Most of this is do with estimating count rates
75
+ self.TINS = {
76
+ 'WHT': {
77
+ 'latitude': 28.7598742, # latitude degrees, North positive
78
+ 'longitude': -17.8793802, # longitude degrees, East positive
79
+ 'elevation': 2327., # Elevation above sea level, metres
80
+ 'plateScale': 0.3, # Arcsecs/unbinned pixel
81
+ 'zerop': {
82
+ 'u': 25.67,
83
+ 'g': 27.25,
84
+ 'r': 26.65,
85
+ 'i': 26.79,
86
+ 'z': 26.39
87
+ }
88
+ },
89
+ 'GTC': {
90
+ 'latitude': 28.762, # latitude degrees, North positive
91
+ 'longitude': -17.87764, # longitude degrees, East positive
92
+ 'elevation': 2300., # Elevation above sea level, metres
93
+ 'plateScale': 0.081, # Arcsecs/unbinned pixel (WHT Collimator)
94
+ 'zerop': {
95
+ 'u': 27.47,
96
+ 'g': 29.06,
97
+ 'r': 28.45,
98
+ 'i': 28.60,
99
+ 'z': 28.20
100
+ }
101
+ },
102
+ }
103
+
104
+ # Sky brightness, mags/sq-arsec
105
+ self.SKY = {
106
+ 'd': {'u': 22.4, 'g': 22.2, 'r': 21.4, 'i': 20.7, 'z': 20.3},
107
+ 'g': {'u': 21.4, 'g': 21.2, 'r': 20.4, 'i': 20.1, 'z': 19.9},
108
+ 'b': {'u': 18.4, 'g': 18.2, 'r': 17.4, 'i': 17.9, 'z': 18.3},
109
+ }
110
+
111
+ # Extinction per unit airmass
112
+ self.EXTINCTION = {'u': 0.5, 'g': 0.19, 'r': 0.09, 'i': 0.05, 'z': 0.04}
113
+
114
+ # Fonts set by drivers.add_style later
115
+ # Default font, e.g. used for fixed labels
116
+ self.DEFAULT_FONT = None
117
+
118
+ # Font for menus
119
+ self.MENU_FONT = None
120
+
121
+ # Entry font, used for data entry points and mutable
122
+ # information
123
+ self.ENTRY_FONT = None
124
+
125
+ # URL for posting setups
126
+ self.SERVER_POST_PATH = "setup"
127
+
128
+ # Command log widget. Used to report actions and results
129
+ self.clog = None
130
+
131
+ # Response log widget. Used to report server responses
132
+ self.rlog = None
133
+
134
+ # Configuration parameter dictionary: configurable options
135
+ self.cpars = None
136
+
137
+ # Instrument parameters widget
138
+ self.ipars = None
139
+
140
+ # Run parameters widget
141
+ self.rpars = None
142
+
143
+ # Astronomical information widget
144
+ self.astro = None
145
+
146
+ # Information widget
147
+ self.info = None
148
+
149
+ # Focal plane slide widget
150
+ self.fpslide = None
151
+
152
+ # Observing widget
153
+ self.observe = None
154
+
155
+ # Count rates, S-to-N etc widget
156
+ self.count = None
157
+
158
+ # Instrument setup widget
159
+ self.setup = None
160
+
161
+ # ccd hw monitor widget
162
+ self.ccd_hw = None
163
+
164
+ # Logging file
165
+ self.logfile = None