def main(args):
    with open(os.path.join(os.path.dirname(__file__),
        'precisiondata.cpickle')) as filedata:
        exptimes, crosspoints, satpoints = pickle.load(filedata)

    x_range = [9, 14]

    interpcross = interp1d(exptimes, crosspoints, kind='linear')
    interpsat = interp1d(exptimes, satpoints, kind='linear')


    N = 5
    colours = np.arange(2, 2 + N, 1)
    exptimes = np.arange(1, N + 1) * 10
    if args.besancon:
        all_vmags = get_besancon_mag_data()
        yhigh = 0.3
        title = 'Besancon'
    else:
        all_vmags = get_nomad_mag_data()
        yhigh = 0.4
        title = 'NOMAD'

    ytot = yhigh * len(all_vmags)


    with pgh.open_plot(args.output):

        pg.pgvstd()


        pg.pgswin(x_range[0], x_range[1], 0, yhigh)
        for exptime, colour in zip(exptimes, colours):
            satpoint = interpsat(exptime)
            crosspoint = interpcross(exptime)

            selected = all_vmags[(all_vmags > satpoint) & (all_vmags <=
                crosspoint)]
            print(exptime, len(selected))


            xdata, ydata = cumulative_hist(np.array(selected),
                    min_val=x_range[0], max_val=x_range[1], norm=len(all_vmags))
            ydata /= float(len(all_vmags))

            with pgh.change_colour(colour):
                pg.pgbin(xdata, ydata, False)


        pg.pgbox('bcnst', 0, 0, 'bcnst', 0, 0)
        pg.pglab(r'V magnitude', 'High precision fraction', title)
        # Label the right hand side
        pg.pgswin(x_range[0], x_range[1], 0, ytot)
        pg.pgbox('', 0, 0, 'smt', 0, 0)
        pg.pgmtxt('r', 2., 0.5, 0.5, 'N')

        # Create the legend
        pg.pgsvp(0.7, 0.9, 0.1, 0.3)
        pg.pgswin(0., 1., 0., 1.)

        for i, (exptime, colour) in enumerate(zip(exptimes, colours)):
            yval = 0.1 + 0.8 * i / len(exptimes)

            with pgh.change_colour(colour):
                pg.pgline(np.array([0.2, 0.4]), np.ones(2) * yval)

            pg.pgtext(0.5, yval, r'{:d} s'.format(exptime))
示例#2
0
    def run(self):
        '''
        Main function
        '''
        radius = 3.5  # Radius of flux extraction aperture
        npix = np.pi * radius ** 2
        detector = ae.WASPDetector()
        extinction = 0.08
        targettime = self.args.totaltime
        height = 2400.
        apsize = 0.111
        airmass = 1.
        readnoise = ReadNoise
        #zp = srw.ZP(1.)
        #zp = 15  # from RGW
        zp = 18.545

        if self.args.skylevel == "dark": skypersecperpix = 18.
        elif self.args.skylevel == "bright": skypersecperpix = 18.


        for mag in self.mag:
            errob = ae.ErrorContribution(mag, npix, detector.readTime(),
                    extinction, targettime, height, apsize, zp, readnoise)
            self.source.append(errob.sourceError(airmass, self.exptime))
            self.sky.append(errob.skyError(airmass, self.exptime,
                skypersecperpix))
            self.read.append(errob.readError(airmass, self.exptime))
            self.scin.append(errob.scintillationError(airmass, self.exptime))
            self.total.append(errob.totalError(airmass, self.exptime,
                skypersecperpix))

        self.source = np.log10(self.source)
        self.sky = np.log10(self.sky)
        self.read = np.log10(self.read)
        self.scin = np.log10(self.scin)
        self.total = np.log10(self.total)

        pgopen(self.args.device)
        pgvstd()
        pgswin(self.plotLimits[0], self.plotLimits[1], self.plotLimits[2],
                self.plotLimits[3])

        if self.args.plotwasp: self.plotWASPData()
        if self.args.plotngts: self.plotNGTSData()

        #if self.args.satlimit: self.saturationLimit()

        # Draw the 1mmag line
        #pgsls(2)
        #pgsci(15)
        #pgline(np.array([self.mag.max(), self.mag.min()]),
                #np.array([-3., -3.]))
        #pgsci(1)
        #pgsls(1)


        # Plot a line at the point when the total error meets
        # the 1mmag line
        #distFrom1mmag = np.abs(self.total + 3.)
        #ind = distFrom1mmag==distFrom1mmag.min()
        #self.crossPoint = self.mag[ind][0]


        #pgsls(2)
        #pgsci(15)
        #pgline(np.array([self.crossPoint, self.crossPoint]),
                #np.array([-6, -1])
                #)
        #pgsci(1)
        #pgsls(1)



        #pglab(r"V magnitude", "Fractional error", r"t\de\u: %.1f s, "
                #"t\dI\u: %.1f hours, sky: %s, 1mmag @ %.3f mag" % (
                    #self.exptime, targettime/3600., self.args.skylevel,
                    #self.crossPoint))
        pglab(r'V magnitude', r'Fractional error', r'')

        # Draw the lines
        with pgh.change_colour(COLOURS['read']):
            pgline(self.mag, self.read)
        with pgh.change_colour(COLOURS['sky']):
            pgline(self.mag, self.sky)
        with pgh.change_colour(COLOURS['source']):
            pgline(self.mag, self.source)
        with pgh.change_colour(COLOURS['scin']):
            pgline(self.mag, self.scin)
        with pgh.change_colour(COLOURS['total']):
            pgline(self.mag, self.total)
        pgbox('bcnst', 0, 0, 'bcnstl', 0, 0)

        # Create the legend
        pgsvp(0.08, 0.35, 0.12, 0.32)
        pgswin(0, 1, 0, 1)
        #pgbox('bcnst', 0, 0, 'bcnst', 0, 0)
        yinc = 0.8 / 5.
        ylevel = 0.1
        line_data = np.array([0.2, 0.4])

        for i, (key, label) in enumerate([
            ('scin', 'Scintillation'),
            ('read', 'Read'),
            ('sky', 'Sky'),
            ('source', 'Source'),
            ('total', 'Total')]):
            with pgh.change_colour(COLOURS[key]):
                ylevel = 0.1 + i * yinc
                pgline(line_data,
                        np.array([ylevel, ylevel])
                        )
            pgtext(0.5, ylevel, label)

        pgclos()

        if self.args.verbose:
            if self.darkLimit:
                print "SATLEVEL DARK: %f" % self.darkLimit

            if self.brightLimit:
                print "SATLEVEL BRIGHT: %f" % self.brightLimit

            print "CROSSPOINT: %f" % self.crossPoint