diff --git a/lib/matplotlib/testing/jpl_units/Duration.py b/lib/matplotlib/testing/jpl_units/Duration.py index bdfb4cfb5f9d..00cc755cda1a 100644 --- a/lib/matplotlib/testing/jpl_units/Duration.py +++ b/lib/matplotlib/testing/jpl_units/Duration.py @@ -1,28 +1,13 @@ -# ========================================================================== -# -# Duration -# -# ========================================================================== - - """Duration module.""" -# ========================================================================== -# Place all imports after here. -# import operator -# -# Place all imports before here. -# ========================================================================== -# ========================================================================== class Duration(object): """Class Duration in development. """ allowed = ["ET", "UTC"] - # ---------------------------------------------------------------------- def __init__(self, frame, seconds): """Create a new Duration object. @@ -41,31 +26,25 @@ def __init__(self, frame, seconds): self._frame = frame self._seconds = seconds - # ---------------------------------------------------------------------- def frame(self): """Return the frame the duration is in.""" return self._frame - # ---------------------------------------------------------------------- def __abs__(self): """Return the absolute value of the duration.""" return Duration(self._frame, abs(self._seconds)) - # ---------------------------------------------------------------------- def __neg__(self): """Return the negative value of this Duration.""" return Duration(self._frame, -self._seconds) - # ---------------------------------------------------------------------- def seconds(self): """Return the number of seconds in the Duration.""" return self._seconds - # ---------------------------------------------------------------------- def __bool__(self): return self._seconds != 0 - # ---------------------------------------------------------------------- def __eq__(self, rhs): return self._cmp(rhs, operator.eq) @@ -97,7 +76,6 @@ def _cmp(self, rhs, op): self.checkSameFrame(rhs, "compare") return op(self._seconds, rhs._seconds) - # ---------------------------------------------------------------------- def __add__(self, rhs): """Add two Durations. @@ -119,7 +97,6 @@ def __add__(self, rhs): self.checkSameFrame(rhs, "add") return Duration(self._frame, self._seconds + rhs._seconds) - # ---------------------------------------------------------------------- def __sub__(self, rhs): """Subtract two Durations. @@ -135,7 +112,6 @@ def __sub__(self, rhs): self.checkSameFrame(rhs, "sub") return Duration(self._frame, self._seconds - rhs._seconds) - # ---------------------------------------------------------------------- def __mul__(self, rhs): """Scale a UnitDbl by a value. @@ -147,7 +123,6 @@ def __mul__(self, rhs): """ return Duration(self._frame, self._seconds * float(rhs)) - # ---------------------------------------------------------------------- def __rmul__(self, lhs): """Scale a Duration by a value. @@ -159,7 +134,6 @@ def __rmul__(self, lhs): """ return Duration(self._frame, self._seconds * float(lhs)) - # ---------------------------------------------------------------------- def __div__(self, rhs): """Divide a Duration by a value. @@ -171,7 +145,6 @@ def __div__(self, rhs): """ return Duration(self._frame, self._seconds / rhs) - # ---------------------------------------------------------------------- def __rdiv__(self, rhs): """Divide a Duration by a value. @@ -183,17 +156,14 @@ def __rdiv__(self, rhs): """ return Duration(self._frame, rhs / self._seconds) - # ---------------------------------------------------------------------- def __str__(self): """Print the Duration.""" return "%g %s" % (self._seconds, self._frame) - # ---------------------------------------------------------------------- def __repr__(self): """Print the Duration.""" return "Duration('%s', %g)" % (self._frame, self._seconds) - # ---------------------------------------------------------------------- def checkSameFrame(self, rhs, func): """Check to see if frames are the same. @@ -210,5 +180,3 @@ def checkSameFrame(self, rhs, func): "LHS: %s\n" \ "RHS: %s" % (func, self._frame, rhs._frame) raise ValueError(msg) - -# ========================================================================== diff --git a/lib/matplotlib/testing/jpl_units/Epoch.py b/lib/matplotlib/testing/jpl_units/Epoch.py index 8cf956366d53..97d3a6bde523 100644 --- a/lib/matplotlib/testing/jpl_units/Epoch.py +++ b/lib/matplotlib/testing/jpl_units/Epoch.py @@ -1,25 +1,11 @@ -# =========================================================================== -# -# Epoch -# -# =========================================================================== - - """Epoch module.""" -# =========================================================================== -# Place all imports after here. -# import operator import math import datetime as DT from matplotlib.dates import date2num -# -# Place all imports before here. -# =========================================================================== -# =========================================================================== class Epoch(object): # Frame conversion offsets in seconds # t(TO) = t(FROM) + allowed[ FROM ][ TO ] @@ -32,7 +18,6 @@ class Epoch(object): }, } - # ----------------------------------------------------------------------- def __init__(self, frame, sec=None, jd=None, daynum=None, dt=None): """Create a new Epoch object. @@ -44,7 +29,6 @@ def __init__(self, frame, sec=None, jd=None, daynum=None, dt=None): or using a matplotlib day number # Epoch('ET', daynum=730119.5) - = ERROR CONDITIONS - If the input units are not in the allowed list, an error is thrown. @@ -97,7 +81,6 @@ def __init__(self, frame, sec=None, jd=None, daynum=None, dt=None): self._jd += deltaDays self._seconds -= deltaDays * 86400.0 - # ----------------------------------------------------------------------- def convert(self, frame): if self._frame == frame: return self @@ -106,11 +89,9 @@ def convert(self, frame): return Epoch(frame, self._seconds + offset, self._jd) - # ----------------------------------------------------------------------- def frame(self): return self._frame - # ----------------------------------------------------------------------- def julianDate(self, frame): t = self if frame != self._frame: @@ -118,7 +99,6 @@ def julianDate(self, frame): return t._jd + t._seconds / 86400.0 - # ----------------------------------------------------------------------- def secondsPast(self, frame, jd): t = self if frame != self._frame: @@ -127,7 +107,6 @@ def secondsPast(self, frame, jd): delta = t._jd - jd return t._seconds + delta * 86400 - # ----------------------------------------------------------------------- def __eq__(self, rhs): return self._cmp(rhs, operator.eq) @@ -165,7 +144,6 @@ def _cmp(self, rhs, op): return op(t._seconds, rhs._seconds) - # ----------------------------------------------------------------------- def __add__(self, rhs): """Add a duration to an Epoch. @@ -183,7 +161,6 @@ def __add__(self, rhs): return Epoch(t._frame, sec, t._jd) - # ----------------------------------------------------------------------- def __sub__(self, rhs): """Subtract two Epoch's or a Duration from an Epoch. @@ -214,17 +191,15 @@ def __sub__(self, rhs): return U.Duration(rhs._frame, days*86400 + sec) - # ----------------------------------------------------------------------- def __str__(self): """Print the Epoch.""" return "%22.15e %s" % (self.julianDate(self._frame), self._frame) - # ----------------------------------------------------------------------- def __repr__(self): """Print the Epoch.""" return str(self) - # ----------------------------------------------------------------------- + @staticmethod def range(start, stop, step): """Generate a range of Epoch objects. @@ -252,7 +227,3 @@ def range(start, stop, step): i += 1 return elems - - range = staticmethod(range) - -# =========================================================================== diff --git a/lib/matplotlib/testing/jpl_units/EpochConverter.py b/lib/matplotlib/testing/jpl_units/EpochConverter.py index cc85d104409a..f66932ac9927 100644 --- a/lib/matplotlib/testing/jpl_units/EpochConverter.py +++ b/lib/matplotlib/testing/jpl_units/EpochConverter.py @@ -1,26 +1,12 @@ -# ========================================================================== -# -# EpochConverter -# -# ========================================================================== - - """EpochConverter module containing class EpochConverter.""" -# ========================================================================== -# Place all imports after here. -# import matplotlib.units as units import matplotlib.dates as date_ticker from matplotlib.cbook import iterable -# -# Place all imports before here. -# ========================================================================== __all__ = ['EpochConverter'] -# ========================================================================== class EpochConverter(units.ConversionInterface): """: A matplotlib converter class. Provides matplotlib conversion functionality for Monte Epoch and Duration classes. @@ -30,7 +16,6 @@ class EpochConverter(units.ConversionInterface): # matplotlib really wants "Jan 0, 0001" jdRef = 1721425.5 - 1 - # ----------------------------------------------------------------------- @staticmethod def axisinfo(unit, axis): """: Returns information on how to handle an axis that has Epoch data. @@ -49,7 +34,6 @@ def axisinfo(unit, axis): return units.AxisInfo(majloc=majloc, majfmt=majfmt, label=unit) - # ----------------------------------------------------------------------- @staticmethod def float2epoch(value, unit): """: Convert a matplotlib floating-point date into an Epoch of the @@ -68,7 +52,6 @@ def float2epoch(value, unit): secPastRef = value * 86400.0 * U.UnitDbl(1.0, 'sec') return U.Epoch(unit, secPastRef, EpochConverter.jdRef) - # ----------------------------------------------------------------------- @staticmethod def epoch2float(value, unit): """: Convert an Epoch value to a float suitible for plotting as a @@ -83,7 +66,6 @@ def epoch2float(value, unit): """ return value.julianDate(unit) - EpochConverter.jdRef - # ----------------------------------------------------------------------- @staticmethod def duration2float(value): """: Convert a Duration value to a float suitible for plotting as a @@ -97,7 +79,6 @@ def duration2float(value): """ return value.seconds() / 86400.0 - # ----------------------------------------------------------------------- @staticmethod def convert(value, unit, axis): """: Convert value using unit to a float. If value is a sequence, return @@ -139,7 +120,6 @@ def convert(value, unit, axis): else: return EpochConverter.epoch2float(value, unit) - # ----------------------------------------------------------------------- @staticmethod def default_units(value, axis): """: Return the default unit for value, or None. diff --git a/lib/matplotlib/testing/jpl_units/StrConverter.py b/lib/matplotlib/testing/jpl_units/StrConverter.py index 7b6d8b3847fa..ac6b847e93a5 100644 --- a/lib/matplotlib/testing/jpl_units/StrConverter.py +++ b/lib/matplotlib/testing/jpl_units/StrConverter.py @@ -1,25 +1,11 @@ -# ========================================================================== -# -# StrConverter -# -# ========================================================================== - - """StrConverter module containing class StrConverter.""" -# ========================================================================== -# Place all imports after here. -# import matplotlib.units as units from matplotlib.cbook import iterable -# -# Place all imports before here. -# ========================================================================== __all__ = ['StrConverter'] -# ========================================================================== class StrConverter(units.ConversionInterface): """: A matplotlib converter class. Provides matplotlib conversion functionality for string data values. @@ -31,7 +17,6 @@ class StrConverter(units.ConversionInterface): - 'sorted-inverted' : A combination of 'sorted' and 'inverted' """ - # ----------------------------------------------------------------------- @staticmethod def axisinfo(unit, axis): """: Returns information on how to handle an axis that has string data. @@ -48,7 +33,6 @@ def axisinfo(unit, axis): return None - # ----------------------------------------------------------------------- @staticmethod def convert(value, unit, axis): """: Convert value using unit to a float. If value is a sequence, return @@ -105,10 +89,10 @@ def convert(value, unit, axis): # DISABLED: this is due to design and is not really a bug. # DISABLED: If this gets changed, then we can activate the following # DISABLED: block of code. Note that this works for line plots. - # DISABLED if (unit): - # DISABLED if (unit.find("sorted") > -1): + # DISABLED if unit: + # DISABLED if unit.find("sorted") > -1: # DISABLED labels.sort() - # DISABLED if (unit.find("inverted") > -1): + # DISABLED if unit.find("inverted") > -1: # DISABLED labels = labels[::-1] # add padding (so they do not appear on the axes themselves) @@ -140,7 +124,6 @@ def convert(value, unit, axis): ax.viewLim.ignore(-1) return result - # ----------------------------------------------------------------------- @staticmethod def default_units(value, axis): """: Return the default unit for value, or None. diff --git a/lib/matplotlib/testing/jpl_units/UnitDbl.py b/lib/matplotlib/testing/jpl_units/UnitDbl.py index b65b6a357bd6..898e1bae43c0 100644 --- a/lib/matplotlib/testing/jpl_units/UnitDbl.py +++ b/lib/matplotlib/testing/jpl_units/UnitDbl.py @@ -1,26 +1,11 @@ -# ========================================================================== -# -# UnitDbl -# -# ========================================================================== - - """UnitDbl module.""" -# ========================================================================== -# Place all imports after here. -# import operator -# -# Place all imports before here. -# ========================================================================== -# ========================================================================== class UnitDbl(object): """Class UnitDbl in development. """ - # ---------------------------------------------------------------------- # Unit conversion table. Small subset of the full one but enough # to test the required functions. First field is a scale factor to # convert the input units to the units of the second field. Only @@ -44,7 +29,6 @@ class UnitDbl(object): "sec": "time", } - # ---------------------------------------------------------------------- def __init__(self, value, units): """Create a new UnitDbl object. @@ -67,7 +51,6 @@ def __init__(self, value, units): self._value = float(value * data[0]) self._units = data[1] - # ---------------------------------------------------------------------- def convert(self, units): """Convert the UnitDbl to a specific set of units. @@ -96,22 +79,18 @@ def convert(self, units): return self._value / data[0] - # ---------------------------------------------------------------------- def __abs__(self): """Return the absolute value of this UnitDbl.""" return UnitDbl(abs(self._value), self._units) - # ---------------------------------------------------------------------- def __neg__(self): """Return the negative value of this UnitDbl.""" return UnitDbl(-self._value, self._units) - # ---------------------------------------------------------------------- def __bool__(self): """Return the truth value of a UnitDbl.""" return bool(self._value) - # ---------------------------------------------------------------------- def __eq__(self, rhs): return self._cmp(rhs, operator.eq) @@ -147,7 +126,6 @@ def _cmp(self, rhs, op): self.checkSameUnits(rhs, "compare") return op(self._value, rhs._value) - # ---------------------------------------------------------------------- def __add__(self, rhs): """Add two UnitDbl's. @@ -164,7 +142,6 @@ def __add__(self, rhs): self.checkSameUnits(rhs, "add") return UnitDbl(self._value + rhs._value, self._units) - # ---------------------------------------------------------------------- def __sub__(self, rhs): """Subtract two UnitDbl's. @@ -181,7 +158,6 @@ def __sub__(self, rhs): self.checkSameUnits(rhs, "subtract") return UnitDbl(self._value - rhs._value, self._units) - # ---------------------------------------------------------------------- def __mul__(self, rhs): """Scale a UnitDbl by a value. @@ -193,7 +169,6 @@ def __mul__(self, rhs): """ return UnitDbl(self._value * rhs, self._units) - # ---------------------------------------------------------------------- def __rmul__(self, lhs): """Scale a UnitDbl by a value. @@ -205,7 +180,6 @@ def __rmul__(self, lhs): """ return UnitDbl(self._value * lhs, self._units) - # ---------------------------------------------------------------------- def __div__(self, rhs): """Divide a UnitDbl by a value. @@ -217,22 +191,18 @@ def __div__(self, rhs): """ return UnitDbl(self._value / rhs, self._units) - # ---------------------------------------------------------------------- def __str__(self): """Print the UnitDbl.""" return "%g *%s" % (self._value, self._units) - # ---------------------------------------------------------------------- def __repr__(self): """Print the UnitDbl.""" return "UnitDbl(%g, '%s')" % (self._value, self._units) - # ---------------------------------------------------------------------- def type(self): """Return the type of UnitDbl data.""" return self._types[self._units] - # ---------------------------------------------------------------------- def range(start, stop, step=None): """Generate a range of UnitDbl objects. @@ -267,7 +237,6 @@ def range(start, stop, step=None): range = staticmethod(range) - # ---------------------------------------------------------------------- def checkUnits(self, units): """Check to see if some units are valid. @@ -282,7 +251,6 @@ def checkUnits(self, units): "types of %s" % ( units, list(self.allowed.keys()))) - # ---------------------------------------------------------------------- def checkSameUnits(self, rhs, func): """Check to see if units are the same. @@ -299,5 +267,3 @@ def checkSameUnits(self, rhs, func): "LHS: %s\n" \ "RHS: %s" % (func, self._units, rhs._units) raise ValueError(msg) - -# ========================================================================== diff --git a/lib/matplotlib/testing/jpl_units/UnitDblConverter.py b/lib/matplotlib/testing/jpl_units/UnitDblConverter.py index cf2b4a2c4784..b53291b48300 100644 --- a/lib/matplotlib/testing/jpl_units/UnitDblConverter.py +++ b/lib/matplotlib/testing/jpl_units/UnitDblConverter.py @@ -1,26 +1,13 @@ -# ========================================================================== -# -# UnitDblConverter -# -# ========================================================================== - """UnitDblConverter module containing class UnitDblConverter.""" -# ========================================================================== -# Place all imports after here. -# import numpy as np import matplotlib.units as units import matplotlib.projections.polar as polar from matplotlib.cbook import iterable -# -# Place all imports before here. -# ========================================================================== __all__ = ['UnitDblConverter'] -# ========================================================================== # A special function for use with the matplotlib FuncFormatter class # for formatting axes with radian units. # This was copied from matplotlib example code. @@ -39,7 +26,6 @@ def rad_fn(x, pos=None): return r'$%s\pi/2$' % (n,) -# ========================================================================== class UnitDblConverter(units.ConversionInterface): """: A matplotlib converter class. Provides matplotlib conversion functionality for the Monte UnitDbl class. @@ -51,7 +37,6 @@ class UnitDblConverter(units.ConversionInterface): "time": 'sec', } - # ----------------------------------------------------------------------- @staticmethod def axisinfo(unit, axis): """: Returns information on how to handle an axis that has Epoch data. @@ -75,7 +60,7 @@ def axisinfo(unit, axis): else: label = None - if (label == "deg") and isinstance(axis.axes, polar.PolarAxes): + if label == "deg" and isinstance(axis.axes, polar.PolarAxes): # If we want degrees for a polar plot, use the PolarPlotFormatter majfmt = polar.PolarAxes.ThetaFormatter() else: @@ -83,7 +68,6 @@ def axisinfo(unit, axis): return units.AxisInfo(majfmt=majfmt, label=label) - # ----------------------------------------------------------------------- @staticmethod def convert(value, unit, axis): """: Convert value using unit to a float. If value is a sequence, return @@ -110,13 +94,13 @@ def convert(value, unit, axis): # We need to check to see if the incoming value is actually a # UnitDbl and set a flag. If we get an empty list, then just # return an empty list. - if (isinstance(value, U.UnitDbl)): + if isinstance(value, U.UnitDbl): isNotUnitDbl = False # If the incoming value behaves like a number, but is not a UnitDbl, # then just return it because we don't know how to convert it # (or it is already converted) - if (isNotUnitDbl and units.ConversionInterface.is_numlike(value)): + if isNotUnitDbl and units.ConversionInterface.is_numlike(value): return value # If no units were specified, then get the default units to use. @@ -130,7 +114,6 @@ def convert(value, unit, axis): return value.convert(unit) - # ----------------------------------------------------------------------- @staticmethod def default_units(value, axis): """: Return the default unit for value, or None. diff --git a/lib/matplotlib/testing/jpl_units/UnitDblFormatter.py b/lib/matplotlib/testing/jpl_units/UnitDblFormatter.py index 25ebf6042c78..7966e572f919 100644 --- a/lib/matplotlib/testing/jpl_units/UnitDblFormatter.py +++ b/lib/matplotlib/testing/jpl_units/UnitDblFormatter.py @@ -1,24 +1,10 @@ -# ========================================================================== -# -# UnitDblFormatter -# -# ========================================================================== - - """UnitDblFormatter module containing class UnitDblFormatter.""" -# ========================================================================== -# Place all imports after here. -# import matplotlib.ticker as ticker -# -# Place all imports before here. -# ========================================================================== __all__ = ['UnitDblFormatter'] -# ========================================================================== class UnitDblFormatter(ticker.ScalarFormatter): """The formatter for UnitDbl data types. This allows for formatting with the unit string. diff --git a/lib/matplotlib/testing/jpl_units/__init__.py b/lib/matplotlib/testing/jpl_units/__init__.py index 47e6c3dee554..45fa99e0e573 100644 --- a/lib/matplotlib/testing/jpl_units/__init__.py +++ b/lib/matplotlib/testing/jpl_units/__init__.py @@ -1,5 +1,3 @@ -# ====================================================================== - """ This is a sample set of units for use with testing unit conversion of matplotlib routines. These are used because they use very strict @@ -30,8 +28,6 @@ in one frame may not be the same in another. """ -# ====================================================================== - from .Duration import Duration from .Epoch import Epoch from .UnitDbl import UnitDbl @@ -42,7 +38,6 @@ from .UnitDblFormatter import UnitDblFormatter -# ====================================================================== __version__ = "1.0" @@ -55,7 +50,6 @@ ] -# ====================================================================== def register(): """Register the unit conversion classes with matplotlib.""" import matplotlib.units as mplU @@ -65,19 +59,15 @@ def register(): mplU.registry[Duration] = EpochConverter() mplU.registry[UnitDbl] = UnitDblConverter() -# ====================================================================== -# Some default unit instances - +# Some default unit instances # Distances m = UnitDbl(1.0, "m") km = UnitDbl(1.0, "km") mile = UnitDbl(1.0, "mile") - # Angles deg = UnitDbl(1.0, "deg") rad = UnitDbl(1.0, "rad") - # Time sec = UnitDbl(1.0, "sec") min = UnitDbl(1.0, "min")