Commit 983e9e3d authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch 'tmp-merged' into 'dev'

Tmp merged

See merge request !19
parents 4921bfe6 b684b47e
......@@ -48,10 +48,10 @@ from matplotlib import is_interactive
from matplotlib import rcParams
from matplotlib import use
rcParams['backend'] = u'GTKAgg'
rcParams['backend'] = u'TKAgg'
# myplotlib
from myData import MyData
from .myData import MyData
# FORM -----------------------------------------------------------------
INFO = " > info-: "
......@@ -92,8 +92,8 @@ rc('lines', markersize=6)
rc('axes', linewidth=1.5)
rc('xtick.major', width=1.5, pad=10., size=10.)
rc('ytick.major', width=1.5, pad=8., size=10.)
rc('xtick.minor', width=1.5, size=5.)
rc('ytick.minor', width=1.5, size=5.)
rc('xtick.minor', width=1.5, size=5., visible=False)
rc('ytick.minor', width=1.5, size=5., visible=False)
rc('figure', dpi = 75.0)
# FUNCTIONS ------------------------------------------------------------
......@@ -114,10 +114,11 @@ else:
print(SEVR + "The backend you choosed is not supported interactive mode not available")
# myTool.*: interface functions to use myplotlib interactively
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 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 .test import myTest
......@@ -133,7 +134,7 @@ from .test import test600
# the tests to run
testList = [test100,
test200, test201, test202,
test201, test202,
test300, test301, test302, test303, test304, test305,
test306, test307, test308, test309, test310,
test400, test401, test402,
......
......@@ -31,9 +31,9 @@
#
#
# IMPORT ---------------------------------------------------------------
from .__init__ import INFO, SPCE, DBUG
from .__init__ import myTest, testList
from .__init__ import __dict__
from . import INFO, SPCE, DBUG
from . import myTest, testList
from . import __dict__
import sys
import getopt
......
_D_PATH2_MYDESIGNS = './myplotlib/design/myDesigns/'
_D_PATH2_MYFIGURES = './myplotlib/design/myFigures/'
_D_PATH2_MYAXES = './myplotlib/design/myAxes/'
from myDesignTool import getSectionFromDesign
from myDesignTool import savePlot
from axDesign import AxDesign
from figDesign import FigDesign
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v0.0.0,
#
# @file myAxes.py
# @author Yori 'AGy' Fournier
# @licence CC-BY-SA
#
# MyAxes class: Overlay of matplotlib Axes class
# It is done such that the user can concentrate on
# the important aspect of the figure and not the
# technical part. It consists of a constructor,
# that requires a Figure, the ratio of the xaxis over
# the yaxis, and the frame in which the figure
# should be plotted.
#
# @Class MyAxes
#
# @Constructor(self, fig, ratio, frame, +user defined kw):
#
# @section Functions
#
# - plotting: this is the overwritten function
# from Axes. It is called by it's
# parent-figure's function .plot()
#
# - formatRawData: it computes out of the rawData
# given as argument some quantities that
# are returned as a dictionary and
# become accessable for plotting.
#
# @section History
#
# v 0.0.0 - MyAxes class for the myplotlib module, consists
# of a constructor, a pltting function and
# formatRawData.
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG, INFO
from .. import MyAxes
class AxDesign(MyAxes):
def __init__(self, fig, emulatedAxes, ratio, frameRect, *args, **kwargs):
self.emulatedAxes = emulatedAxes
MyAxes.__init__(self, fig, ratio, frameRect, *args, **kwargs)
def plotting(self):
exec(''.join(self.fig.designSections[self.emulatedAxes]['plotting']))
return(True)
def formatRawData(self, rawdata):
exec(''.join(self.fig.designSections[self.emulatedAxes]['formatRawData']))
return(True)
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v1.0.1,
#
# @file myFig.py
# @author Yori 'AGy' Fournier
# @licence CC-BY-SA
#
# MyFig class: Overlay of matplotlib Figure class
# It is done such that the user can concentrate on
# the important aspect of the figure and not the
# technical part.
#
# @Class MyFig
#
# @Constructor
#
# fignum: number of the Figure.
# inputarg: identifier of the raw data in G_RAWDATA.
# reformat: flag for reComputing plotted data
# from rawData.
# debug: flag for debugging, more verbatile.
# (kw)args: user defined arguments and keywords.
#
# @section Functions
#
# - printDebug: print some debug information.
#
# - plot: overlay of Figure.plot() function,
# should be overwrited by the user.
# Consists of
# - creating axes,
# - formating the data,
# - adding the axis to the figure
# - plotting the axis
#
# - update: update the parameters in the
# keywords dictionary.
#
# @section History
#
# v 0.1.1 - MyFig class for the myplotlib module.
#
# v 1.0.0 - Changed rawdata with inputarg to allows any type
# of rawdata, can be an array.
#
# replace the attribute format (reserved word) with
# formatted.
#
# v 1.0.1 - Suppress the explicit definitions of the keywords.
# by the introduction of the keywords dictionary.
# All parameters in this dictionary are automatically
# updated.
#
# suppress the default value of fignum and hardcode it
# to be -1.
#
# add the attribute boundedToWin required for the
# interactive mode of myplotlib.
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
from .. import os
from .. import DBUG, SEVR, INFO, SPCE, WARN
from .. import MyFig
from . import AxDesign
from myDesignTool import getSectionFromDesign
class FigDesign(MyFig):
FIGSIZE = (8., 6.)
def __init__(self, rawdata, designFile, *args, **kwargs):
self.designFile = designFile
self.readDesignFile()
MyFig.__init__(self, rawdata, *args, **kwargs)
def readDesignFile(self):
print(INFO + "I read the design file again!")
self.designSections = getSectionFromDesign(self.designFile)
# look for the emulated figure
figureFound = False
self.emulatedFigure = None
# for all sections
for className in self.designSections.keys():
# if one section has addAxes then set it to be the figure
if 'addAxes' in self.designSections[className].keys():
if not figureFound:
self.emulatedFigure = str(className)
figureFound = True
else:
print(WARN + "apparently you have two figures in that design file... only the first one will be set up")
if self.emulatedFigure is None:
print(WARN + "No figure found... will exit")
return(False)
return(True)
def addAxes(self):
exec(''.join(self.designSections[self.emulatedFigure]['addAxes']))
def declareKeywords(self):
if 'declareKeywords' in self.designSections[self.emulatedFigure].keys():
exec(''.join(self.designSections[self.emulatedFigure]['declareKeywords']))
else:
pass
def update(self, **kwargs):
status = MyFig.update(self, **kwargs)
if not status: return(False)
status = self.readDesignFile()
return(status)
# IMPORT --------------------------------------------------------------
YOU NEED TO DO THAT YOURSELF!
# CLASS AxTest=========================================================
class AxTest(MyAxes):
# FORMAT RAWDATA --------------------------------------------------
def formatRawData(self):
print("AxTest::formatRawData")
self.data = {'xdata': [0., 5.],
'ydata': [1., 6.]}
# PLOTTING --------------------------------------------------------
def plotting(self):
print("AxTest::plotting")
self.set_xlim(self.fig.keywords['xrange'])
self.set_ylim(self.fig.keywords['yrange'])
self.plot(self.data['xdata'], self.data['ydata'])
# IMPORT --------------------------------------------------------------
YOU NEED TO DO THAT YOURSELF!
# CLASS AxTest2========================================================
class AxTest2(MyAxes):
# FORMAT RAWDATA --------------------------------------------------
def formatRawData(self):
print("AxTest2::formatRawData")
self.data = {'xdata': [5., 0.],
'ydata': [1., 6.]}
# PLOTTING --------------------------------------------------------
def plotting(self):
print("AxTest::plotting")
self.set_xlim(self.fig.keywords['xrange'])
self.set_ylim(self.fig.keywords['yrange'])
self.plot(self.data['xdata'], self.data['ydata'])
from . import _D_PATH2_MYDESIGNS
from . import _D_PATH2_MYFIGURES
from . import _D_PATH2_MYAXES
from .. import WARN, INFO
def getSectionFromDesign(designFile):
if '/' in str(designFile):
f = open(str(designFile))
else:
f = open(_D_PATH2_MYDESIGNS + str(designFile))
designSections = {}
startProcedure = False
className = ''
functionName = ''
procedure = []
for line in f.readlines():
# If recording a procedure
if startProcedure:
# and found the end of it
if line.startswith('/>'):
print(INFO + str(className) + ' ' + str(functionName))
# Save the procedure
if str(className) in designSections.keys():
designSections[str(className)].update({str(functionName): procedure})
else:
designSections.update({str(className): {}})
designSections[str(className)].update({str(functionName): procedure})
# reset
className = ''
functionName = ''
procedure = []
startProcedure = False
# and found bgining of a new one print WARNING
elif line.startswith('<'):
print(WARN + "I found a line starting with '<' before the end of the section, you may have forgot to close it.")
# record the procedure
else:
procedure.append(line)
# if not recording and found begining of a section
if (line.startswith('<')) and (startProcedure is False):
# check the format
if line.startswith('< '):
# get the ClassName and FunctionName
label = line.split(' ')
if len(label) < 2:
print(WARN + "apparently the format you use to declare this section is incrorrect. use: '< ClassName::FunctionName'")
className, functionName = label[1].split('::')
if('\n' in str(className)):
className = className[:-1]
if('\n' in str(functionName)):
functionName = functionName[:-1]
print(INFO + str(className) + ' ' + str(functionName))
procedure = []
# start recording
startProcedure = True
# if format wrong print WARNING
else:
print(WARN + "apparently you forgot a space after opening the section. please strictly use: '< ClassName::FunctionName'")
for className in designSections.keys():
print(INFO + str(className) + ": " + str(designSections[className].keys()))
f.close()
return(designSections)
def savePlot(filename, path2myfigures=_D_PATH2_MYFIGURES, path2myaxes=_D_PATH2_MYAXES):
designSections = getSectionFromDesign(filename)
figureClassName = None
# IDENTIFY THE FIGURE
for className in designSections.keys():
if 'addAxes' in designSections[str(className)].keys():
figureClassName = className
# OBTAIN THE FUNCTIONS
if 'declareKeywords' in designSections[str(figureClassName)].keys():
declareKeywordsString = '\t'.join(designSections[str(figureClassName)]['declareKeywords'])
else:
declareKeywordsString = ''
if 'addAxes' in designSections[str(figureClassName)].keys():
addAxesString = '\t'.join(designSections[str(figureClassName)]['addAxes'])
else:
addAxesString = ''
if figureClassName is None or addAxesString == '':
print(WARN + "Either the clasName could not be found, either there is no axes...")
# PUT THEM INTO THE STRUCTURE
template = _CLASS_TEMPLATE.format(className=figureClassName,
declareKeywords=declareKeywordsString,
addAxes=addAxesString)
# CREATE THE FIGURE FILE
f = open(str(path2myfigures) + str(figureClassName)[0].lower() + str(figureClassName)[1:] + '.py', 'w')
# WRITE THE FIGURE
f.writelines(template)
f.close()
del designSections[str(figureClassName)]
# IDENTIFY THE AXES
for axes in designSections.keys():
axesClassName = axes
if 'formatRawData' in designSections[axes].keys():
formatRawDataString = '\t'.join(designSections[axes]['formatRawData'])
if 'plotting' in designSections[axes].keys():
plottingString = '\t'.join(designSections[axes]['plotting'])
# OPEN THE FILE
f = open(path2myaxes + str(axesClassName)[0].lower() + str(axesClassName)[1:] + '.py', 'w')
template = _AXES_TEMPLATE.format(axesName=axesClassName,
formatRawData=formatRawDataString,
plotting=plottingString)
f.writelines(template)
f.close()
_AXES_TEMPLATE = '''# IMPORT --------------------------------------------------------------
YOU NEED TO DO THAT YOURSELF!
# CLASS {axesName:=<63}
class {axesName}(MyAxes):
# FORMAT RAWDATA --------------------------------------------------
def formatRawData(self, rawdata):
{formatRawData}
# PLOTTING --------------------------------------------------------
def plotting(self):
{plotting}
'''
_CLASS_TEMPLATE = '''# IMPORT --------------------------------------------------------------
YOU NEED TO DO THAT YOURSELF!
# CLASS {className:=<63}
class {className}(MyFig):
# DECLARE KEYWORDS ------------------------------------------------
def declareKeywords(self):
{declareKeywords}
# ADD AXES --------------------------------------------------------
def addAxes(self):
{addAxes}
'''
# FIGTEST =============================================================
< FigMyCrazy::addAxes
ratio = 3./8.
frame = [0., 0.1, 1.0, 0.6]
frame2 = [0., 0.6, 1.0, 0.4]
self.add_axes(AxDesign(self, 'AxMyCrazy1', ratio, frame))
self.add_axes(AxDesign(self, 'AxMyCrazy2', ratio, frame2))
/>
# ---------------------------------------------------------------------
< FigMyCrazy::declareKeywords
self.keywords = {'xrange': [0, 5],
'yrange': [0, 10]}
/>
# AXTEST ==============================================================
< AxMyCrazy1::formatRawData
print("AxTest::formatRawData")
self.data = {'xdata': [0., 5.],
'ydata': [1., 6.]}
/>
# ---------------------------------------------------------------------
< AxMyCrazy1::plotting
print("AxTest::plotting")
self.set_xlim(self.fig.keywords['xrange'])
self.set_ylim(self.fig.keywords['yrange'])
self.plot(self.data['xdata'], self.data['ydata'])
self.set_xlabel(r'$B_{\rm quench}$')
self.set_ylabel(r'$C_{\rm S}$')
self.lines[0].set_color('k')
self.lines[0].set_linestyle('--')
/>
# AXTEST2 ==============================================================
< AxMyCrazy2::formatRawData
print("AxTest2::formatRawData")
self.data = {'xdata': [5., 0.],
'ydata': [1., 8.]}
/>
# ---------------------------------------------------------------------
< AxMyCrazy2::plotting
print("AxTest::plotting")
self.set_xlim(self.fig.keywords['xrange'])
self.set_ylim(self.fig.keywords['yrange'])
self.plot(self.data['xdata'], self.data['ydata'])
self.lines[0].set_color('g')
self.lines[0].set_linestyle('-.')
self.set_xlabel(r'Time [$\tau$]', fontsize=16)
/>
# =====================================================================
# IMPORT --------------------------------------------------------------
YOU NEED TO DO THAT YOURSELF!
# CLASS FigTest========================================================
class FigTest(MyFig):
# DECLARE KEYWORDS ------------------------------------------------
def declareKeywords(self):
self.keywords = {'xrange': [0, 5],
'yrange': [0, 10]}
# ADD AXES --------------------------------------------------------
def addAxes(self):
ratio = 3./8.
frame = [0., 0., 1.0, 0.5]
frame2 = [0., 0.5, 1.0, 0.5]
self.add_axes(AxDesign(self, 'AxTest', ratio, frame))
self.add_axes(AxDesign(self, 'AxTest2', ratio, frame2))