Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1bb33c

Browse files
committed
Make jpl_units a bit less painful to read.
1 parent 32ad86f commit e1bb33c

File tree

8 files changed

+8
-181
lines changed

8 files changed

+8
-181
lines changed

lib/matplotlib/testing/jpl_units/Duration.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
1-
# ==========================================================================
2-
#
3-
# Duration
4-
#
5-
# ==========================================================================
6-
7-
81
"""Duration module."""
92

10-
# ==========================================================================
11-
# Place all imports after here.
12-
#
133
import operator
14-
#
15-
# Place all imports before here.
16-
# ==========================================================================
174

185

19-
# ==========================================================================
206
class Duration(object):
217
"""Class Duration in development.
228
"""
239
allowed = ["ET", "UTC"]
2410

25-
# ----------------------------------------------------------------------
2611
def __init__(self, frame, seconds):
2712
"""Create a new Duration object.
2813
@@ -41,31 +26,25 @@ def __init__(self, frame, seconds):
4126
self._frame = frame
4227
self._seconds = seconds
4328

44-
# ----------------------------------------------------------------------
4529
def frame(self):
4630
"""Return the frame the duration is in."""
4731
return self._frame
4832

49-
# ----------------------------------------------------------------------
5033
def __abs__(self):
5134
"""Return the absolute value of the duration."""
5235
return Duration(self._frame, abs(self._seconds))
5336

54-
# ----------------------------------------------------------------------
5537
def __neg__(self):
5638
"""Return the negative value of this Duration."""
5739
return Duration(self._frame, -self._seconds)
5840

59-
# ----------------------------------------------------------------------
6041
def seconds(self):
6142
"""Return the number of seconds in the Duration."""
6243
return self._seconds
6344

64-
# ----------------------------------------------------------------------
6545
def __bool__(self):
6646
return self._seconds != 0
6747

68-
# ----------------------------------------------------------------------
6948
def __eq__(self, rhs):
7049
return self._cmp(rhs, operator.eq)
7150

@@ -97,7 +76,6 @@ def _cmp(self, rhs, op):
9776
self.checkSameFrame(rhs, "compare")
9877
return op(self._seconds, rhs._seconds)
9978

100-
# ----------------------------------------------------------------------
10179
def __add__(self, rhs):
10280
"""Add two Durations.
10381
@@ -119,7 +97,6 @@ def __add__(self, rhs):
11997
self.checkSameFrame(rhs, "add")
12098
return Duration(self._frame, self._seconds + rhs._seconds)
12199

122-
# ----------------------------------------------------------------------
123100
def __sub__(self, rhs):
124101
"""Subtract two Durations.
125102
@@ -135,7 +112,6 @@ def __sub__(self, rhs):
135112
self.checkSameFrame(rhs, "sub")
136113
return Duration(self._frame, self._seconds - rhs._seconds)
137114

138-
# ----------------------------------------------------------------------
139115
def __mul__(self, rhs):
140116
"""Scale a UnitDbl by a value.
141117
@@ -147,7 +123,6 @@ def __mul__(self, rhs):
147123
"""
148124
return Duration(self._frame, self._seconds * float(rhs))
149125

150-
# ----------------------------------------------------------------------
151126
def __rmul__(self, lhs):
152127
"""Scale a Duration by a value.
153128
@@ -159,7 +134,6 @@ def __rmul__(self, lhs):
159134
"""
160135
return Duration(self._frame, self._seconds * float(lhs))
161136

162-
# ----------------------------------------------------------------------
163137
def __div__(self, rhs):
164138
"""Divide a Duration by a value.
165139
@@ -171,7 +145,6 @@ def __div__(self, rhs):
171145
"""
172146
return Duration(self._frame, self._seconds / rhs)
173147

174-
# ----------------------------------------------------------------------
175148
def __rdiv__(self, rhs):
176149
"""Divide a Duration by a value.
177150
@@ -183,17 +156,14 @@ def __rdiv__(self, rhs):
183156
"""
184157
return Duration(self._frame, rhs / self._seconds)
185158

186-
# ----------------------------------------------------------------------
187159
def __str__(self):
188160
"""Print the Duration."""
189161
return "%g %s" % (self._seconds, self._frame)
190162

191-
# ----------------------------------------------------------------------
192163
def __repr__(self):
193164
"""Print the Duration."""
194165
return "Duration('%s', %g)" % (self._frame, self._seconds)
195166

196-
# ----------------------------------------------------------------------
197167
def checkSameFrame(self, rhs, func):
198168
"""Check to see if frames are the same.
199169
@@ -210,5 +180,3 @@ def checkSameFrame(self, rhs, func):
210180
"LHS: %s\n" \
211181
"RHS: %s" % (func, self._frame, rhs._frame)
212182
raise ValueError(msg)
213-
214-
# ==========================================================================

lib/matplotlib/testing/jpl_units/Epoch.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
# ===========================================================================
2-
#
3-
# Epoch
4-
#
5-
# ===========================================================================
6-
7-
81
"""Epoch module."""
92

10-
# ===========================================================================
11-
# Place all imports after here.
12-
#
133
import operator
144
import math
155
import datetime as DT
166
from matplotlib.dates import date2num
17-
#
18-
# Place all imports before here.
19-
# ===========================================================================
207

218

22-
# ===========================================================================
239
class Epoch(object):
2410
# Frame conversion offsets in seconds
2511
# t(TO) = t(FROM) + allowed[ FROM ][ TO ]
@@ -32,7 +18,6 @@ class Epoch(object):
3218
},
3319
}
3420

35-
# -----------------------------------------------------------------------
3621
def __init__(self, frame, sec=None, jd=None, daynum=None, dt=None):
3722
"""Create a new Epoch object.
3823
@@ -44,7 +29,6 @@ def __init__(self, frame, sec=None, jd=None, daynum=None, dt=None):
4429
or using a matplotlib day number
4530
# Epoch('ET', daynum=730119.5)
4631
47-
4832
= ERROR CONDITIONS
4933
- If the input units are not in the allowed list, an error is thrown.
5034
@@ -97,7 +81,6 @@ def __init__(self, frame, sec=None, jd=None, daynum=None, dt=None):
9781
self._jd += deltaDays
9882
self._seconds -= deltaDays * 86400.0
9983

100-
# -----------------------------------------------------------------------
10184
def convert(self, frame):
10285
if self._frame == frame:
10386
return self
@@ -106,19 +89,16 @@ def convert(self, frame):
10689

10790
return Epoch(frame, self._seconds + offset, self._jd)
10891

109-
# -----------------------------------------------------------------------
11092
def frame(self):
11193
return self._frame
11294

113-
# -----------------------------------------------------------------------
11495
def julianDate(self, frame):
11596
t = self
11697
if frame != self._frame:
11798
t = self.convert(frame)
11899

119100
return t._jd + t._seconds / 86400.0
120101

121-
# -----------------------------------------------------------------------
122102
def secondsPast(self, frame, jd):
123103
t = self
124104
if frame != self._frame:
@@ -127,7 +107,6 @@ def secondsPast(self, frame, jd):
127107
delta = t._jd - jd
128108
return t._seconds + delta * 86400
129109

130-
# -----------------------------------------------------------------------
131110
def __eq__(self, rhs):
132111
return self._cmp(rhs, operator.eq)
133112

@@ -165,7 +144,6 @@ def _cmp(self, rhs, op):
165144

166145
return op(t._seconds, rhs._seconds)
167146

168-
# -----------------------------------------------------------------------
169147
def __add__(self, rhs):
170148
"""Add a duration to an Epoch.
171149
@@ -183,7 +161,6 @@ def __add__(self, rhs):
183161

184162
return Epoch(t._frame, sec, t._jd)
185163

186-
# -----------------------------------------------------------------------
187164
def __sub__(self, rhs):
188165
"""Subtract two Epoch's or a Duration from an Epoch.
189166
@@ -214,17 +191,15 @@ def __sub__(self, rhs):
214191

215192
return U.Duration(rhs._frame, days*86400 + sec)
216193

217-
# -----------------------------------------------------------------------
218194
def __str__(self):
219195
"""Print the Epoch."""
220196
return "%22.15e %s" % (self.julianDate(self._frame), self._frame)
221197

222-
# -----------------------------------------------------------------------
223198
def __repr__(self):
224199
"""Print the Epoch."""
225200
return str(self)
226201

227-
# -----------------------------------------------------------------------
202+
@staticmethod
228203
def range(start, stop, step):
229204
"""Generate a range of Epoch objects.
230205
@@ -252,7 +227,3 @@ def range(start, stop, step):
252227
i += 1
253228

254229
return elems
255-
256-
range = staticmethod(range)
257-
258-
# ===========================================================================

lib/matplotlib/testing/jpl_units/EpochConverter.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
# ==========================================================================
2-
#
3-
# EpochConverter
4-
#
5-
# ==========================================================================
6-
7-
81
"""EpochConverter module containing class EpochConverter."""
92

10-
# ==========================================================================
11-
# Place all imports after here.
12-
#
133
import matplotlib.units as units
144
import matplotlib.dates as date_ticker
155
from matplotlib.cbook import iterable
16-
#
17-
# Place all imports before here.
18-
# ==========================================================================
196

207
__all__ = ['EpochConverter']
218

229

23-
# ==========================================================================
2410
class EpochConverter(units.ConversionInterface):
2511
""": A matplotlib converter class. Provides matplotlib conversion
2612
functionality for Monte Epoch and Duration classes.
@@ -30,7 +16,6 @@ class EpochConverter(units.ConversionInterface):
3016
# matplotlib really wants "Jan 0, 0001"
3117
jdRef = 1721425.5 - 1
3218

33-
# -----------------------------------------------------------------------
3419
@staticmethod
3520
def axisinfo(unit, axis):
3621
""": Returns information on how to handle an axis that has Epoch data.
@@ -49,7 +34,6 @@ def axisinfo(unit, axis):
4934

5035
return units.AxisInfo(majloc=majloc, majfmt=majfmt, label=unit)
5136

52-
# -----------------------------------------------------------------------
5337
@staticmethod
5438
def float2epoch(value, unit):
5539
""": Convert a matplotlib floating-point date into an Epoch of the
@@ -68,7 +52,6 @@ def float2epoch(value, unit):
6852
secPastRef = value * 86400.0 * U.UnitDbl(1.0, 'sec')
6953
return U.Epoch(unit, secPastRef, EpochConverter.jdRef)
7054

71-
# -----------------------------------------------------------------------
7255
@staticmethod
7356
def epoch2float(value, unit):
7457
""": Convert an Epoch value to a float suitible for plotting as a
@@ -83,7 +66,6 @@ def epoch2float(value, unit):
8366
"""
8467
return value.julianDate(unit) - EpochConverter.jdRef
8568

86-
# -----------------------------------------------------------------------
8769
@staticmethod
8870
def duration2float(value):
8971
""": Convert a Duration value to a float suitible for plotting as a
@@ -97,7 +79,6 @@ def duration2float(value):
9779
"""
9880
return value.seconds() / 86400.0
9981

100-
# -----------------------------------------------------------------------
10182
@staticmethod
10283
def convert(value, unit, axis):
10384
""": Convert value using unit to a float. If value is a sequence, return
@@ -139,7 +120,6 @@ def convert(value, unit, axis):
139120
else:
140121
return EpochConverter.epoch2float(value, unit)
141122

142-
# -----------------------------------------------------------------------
143123
@staticmethod
144124
def default_units(value, axis):
145125
""": Return the default unit for value, or None.

lib/matplotlib/testing/jpl_units/StrConverter.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
# ==========================================================================
2-
#
3-
# StrConverter
4-
#
5-
# ==========================================================================
6-
7-
81
"""StrConverter module containing class StrConverter."""
92

10-
# ==========================================================================
11-
# Place all imports after here.
12-
#
133
import matplotlib.units as units
144
from matplotlib.cbook import iterable
15-
#
16-
# Place all imports before here.
17-
# ==========================================================================
185

196
__all__ = ['StrConverter']
207

218

22-
# ==========================================================================
239
class StrConverter(units.ConversionInterface):
2410
""": A matplotlib converter class. Provides matplotlib conversion
2511
functionality for string data values.
@@ -31,7 +17,6 @@ class StrConverter(units.ConversionInterface):
3117
- 'sorted-inverted' : A combination of 'sorted' and 'inverted'
3218
"""
3319

34-
# -----------------------------------------------------------------------
3520
@staticmethod
3621
def axisinfo(unit, axis):
3722
""": Returns information on how to handle an axis that has string data.
@@ -48,7 +33,6 @@ def axisinfo(unit, axis):
4833

4934
return None
5035

51-
# -----------------------------------------------------------------------
5236
@staticmethod
5337
def convert(value, unit, axis):
5438
""": Convert value using unit to a float. If value is a sequence, return
@@ -105,10 +89,10 @@ def convert(value, unit, axis):
10589
# DISABLED: this is due to design and is not really a bug.
10690
# DISABLED: If this gets changed, then we can activate the following
10791
# DISABLED: block of code. Note that this works for line plots.
108-
# DISABLED if (unit):
109-
# DISABLED if (unit.find("sorted") > -1):
92+
# DISABLED if unit:
93+
# DISABLED if unit.find("sorted") > -1:
11094
# DISABLED labels.sort()
111-
# DISABLED if (unit.find("inverted") > -1):
95+
# DISABLED if unit.find("inverted") > -1:
11296
# DISABLED labels = labels[::-1]
11397

11498
# add padding (so they do not appear on the axes themselves)
@@ -140,7 +124,6 @@ def convert(value, unit, axis):
140124
ax.viewLim.ignore(-1)
141125
return result
142126

143-
# -----------------------------------------------------------------------
144127
@staticmethod
145128
def default_units(value, axis):
146129
""": Return the default unit for value, or None.

0 commit comments

Comments
 (0)