Skip to content

Commit

Permalink
flexible plot size and clumn number
Browse files Browse the repository at this point in the history
  • Loading branch information
revoltek committed Apr 29, 2016
1 parent d20634e commit ee3a5c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 22 additions & 8 deletions losoto/operations/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

logging.debug('Loading PLOT module.')

def plot(Nplots, cmesh, axesInPlot, axisInTable, xvals, yvals, xlabelunit, ylabelunit, datatype, filename, titles, log, dataCube, minZ, maxZ, plotflag, makeMovie, antCoords, outQueue):
def plot(Nplots, NColFig, figSize, cmesh, axesInPlot, axisInTable, xvals, yvals, xlabelunit, ylabelunit, datatype, filename, titles, log, dataCube, minZ, maxZ, plotflag, makeMovie, antCoords, outQueue):
import os, pickle
from itertools import cycle, chain
import numpy as np
Expand All @@ -27,11 +27,22 @@ def plot(Nplots, cmesh, axesInPlot, axisInTable, xvals, yvals, xlabelunit, ylabe
os.system('rm '+dataCube)
dataCube = dataCube_p

autominZ = None; automaxZ = None
Nr = int(np.ceil(np.sqrt(Nplots)))
Nc = int(np.ceil(np.float(Nplots)/Nr))
if makeMovie: figgrid, axa = plt.subplots(Nc, Nr, figsize=(5+2*Nc,4+1*Nr), sharex=True, sharey=True)
else: figgrid, axa = plt.subplots(Nc, Nr, figsize=(10+3*Nc,8+2*Nr), sharex=True, sharey=True)
autominZ = None; automaxZ = None

# if user-defined number of col use that
if NColFig != 0: Nc = NColFig
else: Nc = int(np.ceil(np.sqrt(Nplots)))
Nr = int(np.ceil(np.float(Nplots)/Nc))

if figSize[0] == 0:
if makeMovie: figSize[0]=5+2*Nc
else: figSize[0]=10+3*Nc
elif figSize[1] == 0:
if makeMovie: figSize[1]=4+1*Nr
else: figSize[1]=8+2*Nr

figgrid, axa = plt.subplots(Nr, Nc, figsize=figSize, sharex=True, sharey=True)

if Nplots == 1: axa = np.array([axa])
figgrid.subplots_adjust(hspace=0, wspace=0)
axaiter = chain.from_iterable(axa)
Expand Down Expand Up @@ -77,7 +88,8 @@ def plot(Nplots, cmesh, axesInPlot, axisInTable, xvals, yvals, xlabelunit, ylabe
aspect = ((xvals[-1]-xvals[0])*bbox.height)/((yvals[-1]-yvals[0])*bbox.width)
if log: ax.imshow(np.log10(vals), origin='lower', interpolation="none", cmap=plt.cm.rainbow, extent=[xvals[0],xvals[-1],yvals[0],yvals[-1]], aspect=aspect, vmin=minZ, vmax=maxZ)
else: ax.imshow(vals, origin='lower', interpolation="none", cmap=plt.cm.rainbow, extent=[xvals[0],xvals[-1],yvals[0],yvals[-1]], aspect=aspect, vmin=minZ, vmax=maxZ)
if antCoords != []:
# make an antenna plot
elif antCoords != []:
areas = 5 + np.pi * (10 * ( vals+np.abs(np.min(vals)) ) / np.max( vals+np.abs(np.min(vals)) ))**2 # normalize marker diameter to 0-15 pt
plt.scatter(antCoords[0], antCoords[1], c=vals, s=areas)
else:
Expand Down Expand Up @@ -137,6 +149,8 @@ def normalize(phase):

# 1- or 2-element array in form X, [Y]
axesInPlot = parset.getStringVector('.'.join(["LoSoTo.Steps", step, "Axes"]), [] )
NColFig = parset.getInt('.'.join(["LoSoTo.Steps", step, "Columns"]), 0 )
figSize = parset.getIntVector('.'.join(["LoSoTo.Steps", step, "FigSize"]), [0,0] )
minZ, maxZ = parset.getDoubleVector('.'.join(["LoSoTo.Steps", step, "MinMax"]), [0,0] )
if minZ == 0: minZ = None
if maxZ == 0: maxZ = None
Expand Down Expand Up @@ -365,7 +379,7 @@ def normalize(phase):
pickle.dump(dataCube, open(pfile, 'wb'))
dataCube = pfile

mpm.put([Nplots, cmesh, axesInPlot, axisInTable, xvals, yvals, xlabelunit, ylabelunit, datatype, prefix+filename, titles, log, dataCube, minZ, maxZ, plotflag, makeMovie, antCoords])
mpm.put([Nplots, NColFig, figSize, cmesh, axesInPlot, axisInTable, xvals, yvals, xlabelunit, ylabelunit, datatype, prefix+filename, titles, log, dataCube, minZ, maxZ, plotflag, makeMovie, antCoords])
if makeMovie: pngs.append(prefix+filename+'.png')

mpm.wait()
Expand Down
2 changes: 2 additions & 0 deletions parsets/losoto.parset
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ LoSoTo.Steps.norm.NormAxes = [time,ant]
# PARALLEL
LoSoTo.Steps.plot.Operation = PLOT
LoSoTo.Steps.plot.Axes = [] # 1- or 2-element array which says the coordinates to plot (2 for 3D plots)
LoSoTo.Steps.plot.Columns = 0 # Number of columns in a multi-table image, if 0 then it is automatically chosen
LoSoTo.Steps.plot.FigSize = [0,0] # Size of the image [x,y], if one of the values is 0, then it is automatically chosen
LoSoTo.Steps.plot.MinMax = [0,0] # min max value for the independent variable (0 means automatic)
LoSoTo.Steps.plot.TableAxis = [] # the axis to plot on a page - e.g. ant to get all antenna's on one file
LoSoTo.Steps.plot.ColorAxis = [] # the axis to plot in different colours - e.g. pol to get correlations with different colors
Expand Down

0 comments on commit ee3a5c0

Please sign in to comment.