Example #1
0
def main(outfile):
    # note - avoid putting text in here to avoid font issues

    embed = veusz.Embedded(hidden=True)
    x = N.arange(5)
    y = x**2
    embed.SetData('a', x)
    embed.SetData('b', y)

    page = embed.Root.Add('page')
    graph = page.Add('graph')
    xy = graph.Add('xy', xData='a', yData='b', marker='square')
    graph.x.TickLabels.hide.val = True
    graph.y.TickLabels.hide.val = True
    xy.MarkerFill.color.val = 'blue'

    embed.Export(outfile)
Example #2
0
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
##############################################################################
"""An example embedding program. Veusz needs to be installed into
the Python path for this to work (use setup.py)

This animates a sin plot, then finishes
"""

import time
import numpy
import veusz.embed as veusz

# construct a Veusz embedded window
# many of these can be opened at any time
g = veusz.Embedded('window title')
g.EnableToolbar()

# construct the plot
g.To(g.Add('page'))
g.To(g.Add('graph'))
g.Add('xy', marker='tiehorz', MarkerFill__color='green')

# this stops intelligent axis extending
g.Set('x/autoExtend', False)
g.Set('x/autoExtendZero', False)

# zoom out
g.Zoom(0.8)

# loop, changing the values of the x and y datasets
Example #3
0
        except (ImportError, ModuleNotFoundError) as e:
            print(standard_error_info(e), '- Can not load module "embed". Trying add to sys.path first...')
            # python3 will require this
            if cfg['program']['veusz_path'] not in sys.path:
                sys.path = [cfg['program']['veusz_path']] + sys.path
            from veusz import embed as veusz_embed
        # @-others
        # @-<<declarations>>

        # veusz_embed = import_file(cfg['program']['veusz_path'], 'embed')

        # sys.path = [os.path.dirname(cfg['program']['veusz_path'])] + sys.path
        cfg['in']['pattern_path'] = '/mnt/D/workData/_source/BalticSea/180418/_source/180510_1653Pdetrend&envelop14.vsz'
        path_vsz = Path(cfg['in']['pattern_path'])
        print(f'opening {path_vsz}')
        veusze = veusz_embed.Embedded(path_vsz.name + ' - opened' if path_vsz.is_file() else ' - was created')
        veusze.Load(cfg['in']['pattern_path'])
        # run_module_main('veusz', fun='run')

        veusze.EnableToolbar()

        veusze.SetData('time', int64(df.index.values - datetime64('2009-01-01T00:00:00')) * 1E-9 + TimeShiftedFromUTC_s)
        veusze.SetData('P', df.P_detrend.values)
        veusze.SetData('ind_crest', ind_crest)
        veusze.SetData('ind_trough', ind_trough)
        veusze.SetData('i_burst', i_burst)
        path_vsz_save = Path(cfg['out']['db_path']).with_name(
            cfg['out']['table'] + '_P_detrend').with_suffix('.vszh5')
        print(f'saving {path_vsz_save.name} ...', end='')

        veusze.Save(str(path_vsz_save), mode='hdf5')  # veusze.Save(str(path_vsz_save)) saves time with bad resolution
Example #4
0
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
##############################################################################
"""An example embedding program. Veusz needs to be installed into
the Python path for this to work (use setup.py)

This animates a sin plot, then finishes
"""

import time
import numpy
import veusz.embed as veusz

# construct a Veusz embedded window
# many of these can be opened at any time
g = veusz.Embedded('window title', compatlevel=-1)
g.EnableToolbar()

# construct the plot
g.To(g.Add('page'))
g.To(g.Add('graph'))
g.Add('xy', marker='tiehorz', MarkerFill__color='green')

# this stops intelligent axis extending
g.Set('x/autoRange', 'exact')

# zoom out
g.Zoom(0.8)

# loop, changing the values of the x and y datasets
for i in range(10):
Example #5
0
    def plotProfiles(self,
                     logx=True,
                     logy=False,
                     showback=True,
                     rates=False,
                     title='mbproj2 profiles',
                     mode='update',
                     savefilename=None,
                     exportfilename=None):
        """Plot surface brightness profiles of model and data if Veusz is
        installed.

        :param logx: Use log x axis
        :param logy: Use log y axis
        :param showback: Whether to show background curves
        :param rates: Show rates (cts/s/arcmin2) instead of cts/annulus
        :param title: Veusz window title
        :param mode: "hidden"=hidden window for export, "new"=new window, "update"=update last window
        :param savefilename: Save Veusz document to file
        :param exportfilename: Export Veusz document to graphics file
        """
        if veusz is None:
            raise RuntimeError('Veusz not found')

        update = False
        if mode == 'hidden':
            embed = veusz.Embedded(hidden=True)
        elif mode == 'new' or len(self._veuszembed)==0:
            embed = veusz.Embedded(title)
            self._veuszembed.append(embed)
        elif mode == 'update':
            embed = self._veuszembed[-1]
            update = True
        else:
            raise ValueError("Invalid mode")

        if not update:
            root = embed.Root
            root.colorTheme.val = 'default-latest'
            page = root.Add('page')
            page.height.val = '%gcm' % (len(self.data.bands)*5)
            grid = page.Add('grid', columns=1)
            xaxis = grid.Add(
                'axis', name='x', direction='horizontal',
                autoRange='+2%')
            if logx:
                axis.log.val = True

            for i in range(len(self.data.bands)):
                graph = grid.Add('graph', name='graph%i' % i)
                if logy:
                    graph.y.log.val = True

                xydata = graph.Add(
                    'xy', marker='none', name='data',
                    xData='radius', yData='data_%i' % i)
                xymodel = graph.Add(
                    'xy', marker='none', name='model',
                    xData='radius', yData='model_%i' % i)
                if showback:
                    xyback = graph.Add(
                        'xy', marker='none', name='back',
                        xData='radius', yData='back_%i' % i)

            edges = self.data.annuli.edges_arcmin
            embed.SetData(
                'radius', 0.5*(edges[1:]+edges[:-1]),
                symerr=0.5*(edges[1:]-edges[:-1]))
            grid.Action('zeroMargins')

        if 'backscale' in self.pars:
            backscale = self.pars['backscale'].val
        else:
            backscale = 1.

        profs = self.calcProfiles()
        for i, (band, prof) in enumerate(zip(self.data.bands, profs)):
            factor = (
                1/(self.data.annuli.geomarea_arcmin2*band.areascales*band.exposures)
                if rates else 1 )
            embed.SetData('data_%i' % i, band.cts*factor)
            embed.SetData('model_%i' % i, prof*factor)
            embed.SetData(
                'back_%i' % i, band.backrates*self.data.annuli.geomarea_arcmin2*
                band.areascales*band.exposures*factor*backscale)

        if savefilename:
            embed.Save(savefilename)
        if exportfilename:
            embed.Export(exportfilename)

        if mode == 'hidden':
            embed.Close()
Example #6
0
    def __post_init__(self):
        self.storer = Storer(exit_dump=False)

        self.g = veusz.Embedded(name=self.title, hidden=self.hidden)
        self.g.EnableToolbar()
        self.init_pages()
Example #7
0
def main():

    #cli.full_path, s_sim, lmf, nbI, nbF, RVset, xscale, oc_fit = get_args()
    cli = get_args()

    # write to screen the intro
    intro(cli.full_path, cli.nbI, cli.nbF)

    # prepare stuff for plots
    #font = "Times New Roman"
    #font = "Utopia"
    font = 'URW Palladio L'
    markers = ["circle", "square", "triangle", "diamond", "star", "pus"]
    sizeO = '0.8pt'  # size of Obsevation markers
    sizeS = '1.5pt'  # size of Simulation markers
    sizeTL = '8pt'  # size of ticklabels
    #sizeLab = '10pt'
    sizeLab = '8pt'  # size of labels

    #gRows = (cli.nbF + 1) - cli.nbI + 2 # added another +1 to allow legend
    nbPlt = (cli.nbF - cli.nbI) + 1
    print " First body %d , last body %d ==> bodies to plot: %d" % (
        cli.nbI, cli.nbF, nbPlt)
    gRows = nbPlt * 2 + 1  # O-C + res x nbPlt + 1 legend
    #if cli.nbI == 0:
    if (cli.nbI <= 1):
        gRows = 1  # if you do not want to plot any O-C, only legend

    if cli.RVset != '0':
        RV, gamma, nRV_set, statRV = read_simRV(cli.full_path, cli.idsim,
                                                cli.lmflag)
        #read_obsRV(fullpath)
        if statRV:
            gRows = gRows + 2  # added +2 rows to allow RV plot

    print "Number of rows of the grid: %d" % (gRows)

    gCols = 1
    # define height of the page in cm
    hPage = "15cm"
    #if (cli.nbF-cli.nbI+1) > 3:
    if gRows > 7:
        hVal = (15. * float(gRows) / 3.)
        if hVal > 23.:
            hVal = 23.
        hPage = "%4.2fcm" % (hVal)
    scRows = scalingRows(gRows)
    print 'scaling rows: ', scRows

    letters = ["b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"]

    ocWin = vsz.Embedded("O-C Plot")
    ocWin.ResizeWindow(800, 800)
    ocPage = ocWin.Root.Add(
        'page',
        height=hPage,
        width=hPage  # squared page
    )
    gridOC = ocPage.Add(
        'grid',
        name='gridOC',
        autoadd=False,
        rows=gRows,
        columns=gCols,
        scaleRows=scRows,
        leftMargin='0.2cm',
        rightMargin='0.2cm',
        topMargin='0.5cm',
        bottomMargin='0.1cm',
    )

    # prepare margins for each plot
    # O-C plot
    loc = "1.3cm"  # left margin
    roc = "1.3cm"  # right margin
    toc = "0.0cm"  # top margin
    boc = "0.0cm"  # bottom margin
    # res plot
    lres = "1.3cm"  # left margin
    rres = "1.3cm"  # right margin
    tres = "0.1cm"  # top margin
    bres = "1.cm"  # bottom margin
    # define Min and Max Position of the plots from axis. Range [0.-1.]
    lPos = 0.03  # lowerPosition
    uPos = 1. - lPos  # upperPosition

    if (cli.xscale is None):
        t_subtract = 2440000.5
    else:
        t_subtract = np.float64(cli.xscale)

    # read samples_file if provided
    #rv_samples, oc_samples = read_samples(samples_file=cli.samples_file, nbI=cli.nbI, nbF=cli.nbF)
    samples = read_samples(samples_file=cli.samples_file)

    xoc_list = []  # xaxis of O-C and res plots <-> T0

    if (cli.nbI > 1):
        min_max_time = np.zeros((nbPlt, 2))

        for inb in range(cli.nbI, cli.nbF + 1):

            #epo, oc, res, err = read_simT0(cli.full_path, cli.idsim, cli.lmflag, inb)
            #if(t0_samples is None):
            #ttra_samples = None
            #else:
            #ttra_samples=t0_samples['%d' %(inb)]
            epo, t_obs_base, oc, res, err, samples = read_simT0(
                cli.full_path,
                cli.idsim,
                cli.lmflag,
                inb,
                t_subtract,
                cli.oc_fit,
                samples=samples)
            print ""

            keyObs = ""
            keySim = ""
            if (inb == cli.nbI):
                keyObs = "observations"
                keySim = "simulations"

            #minEpo = int(np.min(epo)) - 1
            #maxEpo = int(np.max(epo)) + 1
            min_time, max_time = lims(t_obs_base, t_obs_base)
            min_max_time[inb - cli.nbI, 0] = min_time
            min_max_time[inb - cli.nbI, 1] = max_time

            if (t_subtract != 0.):
                xlab = "BJD_{TDB} - %.1f" % (t_subtract)
            else:
                xlab = "BJD_{TDB}"
            xlab = '%s (planet %s)' % (xlab, letters[inb - 2])

            # O-C

            #minOCd, maxOCd = lims(oc[:,0], oc[:,3])
            #minOCm, maxOCm = lims(oc[:,1], oc[:,4])

            min0, max0 = lims((oc[:, 0] - err[:, 0]), (oc[:, 0] + err[:, 0]))
            minOCd, maxOCd = lims((min0, max0), oc[:, 3])
            minOCm = minOCd * 1440.
            maxOCm = maxOCd * 1440.

            ylab_l = "O-C [d]"
            ylab_r = "O-C [m]"

            ocname = "oc_%d_%s" % (inb, letters[inb - 2])
            ocPlot = gridOC.Add(
                'graph',
                name=ocname,
                autoadd=False,
                leftMargin=loc,
                rightMargin=roc,
                topMargin=toc,
                bottomMargin=boc,
            )

            xname = 'x%d' % (inb)
            #x_oc = xOC(ocPlot, xname, xlab, minEpo, maxEpo, font, sizeLab, True, sizeTL)
            x_oc = xOC(ocPlot, xname, xlab, min_time, max_time, font, sizeLab,
                       True, sizeTL)
            xoc_list.append(x_oc)

            yname = 'y%d_l' % (inb)
            y_l_oc = yOC(ocPlot, yname, ylab_l, 0, '0', sizeLab, minOCd,
                         maxOCd, lPos, uPos, font, sizeTL)

            xyname = "xy_d_obs_%s" % (letters[inb - 2])
            xy_d_obs = ocPlot.Add(
                'xy',
                name=xyname,
                autoadd=False,
                #xData = epo,
                #yData = oc[:,0],
                xAxis=xname,
                yAxis=yname,
                PlotLine__hide=True,
                marker=markers[0],
                markerSize=sizeO,
                MarkerFill__color='black',
                MarkerFill__hide=False,
                MarkerLine__color='black',
                errorStyle='bar',
                ErrorBarLine__color='black',
                ErrorBarLine__hideHorz=True,
                FillBelow__color='black',
                FillBelow__hide=True,
                FillBelow__hideerror=False,
                FillAbove__color='black',
                key=keyObs,
            )
            #epoName = 'epo_' + letters[inb-2]
            #ocWin.SetData(epoName, epo)
            time_name = 'xtime_%s' % (letters[inb - 2])
            ocWin.SetData(time_name, t_obs_base)
            dataYname = "oc_d_obs_%s" % (letters[inb - 2])
            ocWin.SetData(dataYname, oc[:, 0], symerr=err[:, 0])
            #xy_d_obs.xData.val = epoName
            xy_d_obs.xData.val = time_name
            xy_d_obs.yData.val = dataYname
            #xy_d_obs.yData.val = oc[:,0]

            if (inb == cli.nbI):
                legend = ocPlot.Add(
                    'key',
                    name='legend',
                    autoadd=False,
                    #Text__size = '12pt',
                    Text__font=font,
                    Text__size=sizeLab,
                    Border__hide=True,
                    horzPosn='centre',
                    vertPosn='manual',
                    keyLength='0.35cm',
                    keyAlign='top',
                    #horzManual = 0,
                    vertManual=1.001,
                    marginSize=0.3,
                    columns=2,
                )

            xyname = "xy_d_sim_%s" % (letters[inb - 2])
            xy_d_sim = ocPlot.Add(
                'xy',
                name=xyname,
                autoadd=False,
                #xData = epo,
                #yData = oc[:,3],
                xAxis=xname,
                yAxis=yname,
                PlotLine__hide=True,
                marker=markers[0],
                markerSize=sizeS,
                MarkerFill__color='white',
                MarkerFill__hide=False,
                MarkerLine__color='blue',
                key=keySim,
            )
            #epoName = 'epo_' + letters[inb-2]
            #ocWin.SetData(epoName, epo)
            time_name = 'xtime_%s' % (letters[inb - 2])
            ocWin.SetData(time_name, t_obs_base)
            dataYname = "oc_d_sim_%s" % (letters[inb - 2])
            ocWin.SetData(dataYname, oc[:, 3])
            #xy_d_sim.xData.val = epoName
            xy_d_sim.xData.val = time_name
            xy_d_sim.yData.val = dataYname

            # add samples plot for current body!
            if (samples is not None):
                plot_oc_samples(ocWin,
                                ocPlot,
                                xname,
                                yname,
                                samples,
                                letters,
                                id_body=inb)

            zeroLine = ocPlot.Add(
                'function',
                name='zeroLine',
                autoadd=False,
                function='0.',
                Line__color='black',
                Line__style='solid',
                Line__width='0.5pt',
                xAxis=xname,
                yAxis=yname,
            )

            yname = 'y%d_r' % (inb)
            y_r_oc = yOC(ocPlot, yname, ylab_r, 1, '180', sizeLab, minOCm,
                         maxOCm, lPos, uPos, font, sizeTL)

            # Residuals

            #minResd, maxResd = lims(res[:,0], res[:,0])
            #minResm, maxResm = lims(res[:,1], res[:,1])

            minResd, maxResd = lims((res[:, 0] - err[:, 0]),
                                    (res[:, 0] + err[:, 0]))
            minResm = minResd * 1440.
            maxResm = maxResd * 1440.

            ylab_l = "res [d]"
            ylab_r = "res [m]"
            #print xlab, ylab_l, ylab_r

            resname = "res_%d_%s" % (inb, letters[inb - 2])
            resPlot = gridOC.Add(
                'graph',
                name=resname,
                autoadd=False,
                leftMargin=lres,
                rightMargin=rres,
                topMargin=tres,
                bottomMargin=bres,
            )

            xname = 'x%d' % (inb)
            #x_res = xOC(resPlot, xname, xlab, minEpo, maxEpo, font, sizeLab, False, sizeTL)
            x_res = xOC(resPlot, xname, xlab, min_time, max_time, font,
                        sizeLab, False, sizeTL)
            xoc_list.append(x_res)

            yname = 'y%d_l' % (inb)
            y_l_res = yRES(resPlot, yname, ylab_l, 0., '0', sizeLab, minResd,
                           maxResd, lPos, uPos, font, sizeTL)

            xyname = "res_d_%s" % (letters[inb - 2])
            res_d = resPlot.Add(
                'xy',
                name=xyname,
                autoadd=False,
                xAxis=xname,
                yAxis=yname,
                PlotLine__hide=True,
                marker=markers[0],
                markerSize=sizeS,
                MarkerFill__color='blue',
                MarkerFill__hide=True,
                MarkerLine__color='blue',
                errorStyle='bar',
                ErrorBarLine__color='blue',
                ErrorBarLine__hideHorz=True,
                FillBelow__color='blue',
                FillBelow__hide=True,
                FillBelow__hideerror=False,
                FillAbove__color='blue',
            )
            #epoName = 'epo_' + letters[inb-2]
            #ocWin.SetData(epoName, epo)
            time_name = 'xtime_%s' % (letters[inb - 2])
            ocWin.SetData(time_name, t_obs_base)
            dataYname = "res_d_%s" % (letters[inb - 2])
            ocWin.SetData(dataYname, res[:, 0], symerr=err[:, 0])
            #res_d.xData.val = epoName
            res_d.xData.val = time_name
            res_d.yData.val = dataYname

            zeroLine = resPlot.Add(
                'function',
                name='zeroLine',
                autoadd=False,
                function='0.',
                Line__color='black',
                Line__style='solid',
                Line__width='0.5pt',
                xAxis=xname,
                yAxis=yname,
            )

            yname = 'y%d_r' % (inb)
            y_r_res = yRES(resPlot, yname, ylab_r, 1, '180', sizeLab, minResm,
                           maxResm, lPos, uPos, font, sizeTL)

            # print T0 residuals rms
            rms_oc = np.sqrt(np.mean(oc * oc, axis=0))
            rms_resT0 = np.sqrt(np.mean(res * res, axis=0))
            print 'rms(OC)obs = %.8f days = %.6f min = %.4f sec' % (
                rms_oc[0], rms_oc[1], rms_oc[2])
            print 'rms(OC)sim = %.8f days = %.6f min = %.4f sec' % (
                rms_oc[3], rms_oc[4], rms_oc[5])
            print 'rms(T0)    = %.8f days = %.6f min = %.4f sec' % (
                rms_resT0[0], rms_resT0[1], rms_resT0[2])
            print ''

        # set properly the xaxis of all the O-C and res plots
        min_time = float(np.min(min_max_time))
        max_time = float(np.max(min_max_time))
        print 'min time = %.5f max time = %.5f' % (min_time, max_time)
        for ii in range(len(xoc_list)):
            xoc_list[ii].min.val = min_time
            xoc_list[ii].max.val = max_time

    #if cli.RVset != '0':
    if (cli.RVset):
        if statRV:
            #print " Velocity of the system "
            #print " RV gamma = %.7f +/- %.7f" %(gamma[0], gamma[1])
            RVbkc = RV.copy()
            RV[:, 1] = RV[:, 1] - gamma[:, 0]
            RV[:, 4] = RV[:, 4] - gamma[:, 0]
            min0, max0 = lims((RV[:, 1] - RV[:, 2]), (RV[:, 1] + RV[:, 2]))
            minRV, maxRV = lims((min0, max0), RV[:, 4])
            # insert model RV from #_rotorbit.dat file
            jd_lte, RVmod, statMod = read_orbit(cli.full_path, cli.idsim,
                                                cli.lmflag)
            jd_lte_bck = jd_lte.copy()
            jd_lte = jd_lte - t_subtract
            jd = RV[:, 0] - t_subtract
            #minJD, maxJD = lims(jd, jd_lte)
            minJD, maxJD = lims(jd, jd)
            print " limits of BJD = ", minJD, maxJD
            minRV, maxRV = lims((minRV, maxRV), RVmod)
            #print minRV, maxRV
            dRV = RV[:, 1] - RV[:, 4]
            RV_rms = np.sqrt(np.mean(dRV * dRV))
            print ' RV summary '
            print ' RMS( RV_obs - RV_sim ) = %.7f m/s' % (RV_rms)
            print_gamma = np.zeros((nRV_set, 2))  # gamma, err_gamma
            print_gamma[0, :] = RV[0, 5:7]
            for i in range(1, nRV_set):
                for j in range(1, RV.shape[0]):
                    if (RV[j, 5] != RV[j - 1, 5]):
                        #print i,j,RV[j,5],RV[j-1,5]
                        print_gamma[i, :] = RV[j, 5:7]
            print 'gamma'.rjust(15), '+/-', 'err_gamma'.rjust(15)
            for i in range(0, nRV_set):
                print '%15.6f +/- %15.6f' % (print_gamma[i, 0], print_gamma[i,
                                                                            1])

            # RVplot
            RVname = 'RVPlot'
            RVPlot = gridOC.Add(
                'graph',
                name=RVname,
                autoadd=False,
                leftMargin=loc,
                rightMargin=roc,
                topMargin=toc,
                bottomMargin=boc,
            )

            if (t_subtract != 0.):
                xlab = "BJD_{TDB} - %.1f" % (t_subtract)
            else:
                xlab = "BJD_{TDB}"
            xname = 'x_rv'
            x_RV = xRV(RVPlot, xname, xlab, minJD, maxJD, font, sizeLab, True,
                       sizeTL)

            ylab = "RV [m/s]"
            yname = 'y_rv'
            y_RV = RVPlot.Add(
                'axis',
                name=yname,
                autoadd=False,
                label=ylab,
                direction='vertical',
                mode="numeric",
                autoExtend=False,
                autoExtendZero=False,
                otherPosition=0,
                Label__rotate=0.,
                Label__offset='0pt',
                log=False,
                #min = 'Auto',
                #max = 'Auto',
                min=minRV,
                max=maxRV,
                lowerPosition=lPos,
                upperPosition=uPos,
                autoMirror=True,
                Label__hide=False,
                Label__font=font,
                Label__size=sizeLab,
                Label__atEdge=True,
                TickLabels__size=sizeTL,
                TickLabels__font=font,
                MajorTicks__number=5,
                TickLabels__format="%.2f",
            )

            # plot with different colors and markers
            #xyname = 'obsRV'
            #xy_RVobs = RVPlot.Add('xy', name = xyname, autoadd = False,
            #xAxis = xname,
            #yAxis = yname,
            #PlotLine__hide = True,
            #marker = markers[0],
            #markerSize = sizeO,
            #MarkerFill__color = 'black',
            #MarkerFill__hide = False,
            #MarkerLine__color = 'black',
            #errorStyle = 'bar',
            #ErrorBarLine__color = 'black',
            #ErrorBarLine__hideHorz = True,
            #FillBelow__color = 'black',
            #FillBelow__hide = True,
            #FillBelow__hideerror = False,
            #FillAbove__color = 'black',
            #)
            #jdName = "jdRV"
            #ocWin.SetData(jdName, jd)
            #dataYname = "RVo"
            #ocWin.SetData(dataYname, RV[:,1], symerr = RV[:,2])
            #xy_RVobs.xData.val = jdName
            #xy_RVobs.yData.val = dataYname

            rv_colors = ['red', 'green', 'black', 'blue', 'yellow', 'cyan']
            rv_obs_size = '1.25pt'
            for i_set in range(0, nRV_set):
                jd_sel = jd[RV[:, 7] == i_set + 1]
                RVo_sel = RV[RV[:, 7] == i_set + 1, 1]
                eRVo_sel = RV[RV[:, 7] == i_set + 1, 2]
                xyname = 'obsRV_%03d' % (i_set + 1)
                label_key = "RVset#%02d" % (i_set + 1)
                xy_RVobs = RVPlot.Add('xy',
                                      name=xyname,
                                      autoadd=False,
                                      xAxis=xname,
                                      yAxis=yname,
                                      PlotLine__hide=True,
                                      marker=markers[i_set],
                                      markerSize=rv_obs_size,
                                      MarkerFill__color=rv_colors[i_set],
                                      MarkerFill__hide=False,
                                      MarkerLine__color='black',
                                      errorStyle='bar',
                                      ErrorBarLine__color='black',
                                      ErrorBarLine__hideHorz=True,
                                      FillBelow__color='black',
                                      FillBelow__hide=True,
                                      FillBelow__hideerror=False,
                                      FillAbove__color='black',
                                      key=label_key)
                jdName = "jdRV_%03d" % (i_set + 1)
                ocWin.SetData(jdName, jd_sel)
                dataYname = "RVo_%03d" % (i_set + 1)
                ocWin.SetData(dataYname, RVo_sel, symerr=eRVo_sel)
                xy_RVobs.xData.val = jdName
                xy_RVobs.yData.val = dataYname

            xyname = 'simRV'
            xy_RVsim = RVPlot.Add(
                'xy',
                name=xyname,
                autoadd=False,
                xAxis=xname,
                yAxis=yname,
                PlotLine__hide=True,
                marker=markers[0],
                markerSize=sizeS,
                MarkerFill__color='white',
                MarkerFill__hide=False,
                MarkerLine__color='blue',
            )
            jdName = "jdRV"
            ocWin.SetData(jdName, jd)
            dataYname = "RVs"
            ocWin.SetData(dataYname, RV[:, 4])
            xy_RVsim.xData.val = jdName
            xy_RVsim.yData.val = dataYname

            if (statMod):
                jdmod = jd_lte  # - 2454000.
                xyname = 'modRV'
                xy_modRV = RVPlot.Add(
                    'xy',
                    name=xyname,
                    autoadd=False,
                    xAxis=xname,
                    yAxis=yname,
                    PlotLine__hide=False,
                    PlotLine__color='blue',
                    #PlotLine__color = '#33ADFF',
                    #PlotLine__color = '#B2B2B2',
                    PlotLine__width='1pt',
                    PlotLine__style='dot1',
                    marker='none',
                    key="RV model")
                jdName = "jdMod"
                ocWin.SetData(jdName, jdmod)
                dataYname = "RVmod"
                ocWin.SetData(dataYname, RVmod)
                xy_modRV.xData.val = jdName
                xy_modRV.yData.val = dataYname

            else:
                print "I did not find the orbit file to plot RV model. Skipping."

            #if(rv_samples is not None):
            if (samples is not None):
                print '\nPlotting rv samples ... it would take some time ...',
                plot_rv_samples(ocWin,
                                RVPlot,
                                xname,
                                yname,
                                samples,
                                t_subtract=t_subtract,
                                t_rv_min=minJD,
                                t_rv_max=maxJD)
                print 'done'

            legend = RVPlot.Add(
                'key',
                name='legendRV',
                autoadd=False,
                #Text__font ='URW Palladio L',
                #Text__size = '8pt',
                Text__font=font,
                Text__size='6pt',
                Background__color='white',
                Background__hide=True,
                Border__hide=True,
                horzPosn='manual',
                vertPosn='manual',
                keyLength='0.25cm',
                keyAlign='centre',
                #horzManual = 1.0025,
                horzManual=0.955,
                #vertManual = -0.7,
                #vertManual = 0.8,
                vertManual=-0.9,
                marginSize=0.,
                columns=1,
                symbolswap=True,
            )

            zeroLine = RVPlot.Add(
                'function',
                name='zeroLine',
                autoadd=False,
                function='0.',
                Line__color='black',
                Line__style='solid',
                Line__width='0.5pt',
                xAxis=xname,
                yAxis=yname,
            )

            # RVresiduals

            resRV = RV[:, 1] - RV[:, 4]
            minRVres, maxRVres = lims((resRV - RV[:, 2]), (resRV + RV[:, 2]))

            resname = "res_RV"
            resRVplot = gridOC.Add(
                'graph',
                name=resname,
                autoadd=False,
                leftMargin=lres,
                rightMargin=rres,
                topMargin=tres,
                bottomMargin=bres,
            )

            xname = 'x_RVres'
            x_RVres = xOC(resRVplot, xname, xlab, minJD, maxJD, font, sizeLab,
                          False, sizeTL)

            ylab = "res [m/s]"
            yname = 'y_RVres'
            y_RVres = resRVplot.Add(
                'axis',
                name=yname,
                autoadd=False,
                label=ylab,
                direction='vertical',
                mode="numeric",
                autoExtend=False,
                autoExtendZero=False,
                otherPosition=0,
                Label__rotate=0.,
                Label__offset='0pt',
                log=False,
                min=minRVres,
                max=maxRVres,
                lowerPosition=lPos,
                upperPosition=uPos,
                autoMirror=True,
                Label__hide=False,
                Label__font=font,
                Label__size=sizeLab,
                Label__atEdge=True,
                TickLabels__size=sizeTL,
                TickLabels__format="%.2f",
                MajorTicks__number=3,
                MinorTicks__hide=True,
            )

            xyname = "res_RV"
            res_RV = resRVplot.Add(
                'xy',
                name=xyname,
                autoadd=False,
                xAxis=xname,
                yAxis=yname,
                PlotLine__hide=True,
                marker=markers[0],
                markerSize=sizeS,
                MarkerFill__color='blue',
                MarkerFill__hide=True,
                MarkerLine__color='blue',
                errorStyle='bar',
                ErrorBarLine__color='blue',
                ErrorBarLine__hideHorz=True,
                FillBelow__color='blue',
                FillBelow__hide=True,
                FillBelow__hideerror=False,
                FillAbove__color='blue',
            )
            jdName = "jdRV"
            ocWin.SetData(jdName, jd)
            dataYname = "res_RV"
            ocWin.SetData(dataYname, resRV, symerr=RV[:, 2])
            res_RV.xData.val = jdName
            res_RV.yData.val = dataYname

            zeroLine = resRVplot.Add(
                'function',
                name='zeroLine',
                autoadd=False,
                function='0.',
                Line__color='black',
                Line__style='solid',
                Line__width='0.5pt',
                xAxis=xname,
                yAxis=yname,
            )

    # ---------
    # save plot
    s_nbIF = "_%d-%d" % (cli.nbI, cli.nbF)
    plotFolder = os.path.join(cli.full_path, "plots")
    if not os.path.isdir(plotFolder):
        createDir = "mkdir -p " + plotFolder
        os.system(createDir)
    fveusz = os.path.join(plotFolder,
                          '%d_%d_oc%s' % (cli.idsim, cli.lmflag, s_nbIF))
    print '\nSaving vsz file ...',
    ocWin.Save(fveusz + ".vsz")
    print 'done.\nSaving eps file ...',
    ocWin.Export(fveusz + ".eps")
    print 'done.\nSaving pdf file ...',
    ocWin.Export(fveusz + ".pdf")
    print 'done.\nSaving png150dpi file ...',
    ocWin.Export(fveusz + "_150dpi.png",
                 dpi=150,
                 antialias=True,
                 quality=100,
                 backcolor='white')
    print 'done.\nSaving png300dpi file ...',
    ocWin.Export(fveusz + "_300dpi.png",
                 dpi=300,
                 antialias=True,
                 quality=100,
                 backcolor='white')
    print 'done.\nSaving svg file ...',
    ocWin.Export(fveusz + ".svg")
    print 'done.'
    ocWin.Close()

    return
Example #8
0
def plotFunc(inpath="./", outpath="./"):
    font = "Times New Roman"
    colors = [u'blue', u'green']
    xmin = ["auto", "auto"]
    xmax = ["auto", "auto"]
    ymin = ["auto", 0]
    ymax = ["auto", "auto"]

    xData = np.arange(100)
    yData = np.random.randint(0, 100, size=100) + np.sin(np.arange(100))

    doc = ve.Embedded("doc_1")
    page = doc.Root.Add('page', width='30cm', height='15cm')
    grid = page.Add('grid',
                    autoadd=False,
                    rows=1,
                    columns=2,
                    scaleRows=[0.2],
                    topMargin='1cm',
                    bottomMargin='1cm')
    graphList = []

    graphList.append(
        grid.Add(
            'graph',
            name="scatter",
            autoadd=False,
            hide=False,
            Border__width='2pt',
            leftMargin='0.6cm',
            rightMargin='0.4cm',
            topMargin='0.5cm',
            bottomMargin='1cm',
        ))

    graphList.append(
        grid.Add(
            'graph',
            name="hist",
            autoadd=False,
            hide=False,
            Border__width='2pt',
            leftMargin='2cm',
            rightMargin='0.4cm',
            topMargin='0.5cm',
            bottomMargin='1cm',
        ))

    for i in range(len(graphList)):
        graphList[i].Add('axis',
                         name='x',
                         label="x",
                         min=xmin[i],
                         max=xmax[i],
                         log=False,
                         Label__size='25pt',
                         Label__font=font,
                         TickLabels__size='17pt',
                         TickLabels__format=u'Auto',
                         MajorTicks__width='2pt',
                         MajorTicks__length='10pt',
                         MinorTicks__width='1pt',
                         MinorTicks__length='6pt')
        graphList[i].Add('axis',
                         name='y',
                         label="y",
                         direction='vertical',
                         min=ymin[i],
                         max=ymax[i],
                         log=False,
                         autoRange=u'+5%',
                         Label__size='25pt',
                         Label__font=font,
                         TickLabels__size='20pt',
                         TickLabels__format=u'Auto',
                         MajorTicks__width='2pt',
                         MajorTicks__length='10pt',
                         MinorTicks__width='1pt',
                         MinorTicks__length='6pt')

    graphList[0].Add(
        'xy',
        key="scatterPlotKey",
        name='scatterPlotName',
        marker=u'circle',
        MarkerFill__color=colors[0],
        markerSize=u'3pt',
    )

    xDataName = "xScatterData"
    yDataName = "yScatterData"
    doc.SetData(xDataName, xData)
    doc.SetData(yDataName, yData)
    graphList[0].scatterPlotName.xData.val = xDataName
    graphList[0].scatterPlotName.yData.val = yDataName

    counts, bin_edges = sm_hist2(yData, delta=5)

    graphList[1].Add(
        'xy',
        key="histPlotKey",
        name='histPlotName',
        xData=bin_edges,
        yData=counts,
        marker='none',
        PlotLine__steps=u'left',
        PlotLine__color=colors[1],
        PlotLine__style=u"solid",
        PlotLine__width=u'3',
        FillBelow__color=colors[1],
        FillBelow__style="forward 2",
        FillBelow__hide=False,
        FillBelow__transparency=70,
        #FillBelow__backtransparency = 50,
        FillBelow__linewidth='1pt',
        FillBelow__linestyle='solid',
        FillBelow__backcolor="white",
        FillBelow__backhide=True,
        Label__posnHorz='right',
        Label__size='14pt',
        Label__color='black')

    histKey = graphList[1].Add('key',
                               autoadd=False,
                               horzPosn='right',
                               vertPosn='top',
                               Text__font=font,
                               Text__size='15',
                               Border__width='1.5pt')

    end = raw_input("Press any key to finish...")

    doc.Save("example.vsz")
    doc.Export("example.png", backcolor='#ffffff')
    doc.Export("example.pdf")