Commit c1866284 authored by Philipp Gast's avatar Philipp Gast
Browse files

Merge remote-tracking branch 'origin/myTool-update' into move-keywords

Conflicts:
	test/__init__.py
	test/tests.py
parents 7c1797c6 3ca89089
......@@ -86,7 +86,7 @@ from .mytool import window_exists, getCurrentWindowIDs
from .mytool import print2file, print2screen, printListCurrentWindows
from .mytool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
from .mytool import closeWindow, closeAllWindows
from .mytool import FigOneAxes_base, FigOneAxes2D, FigOneAxes3D
from .mytool import FigOneAxes
from .test import myTest
......@@ -98,7 +98,8 @@ from .test import test306, test307, test308, test309, test310, test311
from .test import test312
from .test import test400, test401, test402, test403
from .test import test500, test501, test502, test503, test504
from .test import test505, test506, test507, test508
from .test import test505, test506, test507, test508, test509
from .test import test510, test511
from .test import test600
# the tests to run
......@@ -109,6 +110,6 @@ testList = [test100,
test312,
test400, test401, test402,
test503, test506, test500, test507, test501, test502,
test504, test505, test508,
test504, test505, test508, test509, test510, test511,
test600,
]
......@@ -11,7 +11,6 @@ from .myTool import drawFigOnWindow
from .myTool import closeAllWindows
from .myTool import closeWindow
from .figOneAxes_base import FigOneAxes_base
from .figOneAxes2D import FigOneAxes2D
from .figOneAxes3D import FigOneAxes3D
from .figOneAxes import FigOneAxes
from .axPlot2D import AxPlot2D
from .axPlots2D import AxPlots2D
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG, INFO
from .. import MyAxes
D_XRANGE = None
D_YRANGE = None
D_LOGY = False
D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxPlot2D(MyAxes):
# DECLARE KEYWORDS --------------------------------------------------
def declareKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE,
'logx': D_LOGX,
'logy': D_LOGY}
return(True)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
# GET ALL PARAMETERS
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
logx = self.keywords.get('logx')
logy = self.keywords.get('logy')
xlabel = self.data.get('xlabel')
ylabel = self.data.get('ylabel')
xdata = self.data.get('xdata')
ydata = self.data.get('ydata')
# CHECK IF THE DATA EXISTS
if (xdata is None):
print(SEVR + "I need axes.data['xdata'] to plot... got None")
return(False)
if (ydata is None):
print(SEVR + "I need axes.data['ydata'] to plot... got None")
return(False)
# TRY TO PLOT
try:
# IF XLIN - YLIN
if (not logx) and (not logy):
self.plot(xdata, ydata)
# XLIN - YLOG
elif (not logx) and logy:
self.semilogy(xdata, ydata)
# XLOG - YLIN
elif (not logy) and logx:
self.semilogx(xdata, ydata)
# XLOG - YLOG
else:
self.loglog(xdata, ydata)
except:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
# SET THE LABELS
if (xlabel): self.set_xlabel(xlabel)
if (ylabel): self.set_ylabel(ylabel)
# SET THE RANGES
if (xRange): self.set_xlim(xRange)
if (yRange): self.set_ylim(yRange)
return(True)
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG, INFO
from .. import MyAxes
from itertools import repeat
D_XRANGE = None
D_YRANGE = None
D_LOGY = False
D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxPlots2D(MyAxes):
# DECLARE KEYWORDS --------------------------------------------------
def declareKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE,
'logx': D_LOGX,
'logy': D_LOGY}
return(True)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
# GET ALL PARAMETERS
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
logx = self.keywords.get('logx')
logy = self.keywords.get('logy')
xlabel = self.data.get('xlabel')
ylabel = self.data.get('ylabel')
labels = self.data.get('labels', repeat(None))
xdata = self.data.get('xdata')
ydatas = self.data.get('ydatas')
# CHECK IF THE DATA EXISTS
if (xdata is None):
print(SEVR + "I need axes.data['xdata'] to plot... got None")
return(False)
if (ydatas is None):
print(SEVR + "I need axes.data['ydatas'] to plot... got None")
return(False)
# TRY TO PLOT
try:
# IF XLIN - YLIN
if (not logx) and (not logy):
for ydata, label in zip(ydatas, labels):
self.plot(xdata, ydata, label=label)
# XLIN - YLOG
elif (not logx) and logy:
for ydata, label in zip(ydatas, labels):
self.semilogy(xdata, ydata, label=label)
# XLOG - YLIN
elif (not logy) and logx:
for ydata, label in zip(ydatas, labels):
self.semilogx(xdata, ydata, label=label)
# XLOG - YLOG
else:
for ydata, label in zip(ydatas, labels):
self.loglog(xdata, ydata, label=label)
except:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
# SET THE LABELS
if (xlabel): self.set_xlabel(xlabel)
if (ylabel): self.set_ylabel(ylabel)
# SET THE RANGES
if (xRange): self.set_xlim(xRange)
if (yRange): self.set_ylim(yRange)
self.legend(bbox_to_anchor=(0.03, 0.97), loc=2, borderpad=0.5, prop={'size': 14})
return(True)
# Import --------------------------------------------------------------
from .. import MyFig
from .. import rcParams
# CLASS MyNewFig ------------------------------------------------------
class FigOneAxes(MyFig):
# Set the size of the Figure in inch
FIGSIZE = (8., 6.)
# CONSTRUCTOR -----------------------------------------------------
def __init__(self, AxClass, rawdata, *args, **kwargs):
self.AxClass = AxClass
MyFig.__init__(self, rawdata, *args, **kwargs)
# ADD AXES --------------------------------------------------------
def addAxes(self):
ratio = self.FIGSIZE[1] / self.FIGSIZE[0]
frame = [0.0, 0.0, 1.0, 1.0]
smartFrame = self.computeSmartRect(ratio, frame)
self.add_axes(self.AxClass(self, ratio, smartFrame), 'axes')
# Compute smart frame --------------------------------------------
def computeSmartRect(self, ratio, frameRect):
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
# get the size of the figure
figWidth = self.get_figwidth()
figHeight = self.get_figheight()
figDpi = self.get_dpi()
# get the font size in inches
fontsize = rcParams['font.size'] / figDpi
# the largest width and height allowed in inches
maxWidth = figWidth * frameWidth - 8. * (figDpi / 75.) * fontsize
maxHeight = figHeight * frameHeight - 4. * (figDpi / 75.) * fontsize
# the hypothetical width and height in inches
# for a given aspect ratio
hypoWidth = maxHeight / ratio
hypoHeight = maxWidth * ratio
# if the hypothetical width is larger that the
# maximum allowed width (in inches) then chose
# the hypothetical Height
if (hypoWidth > maxWidth):
height = hypoHeight / figHeight # height in percent
width = maxWidth / figWidth # width in percent
posX = framePosX + 4. * (figDpi / 75.) * fontsize / figWidth # posX
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight # posY
else:
height = maxHeight / figHeight
width = hypoWidth / figWidth
posX = framePosX + (frameWidth - width) / 2.
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight
rect = [posX, posY, width, height]
return(rect)
# Import --------------------------------------------------------------
from .figOneAxes_base import FigOneAxes_base
# Default values ------------------------------------------------------
_D_XRANGE = None
_D_YRANGE = None
_D_LOGX = False
_D_LOGY = False
# CLASS MyNewFig ------------------------------------------------------
class FigOneAxes2D(FigOneAxes_base):
# DECLARE kEYWORDS ------------------------------------------------
def declareKeywords(self):
self.keywords = {'xrange' : _D_XRANGE,
'yrange' : _D_YRANGE,
'logx' : _D_LOGX,
'logy' : _D_LOGY}
# Import --------------------------------------------------------------
from .figOneAxes_base import FigOneAxes_base
# Default values ------------------------------------------------------
_D_XRANGE = None
_D_YRANGE = None
_D_ZRANGE = None
_D_LOGX = False
_D_LOGY = False
_D_LOGZ = False
# CLASS MyNewFig ------------------------------------------------------
class FigOneAxes3D(FigOneAxes_base):
# DECLARE kEYWORDS ------------------------------------------------
def declareKeywords(self):
self.keywords = {'xrange' : _D_XRANGE,
'yrange' : _D_YRANGE,
'zrange' : _D_ZRANGE,
'logx' : _D_LOGX,
'logy' : _D_LOGY,
'logz' : _D_LOGZ}
# Import --------------------------------------------------------------
from .. import MyFig
# Default values ------------------------------------------------------
_D_XRANGE = None
_D_YRANGE = None
_D_LOG = False
# CLASS MyNewFig ------------------------------------------------------
class FigOneAxes_base(MyFig):
# Set the size of the Figure in inch
FIGSIZE = (8., 6.)
# CONSTRUCTOR -----------------------------------------------------
def __init__(self, rawdata, AxClass, *args, **kwargs):
self.AxClass = AxClass
MyFig.__init__(self, rawdata, *args, **kwargs)
# DECLARE kEYWORDS ------------------------------------------------
def declareKeywords(self):
self.keywords = {'xrange' : _D_XRANGE,
'yrange' : _D_YRANGE,
'log' : _D_LOG}
# ADD AXES --------------------------------------------------------
def addAxes(self):
ratio = 6. / 8.
frame = [0.0, 0.0, 1.0, 1.0]
self.add_axes(self.AxClass(self, ratio, frame))
from .myIOs import readStupidData, readStupidData2
from .axTest1 import AxTest1
from .axTest1 import AxTestPlot2D, AxTestPlots2D
from .figTest import FigTest1, FigTest2
from .tests import myTest
......@@ -13,6 +14,7 @@ from .tests import test306, test307, test308, test309, test310, test311
from .tests import test312
from .tests import test400, test401, test402, test403
from .tests import test500, test501, test502, test503, test504
from .tests import test505, test506, test507, test508
from .tests import test505, test506, test507, test508, test509
from .tests import test510, test511
from .tests import test600
......@@ -44,9 +44,12 @@
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG, INFO
from .. import MyAxes
from ..mytool import AxPlot2D, AxPlots2D
D_XRANGE = None
D_YRANGE = None
D_LOGY = False
D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
......@@ -93,3 +96,53 @@ class AxTest1(MyAxes):
if (yRange): self.set_ylim(yRange)
return(True)
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTestPlots2D(AxPlots2D):
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydatas': ([rawdata.data[2], rawdata.data[3]],
[rawdata.data[3], rawdata.data[2]]),
'xlabel': 'Some X Label',
'ylabel': 'Some Y Label',
'labels': ('curve 1', 'curve 2')}
except(TypeError, KeyError, IndexError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
if(self.fig.debug):
print(DBUG + 'I formatted the raw data!')
return(True)
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTestPlot2D(AxPlot2D):
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
# 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]],
'xlabel': 'Some X Label',
'ylabel': 'Some Y Label'}
except(TypeError, KeyError, IndexError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
if(self.fig.debug):
print(DBUG + 'I formatted the raw data!')
return(True)
......@@ -7,12 +7,14 @@ from .. import G_RAWDATAS, _G_WINDOWS
from . import readStupidData, readStupidData2
from . import FigTest1,FigTest2, AxTest1
from . import AxTestPlot2D, AxTestPlots2D
from .. import window_exists, getCurrentWindowIDs
from .. import getFigOnWindow, getWindow
from .. import closeWindow, closeAllWindows
from .. import print2screen, print2file, printListCurrentWindows
from .. import drawFigOnWindow, giveDataToWindow
from .. import FigOneAxes
# TESTER
......@@ -907,6 +909,48 @@ def test508(debug):
return(status)
# TEST 5.09: FigOneAxes
def test509(debug):
status = True
data1 = readStupidData('data1')
fig = FigOneAxes(AxTest1, (data1,))
status = fig.plot()
return(status)
# TEST 5.10: AxTestPlot2D
def test510(debug):
status = True
data1 = readStupidData('data1')
fig = FigOneAxes(AxTestPlot2D, (data1,))
status = fig.plot()
return(status)
# TEST 5.11: AxTestPlots2D
def test511(debug):
status = True
data1 = readStupidData('data1')
fig = FigOneAxes(AxTestPlots2D, (data1,))
status = fig.plot()
return(status)
# TEST 600: Test Adding Axes on the Fly (EXPECTED: True)
def test600(debug):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment