Commit 875c34f7 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

First commit for the template

The suggested structure is there, with some nice
imports. Only test is missing.

Axes
 - axMaxResults
 - axParameterSpace
 - axResults
 - axTemplate

IOs
 - readRun (structured data set)
 - readSerie (data base like data set)
parents
myplotlib*
# THIS IS JUST NEEDED
import numpy as np
# SOME DECORATION
INFO = ' > info-: '
WARN = ' > warn-: '
SEVR = ' > sevr-: '
DBUG = ' > dbug-: '
SPCE = ' > -----: '
# DEBUG FLAG
DEBUG = False
# IMPORT myplotlib MyWin
from myplotlib import MyWin
# IMPORT myplotlib MYTOOL toolbox
from myplotlib.mytool import *
# IMPORT USER'S IOs
from myIOs import readRun
from myIOs import readSerie
# IMPORT USER'S Axes
from myAxes import *
# IMPORT USER'S Figures
from myFigures import *
name: 'run1'
input0: 100
input1: 100.
input2: 200
results: [[10, 20],[5,40]]
name: 'run2'
input0: 100
input1: 50.
input2: 300
results: [[2, 5],[10, 30]]
name: 'run3'
input0: 100
input1: 80.
input2: 320
results: [[8, 1],[70, 40]]
| name | input0 | input1 | input2 | maxResults |
|--------+--------+---------+--------+------------|
| 'run1' | 100 | 100. | 200 | 40 |
| 'run2' | 100 | 50. | 300 | 30 |
| 'run3' | 100 | 80. | 320 | 70 |
name: 'run1'
input0: 10
input1: 100.
input2: 200
results: [[2, 0.1],[4, 8]]
name: 'run2'
input0: 10
input1: 50.
input2: 300
results: [[0.1, 0.2],[5, 3]]
| name | input0 | input1 | input2 | maxResults |
|--------+--------+---------+--------|------------|
| 'run1' | 10 | 100. | 200 | 40 |
| 'run2' | 10 | 50. | 300 | 30 |
from axMaxResults import AxMaxResults
from axParameterSpace import AxParameterSpace
from axResults import AxResults
# Import --------------------------------------------------------------
from ..myplotlib import MyAxes
from .. import np
# CLASS AxActivity ----------------------------------------------------
class AxMaxResults(MyAxes):
# FORMATTING --------------------------------------------------------
def formatRawData(self, rawdata):
# Get the data from the rawData
runName_tmp = rawdata.data['name']
maxResult_tmp = rawdata.data['maxResults']
input0 = rawdata.data['input0']
runName = runName_tmp
maxResult = maxResult_tmp * input0
nbrRuns = len(runName)
xdata = range(0, nbrRuns)
# SET THE FORMATTED DATA -------------------------------------------
self.data = {'xdata' : xdata,
'ydata' : maxResult,
'nbrRuns': nbrRuns,
'runName': runName}
return(True)
# PLOTTTING ----------------------------------------------------------
def plotting(self):
# Get some keywords
yRange = self.fig.keywords.get('yrange', None)
# xlabel, ylabel
xlabel = r"runs"
ylabel = r"max Results"
self.xaxis.set_label_text(xlabel)
self.yaxis.set_label_text(ylabel)
# plot the max of results for each run
self.plot(self.data['xdata'], self.data['ydata'], 'o-')
if(yRange is not None):
self.set_ylim(yRange)
else:
self.set_ylim([0., max(self.data['ydata']) * 1.1])
nbrRuns = self.data['nbrRuns']
self.set_xlim([-1. / (nbrRuns + 1.), nbrRuns - nbrRuns / (nbrRuns + 1.)])
# some stylistics
self.xaxis.set_ticks(self.data['xdata'])
tickLabels = []
for run in self.data['runName']:
tickLabels.append(r'${\rm ' + str(run) + '}$')
self.xaxis.set_ticklabels(tickLabels)
return(True)
# Import --------------------------------------------------------------
from ..myplotlib import MyAxes
from .. import np
# CLASS AxActivity ----------------------------------------------------
class AxParameterSpace(MyAxes):
# FORMATTING --------------------------------------------------------
def formatRawData(self, rawdata):
# Get the data from the rawData
xdata_tmp = rawdata.data['input1']
ydata_tmp = rawdata.data['input2']
xdata = xdata_tmp
ydata = ydata_tmp
minx = min(xdata)
maxx = max(xdata)
miny = min(ydata)
maxy = max(ydata)
dx = 0.1 * (maxx - minx)
dy = 0.1 * (maxy - miny)
D_XRANGE = [minx-dx, maxx+dx]
D_YRANGE = [miny-dy, maxy+dy]
# SET THE FORMATTED DATA -------------------------------------------
self.data = {'xdata' : xdata,
'ydata' : ydata,
'dxrange': D_XRANGE,
'dyrange': D_YRANGE}
return(True)
# PLOTTTING ----------------------------------------------------------
def plotting(self):
# Get some keywords
xRange = self.fig.keywords.get('xRange', self.data['dxrange'])
yRange = self.fig.keywords.get('yRange', self.data['dyrange'])
# xlabel, ylabel
xlabel = r"${\rm input1}$"
ylabel = r"${\rm input2}$"
self.xaxis.set_label_text(xlabel)
self.yaxis.set_label_text(ylabel)
# plot stuff
self.plot(self.data['xdata'],
self.data['ydata'], 'o', markersize=14)
# put some limits
self.set_xlim(xRange)
self.set_ylim(yRange)
return(True)
# Import --------------------------------------------------------------
from ..myplotlib import MyAxes
from .. import np
# CLASS AxActivity ----------------------------------------------------
class AxResults(MyAxes):
# FORMATTING --------------------------------------------------------
def formatRawData(self, rawdata):
# Get the data from the rawData
zdata_tmp = rawdata.data['results']
zdata = zdata_tmp
# SET THE FORMATTED DATA -------------------------------------------
self.data = {'zdata' : zdata}
return(True)
# PLOTTTING ----------------------------------------------------------
def plotting(self):
# Get some keywords
xRange = self.fig.keywords.get('xrange', None)
yRange = self.fig.keywords.get('yrange', None)
zRange = self.fig.keywords.get('zrange', None)
# xlabel, ylabel
xlabel = r"${\rm x}~[{\rm m}]$"
ylabel = r"${\rm y}~[{\rm m}]$"
self.xaxis.set_label_text(xlabel)
self.yaxis.set_label_text(ylabel)
# plot stuff
if(zRange is not None):
vmin, vmax = zRange
else:
vmin, vmax = [None, None]
self.imshow(self.data['zdata'],
aspect='auto',
vmin=vmin,
vmax=vmax)
# put some limits
if(xRange is not None):
self.set_xlim(xRange)
if(yRange is not None):
self.set_xlim(yRange)
return(True)
# Import --------------------------------------------------------------
from ..myplotlib import MyAxes
from .. import np
# CLASS AxActivity ----------------------------------------------------
class AxTemplate(MyAxes):
# FORMATTING --------------------------------------------------------
def formatRawData(self, rawdata):
# Get the data from the rawData
xdata_tmp = rawdata.data['<some var>']
ydata_tmp = rawdata.data['<some var>']
parameter = rawdata.data['<some param>']
# HERE YOU CAN FORMAT THE DATA THE WAY YOU WANT!
# ...
xdata = xdata_tmp
ydata = ydata_tmp * parameter
# SET THE FORMATTED DATA -------------------------------------------
self.data = {'xdata' : xdata,
'ydata' : ydata}
return(True)
# PLOTTTING ----------------------------------------------------------
def plotting(self):
# Get some keywords
xRange = self.fig.keywords.get('xrange', None)
yRange = self.fig.keywords.get('yrange', None)
logy = self.fig.keywords.get('logy', None)
# MORE KEYWORDS? Go ON ...
# xlabel, ylabel
xlabel = r"<Some Latex label>"
ylabel = r"<Some Latex label>"
self.xaxis.set_label_text(xlabel)
self.yaxis.set_label_text(ylabel)
# plot stuff
if(logy):
self.semilogy(self.data['xdata'],
self.data['ydata'])
else:
self.plot(self.data['xdata'],
self.data['ydata'])
# put some limits
if(xRange is not None):
self.set_xlim(xRange)
if(yRange is not None):
self.set_xlim(yRange)
# some stylistics
if(not logy):
self.ticklabel_format(axis='y', style='sci', scilimits=(-2, 2))
return(True)
from readRun import readRun
from readSerie import readSerie
# IMPORT
import ast # https://docs.python.org/2/library/ast.html (very practicle)
from ..myplotlib import MyData # Data structure from myplotlib
from .. import INFO, SEVR, DBUG, WARN, SPCE # User defined FORMS
# Function Read Run
def readRun(filename):
# initialize the rawdata object (type MyData)
rawdata = MyData()
rawdata.name = filename
# this is a dictionary
rawdata.data = {}
# Open the file in a proper manner
try:
f = open(filename)
except IOError:
print(SEVR + "I could not read the file.")
return(None)
except:
print(SEVR + "Something wrong happend while opening the file.")
return(None)
# read the file line by line
for line in f.readlines():
# get key and value separated by a ":"
key, value = line.split(':')
value = value.replace(' ', '')
# put the pair key and value into the rawdata.data dictionary
rawdata.data.update({key: ast.literal_eval(value)})
# print some infos
print(INFO + "I read the run " + str(filename))
# close the file
f.close()
return(rawdata)
# IMPORT
import ast # https://docs.python.org/2/library/ast.html (very practicle)
from ..myplotlib import MyData # Data structure from myplotlib
from .. import np
from .. import INFO, SEVR, DBUG, WARN, SPCE # User defined FORMS
from .. import DEBUG
# Function Read Serie
def readSerie(filename):
# initialize the rawdata object (type MyData)
rawdata = MyData()
rawdata.name = filename
rawdata.data = None
# Open the file in a proper manner
try:
f = open(filename)
except IOError:
print(SEVR + "I could not read the file.")
return(rawdata)
except:
print(SEVR + "Something wrong happend while opening the file.")
return(rawdata)
if(DEBUG): print(DBUG + "I opened the file: " + str(filename))
# initialize the loop
header = True
firstLine = True
dataTypes = []
dataIndex = 0
lineIndex = 0
formatedDatii = []
for line in f.readlines():
# ignore decoration
if line.startswith('|-'):
pass
# if meaningful line
elif line.startswith('| '):
# read header
if(header):
names = line.split('|')[1:-1]
index = 0
for name in names:
names[index] = name.replace(' ', '')
index = index + 1
header = False
if(DEBUG): print(DBUG + "The header is: " + str(names))
# read data
else:
# add a line
formatedDatii.append(())
# detect the data
datii = line.split('|')[1:-1]
if(DEBUG): print(DBUG + "DATII are " + str(datii))
# for each element
for data in datii:
# remove spaces
data = data.replace(' ', '')
if(DEBUG): print(DBUG + "data is " + str(data))
# evaluate the data
evalData = ast.literal_eval(data)
if(DEBUG): print(SPCE + "evalData is " + str(evalData))
# if this is the first line detect the types
if(firstLine):
dataTypes.append(type(evalData))
# if not the first line
else:
# check the type
if(type(evalData) != dataTypes[dataIndex]):
print(WARN + "Type mismatch in line {lindex} column {cindex}".format(lindex=lineIndex, cindex=dataIndex))
# if type different retype and warn
evalData = dataTypes[dataIndex](data)
if(DEBUG): print(SPCE + "new evalData is " + str(evalData))
else:
pass
if(DEBUG): print(SPCE + "dataType is " + str(dataTypes[dataIndex]))
if(DEBUG): print('')
# put the data in the array
formatedDatii[lineIndex] = formatedDatii[lineIndex] + (evalData,)
dataIndex = dataIndex + 1
if(DEBUG): print(DBUG + "The line " + str(lineIndex) + " is " + str(formatedDatii[lineIndex]))
if(DEBUG and firstLine): print(SPCE + "The dataTypes are " + str(dataTypes))
if(DEBUG): print('')
dataIndex = 0
firstLine = False
lineIndex = lineIndex + 1
# if comment line
else:
pass
# Format the name and dtypes
dtypes = []
for name, dataType in zip(names, dataTypes):
dtypes.append((str(name), dataType))
# Format the string instances
index = 0
for dtype in dtypes:
if isinstance('42', dtype[1]):
dtypes[index] = (dtype[0], '|S64')
index = index + 1
# put the data under the form of a recarray
rawdata.data = np.array(formatedDatii, dtype=dtypes)
# print some infos
print(INFO + "I read the serie " + str(filename))
return(rawdata)
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