Example #1
0
def quick_processing(simple_hypercube_1, simple_hypercube_2, plot=True):
    diff_cube = simple_hypercube_1 - simple_hypercube_2
    if plot:
        quicklook_im(np.mean(simple_hypercube_1[:,-2], axis=0))
        quicklook_im(np.mean(simple_hypercube_2[:,-2], axis=0))
        quicklook_im(np.mean(diff_cube[:,-2], axis=0))

    Lmaps = np.zeros((diff_cube.shape[1], diff_cube.shape[2], diff_cube.shape[3]))
    rmaps = np.zeros_like(Lmaps)
    for iw in range(diff_cube.shape[1]):
        dprint((diff_cube.shape, iw))
        LCcube = np.transpose(diff_cube[:, iw:iw + 1], (2, 3, 0, 1))
        rmaps[iw] = Analysis.stats.get_skew(LCcube)#, xinspect = range(233,236), yinspect = range(233,236), inspect = True)#, xinspect = range(40,50), yinspect = range(40,50), inspect = True)
        # quicklook_im(rmaps[iw], logAmp=True)
        Lmaps[iw] = Analysis.stats.get_Dmap(LCcube, binning=10, plot=False, threshold=0.01)
    if plot:
        loop_frames(rmaps)
        loop_frames(Lmaps)
    SDI = Analysis.phot.do_SDI(rmaps*Lmaps)
    if plot: quicklook_im(SDI)
    return [np.mean(simple_hypercube_1[:,0], axis=0),
            np.mean(diff_cube[:,0], axis=0),
            Lmaps[0],
            SDI]
Example #2
0
def get_integ_hypercube(plot=False):
    import Detector.get_photon_data as gpd
    print(os.path.isfile(iop.hyperFile), iop.hyperFile)
    print(ap.numframes)

    if os.path.isfile(iop.hyperFile):
        dprint(iop.hyperFile[-3:])
        if iop.hyperFile[-3:] == '.h5':
            # try:
            hypercube = open_hypercube_hdf5(HyperCubeFile=iop.hyperFile)
        else:
            # except:
            hypercube = open_hypercube(HyperCubeFile=iop.hyperFile)
        dprint(hypercube.shape)
        dprint(np.sum(hypercube))
    else:

        # hypercube = gpd.run()
        hypercube = gpd.take_obs_data()
        dprint(np.sum(hypercube))
        if plot:
            loop_frames(hypercube[:, 0])
            loop_frames(hypercube[0])
        print('finished run')
        print(np.shape(hypercube))
        if plot: view_datacube(hypercube[0], logAmp=True)

        if tp.detector == 'H2RG':
            hypercube = H2RG.scale_to_luminos(hypercube)
            if plot: view_datacube(hypercube[0], logAmp=True)

        # hypercube = take_exposure(hypercube)
        # if tp.detector == 'H2RG':
        if tp.detector == 'H2RG' and hp.use_readnoise == True:
            hypercube = H2RG.add_readnoise(hypercube, hp.readnoise)
            # if plot: view_datacube(hypercube[0], logAmp=True)

        if plot: view_datacube(hypercube[0], logAmp=True)
        # save_hypercube(hypercube, HyperCubeFile=iop.hyperFile)
        dprint(iop.hyperFile)
        save_hypercube_hdf5(hypercube, HyperCubeFile=iop.hyperFile)
    # print np.shape(hypercube)

    if plot: loop_frames(hypercube[:, 0])
    if plot: loop_frames(hypercube[0])
    return hypercube
Example #3
0
    wsamples = np.linspace(tp.band[0], tp.band[1], tp.nwsamp)
    # scale_list = tp.band[0] / wsamples
    scale_list = wsamples / tp.band[0]

    angle_list = np.zeros((tp.nwsamp))
    print np.mean(simple_hypercube, axis=0).shape
    static_psf = pca.pca(np.mean(simple_hypercube, axis=0),
                         angle_list=angle_list,
                         scale_list=scale_list,
                         mask_center_px=None,
                         full_output=True)
    # quicklook_im(pca.pca(np.mean(simple_hypercube,axis=0), angle_list=angle_list, scale_list=scale_list[::-1],
    #               mask_center_px=None))

    quicklook_im(np.sum(simple_hypercube, axis=(0, 1)))
    loop_frames(np.sum(simple_hypercube, axis=0))
    # scale_list = np.linspace(scale_list[-1],scale_list[0],8)
    scale_list = tp.band[1] / wsamples
    # scale_list = scale_list[::-1]
    print scale_list
    # loop_frames(static_psf[0], logAmp=False)
    # loop_frames(static_psf[1], logAmp=False)
    # loop_frames(static_psf[2], logAmp=False)
    # loop_frames(static_psf[3], logAmp=False)
    static_psf = static_psf[1][0]
    import scipy.ndimage
    dprint(star_phot)
    static_psf = scipy.ndimage.zoom(static_psf,
                                    float(simple_hypercube.shape[-1]) /
                                    static_psf.shape[-1],
                                    order=0)
Example #4
0
# for row in ob.photonTable:
# 	for phot in row:
# 		print phot[:2]
# 	exit()

with h5py.File(fname, 'r') as hf:
    images = []
    for i in range(195):
        image = np.array(hf.get('Images/%i' % (1491896000 + i)))
        images.append(image)
images = np.array(images)

# images[images>40] = 0
dark_sub = images - dark
# loop_frames(images - dark, vmin=-0, vmax=40)
loop_frames(dark_sub, logAmp=True, vmin=1)
dark_sub[dark_sub > 5] = 0
dark_sub[dark_sub <= 0] = 1e-1
loop_frames(dark_sub, logAmp=True, vmin=1)
loop_frames(dark_sub / flat, logAmp=True, vmin=1)
quicklook_im(np.mean(dark_sub, axis=0), logAmp=True, vmin=1)
quicklook_im(np.mean(dark_sub / flat, axis=0), logAmp=True, vmin=1)

# loop_frames(dark_sub+1e-9, logAmp=True)

# quicklook_im((np.median(images, axis=0) - dark), vmin=-0, vmax=40)
# quicklook_im((np.median(images, axis=0) - dark) / flat, vmin=0, vmax=40)
# quicklook_im(np.median(images / flat, axis=0), vmin=0, vmax=40)
# quicklook_im(np.mean(images - dark / flat, axis=0), vmin=0, vmax=40)

# def loadStack(dataDir, start, stop, useImg = False, nCols=80, nRows=125):
Example #5
0
    # diff_cube = simple_hypercube_1#-simple_hypercube_2

    Analysis.stats.Dmap_quad(simple_hypercube_1, simple_hypercube_2, binning=2)
    # factor = 1000
    # diff_cube = np.zeros(((simple_hypercube_1.shape[0]/factor)**2,1,mp.array_size[0],mp.array_size[1]))
    # k = 0
    # for a in simple_hypercube_1[::factor,0]:
    #     for b in simple_hypercube_2[::factor,0]:
    #         # quicklook_im(a)
    #         # quicklook_im(b)
    #         diff_cube[k] = a - b
    #         print k
    #         k += 1
    # # diff_cube = np.array([[i-j] for i in simple_hypercube_1[::10,0] for j in simple_hypercube_2[::10,0]])
    dprint(np.shape(diff_cube))
    loop_frames(diff_cube[:, 0], logAmp=False)
    # # quicklook_im(np.mean(diff_cube[:,0],axis=0), logAmp=False)
    # quicklook_im(np.mean(diff_cube[:, 0], axis=0), logAmp=True)
    # quicklook_im(np.median(diff_cube[:, 0], axis=0), logAmp=True)
    # #
    LCcube = np.transpose(diff_cube, (2, 3, 0, 1))
    algo_dict = {'thresh': 0}
    Dmap = Analysis.stats.get_Dmap(LCcube, algo_dict['thresh'], binning=2)
    # quicklook_im(Dmap, annos=['MKIDs'], title=  r'  $I_L / I^{*}$', mark_star=True)
    # # indep_images([np.mean(diff_cube[:, 0], axis=0) / star_phot, Dmap / star_phot], logAmp=True,
    # #              titles=[r'  $I / I^{*}$', r'  $I_L / I^{*}$'], annos=['Mean', 'MKIDs'])
    #

    algo_dict = {'full_target_cube': simple_hypercube_1, 'thru': True}
    angle_list = np.zeros((len(simple_hypercube_1)))
Example #6
0
    # rad_samp = np.linspace(0,tp.platescale/1000.*40,40)
    # print rad_samp
    # # Get unocculted PSF for intensity
    # psf_template = Analysis.phot.get_unoccult_psf(hyperFile='/IntHyperUnOccult.pkl', plot=False)
    # # star_phot = np.sum(psf_template)
    # star_phot = phot.contrcurve.aperture_flux(psf_template,[64],[64],lod,1)[0]/ap.numframes
    # psf_template = psf_template[:-1,:-1]

    # bunching
    ap.companion = True
    iop.hyperFile = iop.datadir + '/bunchingOldAtmos_ArteficialSpecksDim2sec.pkl'
    bunch_hypercube = read.get_integ_hypercube(plot=False)  # / ap.numframes
    print bunch_hypercube.shape

    loop_frames(bunch_hypercube[:, 0], axis=None)

    def sub_sums_ophion(arr, ncols):
        arr = arr.reshape(1, -1)
        nrows = 1
        h, w = arr.shape
        h = (h // nrows) * nrows
        w = (w // ncols) * ncols
        arr = arr[:h, :w]
        return np.einsum('ijkl->ik', arr.reshape(h // nrows, nrows, -1, ncols))

    full_counts = np.zeros((2, num_exp))
    full_counts[0] = bunch_hypercube[:, 0, 40, 40]
    full_counts[1] = bunch_hypercube[:, 0, 41, 88]

    print full_counts, 'lol'
Example #7
0
    # RDI (for SDI)
    ap.companion = True
    ap.contrast = [1e-5, 1e-6]  # [0.1,0.1]
    ap.lods = [[-2.5, 2.5], [-4.5, 4.5]]
    tp.detector = 'MKIDs'  #'ideal'#
    iop.hyperFile = iop.datadir + 'far_out1MKIDs7.pkl'  # 5
    # iop.hyperFile = iop.datadir + 'noWnoRollHyperWcomp1000cont_Aug_1stMKIDs2.pkl'#5
    simple_hypercube_1 = read.get_integ_hypercube(plot=False)  #/ap.numframes

    ap.startframe = ap.numframes
    ap.companion = False
    iop.hyperFile = iop.datadir + 'far_out2MKIDs7.pkl'  # 5
    # iop.hyperFile = iop.datadir + 'noWnoRollHyperWcomp1000cont_Aug_2ndMKIDs2.pkl'#5
    simple_hypercube_2 = read.get_integ_hypercube(plot=False)  #/ap.numframes

    loop_frames(simple_hypercube_1[::10, 0], logAmp=True)
    loop_frames(simple_hypercube_2[:, 0], logAmp=True)
    diff_cube = simple_hypercube_1[2:] - simple_hypercube_2[2:]
    loop_frames(diff_cube[:, 0], logAmp=False)
    # quicklook_im(np.mean(diff_cube[:,0],axis=0), logAmp=False)
    quicklook_im(np.mean(diff_cube[:, 0], axis=0), logAmp=True)
    quicklook_im(np.median(diff_cube[:, 0], axis=0), logAmp=True)
    #
    LCcube = np.transpose(diff_cube, (2, 3, 0, 1))
    algo_dict = {'thresh': 0}
    Dmap = Analysis.stats.get_Dmap(LCcube, algo_dict['thresh'])
    # DSI
    indep_images([Dmap], vmins=[0.01], vmaxs=[0.5], logAmp=True)

    #SDI +DSI
    iop.hyperFile = iop.datadir + '/noWnoRollHyperWcomp1000cont_Aug_1st.pkl'  #5
Example #8
0
    # Amplitude
    tp.detector = 'ideal'#'MKIDs'  #
    tp.use_ao = True
    tp.use_atmos = False
    tp.NCPA_type = None#'Static'
    tp.CPA_type = 'Amp'
    # tp.CPA_type = 'test'
    # tp.CPA_type = None#'Static'#'test'
    ap.lods = [[2, 0]]  # initial location (no rotation)
    tp.active_null = True
    tp.speckle_kill = True
    iop.hyperFile = iop.datadir + '/amp_abs2.pkl'
    # tp.active_modulate = True
    perfect_hypercube = read.get_integ_hypercube(plot=False)  # /ap.numframes
    quicklook_im(np.sum(perfect_hypercube[:, 0], axis=0), axis=None, title=r'  $I / I^{*}$', anno='Integration')
    loop_frames(perfect_hypercube[::20, 0])
    # compare_images([perfect_hypercube[0,0],perfect_hypercube[10,0],perfect_hypercube[100,0],perfect_hypercube[1000,0]], logAmp=True)
    annos = ['Frame: 0', 'Frame: 20', 'Frame: 500', 'Frame: 2000']
    compare_images(
        [perfect_hypercube[0, 0], perfect_hypercube[20, 0], perfect_hypercube[500, 0], perfect_hypercube[-1, 0]],
        logAmp=True, title='A.U', annos= annos)

    # Perfect
    tp.detector = 'ideal'#'MKIDs'  #
    tp.use_ao = False
    tp.use_atmos = False
    tp.NCPA_type = None#'Static'
    tp.CPA_type = None#'Static'
    tp.active_null = False
    iop.hyperFile = iop.datadir + '/perfect.pkl'
    # tp.active_modulate = True
Example #9
0
tp.detector = 'H2RG'  #''MKIDs'#
sp.save_obs = False
sp.show_wframe = False  #True#'continuous'
if sp.show_wframe == 'continuous':
    sp.fig = plt.figure()

sp.show_cube = False
sp.return_cube = True
tp.nwsamp = 4
# tp.use_atmos = True # have to for now because ao wfs reads in map produced but not neccessary
# tp.use_ao = True
# tp.active_null=False
# tp.satelite_speck = True
# tp.speck_locs = [[40,40]]
# ap.frame_time = 0.001
num_exp = 25
ap.exposure_time = 0.01
ap.numframes = int(num_exp * ap.exposure_time / cp.frame_time)
sp.num_processes = 1
if __name__ == '__main__':
    hypercube = run()
    print np.shape(hypercube)
    hypercube = read.take_exposure(hypercube)
    print np.shape(hypercube[0, 3]), np.shape(hypercube)
    loop_frames(hypercube[:, 0])
    plt.close()
    loop_frames(hypercube[0])
    plt.show()
    loop_frames(hypercube[:, 0])
    plt.show()
Example #10
0
    #                         algo = pca.pca,full_output=True, **algo_dict)
    # print res_throug[3].shape
    # loop_frames(res_throug[3][0])
    # loop_frames(res_throug[3][:,0])
    # plt.plot(res_throug[0][0])
    # plt.show()
    # phot.contrcurve.contrast_curve(cube=hypercube[0], angle_list=np.zeros((len(hypercube[0]))), psf_template=psf_template, fwhm=10, pxscale=0.13, starphot=star_phots, algo=pca.pca, debug=True, **algo_dict)

    # from vip_hci import pca
    # loop_frames(hypercube[:,0])
    # hypercube[:,:,56,124] = 0
    # hypercube[:,:,119,104] = 0
    datacube = np.mean(hypercube, axis=0) / ap.exposure_time
    # datacube = np.transpose(np.transpose(datacube) / np.max(datacube, axis=(1, 2))) / float(tp.nwsamp)
    dprint(np.sum(datacube, axis=(1, 2)))
    loop_frames(datacube)

    dprint(scale_list)

    SDI = pca.pca(datacube,
                  angle_list=np.zeros((len(hypercube[0]))),
                  scale_list=scale_list,
                  mask_center_px=None)

    # dprint(SDI.shape)
    print hypercube.shape
    # SDI[SDI<=0] = 1e-5
    # quicklook_im(np.sum(hypercube, axis=(0,1)), logAmp=True)
    # quicklook_im(SDI, logAmp=True)
    SDI = SDI.reshape(1, SDI.shape[0], SDI.shape[1])
Example #11
0
    # #
    # quicklook_im(method_out[1], axis=None, title=r'  $I_r / I^{*}$', anno='DSI')


    conv_steps = 110
    # DSI
    iop.hyperFile = iop.datadir + '/modulate.pkl'
    # tp.active_modulate = True
    simple_hypercube = read.get_integ_hypercube(plot=False)#/ap.numframes
    print 'star_phot', star_phot
    quicklook_im(np.sum(simple_hypercube[conv_steps:,0], axis=0)/star_phot, axis=None, title=r'  $I / I^{*}$', anno='Integration')
    angle_list = np.zeros((len(simple_hypercube)-conv_steps))
    # algo_dict = {'DSI_starphot': DSI_starphot, 'thresh': 1e-5}
    algo_dict = {'thresh': 1e-5}

    loop_frames(simple_hypercube[:,0])
    plt.figure()
    # plt.plot(simple_hypercube[:,0,53,53])
    # plt.plot(simple_hypercube[:, 0, 54, 54])
    # plt.plot(simple_hypercube[:, 0, 53, 54])
    # plt.plot(simple_hypercube[:, 0, 54, 53])
    # plt.plot(simple_hypercube[:, 0, 74, 63])
    # plt.plot(simple_hypercube[:, 0, 75, 63])
    # plt.plot(simple_hypercube[:, 0, 74, 64])
    # plt.plot(simple_hypercube[:, 0, 75, 64])
    # plt.plot(simple_hypercube[:, 0, 74, 55])
    # plt.plot(simple_hypercube[:, 0, 75, 56])
    # plt.plot(simple_hypercube[:, 0, 74, 55])
    # plt.plot(simple_hypercube[:, 0, 75, 56])
    plt.plot(simple_hypercube[:, 0, 72, 57])
    plt.plot(simple_hypercube[:, 0, 71, 58])
Example #12
0
sys.path.append('D:/dodkins/MEDIS/MEDIS')
import numpy as np
import matplotlib.pylab as plt
from params import ap, cp, tp, mp
# import Detector.readout as read
import Detector.pipeline as pipe
# import Detector.temporal as temp
from Utils.plot_tools import view_datacube, quicklook_im, loop_frames
import cPickle as pickle

framesFile = 'backup/frames.pkl'
if os.path.isfile(framesFile):
    with open(framesFile, 'rb') as handle:
        frames = pickle.load(handle)
else:
    frames = []
    max_photons = 1e6
    for i in range(10):
        start = i * max_photons
        print start, start + max_photons
        packets = pipe.read_obs(max_photons=max_photons, start=start)

        image = pipe.make_intensity_map_packets(packets)
        # quicklook_im(image)
        frames.append(image)
    frames = np.array(frames)
    with open(framesFile, 'wb') as handle:
        pickle.dump(frames, handle, protocol=pickle.HIGHEST_PROTOCOL)

loop_frames(frames)