Ejemplo n.º 1
0
    def load_from_smart(cls, radpath, name=None):
        # Read-in .rad file
        wlhr, wno, solar_spec, TOA_flux, rad_streams = readsmart.rad(
            radfile, getdata=True)

        # Calculate Hi-res reflectivity spectrum
        Ahr = (TOA_flux / solar_spec)  #* np.pi / planet.Phi
Ejemplo n.º 2
0
def smart_observation(radfile,
                      itime,
                      telescope,
                      planet,
                      star,
                      ref_lam=0.55,
                      tag='',
                      plot=True,
                      saveplot=False,
                      savedata=False):
    """Uses coronagraph noise model to create an observation of high resolution SMART output.

    Parameters
    ----------
    radfile : string
        Location and name of file to be read in
    itime : float
        Integration time (hours)
    telescope : Telescope
        Telescope object
    planet : Planet
        Planet object
    star : Star
        Star object
    tag : string
        ID for output files
    plot : boolean
        Set to True to make plot
    saveplot : boolean
        Set to True to save the plot as a PDF
    savedata : boolean
        Set to True to save data file of observation

    Returns
    ----------
    lam : array
        Wavelength grid of observed spectrum
    spec : array
        Albedo grid of observed spectrum
    sig : array
        One sigma errorbars on albedo spectrum
    rwl : array
        Wavelength grid of SMART output
    Ahr : array
        Albedo grid of SMART output

    Output
    ---------
    If saveplot=True then plot will be saved
    If savedata=True then data will be saved
    """

    # Read-in .rad file
    wlhr, wno, solar_spec, TOA_flux, rad_streams = readsmart.rad(radfile,
                                                                 getdata=True)

    # Calculate Hi-res reflectivity spectrum
    Ahr = (TOA_flux / solar_spec)  #* np.pi / planet.Phi

    # Possibly convolve with gaussian?

    # Skip call_noise and just call: noise
    lam, dlam, A, q, Cratio, cp, csp, cz, cez, cD, cR, cth, DtSNR = \
        make_noise(Ahr, wlhr, solar_spec, telescope, planet, star, wantsnr=10.0, COMPUTE_LAM=True)

    # Calculate background photon count rate
    cb = (cz + cez + csp + cD + cR + cth)

    # Calculate the SNR of observation
    time = itime * 3600.  # Convert hours to seconds
    #SNR = calc_SNR(time, cp, cb)

    # Generate noisy spectrum by drawing data points from a normal distribution
    #spec, sig = draw_noisy_spec(A, SNR)

    # Calculate SNR, sigma, and noised-up spectrum
    spec, sig, SNR = process_noise(time, Cratio, cp, cb)

    if plot:

        # Set string for plot text
        if itime > 2.0:
            timestr = "{:.0f}".format(itime) + ' hours'
        else:
            timestr = "{:.0f}".format(itime * 60) + ' mins'
        plot_text = r'Distance = '+"{:.1f}".format(planet.distance)+' pc'+\
        '\n Integration time = '+timestr

        # If a reference wavelength is specified then return the SNR at that wl
        # corresponding to the integration time given
        if ref_lam:
            ireflam = find_nearest(lam, ref_lam)
            ref_SNR = SNR[ireflam]
            plot_text = plot_text + '\n SNR = '+"{:.1f}".format(ref_SNR)+\
                ' at '+"{:.2f}".format(lam[ireflam])+r' $\mu$m'

        # Plot observed spectrum; save pdf if saveplot=True
        lammin, lammax = np.min(lam) - 0.1, np.max(lam) + 0.1
        Amin, Amax = np.min(A) - np.max(sig) * 1.1, np.max(
            A) + np.max(sig) * 1.1
        tmin = np.min(Ahr[(wlhr > lammin) & (wlhr < lammax)])
        tmax = np.max(Ahr[(wlhr > lammin) & (wlhr < lammax)])
        if tmin < Amin: Amin = tmin
        if tmax > Amax: Amax = tmax
        #ymin,ymax = np.min(A), np.max(A)
        plot_tag = 'observed_smart_' + tag + '.pdf'
        fig = plt.figure(figsize=(15, 10))
        gs = gridspec.GridSpec(1, 1)
        ax0 = plt.subplot(gs[0])
        ax0.plot(wlhr, Ahr, alpha=0.5, c='k')
        if telescope.mode != 'Imaging':
            ax0.plot(lam,
                     A,
                     alpha=0.7,
                     color='orange',
                     drawstyle='steps-mid',
                     lw=2.0)
        else:
            ax0.plot(lam, A, 'o', alpha=0.7, color='orange', ms=10.0)
            telescope.filter_wheel.plot(ax=ax0)
        ax0.errorbar(lam, spec, yerr=sig, fmt='o', color='k', ms=10.0)
        ax0.set_ylabel('Fp/Fs')
        ax0.set_xlabel('Wavelength [$\mu$m]')
        ax0.set_xlim([lammin, lammax])
        ax0.set_ylim([Amin, Amax])
        #ax0.set_ylim([-0.01,ymax+0.1])
        #ax0.set_ylim([-0.01,1.01])
        ax0.text(0.99, 0.99, plot_text,\
             verticalalignment='top', horizontalalignment='right',\
             transform=ax0.transAxes,\
             color='black', fontsize=20)
        # Save plot if saveplot==True
        if saveplot:
            fig.savefig(plot_tag)
            print 'Saved: ' + plot_tag
        fig.show()

    # Save Synthetic data file (wavelength, albedo, error) if savedata=True
    if savedata:
        data_tag = 'observed_smart_' + tag + '.txt'
        y_sav = np.array([lam, spec, sig])
        np.savetxt(data_tag, y_sav.T)
        print 'Saved: ' + data_tag

    # Return Synthetic data and high-res spec

    return lam, spec, sig, wlhr, Ahr
Ejemplo n.º 3
0
def smart_observation(radfile, itime, telescope, planet, star,
                         ref_lam=0.55, tag='', plot=True, saveplot=False, savedata=False):
    """Uses coronagraph noise model to create an observation of high resolution SMART output.

    Parameters
    ----------
    radfile : string
        Location and name of file to be read in
    itime : float
        Integration time (hours)
    telescope : Telescope
        Telescope object
    planet : Planet
        Planet object
    star : Star
        Star object
    tag : string
        ID for output files
    plot : boolean
        Set to True to make plot
    saveplot : boolean
        Set to True to save the plot as a PDF
    savedata : boolean
        Set to True to save data file of observation

    Returns
    ----------
    lam : array
        Wavelength grid of observed spectrum
    spec : array
        Albedo grid of observed spectrum
    sig : array
        One sigma errorbars on albedo spectrum
    rwl : array
        Wavelength grid of SMART output
    Ahr : array
        Albedo grid of SMART output

    Output
    ---------
    If saveplot=True then plot will be saved
    If savedata=True then data will be saved
    """

    # Read-in .rad file
    wlhr, wno, solar_spec, TOA_flux, rad_streams = readsmart.rad(radfile,getdata=True)

    # Calculate Hi-res reflectivity spectrum
    Ahr = (TOA_flux / solar_spec) #* np.pi / planet.Phi

    # Possibly convolve with gaussian?

    # Skip call_noise and just call: noise
    lam, dlam, A, q, Cratio, cp, csp, cz, cez, cD, cR, cth, DtSNR = \
        make_noise(Ahr, wlhr, solar_spec, telescope, planet, star, wantsnr=10.0, COMPUTE_LAM=True)

    # Calculate background photon count rate
    cb = (cz + cez + csp + cD + cR + cth)

    # Calculate the SNR of observation
    time = itime * 3600. # Convert hours to seconds
    #SNR = calc_SNR(time, cp, cb)

    # Generate noisy spectrum by drawing data points from a normal distribution
    #spec, sig = draw_noisy_spec(A, SNR)

    # Calculate SNR, sigma, and noised-up spectrum
    spec, sig, SNR = process_noise(time, Cratio, cp, cb)

    if plot:

        # Set string for plot text
        if itime > 2.0:
            timestr = "{:.0f}".format(itime)+' hours'
        else:
            timestr = "{:.0f}".format(itime*60)+' mins'
        plot_text = r'Distance = '+"{:.1f}".format(planet.distance)+' pc'+\
        '\n Integration time = '+timestr

        # If a reference wavelength is specified then return the SNR at that wl
        # corresponding to the integration time given
        if ref_lam:
            ireflam = find_nearest(lam,ref_lam)
            ref_SNR = SNR[ireflam]
            plot_text = plot_text + '\n SNR = '+"{:.1f}".format(ref_SNR)+\
                ' at '+"{:.2f}".format(lam[ireflam])+r' $\mu$m'

        # Plot observed spectrum; save pdf if saveplot=True
        lammin,lammax = np.min(lam)-0.1, np.max(lam)+0.1
        Amin, Amax = np.min(A)-np.max(sig)*1.1, np.max(A)+np.max(sig)*1.1
        tmin = np.min(Ahr[(wlhr > lammin) & (wlhr < lammax)])
        tmax = np.max(Ahr[(wlhr > lammin) & (wlhr < lammax)])
        if tmin < Amin: Amin = tmin
        if tmax > Amax: Amax = tmax
        #ymin,ymax = np.min(A), np.max(A)
        plot_tag = 'observed_smart_'+tag+'.pdf'
        fig = plt.figure(figsize=(15,10))
        gs = gridspec.GridSpec(1, 1)
        ax0 = plt.subplot(gs[0])
        ax0.plot(wlhr, Ahr, alpha=0.5, c='k')
        if telescope.mode != 'Imaging':
            ax0.plot(lam, A, alpha=0.7, color='orange', drawstyle='steps-mid', lw=2.0)
        else:
            ax0.plot(lam, A, 'o', alpha=0.7, color='orange', ms = 10.0)
            telescope.filter_wheel.plot(ax=ax0)
        ax0.errorbar(lam, spec, yerr=sig, fmt='o', color='k', ms=10.0)
        ax0.set_ylabel('Fp/Fs')
        ax0.set_xlabel('Wavelength [$\mu$m]')
        ax0.set_xlim([lammin,lammax])
        ax0.set_ylim([Amin, Amax])
        #ax0.set_ylim([-0.01,ymax+0.1])
        #ax0.set_ylim([-0.01,1.01])
        ax0.text(0.99, 0.99, plot_text,\
             verticalalignment='top', horizontalalignment='right',\
             transform=ax0.transAxes,\
             color='black', fontsize=20)
        # Save plot if saveplot==True
        if saveplot:
            fig.savefig(plot_tag)
            print 'Saved: '+plot_tag
        fig.show()

    # Save Synthetic data file (wavelength, albedo, error) if savedata=True
    if savedata:
        data_tag = 'observed_smart_'+tag+'.txt'
        y_sav = np.array([lam,spec,sig])
        np.savetxt(data_tag, y_sav.T)
        print 'Saved: '+data_tag

    # Return Synthetic data and high-res spec

    return lam, spec, sig, wlhr, Ahr
Ejemplo n.º 4
0
    def load_from_smart(cls, radpath, name=None):
        # Read-in .rad file
        wlhr, wno, solar_spec, TOA_flux, rad_streams = readsmart.rad(radfile,getdata=True)

        # Calculate Hi-res reflectivity spectrum
        Ahr = (TOA_flux / solar_spec) #* np.pi / planet.Phi
Ejemplo n.º 5
0
    def from_file(cls, path):

        # Read path file
        if path.endswith(".rad"):
            # Read rad
            wavelength, wavenumber, star_flux, toa_flux, rad_streams = rs.rad(
                path)
            geo_albedo = toa_flux / star_flux
            tmp = np.chararray(len(wavelength), itemsize=1)
            tmp[:] = ""
            flux_transmission, absorbing_radius, tdepth = tmp, tmp, tmp
        elif path.endswith(".tran"):
            # Read tran
            wavelength, flux_transmission, absorbing_radius = rs.tran(path)
            tmp = np.chararray(len(wavelength), itemsize=1)
            tmp[:] = ""
            wavenumber, toa_flux, star_flux, geo_albedo, tdepth = tmp, tmp, tmp, tmp, tmp
        elif path.endswith(".trnst"):
            # Read trnst
            wavelength, wavenumber, absorbing_radius, tdepth = rs.trnst(path)
            tmp = np.chararray(len(wavelength), itemsize=1)
            tmp[:] = ""
            toa_flux, star_flux, geo_albedo, flux_transmission = tmp, tmp, tmp, tmp
        elif path.endswith("data.txt"):
            # Read dat file from Will/Shawn's version
            dat = np.genfromtxt(path, skip_header=8)
            # Parse
            wavelength = dat[:, 0]
            wavenumber = dat[:, 1]
            star_flux = dat[:, 2]
            toa_flux = dat[:, 3]
            geo_albedo = dat[:, 4]
            # Fill transit arrays with empty strings
            tmp = np.chararray(len(wavelength), itemsize=1)
            tmp[:] = ""
            flux_transmission, absorbing_radius, tdepth = tmp, tmp, tmp
        elif path.endswith(".flx"):
            # Read dat file from Will/Shawn's version
            dat = np.genfromtxt(path, skip_header=8)
            # Parse
            wavelength = dat[:, 0]
            wavenumber = dat[:, 1]
            star_flux = dat[:, 2]
            toa_flux = dat[:, 3]
            geo_albedo = dat[:, 4]
            # Fill transit arrays with empty strings
            tmp = np.chararray(len(wavelength), itemsize=1)
            tmp[:] = ""
            flux_transmission, absorbing_radius, tdepth = tmp, tmp, tmp
        elif path.endswith(".trn"):
            # Read dat file from Will/Shawn's version
            dat = np.genfromtxt(path, skip_header=8)
            # Parse
            wavelength = dat[:, 0]
            absorbing_radius = dat[:, 1]
            tdepth = dat[:, 2]
            # Fill transit arrays with empty strings
            tmp = np.chararray(len(wavelength), itemsize=1)
            tmp[:] = ""
            toa_flux, star_flux, geo_albedo, flux_transmission, wavenumber = tmp, tmp, tmp, tmp, tmp
        else:
            print "%s is an invalid path." % path

        # Return new class instance
        return cls(wavelength=wavelength,
                   wavenumber=wavenumber,
                   toa_flux=toa_flux,
                   star_flux=star_flux,
                   geo_albedo=geo_albedo,
                   flux_transmission=flux_transmission,
                   absorbing_radius=absorbing_radius,
                   tdepth=tdepth)
Ejemplo n.º 6
0
def smart_observation(radfile, itime, telescope, planet, star,
                         ref_lam=0.55, tag='', plot=True, saveplot=False, savedata=False,
                         THERMAL=False, wantsnr=10.):
    """Uses coronagraph noise model to create an observation of high resolution SMART output.

    Parameters
    ----------
    radfile : string
        Location and name of file to be read in
    itime : float
        Integration time (hours)
    telescope : Telescope
        Telescope object
    planet : Planet
        Planet object
    star : Star
        Star object
    tag : string
        ID for output files
    plot : boolean
        Set to True to make plot
    saveplot : boolean
        Set to True to save the plot as a PDF
    savedata : boolean
        Set to True to save data file of observation

    Returns
    ----------
    lam : array
        Wavelength grid of observed spectrum
    spec : array
        Albedo grid of observed spectrum
    sig : array
        One sigma errorbars on albedo spectrum
    rwl : array
        Wavelength grid of SMART output
    Ahr : array
        Albedo grid of SMART output

    Output
    ---------
    If saveplot=True then plot will be saved
    If savedata=True then data will be saved
    """

    # try importing readsmart
    try:
        import readsmart as rs
    except ImportError:
        print "Module 'readsmart' not found. Please install on your local machine \
        to proceed with this function. The source can be found at: \
        https://github.com/jlustigy/readsmart"
        return None, None, None, None, None

    # Read-in .rad file
    wlhr, wno, solar_spec, TOA_flux, rad_streams = rs.rad(radfile,getdata=True)

    # Calculate Hi-res reflectivity spectrum
    Ahr = (TOA_flux / solar_spec) #* np.pi / planet.Phi

    # Possibly convolve with gaussian?

    # Skip call_noise and just call: noise
    lam, dlam, A, q, Cratio, cp, csp, cz, cez, cD, cR, cth, DtSNR = \
        make_noise(Ahr, wlhr, solar_spec, telescope, planet, star, wantsnr=wantsnr, COMPUTE_LAM=True, THERMAL=THERMAL)

    # Calculate background photon count rate
    cb = (cz + cez + csp + cD + cR + cth)

    # Calculate the SNR of observation
    time = itime * 3600. # Convert hours to seconds
    #SNR = calc_SNR(time, cp, cb)

    # Generate noisy spectrum by drawing data points from a normal distribution
    #spec, sig = draw_noisy_spec(A, SNR)

    # Calculate SNR, sigma, and noised-up spectrum
    spec, sig, SNR = process_noise(time, Cratio, cp, cb)

    if plot:
        plot_coronagraph_spectrum(lam, spec, sig, itime, planet.distance, ref_lam, SNR, truth=Cratio)

    # Save Synthetic data file (wavelength, albedo, error) if savedata=True
    if savedata:
        data_tag = 'observed_smart_'+tag+'.txt'
        y_sav = np.array([lam,spec,sig])
        np.savetxt(data_tag, y_sav.T)
        print 'Saved: '+data_tag

    # Return Synthetic data and high-res spec

    return lam, spec, sig, wlhr, Ahr