hcam-widgets 0.1.1__tar.gz

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,13 @@
1
+ =======
2
+ Credits
3
+ =======
4
+
5
+ Development Lead
6
+ ----------------
7
+
8
+ * Stuart Littlefair <s.littlefair@shef.ac.uk>
9
+
10
+ Contributors
11
+ ------------
12
+
13
+ None yet. Why not be the first?
@@ -0,0 +1,114 @@
1
+ .. highlight:: shell
2
+
3
+ ============
4
+ Contributing
5
+ ============
6
+
7
+ Contributions are welcome, and they are greatly appreciated! Every
8
+ little bit helps, and credit will always be given.
9
+
10
+ You can contribute in many ways:
11
+
12
+ Types of Contributions
13
+ ----------------------
14
+
15
+ Report Bugs
16
+ ~~~~~~~~~~~
17
+
18
+ Report bugs at https://github.com/StuartLittlefair/hcam_widgets/issues.
19
+
20
+ If you are reporting a bug, please include:
21
+
22
+ * Your operating system name and version.
23
+ * Any details about your local setup that might be helpful in troubleshooting.
24
+ * Detailed steps to reproduce the bug.
25
+
26
+ Fix Bugs
27
+ ~~~~~~~~
28
+
29
+ Look through the GitHub issues for bugs. Anything tagged with "bug"
30
+ and "help wanted" is open to whoever wants to implement it.
31
+
32
+ Implement Features
33
+ ~~~~~~~~~~~~~~~~~~
34
+
35
+ Look through the GitHub issues for features. Anything tagged with "enhancement"
36
+ and "help wanted" is open to whoever wants to implement it.
37
+
38
+ Write Documentation
39
+ ~~~~~~~~~~~~~~~~~~~
40
+
41
+ hcam_widgets could always use more documentation, whether as part of the
42
+ official hcam_widgets docs, in docstrings, or even on the web in blog posts,
43
+ articles, and such.
44
+
45
+ Submit Feedback
46
+ ~~~~~~~~~~~~~~~
47
+
48
+ The best way to send feedback is to file an issue at https://github.com/StuartLittlefair/hcam_widgets/issues.
49
+
50
+ If you are proposing a feature:
51
+
52
+ * Explain in detail how it would work.
53
+ * Keep the scope as narrow as possible, to make it easier to implement.
54
+ * Remember that this is a volunteer-driven project, and that contributions
55
+ are welcome :)
56
+
57
+ Get Started!
58
+ ------------
59
+
60
+ Ready to contribute? Here's how to set up `hcam_widgets` for local development.
61
+
62
+ 1. Fork the `hcam_widgets` repo on GitHub.
63
+ 2. Clone your fork locally::
64
+
65
+ $ git clone git@github.com:your_name_here/hcam_widgets.git
66
+
67
+ 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::
68
+
69
+ $ mkvirtualenv hcam_widgets
70
+ $ cd hcam_widgets/
71
+ $ python setup.py develop
72
+
73
+ 4. Create a branch for local development::
74
+
75
+ $ git checkout -b name-of-your-bugfix-or-feature
76
+
77
+ Now you can make your changes locally.
78
+
79
+ 5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox::
80
+
81
+ $ flake8 hcam_widgets tests
82
+ $ python setup.py test or py.test
83
+ $ tox
84
+
85
+ To get flake8 and tox, just pip install them into your virtualenv.
86
+
87
+ 6. Commit your changes and push your branch to GitHub::
88
+
89
+ $ git add .
90
+ $ git commit -m "Your detailed description of your changes."
91
+ $ git push origin name-of-your-bugfix-or-feature
92
+
93
+ 7. Submit a pull request through the GitHub website.
94
+
95
+ Pull Request Guidelines
96
+ -----------------------
97
+
98
+ Before you submit a pull request, check that it meets these guidelines:
99
+
100
+ 1. The pull request should include tests.
101
+ 2. If the pull request adds functionality, the docs should be updated. Put
102
+ your new functionality into a function with a docstring, and add the
103
+ feature to the list in README.rst.
104
+ 3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check
105
+ https://travis-ci.org/StuartLittlefair/hcam_widgets/pull_requests
106
+ and make sure that the tests pass for all supported Python versions.
107
+
108
+ Tips
109
+ ----
110
+
111
+ To run a subset of tests::
112
+
113
+ $ py.test tests.test_hcam_widgets
114
+
@@ -0,0 +1,8 @@
1
+ =======
2
+ History
3
+ =======
4
+
5
+ 0.1.0 (2017-02-11)
6
+ ------------------
7
+
8
+ * First release on PyPI.
@@ -0,0 +1,11 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2017, Stuart Littlefair
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
+
@@ -0,0 +1,13 @@
1
+
2
+ include AUTHORS.rst
3
+
4
+ include CONTRIBUTING.rst
5
+ include HISTORY.rst
6
+ include LICENSE
7
+ include README.rst
8
+
9
+ recursive-include tests *
10
+ recursive-exclude * __pycache__
11
+ recursive-exclude * *.py[co]
12
+
13
+ recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 1.1
2
+ Name: hcam_widgets
3
+ Version: 0.1.1
4
+ Summary: Common Tkinter widgets for HiPerCAM
5
+ Home-page: https://github.com/StuartLittlefair/hcam_widgets
6
+ Author: Stuart Littlefair
7
+ Author-email: s.littlefair@shef.ac.uk
8
+ License: MIT license
9
+ Download-URL: https://github.com/StuartLittlefair/hcam_widgets/archive/0.2.tar.gz
10
+ Description-Content-Type: UNKNOWN
11
+ Description: ===============================
12
+ hcam-widgets
13
+ ===============================
14
+
15
+
16
+ .. image:: https://img.shields.io/pypi/v/hcam_widgets.svg
17
+ :target: https://pypi.python.org/pypi/hcam_widgets
18
+
19
+ .. image:: https://img.shields.io/travis/StuartLittlefair/hcam_widgets.svg
20
+ :target: https://travis-ci.org/StuartLittlefair/hcam_widgets
21
+
22
+ .. image:: https://readthedocs.org/projects/hcam-widgets/badge/?version=latest
23
+ :target: https://hcam-widgets.readthedocs.io/en/latest/?badge=latest
24
+ :alt: Documentation Status
25
+
26
+ .. image:: https://pyup.io/repos/github/StuartLittlefair/hcam_widgets/shield.svg
27
+ :target: https://pyup.io/repos/github/StuartLittlefair/hcam_widgets/
28
+ :alt: Updates
29
+
30
+
31
+ Tkinter Widgets for HiPerCAM tools
32
+
33
+ ``hcam_widgets`` provides a set of TKinter widgets and utility functions for writing tools to
34
+ plan and carry out HiPERCAM observations. The idea is to create a lightweight and easily-installed
35
+ collection of common widgets. It is compatible with Python2 and Python3.
36
+
37
+ Installation
38
+ ------------
39
+
40
+ The software is written as much as possible to make use of core Python components. It relies
41
+ on the third party library `astropy <http://astropy.org/>`_ for astronomical calculations.
42
+
43
+ Once you have installed astropy, install with the usual::
44
+
45
+ pip install .
46
+
47
+ or if you don't have root access::
48
+
49
+ pip install --user .
50
+
51
+ * Free software: MIT license
52
+
53
+
54
+
55
+
56
+
57
+ =======
58
+ History
59
+ =======
60
+
61
+ 0.1.0 (2017-02-11)
62
+ ------------------
63
+
64
+ * First release on PyPI.
65
+
66
+ Keywords: hcam_widgets
67
+ Platform: UNKNOWN
68
+ Classifier: Development Status :: 2 - Pre-Alpha
69
+ Classifier: Intended Audience :: Developers
70
+ Classifier: License :: OSI Approved :: MIT License
71
+ Classifier: Natural Language :: English
72
+ Classifier: Programming Language :: Python :: 2
73
+ Classifier: Programming Language :: Python :: 2.6
74
+ Classifier: Programming Language :: Python :: 2.7
75
+ Classifier: Programming Language :: Python :: 3
76
+ Classifier: Programming Language :: Python :: 3.3
77
+ Classifier: Programming Language :: Python :: 3.4
78
+ Classifier: Programming Language :: Python :: 3.5
@@ -0,0 +1,44 @@
1
+ ===============================
2
+ hcam-widgets
3
+ ===============================
4
+
5
+
6
+ .. image:: https://img.shields.io/pypi/v/hcam_widgets.svg
7
+ :target: https://pypi.python.org/pypi/hcam_widgets
8
+
9
+ .. image:: https://img.shields.io/travis/StuartLittlefair/hcam_widgets.svg
10
+ :target: https://travis-ci.org/StuartLittlefair/hcam_widgets
11
+
12
+ .. image:: https://readthedocs.org/projects/hcam-widgets/badge/?version=latest
13
+ :target: https://hcam-widgets.readthedocs.io/en/latest/?badge=latest
14
+ :alt: Documentation Status
15
+
16
+ .. image:: https://pyup.io/repos/github/StuartLittlefair/hcam_widgets/shield.svg
17
+ :target: https://pyup.io/repos/github/StuartLittlefair/hcam_widgets/
18
+ :alt: Updates
19
+
20
+
21
+ Tkinter Widgets for HiPerCAM tools
22
+
23
+ ``hcam_widgets`` provides a set of TKinter widgets and utility functions for writing tools to
24
+ plan and carry out HiPERCAM observations. The idea is to create a lightweight and easily-installed
25
+ collection of common widgets. It is compatible with Python2 and Python3.
26
+
27
+ Installation
28
+ ------------
29
+
30
+ The software is written as much as possible to make use of core Python components. It relies
31
+ on the third party library `astropy <http://astropy.org/>`_ for astronomical calculations.
32
+
33
+ Once you have installed astropy, install with the usual::
34
+
35
+ pip install .
36
+
37
+ or if you don't have root access::
38
+
39
+ pip install --user .
40
+
41
+ * Free software: MIT license
42
+
43
+
44
+
@@ -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.1.1'
7
+
8
+
9
+ class DriverError(Exception):
10
+ pass
@@ -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')