Skip to content

Commit

Permalink
finish gp_datdir.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Jan 9, 2014
1 parent c59df5d commit ceda884
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions pyana/examples/gp_datdir.py
Expand Up @@ -5,29 +5,37 @@
from ..aux.utils import getWorkDir, zip_flat, getOpts
from ..aux.config import defaultkey

def gp_datdir(subname):
inDir = os.path.join(getWorkDir(__name__, True), subname)
return 'inDir'
# TODO: prepare data = OrderedDict
outDir = getWorkDir(__name__)
logging.debug(data)
nSets = len(data)
def gp_datdir(subname): # subname = country initial in examples case
inDir = os.path.join(getWorkDir(__name__, True), subname) # inDir for country initial
data = OrderedDict() # OrderedDict with datasets to plot as separate keys
for file in os.listdir(inDir): # loop all files for country initial
country = os.path.splitext(file)[0] # filename stem is country
data[country] = np.loadtxt( open(os.path.join(inDir, file), 'rb') ) # load data
data[country][:, 1:3] /= 1e6 # set unit to 1M
if len(data) > 10: break
yVals = [ n for v in data.values() for n in v[:, 1] ] # all y values
yMin = min(yVals)
yMax = max(yVals)
logging.debug(data) # shown if --log flag given on command line
outname = os.path.join(getWorkDir(__name__), subname) # output filename for make_plot
nSets = len(data) # number of datasets
make_plot(
name = os.path.join(outDir, 'gp_from_txt'), # basename of output file
log = [False, True], # logarithmic axes? [x, y]
xr = [xMin, xMax], yr = [yMin, yMax],
data = data,
using = ['1:2:3'] * nSets,
main_opts = ['points'] * nSets, # yerrorbars, boxerrorbars
extra_opts = zip_flat(
[ 'lt 1 lw 4 ps 2 lc %d pt %d' % (i/2, 18+i%2) for i in xrange(nSets) ],
[ "lt 1 lw 4 lc rgb 'grey'" ] * nSets
),
xlabel = 'xlabel', ylabel = 'ylabel',
titles = data.keys(),
key = defaultkey + [
'maxrows 3', 'top', 'outside', 'opaque', 'samplen 0.8',
'font ",22"', 'width -2', 'height 0.2'
]
name = outname, # extension-less name of output file
log = [False, False], # logarithmic axes? [x, y]
xr = [1999, 2020], yr = [0.9*yMin, 1.1*yMax],
data = data.values(),
using = ['1:2:3'] * nSets, # datapoint format: x y yerr bw
main_opts = ['points'] * nSets, # other options: yerrorbars, boxerrorbars
extra_opts = [ getOpts(i) for i in xrange(nSets*2) ], # len(extra_opts) = nSets*2! pts/err alternately
xlabel = 'year', ylabel = 'total population ({/Symbol \664} 10^{6})',
titles = data.keys(), # using data keys as legend titles
key = defaultkey + [ 'font ",22"', 'width -1' ] # add extra options
)
return 'done'

# MORE CONTROL for extra_opts:
# zip_flat from aux/utils.py takes to lists and zips them flat alternately
# extra_opts = zip_flat(
# [ 'lt 1 lw 4 ps 2 lc %d pt %d' % (i/2, 18+i%2) for i in xrange(nSets) ], # datapoints
# [ "lt 1 lw 4 lc rgb 'grey'" ] * nSets # errors
# ),

0 comments on commit ceda884

Please sign in to comment.