"""
@brief script for running 4D Contour Plot of (X,Y (n2,n1) meshes; Z-vector(n4), ; W-matrix(n4,n2,n1); with w-value being "n3"
@author A. Connors
"""
# @file howto_run_pylab_plot_4example.py
#

from numpy import *
from matplotlib import *
from matplotlib.pylab import *
import pyfits
import matplotlib.axes3d as axes3d
import pylab_plot4d as axes4d
from run_pylab_plot_4example import *

### Right nowthis runs one at a time; later it can be in "run-the-list" format: ###

#### Here is the input path-name
workmain = '/AstroCode/EMC2/'
thisrundir = 'Bayes-Image-Analysis_dvd_060818/'
#thisrundir = ''
#filen='do_emc2c1_PoisDatonPaddedIntTime539.X.060612.it1000.ms100gamttlcnt_1_.05FitS0.060819a.secondconf2.fits'
#filen='do_emc2c1_Nu2SumPoisDatonPaddedIntTime539.X.060529.it1000.ms100gamttlcnt_1_.05FitS0.060819a.secondconf2.fits'
#filen='do_emc2c1_HlfSquishICSPionBremss539.0.060912_on_Pois539.X.060612.it1000.ms100gamttlcnt_1_.05FixS0.061002a.secondconf2.fits'
#filen='do_emc2c1_HlfSquishICSPionBremss539.0.060912_on_Pois539.X.060612.it1000.ms100gamttlcnt_1_.05FixS0.061002a.wrongconf.fits'
#filen='do_emc2c1_HlfSquishICSPionBremss539.0.060912_on_Pois539.X.060612.it1000.ms100gamttlcnt_1_.05FitS0.060914a.DataPlus.fits'
#filen='do_emc2c1_HlfSquishICSPionBremss539.0.060912_on_Pois539.X.060612.it1000.ms100gamttlcnt_1_.05FitS0.060914a.SimpleMoments.fits'
#filen='do_emc2c1_Nu2SumPoisDatonPaddedIntTime539.X.060529.it1000.ms100gamttlcnt_1_.05FitS0.060819a.DataPlus.fits'
#filen='do_emc2c1_PoisDatonPaddedIntTime539.X.060612.it1000.ms100gamttlcnt_1_.05FitS0.060819a.DataPlus.fits'
#filen='do_emc2c1_ModelDataPaddedIntTime539.0.060529_on_PoisDatonPaddedIntTime539.X.060612.it5000.ms100gamttlcnt_1_.05FitS0.All.5percconf2.fits'
filen='do_emc2c1_ModelDataPaddedIntTime539.0.060529_on_Nu3SumPoisDatonPaddedIntTime133.0.070905.it4000.ms100gamttlcnt_1_.05FitS0.070905bcd.5percconf2.fits'

#
InFilePathName=workmain+thisrundir+filen

# Here are the input X, Y, W, Z labels:

inXlabel, inYlabel = 'galactic  l (deg)', ' galactic  b (deg)'
inZWlabel = '  MCMC  E[Cnts/Bin]  (arbitrary offset)'
#inZWlabel = '  Counts/Bin '
#inZWlabel = ''

### Oy! And put better Z-Vector Labels here:
inZlabels = []
inZlabels.append('<5% Tail')
inZlabels.append('Mean')
inZlabels.append('>95% Tail')
#inZlabels.append('Mean')
#inZlabels.append('Sigma')
#inZlabels.append('Skew')
#inZlabels.append('Kurtosis')
#inZlabels.append('Model')
#inZlabels.append('Data')
#inZlabels.append('Mean')

#inTitle='Results'
#inTitle='Pixel-Level Quantiles'
inTitle='Object-Level Quantiles'
#inTitle='Simulated All-Sky Data+Models'
#inTitle='Moments'

## I am assuming this is a 360+padding wide, 180+padding high skymap.
## The padding (used to make it even powers of 2 bins) is enough
## to make it +/- 12 degrees bigger in X; and +/- 19 degrees bigger in Y.
##
## For general work, these should be inputs, I think:
xpaddeg  , ypaddeg   = 12.0, 38.0
xoriginalrangedeg, yoriginalrangedeg = [-180.,180.], [-90.,90.]

inXRanged = [xoriginalrangedeg[0] - xpaddeg, xoriginalrangedeg[1] + xpaddeg]
inYRanged = [yoriginalrangedeg[0] - ypaddeg, yoriginalrangedeg[1] + ypaddeg]

print ' Xrange, Yrange in degrees:', inXRanged, inYRanged, '\n'

#  Note that this variable is the *SUM* of all xpadding (L+R) and ypadding (U+D):
inXYPadd = [2.*xpaddeg, 2.*ypaddeg]

###---------------------------------------------------------###
WorkingPlotStructure = Get4DExampleData(InFilePathName,
        inXlabel, inYlabel, inZWlabel, inZlabels, inTitle,
        inXRanged, inYRanged, inXYPadd )

print '\n\nAfter initializing Working Plot Structure:'
print 'X:', WorkingPlotStructure.X.shape, ' Y.shape:',WorkingPlotStructure.Y.shape,' Z.-all: ',WorkingPlotStructure.Z
print 'W.shape: ',WorkingPlotStructure.W.shape
print 'Labels: ',WorkingPlotStructure.Xlabel, WorkingPlotStructure.Ylabel, WorkingPlotStructure.ZWlabel
print WorkingPlotStructure.Zlabels
print WorkingPlotStructure.title
print ' And zdel: ', WorkingPlotStructure.zdel, '\n \n'

# Initialize plot preferences:
#numcontours= 8
#PlotFileName='Stack08Contour4D'
numcontours= 32
#PlotFileName='FaintModelMismatchSimpleMomentsCont4D3'
PlotFileName='FaintIrregularDiscontinuousQuant5percTailsCont4D3'
#PlotFileName='BrightIrregularDiscontModelDatonsCont4D3'
#PlotFileName='Null539Quant5percTailsCont4D3'
PlotType='PNG'
text_params={'fontsize':'xx-large'}

# Now plot it:

WorkingPlotStructure.PlotStacked4DContours(
            numcontours, PlotFileName, PlotType, text_params )

#--------end of test??------------------#
