Commit 8019259c authored by Yori Fournier's avatar Yori Fournier
Browse files

Modified all local file such that they follow pep8 test_mpl_axes passes now

parent 4d978930
......@@ -99,7 +99,7 @@ else:
raise ImportError
# myplotlib
from .myData import MyData
from .mpl_data import MplData
# CONFIGURATION --------------------------------------------------------
from .config import D_FIGNUM, D_FIGSIZE, D_REFORMAT, D_FORMATTED
......@@ -151,11 +151,11 @@ elif(D_HIERARCHY in ('SERVER', 'server')):
elif D_HIERARCHY in ('LOCAL', 'local'):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes import MyAxes
from .mpl_axes import MplAxes
# MyFig: Overlay on matplotlib.Figure class
from .mplGrid import Grid, VerticalGrid, HorizontalGrid
from .myFig import MyFig
from .mpl_grid import Grid, VerticalGrid, HorizontalGrid
from .mpl_fig import MplFig
from .empty_fig import EmptyFig
from .empty_axes import EmptyAxes
......
from myplotlib import MyAxes
from myplotlib import MplAxes
class EmptyAxes(MyAxes):
class EmptyAxes(MplAxes):
def plotting(self):
return(True)
def format_raw_data(self, rawdata):
def format_rawdata(self, rawdata):
self.data = rawdata.data
return(True)
from myplotlib import MyFig
from myplotlib import MplFig
class EmptyFig(MyFig):
class EmptyFig(MplFig):
def __init__(self, **kwargs):
MyFig.__init__(self, (), **kwargs)
MplFig.__init__(self, (), **kwargs)
def add_axes(self):
def addAxes(self):
pass
......@@ -95,21 +95,21 @@ def compute_fit_rect(fig, ratio, frame_rect):
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxes(Axes):
class MplAxes(Axes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, frame=_D_FRAME, *args, **kwargs):
self.fig = fig
self.declareKeywords()
self.declare_keywords()
rect = self.computeRect(frame, *args, **kwargs)
rect = self.compute_rect(frame, *args, **kwargs)
# clean kwargs
kwargs.pop('ratio', None)
kwargs.pop('forceRatioOnWidth', None)
kwargs.pop('forceRatioOnHeight', None)
kwargs.pop('fitInFrame', None)
kwargs.pop('force_ratio_on_width', None)
kwargs.pop('force_ratio_on_height', None)
kwargs.pop('fit_in_frame', None)
# parent constructor
Axes.__init__(self, fig, rect, **kwargs)
......@@ -164,25 +164,25 @@ class MyAxes(Axes):
return(False)
# UNPACKING --------------------------------------------------------
def unpack_formatted_data(self, packed_data):
'''Get a string return it evaluation.
can be overwritten by user.'''
return(eval(packed_data))
# def unpack_formatted_data(self, packed_data):
# '''Get a string return it evaluation.
# can be overwritten by user.'''
# return(eval(packed_data))
# PACKING ----------------------------------------------------------
def pack_formatted_data(self, formatted_data):
'''Get an object return its representation.
can be overwritten by user.'''
return(str(formatted_data))
# def pack_formatted_data(self, formatted_data):
# '''Get an object return its representation.
# can be overwritten by user.'''
# return(str(formatted_data))
# FORMATTING -------------------------------------------------------
def format_raw_data(self, rawdata):
raise(NotImplementedError, 'You should have overwrite the '
'formatRawData function.')
def format_rawdata(self, rawdata):
raise(NotImplementedError, 'You should have overwritten the '
'format_rawdata method.')
return(False)
# TESTING THE RAWDATA ----------------------------------------------
def test_raw_data(self, rawdata):
def test_rawdata(self, rawdata):
return(True)
# UPDATE -----------------------------------------------------------
......
......@@ -31,7 +31,7 @@ _D_NAME = 'default'
_D_DATA = None
class MyData():
class MplData():
def __init__(self, name=_D_NAME, data=_D_DATA):
......
......@@ -71,14 +71,14 @@ from . import os
from . import D_FIGSIZE, D_INPUTARG, D_DEBUG, D_REFORMAT, D_FORMATTED
from . import D_OFORMAT, D_OPATH
from . import DBUG, SEVR, INFO, SPCE, WARN
from . import MyData
from . import MyAxes
from . import MplData
from . import MplAxes
from . import Figure
from . import HorizontalGrid
# Class MyFig Overwriting Matplotlib.figure.Figure
class MyFig(Figure):
class MplFig(Figure):
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -88,7 +88,7 @@ class MyFig(Figure):
def __init__(self, rawdata, *args, **kwargs):
# for the update function
self._attributesToUpdateKeys = [
self._attributes_to_update_keys = [
'fignum', 'reformat', 'debug', 'formatted', 'aliases']
# initialise the attribute default values and remove them from kwargs
......@@ -106,10 +106,10 @@ class MyFig(Figure):
# This is required for the interactive mode
# it ensures that a figure can not be bounded
# to several windows and prevent the loss of canvas.
self.boundedToWin = False
self.bounded_to_win = False
# add a default Grid to the figure
self.setGrid(HorizontalGrid())
self.set_grid(HorizontalGrid())
# initialise
self._initialize(*args, **kwargs)
......@@ -119,10 +119,10 @@ class MyFig(Figure):
def _initialize(self, *args, **kwargs):
# add the axes
self.addAxes()
self.addAxes() # This will throw a pep8 error but its needed to prevent confusion with matplotlib
# declare the aliases
self.declareAliases()
self.declare_aliases()
# update the attributes and keywords
self.update(**kwargs)
......@@ -138,7 +138,7 @@ class MyFig(Figure):
self.set_rawdata(kwargs['rawdata'])
# if it is an attribute
elif keyword in self._attributesToUpdateKeys:
elif keyword in self._attributes_to_update_keys:
# treat aliases differently: do not replace value but update it
# for replacing the user need to call MyFig.aliases =
# replacement
......@@ -156,7 +156,7 @@ class MyFig(Figure):
for keyword in kwargs.keys():
# ignore figure attributes
if keyword in ['rawdata'] + self._attributesToUpdateKeys:
if keyword in ['rawdata'] + self._attributes_to_update_keys:
pass
# Check if a key of kwargs has an alias for this axes
......@@ -180,7 +180,7 @@ class MyFig(Figure):
return(True)
# DECLARE ALIASES -------------------------------------------------
def declareAliases(self):
def declare_aliases(self):
pass
# ADD AXES ---------------------------------------------------------
......@@ -209,7 +209,7 @@ class MyFig(Figure):
return True
# GET AXES BY NAME -------------------------------------------------
def getAxesByName(self, name):
def get_axes_by_name(self, name):
for ax in self.get_axes():
if ax.name == name:
......@@ -220,7 +220,7 @@ class MyFig(Figure):
return None
# SET LAYOUT -------------------------------------------------------
def setGrid(self, grid):
def set_grid(self, grid):
self.grid = grid
self.grid.fig = self
......@@ -244,7 +244,7 @@ class MyFig(Figure):
if(self.debug):
print(DBUG + "set_rawdata: one item per axes")
self.rawdata = rawdata
status = self.formatRawData()
status = self.format_rawdata()
else:
self.rawdata = None
......@@ -256,12 +256,12 @@ class MyFig(Figure):
return(False)
# CONVINIENT: one object for all axes
elif isinstance(rawdata, MyData):
elif isinstance(rawdata, MplData):
if(self.debug):
print(DBUG + "set_rawdata: one item for all axes")
# This is the trick rawdata becomes a generator (so smart)
self.rawdata = repeat(rawdata)
status = self.formatRawData()
status = self.format_rawdata()
else:
print(SEVR + "set_rawdata: I could not set the rawdata...")
......@@ -275,7 +275,7 @@ class MyFig(Figure):
return(status)
# FORMAT RAW DATA --------------------------------------------------
def formatRawData(self):
def format_rawdata(self):
if self.rawdata is not None:
......@@ -291,14 +291,14 @@ class MyFig(Figure):
str(self.get_axes().index(ax)) +
" formats " +
rawdata.name)
status = ax.testRawData(rawdata)
status = ax.test_rawdata(rawdata)
if status:
status = ax.formatRawData(rawdata)
status = ax.format_rawdata(rawdata)
else:
status = ax.testRawData(rawdata)
status = ax.test_rawdata(rawdata)
if status:
try:
status = ax.formatRawData(rawdata)
status = ax.format_rawdata(rawdata)
except BaseException:
print(SEVR +
"The " +
......@@ -328,7 +328,7 @@ class MyFig(Figure):
print(DBUG + "currently formatting the data...")
if((self.reformat) or (not self.formatted)):
status = self.formatRawData()
status = self.format_rawdata()
if(not status):
return(False)
......@@ -342,8 +342,8 @@ class MyFig(Figure):
ax.cla()
# plot
plottingStatus = ax.plotting()
status = status and plottingStatus
plotting_status = ax.plotting()
status = status and plotting_status
return(status)
......@@ -354,15 +354,15 @@ class MyFig(Figure):
self.plot()
# DEBUG --------------------------------------------------------------
def printDebug(self):
className = str(self.__class__.__name__)
print('\n' + DBUG + " {0} PARAMETERS: ".format(className))
def print_debug(self):
class_name = str(self.__class__.__name__)
print('\n' + DBUG + " {0} PARAMETERS: ".format(class_name))
print(SPCE + " Raw data: " + str(self.rawdata))
print(SPCE + " ID the figure: " + str(self.fignum))
print(SPCE + "Size of the figure: " + str(self.FIGSIZE) + ' [inch] \n')
# PRINT 2 FILE -------------------------------------------------------
def print2file(self, filename, *args, **kwargs):
def print_to_file(self, filename, *args, **kwargs):
# get the keywords
debug = kwargs.get('debug', D_DEBUG)
......@@ -373,18 +373,18 @@ class MyFig(Figure):
# set the dpi
if(oformat == 'png'):
dpi = 300.
addMetaData = True # NOT YET IMPLEENTED
add_metadata = True # NOT YET IMPLEENTED
else:
dpi = 100.
addMetaData = False # NOT YET IMPLEMENTED
add_metadata = False # NOT YET IMPLEMENTED
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
# if the figure is boundedToWin
# save to canvas in a local variable and restore after saving to file.
if self.boundedToWin:
winCanvas = self.canvas
if self.bounded_to_win:
win_canvas = self.canvas
else:
winCanvas = None
win_canvas = None
canvas = FigureCanvas(self) # the canvas of the figure changed
......@@ -441,7 +441,7 @@ class MyFig(Figure):
return(False)
# restore the former canvas
if winCanvas is not None:
self.canvas = winCanvas
if win_canvas is not None:
self.canvas = win_canvas
return(True)
......@@ -20,12 +20,12 @@ class Grid(object):
def layout(self):
if self.contains_a_grid():
for grid in self.getGrids():
for grid in self.get_grids():
grid.layout()
def append_axes(self, ax, axlabel, rawdata):
def append_axes(self, ax, ax_label, rawdata):
self.items.append(ax)
self.fig.add_axes(ax, axlabel)
self.fig.add_axes(ax, ax_label)
self.fig.set_rawdata(self.fig.rawdata + (rawdata,))
def append_grid(self, grid):
......@@ -39,7 +39,7 @@ class Grid(object):
def get_items(self):
return(self.items)
def getGrids(self):
def get_grids(self):
return(self.grids)
def contains_a_grid(self):
......
......@@ -43,23 +43,23 @@
#
# IMPORT ---------------------------------------------------------------
from myplotlib import MyAxes
from myplotlib import MplAxes
from myplotlib import DBUG, SPCE, INFO, WARN, SEVR
D_XRANGE = None
D_YRANGE = None
D_LOGY = False
D_LOGX = False
D_X_RANGE = None
D_Y_RANGE = None
D_LOG_Y = False
D_LOG_X = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest(MyAxes):
class AxTest(MplAxes):
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
def declare_keywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE}
self.keywords = {'x_range': D_X_RANGE,
'y_range': D_Y_RANGE}
return(True)
......@@ -69,8 +69,8 @@ class AxTest(MyAxes):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]]}
self.data = {'x_data': [rawdata.data[0], rawdata.data[1]],
'y_data': [rawdata.data[2], rawdata.data[3]]}
except(TypeError, KeyError, IndexError):
......@@ -84,21 +84,21 @@ class AxTest(MyAxes):
def plotting(self):
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
x_range = self.keywords.get('x_range')
y_range = self.keywords.get('y_range')
try:
self.plot(self.data['xdata'], self.data['ydata'])
self.plot(self.data['x_data'], self.data['y_data'])
except KeyError:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
if (xRange): self.set_xlim(xRange)
if (yRange): self.set_ylim(yRange)
if (x_range): self.set_xlim(x_range)
if (y_range): self.set_ylim(y_range)
return(True)
class AxBroken(MyAxes):
class AxBroken(MplAxes):
def FormatRawdata(self, rawdata):
return(True)
......@@ -106,21 +106,21 @@ class AxBroken(MyAxes):
def Plottting(self):
return(True)
class AxMinimumImplementation(MyAxes):
class AxMinimumImplementation(MplAxes):
def formatRawData(self, rawdata):
def format_rawdata(self, rawdata):
return(True)
def plotting(self):
return(True)
class AxWithKeywords(MyAxes):
class AxWithKeywords(MplAxes):
def declareKeywords(self):
self.keywords = {'xRange': [-1., 1.],
'yRange': [-1., 1.]}
def declare_keywords(self):
self.keywords = {'x_range': [-1., 1.],
'y_range': [-1., 1.]}
def formatRawData(self, rawdata):
def format_rawdata(self, rawdata):
return(True)
def plotting(self):
......
# IMPORT ---------------------------------------------------------------
from myplotlib import MyFig
from axTest import AxTest
from myplotlib import MplFig
from axes_tests import AxTest
class FigTest(MyFig):
class FigTest(MplFig):
FIGSIZE = (8., 6.)
......@@ -10,21 +10,21 @@ class FigTest(MyFig):
self.add_axes(AxTest(self), "p1")
class EmptyFig(MyFig):
class EmptyFig(MplFig):
FIGSIZE = (8., 6.)
def addAxes(self):
pass
class BrokenFigure(MyFig):
class BrokenFigure(MplFig):
FIGSIZE = (12., 6.)
def AddAxes(self):
pass
class FigTestWithAliases(MyFig):
class FigTestWithAliases(MplFig):
FIGSIZE = (8., 6.)
......
......@@ -32,7 +32,7 @@
DBUG = False
D_IPATH=''
from myplotlib import MyData
from myplotlib import MplData
import numpy as np
DATA_1D = np.array([0.0, 0.1, 0.2, 0.25, 0.28, 0.3, 0.31, 0.315, 0.5, 1.0])
......@@ -65,44 +65,44 @@ TEXT_DATA_ARRAY_LABELED = "# X Y1 Y2\n 0.0 0.1 0.15\n 0.1 0.2 0.23\n 0.2 0.25 0.
# the read data functions return either a dictionary of vectors, or a 2D array.
# they determine what is the delimiter, and if there is a commented line.
def readLineData():
def read_line_data():
pass
def readColumnData():
def read_column_data():
pass
def readLabeledColumnData():
def read_labeled_column_data():
pass
def readLabeledLineData():
def read_labeled_line_data():
pass
# READ STUPID DATA -----------------------------------------------------
def readStupidData(ipath=D_IPATH, *args, **kwargs):
def read_stupid_data(ipath=D_IPATH, *args, **kwargs):
debug = kwargs.get('debug', 0)
lrawdata = MyData()
lrawdata.name = str(ipath)
lrawdata.data = [-1., 1., 1, -1.]
l_rawdata = MplData()
l_rawdata.name = str(ipath)
l_rawdata.data = [-1., 1., 1, -1.]
if(debug):
print(DBUG + 'I read the raw data with readStupidData')
return(lrawdata)
return(l_rawdata)
# READ STUPID DATA 2 ---------------------------------------------------
def readStupidData2(ipath=D_IPATH, *args, **kwargs):
def read_stupid_data_2(ipath=D_IPATH, *args, **kwargs):
debug = kwargs.get('debug', 0)
lrawdata = MyData()
lrawdata.name = str(ipath)
lrawdata.data = [-1., 1., -2., 2.]
l_rawdata = MplData()
l_rawdata.name = str(ipath)
l_rawdata.data = [-1., 1., -2., 2.]
if(debug):
print(DBUG + 'I read the raw data with readStupidData2')
return(lrawdata)
return(l_rawdata)
import unittest
from .test_myaxes import TestMyAxes
from .test_myfig import TestMyFig
from .test_grid import TestGrid
from .test_mpl_axes import TestMyAxes
from .test_mpl_fig import TestMyFig
from .test_mpl_grid import TestGrid
......@@ -5,16 +5,15 @@ import unittest
sys.path.append('../')
from myplotlib import MyAxes
from myIOs import readStupidData
from figTest import EmptyFig
from axTest import AxBroken, AxMinimumImplementation, AxWithKeywords, AxTest
from myplotlib import MplAxes, EmptyFig
from ios_tests import read_stupid_data
from axes_tests import AxBroken, AxMinimumImplementation, AxWithKeywords, AxTest
class TestMyAxes(unittest.TestCase):
def setUp(self):
self.data1 = readStupidData('data1')
self.fig = EmptyFig((), figsize=(8., 6.))
self.data_1 = read_stupid_data('data_1')
self.fig = EmptyFig(figsize=(8., 6.))
def test_constructor_axbroken(self):
'''Verify that a NotImplementedError is raised
......@@ -25,7 +24,7 @@ class TestMyAxes(unittest.TestCase):
with self.assertRaises(NotImplementedError):
ax.plotting()
with self.assertRaises(NotImplementedError):
ax.formatRawData(())
ax.format_rawdata(())
def test_constructor_axminimum(self):
'''Verify the required assignments of the constructor.
......@@ -40,28 +39,28 @@ class TestMyAxes(unittest.TestCase):
'''Verify the keywords assignments of the constructor.
'''
ax1 = AxWithKeywords(self.fig)
self.assertEqual(ax1.keywords, {'xRange': [-1., 1.], 'yRange': [-1., 1.]})
ax2 = AxWithKeywords(self.fig, xRange=[1., 2.], yRange=[0., 1.])
self.assertEqual(ax2.keywords, {'xRange': [1., 2.], 'yRange': [0., 1.]})