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

Skip to content

Commit 2898bfa

Browse files
authored
Merge pull request #10618 from TD22057/py3_jpl_units
Fixes #10501. python3 support and pep8 in jpl_units
2 parents 4dfb105 + 04f78be commit 2898bfa

File tree

8 files changed

+1206
-1150
lines changed

8 files changed

+1206
-1150
lines changed

lib/matplotlib/testing/jpl_units/Duration.py

Lines changed: 208 additions & 190 deletions
Large diffs are not rendered by default.

lib/matplotlib/testing/jpl_units/Epoch.py

Lines changed: 221 additions & 199 deletions
Large diffs are not rendered by default.
Lines changed: 145 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#===========================================================================
1+
# ==========================================================================
22
#
33
# EpochConverter
44
#
5-
#===========================================================================
5+
# ==========================================================================
66

77

88
"""EpochConverter module containing class EpochConverter."""
99

10-
#===========================================================================
10+
# ==========================================================================
1111
# Place all imports after here.
1212
#
1313
from __future__ import (absolute_import, division, print_function,
@@ -20,146 +20,145 @@
2020
from matplotlib.cbook import iterable
2121
#
2222
# Place all imports before here.
23-
#===========================================================================
24-
25-
__all__ = [ 'EpochConverter' ]
26-
27-
#===========================================================================
28-
class EpochConverter( units.ConversionInterface ):
29-
""": A matplotlib converter class. Provides matplotlib conversion
30-
functionality for Monte Epoch and Duration classes.
31-
"""
32-
33-
# julian date reference for "Jan 1, 0001" minus 1 day because
34-
# matplotlib really wants "Jan 0, 0001"
35-
jdRef = 1721425.5 - 1
36-
37-
#------------------------------------------------------------------------
38-
@staticmethod
39-
def axisinfo( unit, axis ):
40-
""": Returns information on how to handle an axis that has Epoch data.
41-
42-
= INPUT VARIABLES
43-
- unit The units to use for a axis with Epoch data.
44-
45-
= RETURN VALUE
46-
- Returns a matplotlib AxisInfo data structure that contains
47-
minor/major formatters, major/minor locators, and default
48-
label information.
49-
"""
50-
51-
majloc = date_ticker.AutoDateLocator()
52-
majfmt = date_ticker.AutoDateFormatter( majloc )
53-
54-
return units.AxisInfo( majloc = majloc,
55-
majfmt = majfmt,
56-
label = unit )
57-
58-
#------------------------------------------------------------------------
59-
@staticmethod
60-
def float2epoch( value, unit ):
61-
""": Convert a matplotlib floating-point date into an Epoch of the
62-
specified units.
63-
64-
= INPUT VARIABLES
65-
- value The matplotlib floating-point date.
66-
- unit The unit system to use for the Epoch.
67-
68-
= RETURN VALUE
69-
- Returns the value converted to an Epoch in the specified time system.
70-
"""
71-
# Delay-load due to circular dependencies.
72-
import matplotlib.testing.jpl_units as U
73-
74-
secPastRef = value * 86400.0 * U.UnitDbl( 1.0, 'sec' )
75-
return U.Epoch( unit, secPastRef, EpochConverter.jdRef )
76-
77-
#------------------------------------------------------------------------
78-
@staticmethod
79-
def epoch2float( value, unit ):
80-
""": Convert an Epoch value to a float suitible for plotting as a
81-
python datetime object.
82-
83-
= INPUT VARIABLES
84-
- value An Epoch or list of Epochs that need to be converted.
85-
- unit The units to use for an axis with Epoch data.
86-
87-
= RETURN VALUE
88-
- Returns the value parameter converted to floats.
89-
"""
90-
return value.julianDate( unit ) - EpochConverter.jdRef
91-
92-
#------------------------------------------------------------------------
93-
@staticmethod
94-
def duration2float( value ):
95-
""": Convert a Duration value to a float suitible for plotting as a
96-
python datetime object.
97-
98-
= INPUT VARIABLES
99-
- value A Duration or list of Durations that need to be converted.
100-
101-
= RETURN VALUE
102-
- Returns the value parameter converted to floats.
103-
"""
104-
return value.seconds() / 86400.0
105-
106-
#------------------------------------------------------------------------
107-
@staticmethod
108-
def convert( value, unit, axis ):
109-
""": Convert value using unit to a float. If value is a sequence, return
110-
the converted sequence.
111-
112-
= INPUT VARIABLES
113-
- value The value or list of values that need to be converted.
114-
- unit The units to use for an axis with Epoch data.
115-
116-
= RETURN VALUE
117-
- Returns the value parameter converted to floats.
118-
"""
119-
# Delay-load due to circular dependencies.
120-
import matplotlib.testing.jpl_units as U
121-
122-
isNotEpoch = True
123-
isDuration = False
124-
125-
if ( iterable(value) and not isinstance(value, six.string_types) ):
126-
if ( len(value) == 0 ):
127-
return []
128-
else:
129-
return [ EpochConverter.convert( x, unit, axis ) for x in value ]
130-
131-
if ( isinstance(value, U.Epoch) ):
132-
isNotEpoch = False
133-
elif ( isinstance(value, U.Duration) ):
134-
isDuration = True
135-
136-
if ( isNotEpoch and not isDuration and
137-
units.ConversionInterface.is_numlike( value ) ):
138-
return value
139-
140-
if ( unit == None ):
141-
unit = EpochConverter.default_units( value, axis )
142-
143-
if ( isDuration ):
144-
return EpochConverter.duration2float( value )
145-
else:
146-
return EpochConverter.epoch2float( value, unit )
147-
148-
#------------------------------------------------------------------------
149-
@staticmethod
150-
def default_units( value, axis ):
151-
""": Return the default unit for value, or None.
152-
153-
= INPUT VARIABLES
154-
- value The value or list of values that need units.
155-
156-
= RETURN VALUE
157-
- Returns the default units to use for value.
158-
"""
159-
frame = None
160-
if ( iterable(value) and not isinstance(value, six.string_types) ):
161-
return EpochConverter.default_units( value[0], axis )
162-
else:
163-
frame = value.frame()
164-
165-
return frame
23+
# ==========================================================================
24+
25+
__all__ = ['EpochConverter']
26+
27+
28+
# ==========================================================================
29+
class EpochConverter(units.ConversionInterface):
30+
""": A matplotlib converter class. Provides matplotlib conversion
31+
functionality for Monte Epoch and Duration classes.
32+
"""
33+
34+
# julian date reference for "Jan 1, 0001" minus 1 day because
35+
# matplotlib really wants "Jan 0, 0001"
36+
jdRef = 1721425.5 - 1
37+
38+
# -----------------------------------------------------------------------
39+
@staticmethod
40+
def axisinfo(unit, axis):
41+
""": Returns information on how to handle an axis that has Epoch data.
42+
43+
= INPUT VARIABLES
44+
- unit The units to use for a axis with Epoch data.
45+
46+
= RETURN VALUE
47+
- Returns a matplotlib AxisInfo data structure that contains
48+
minor/major formatters, major/minor locators, and default
49+
label information.
50+
"""
51+
52+
majloc = date_ticker.AutoDateLocator()
53+
majfmt = date_ticker.AutoDateFormatter(majloc)
54+
55+
return units.AxisInfo(majloc=majloc, majfmt=majfmt, label=unit)
56+
57+
# -----------------------------------------------------------------------
58+
@staticmethod
59+
def float2epoch(value, unit):
60+
""": Convert a matplotlib floating-point date into an Epoch of the
61+
specified units.
62+
63+
= INPUT VARIABLES
64+
- value The matplotlib floating-point date.
65+
- unit The unit system to use for the Epoch.
66+
67+
= RETURN VALUE
68+
- Returns the value converted to an Epoch in the specified time system.
69+
"""
70+
# Delay-load due to circular dependencies.
71+
import matplotlib.testing.jpl_units as U
72+
73+
secPastRef = value * 86400.0 * U.UnitDbl(1.0, 'sec')
74+
return U.Epoch(unit, secPastRef, EpochConverter.jdRef)
75+
76+
# -----------------------------------------------------------------------
77+
@staticmethod
78+
def epoch2float(value, unit):
79+
""": Convert an Epoch value to a float suitible for plotting as a
80+
python datetime object.
81+
82+
= INPUT VARIABLES
83+
- value An Epoch or list of Epochs that need to be converted.
84+
- unit The units to use for an axis with Epoch data.
85+
86+
= RETURN VALUE
87+
- Returns the value parameter converted to floats.
88+
"""
89+
return value.julianDate(unit) - EpochConverter.jdRef
90+
91+
# -----------------------------------------------------------------------
92+
@staticmethod
93+
def duration2float(value):
94+
""": Convert a Duration value to a float suitible for plotting as a
95+
python datetime object.
96+
97+
= INPUT VARIABLES
98+
- value A Duration or list of Durations that need to be converted.
99+
100+
= RETURN VALUE
101+
- Returns the value parameter converted to floats.
102+
"""
103+
return value.seconds() / 86400.0
104+
105+
# -----------------------------------------------------------------------
106+
@staticmethod
107+
def convert(value, unit, axis):
108+
""": Convert value using unit to a float. If value is a sequence, return
109+
the converted sequence.
110+
111+
= INPUT VARIABLES
112+
- value The value or list of values that need to be converted.
113+
- unit The units to use for an axis with Epoch data.
114+
115+
= RETURN VALUE
116+
- Returns the value parameter converted to floats.
117+
"""
118+
# Delay-load due to circular dependencies.
119+
import matplotlib.testing.jpl_units as U
120+
121+
isNotEpoch = True
122+
isDuration = False
123+
124+
if iterable(value) and not isinstance(value, six.string_types):
125+
if (len(value) == 0):
126+
return []
127+
else:
128+
return [EpochConverter.convert(x, unit, axis) for x in value]
129+
130+
if isinstance(value, U.Epoch):
131+
isNotEpoch = False
132+
elif isinstance(value, U.Duration):
133+
isDuration = True
134+
135+
if (isNotEpoch and not isDuration and
136+
units.ConversionInterface.is_numlike(value)):
137+
return value
138+
139+
if unit is None:
140+
unit = EpochConverter.default_units(value, axis)
141+
142+
if isDuration:
143+
return EpochConverter.duration2float(value)
144+
else:
145+
return EpochConverter.epoch2float(value, unit)
146+
147+
# -----------------------------------------------------------------------
148+
@staticmethod
149+
def default_units(value, axis):
150+
""": Return the default unit for value, or None.
151+
152+
= INPUT VARIABLES
153+
- value The value or list of values that need units.
154+
155+
= RETURN VALUE
156+
- Returns the default units to use for value.
157+
"""
158+
frame = None
159+
if iterable(value) and not isinstance(value, six.string_types):
160+
return EpochConverter.default_units(value[0], axis)
161+
else:
162+
frame = value.frame()
163+
164+
return frame

0 commit comments

Comments
 (0)