Commit 90d1e373 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Add MyFig_server, MyAxes_server

imports but not yet tested, see axTestServer and figTestServer (not yet)
parent 5962c7f5
......@@ -82,20 +82,18 @@ from .config import D_OPATH, D_OFORMAT
from .config import D_DEBUG
if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
from .rconfig import rcParams
# BACKEND: u'TKAgg', u'GTKAgg', u'WXAgg', u'Qt4Agg', u'MacOSX'
rcParams['backend'] = u'GTKAgg'
# FUNCTIONS ------------------------------------------------------------
# MyAxes: Overlay on matplotlib.Axes class
#from .myAxes import MyAxes
# MyFig: Overlay on matplotlib.Figure class
#from .myFig import MyFig
if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes import MyAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig import MyFig
_G_WINDOWS = []
# MyWin: Overlay on matplotlib.FigureManager class
......@@ -112,6 +110,20 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
else:
print(SEVR + "The backend you choosed is not supported interactive mode not available")
elif(D_HIERARCHY in ('SERVER', 'server')):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes_server import MyAxes_server as MyAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig_server import MyFig_server as MyFig
else:
print(SEVR+'the value of D_HIERARCHY has to be SERVER, CLIENT or LOCAL')
raise ImportError
# myTool.*: interface functions to use myplotlib interactively
#from .mytool import print2file # need to make tools for server ?? or just put them in client/local
#from .mytool import FigOneAxes
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v3.0.1,
#
# @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.
#
# v 2.2.3 - Add testRawData function
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
from . import SEVR, DBUG
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxes_server(object):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
self.fig = fig
self.declareKeywords()
# set a default name. Should be individualized by instance
self.name = 'default'
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
self.keywords = {}
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
return(True)
# TESTING THE RAWDATA ------------------------------------------------
def testRawData(self, rawdata):
return(True)
# UPDATE -------------------------------------------------------------
def update(self, *args, **kwargs):
# myplotlib update
# self.keywords.update({key: value for (key, value) in kwargs.items() if key in self.keywords}) # Not compatible with python2.6
for (key, value) in kwargs.items():
if key in self.keywords:
self.keywords.update({key: value})
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v3.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.
# 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.
#
# v 2.2.3 - Allow the possibility of giving a unique rawdata format
# all axes. /!\ self.rawdata is a generator. /!\
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
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_server
# Class MyFig Overwriting Matplotlib.figure.Figure
class MyFig_server(object):
# Set the size of the Figure in inch
# (private variable can not be updated)
FIGSIZE = D_FIGSIZE
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, rawdata, *args, **kwargs):
# for the update function
self._attributesToUpdateKeys = ['fignum', 'reformat', 'debug', 'formatted', 'aliases']
# initialise the attribute default values and remove them from kwargs
self.fignum = kwargs.pop('fignum', -1) # need to be hard coded for interactive mode
self.reformat = kwargs.pop('reformat', D_REFORMAT)
self.debug = kwargs.pop('debug', D_DEBUG)
self.formatted = kwargs.pop('formatted', D_FORMATTED)
self.aliases = {}
self.FIGSIZE = kwargs.pop('figsize', self.FIGSIZE)
self.axes = []
# initialise
self._initialize(*args, **kwargs)
self.set_rawdata(rawdata)
# INITIALIZE -------------------------------------------------------
def _initialize(self, *args, **kwargs):
# add the axes
self.addAxes()
# declare the aliases
self.declareAliases()
# update the attributes and keywords
self.update(**kwargs)
# UPDATE ----------------------------------------------------------
def update(self, **kwargs):
# check attributes in keywords
for keyword in kwargs.keys():
# if it is the rawdata use the function
if keyword == 'rawdata':
self.set_rawdata(kwargs['rawdata'])
# if it is an attribute
elif keyword in self._attributesToUpdateKeys:
# update value
setattr(self, keyword, kwargs[keyword])
# For each axes update the keywords
for ax in self.get_axes(): # NEED TO CODE GET_AXES
forax = {}
for keyword in kwargs.keys():
# ignore figure attributes
if keyword in ['rawdata'] + self._attributesToUpdateKeys :
pass
# Check if a key of kwargs has an alias for this axes
elif keyword in self.aliases.keys():
alax, alkey = self.aliases[keyword]
# If an alias is found then update axkwargs
if ax == alax:
forax.update(**{alkey: kwargs[keyword]})
# use keyword as it is for the axes
else :
forax.update(**{keyword : kwargs[keyword]})
# Then eventually all collected Keywords are updated in one go
if (forax) :
if self.debug:
print (DBUG+' fig.update ', ax, 'keywords: ', forax)
ax.update(**forax)
return(True)
# DECLARE ALIASES -------------------------------------------------
def declareAliases(self):
pass
# ADD AXES ---------------------------------------------------------
def addAxes(self, *arg, **kwargs):
pass
# GET_AXES ---------------------------------------------------------
def get_axes(self):
return(self.axes)
# This overwrites MPL add_axes. It gives a name to the axis added so that it is easier to refer to
def add_axes(self, ax, name) :
# if isinstance(name, str) and issubclass(ax.__class__, MyAxes): # This lead to an error is ax is not in the same namespace
ax.name = name
# else:
# print(SEVR + " there is an error with the input type of add_axes()")
# return False
# test if an axes with that name is already present
for pax in self.get_axes() :
if pax.name == name :
print(SEVR + " an axes with that name is already present")
return False
self.axes.append(ax)
return True
# GET AXES BY NAME -------------------------------------------------
def getAxesByName(self, name):
for ax in self.get_axes() : # SAME NEED TO CODE GET_AXES
if ax.name == name :
return ax
#if the name is correct we should never get here.
print(SEVR + "The axes name ", name, " was not found")
return None
# SET RAW DATA -----------------------------------------------------
def set_rawdata(self, rawdata):
from collections import Iterable
from itertools import repeat
self.formatted = False
status = False
# DEFAULT: one item per axes in figure
if isinstance(rawdata, Iterable):
if len(rawdata) == len(self.get_axes()):
if(self.debug): print(DBUG + "set_rawdata: one item per axes")
self.rawdata = rawdata
status = self.formatRawData()
else:
self.rawdata = None
print(SEVR + "rawdata should have the dimention of the number of axes: #axes = " + str(len(self.get_axes())) + "; dim of rawdata = " + str(len(rawdata)))
return(False)
# CONVINIENT: one object for all axes
elif isinstance(rawdata, MyData):
if(self.debug): print(DBUG + "set_rawdata: one item for all axes")
self.rawdata = repeat(rawdata) # This is the trick rawdata becomes a generator (so smart)
status = self.formatRawData()
else :
print(SEVR + "set_rawdata: I could not set the rawdata...")
self.rawdata = None
status = False
if not status:
print(SEVR + "set_rawdata: I could not set the rawdata...")
self.rawdata = None
return(status)
# FORMAT RAW DATA --------------------------------------------------
def formatRawData(self):
if self.rawdata is not None:
for ax, rawdata in zip(self.get_axes(), self.rawdata):
status = False
if(self.debug):
print(INFO + "Axes: " + str(ax.__class__.__name__) + " with index " + str(self.get_axes().index(ax)) + " formats " + rawdata.name)
status = ax.testRawData(rawdata)
if status :
status = ax.formatRawData(rawdata)
else:
status = ax.testRawData(rawdata)
if status:
try:
status = ax.formatRawData(rawdata)
except:
print(SEVR + "The " + str(ax.__class__.__name__) + " with index " + str(self.get_axes().index(ax)) + " could not format the rawdata.")
return(False)
if not status:
return(False)
if self.formatted is False:
self.formatted = True
return(True)
else:
return(False)
# DEBUG --------------------------------------------------------------
def printDebug(self):
className = str(self.__class__.__name__)
print('\n' + DBUG + " {0} PARAMETERS: ".format(className))
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')
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v3.0.1,
#
# @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 D_HIERARCHY
from .. import SEVR, DBUG, INFO
if D_HIERARCHY in ('SERVER', 'server'):
print(INFO+"Testing the server.")
else:
print(SEVR+"This is atest for the server, the imports are not correct.")
raise ImportError
from .. import MyAxes
D_XRANGE = None
D_YRANGE = None
D_LOGY = False
D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTestServer(MyAxes):
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE}
return(True)
# 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]]}
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)
Markdown is supported
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