示例#1
0
def main():

    # PROGRAM START TIME + DATE STAMPS
    t0 = time.time()
    d0 = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())

    # PARSE COMMAND LINE ARGUMENTS
    _doc_fmt = [__version__]
    args = core.docopt(__doc__.format(*_doc_fmt), version=__version__)

    log.info("CRIRES+ Forward Simulator (CRIForS) v%s", __version__)
    log.info("Start time: %s", d0)

    # INITIALIZE INSTRUMENT
    instrument = core.Instrument(args)

    # INITIALIZE SIMULATION
    simulator = core.Simulator(instrument)

    # RUN SIMULATION
    simulator.run()

    # SPREAD OUT EACH RAY
    if args["--spread"]:
        simulator.spreadout()

    # ADD NOISE
    if args["--noise"]:
        core.add_noise(simulator)

    if args["--plot"]:
        log.info("Opening plot...")
        import matplotlib.pyplot as plt
        import matplotlib.gridspec as gridspec
        fig = plt.figure("CRIRES+ Simulation results")
        gs = gridspec.GridSpec(2, 1)
        ax1 = plt.subplot(gs[0])
        ax2 = plt.subplot(gs[1])
        ax1.imshow(simulator.outarr, origin="lower", interpolation='nearest', cmap="hot")
        ax2.plot(simulator.source_spectrum[0], simulator.source_spectrum[1])
        ax2.set_xlabel("Wavelength (nm)")
        ax2.set_ylabel("PDF")
        plt.tight_layout()
        plt.show()
    t1 = time.time()
    d1 = time.strftime("%Y-%m-%d_%H.%M.%S", time.gmtime())
    log.info("End time: %s", d1)
    log.info("Run time: %.1f s", t1-t0)

    # WRITE TO FITS FILE
    core.write_to_fits(simulator)

    # SPAWN FITS OUTPUT IMAGE IN SAO-DS9
    if args["--ds9"]:
        if os.path.isfile(simulator.outpath + ".fits.gz"):
            shell_call = "ds9 %s.fits.gz" % simulator.outpath
        elif os.path.isfile(simulator.outpath + ".fits"):
            shell_call = "ds9 %s.fits" % simulator.outpath
        try:
            log.info("Executing '%s'", shell_call)
            subprocess.check_call(shell_call.split())
        except OSError, e:
            log.error(e, exc_info=False)
            log.info("Shell call failed. Just run the following line:", exc_info=False)
            log.info(shell_call, exc_info=False)
示例#2
0
def main():

    # PROGRAM START TIME + DATE STAMPS
    t0 = time.time()
    d0 = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())

    # PARSE COMMAND LINE ARGUMENTS
    _doc_fmt = [__version__]
    args = core.docopt(__doc__.format(*_doc_fmt), version=__version__)

    log.info("CRIRES+ Forward Simulator (CRIForS) v%s", __version__)
    log.info("Start time: %s", d0)

    # INITIALIZE INSTRUMENT
    instrument = core.Instrument(args)

    # INITIALIZE SIMULATION
    simulator = core.Simulator(instrument)

    # RUN SIMULATION
    simulator.run()

    # SPREAD OUT EACH RAY
    if args["--spread"]:
        simulator.spreadout()

    # ADD NOISE
    if args["--noise"]:
        core.noise.add_noise(simulator)

    t1 = time.time()
    d1 = time.strftime("%Y-%m-%d_%H.%M.%S", time.gmtime())
    log.info("End time: %s", d1)
    log.info("Run time: %.1f s", t1-t0)

    if args["--plot"]:
        log.info("Opening plot...")
        import matplotlib.pyplot as plt
        import matplotlib.gridspec as gridspec
        fig = plt.figure("CRIRES+ Simulation results")
        gs = gridspec.GridSpec(2, 1)
        ax1 = plt.subplot(gs[0])
        ax2 = plt.subplot(gs[1])
        if (simulator.wavemap==True):
            im= ax1.imshow(simulator.outwaves, origin="lower", interpolation='nearest', cmap="hot",
            vmin=simulator.det_wl_lim.min(), vmax=simulator.det_wl_lim.max())
            from mpl_toolkits.axes_grid1 import make_axes_locatable		# Tool to get axes to colorbar
            divider=make_axes_locatable(ax1)
            cax=divider.append_axes("right", size="5%", pad=0.05)		# Places colorbar next to image with 'nice' size
            plt.colorbar(im, ax=ax1, cax=cax) # orientation='horizontal' (remove cax if horizontal bar is desired)
            ax1.set_title("CRIRES+ %s-band, echang=%s, Wavemap" % (simulator.band, simulator.echang))
        else:
            ax1.imshow(simulator.outarr, origin="lower", interpolation='nearest', cmap="hot")
            ax1.set_title("CRIRES+ %s-band, echang=%s" % (simulator.band, simulator.echang))
        ax2.plot(simulator.source_spectrum[0], simulator.source_spectrum[1])
        ax2.set_color_cycle(['yellow', 'gold','goldenrod','orange', 'darkorange', 'OrangeRed',
         'red', 'crimson', 'maroon', 'black',])
        for mwaves,mpdf in simulator.mwaves_mpdfs:
            ax2.plot(mwaves,mpdf)
        ax2.set_xlabel("Wavelength (nm)")
        ax2.set_ylabel("PDF")
        #ax2.set_title("PHOENIX model, Teff=3000K, log(g)=5.0, [M/H]=0.0")
        plt.tight_layout()
        plt.show()

    else:
        # WRITE TO FITS FILE
        core.write_to_fits(simulator)

    # SPAWN FITS OUTPUT IMAGE IN SAO-DS9
    if args["--ds9"]:
        if os.path.isfile(simulator.outpath + ".fits.gz"):
            shell_call = "ds9 %s.fits.gz" % simulator.outpath
        elif os.path.isfile(simulator.outpath + ".fits"):
            shell_call = "ds9 %s.fits" % simulator.outpath
        try:
            log.info("Executing '%s'", shell_call)
            subprocess.check_call(shell_call.split())
        except OSError, e:
            log.error(e, exc_info=False)
            log.info("Shell call failed. Just run the following line:", exc_info=False)
            log.info(shell_call, exc_info=False)