Example #1
0
def make_LC_map():
    LCmap = np.zeros((len(xlocs), len(ylocs), num_chunks * num_ints))
    for i in range(num_chunks):

        start = i * max_photons
        # print start, start+max_photons
        packets = pipe.read_obs(max_photons=max_photons, start=start)

        # newpackets = pipe.isolate_interval(packets,[0,0.1])
        # print np.shape(newpackets)
        # cube = pipe.arange_into_cube(newpackets)
        # image = pipe.make_intensity_map(cube)
        # image = pipe.make_intensity_map_packets(packets)
        # # loop_frames
        # quicklook_im(image)
        # print image[58,67]

        # xloc, yloc = 58., 67.
        # xloc, yloc = 60., 60.
        # xloc, yloc = 60., 60.
        start = packets[0, 2]
        end = packets[-1, 2]
        # print start, end

        for ix, xloc in enumerate(xlocs):
            for iy, yloc in enumerate(ylocs):
                print np.shape(packets)
                LC, packets = pipe.get_lightcurve(packets,
                                                  xloc,
                                                  yloc,
                                                  start,
                                                  end + cp.frame_time,
                                                  bin_time=bin_time,
                                                  speed_up=True)
                # print LC['intensity']
                LCmap[ix, iy,
                      i * num_ints:(i + 1) * num_ints] = LC['intensity']
                if (ix * len(ylocs) + iy) % 10 == 0:
                    misc.progressBar(value=(ix * len(ylocs) + iy),
                                     endvalue=len(xlocs) * len(ylocs))
    with open(LCmapFile, 'wb') as handle:
        pickle.dump(LCmap, handle, protocol=pickle.HIGHEST_PROTOCOL)
Example #2
0
def run():
    packets = pipe.read_obs(max_photons=max_photons)
    print packets[:50], packets.shape
    # tp.packets = packets

    print sp.num_processes, 'NUM_PROCESSES'
    p = multiprocessing.Pool(sp.num_processes)
    LCmap = np.zeros((len(xlocs), len(ylocs), num_ints))
    print num_ints, num_chunks
    for i in range(num_chunks):
        packets_chunk = packets[i * max_photons:(i + 1) * max_photons]
        print debprint((i, packets_chunk.shape))
        prod_x = partial(mp_worker, packets=packets_chunk
                         )  # prod_x has only one argument x (y is fixed to 10)
        # idxs = range(tp.grid_size**2)
        idxs = range(len(xlocs) * len(ylocs))
        print debprint(idxs)
        LClist = p.map(prod_x, idxs)
        # LClist = mp_worker(idxs[0])
        # LClist = p.map(mp_worker, idxs)

        # LClist = []
        # for idx in idxs:
        #     ints = p.apply_async(mp_worker, (idx, packets)).get()
        #     print ints
        #     LClist.append(ints)
        # print LClist
        binned_chunk = num_ints / num_chunks
        print debprint((len(LClist[0]), binned_chunk))
        for idx in idxs:
            ix = idx / len(xlocs)
            iy = idx % len(xlocs)
            LCmap[ix, iy,
                  i * binned_chunk:(i + 1) * binned_chunk] = LClist[idx]

    plt.imshow(LCmap[:, :, 0])
    plt.show()
    return LCmap
Example #3
0
def LCmap_speedup_colors():
    allpackets = pipe.read_obs()
    # packets = packets[:,2:]

    phases = allpackets[:, 1] - allpackets[:, 0]
    # packets = np.vstack((phases,packets[:,2:]))
    print phases[:50]
    print np.shape(allpackets)
    wsamples = np.linspace(tp.band[0], tp.band[1], tp.nwsamp)
    print wsamples

    phasebins = spec.phase_cal(wsamples)
    print phasebins
    binnedphase = np.digitize(phases, phasebins)
    print binnedphase[:20]
    LCmaps = np.zeros((len(phasebins), len(xlocs), len(ylocs), num_ints))
    for col in range(len(phasebins)):
        locs = np.where(binnedphase == col)[0]
        packets = allpackets[locs]
        # cube = pipe.arange_into_cube(packets)
        # image = pipe.make_intensity_map(cube)
        # quicklook_im(image)
        print 'Sorting packets (takes a while)'
        ind = np.lexsort((packets[:, 3], packets[:, 4]))
        packets = packets[ind]

        print packets.shape, sp.num_processes
        # exit()
        LCmap = np.zeros((len(xlocs), len(ylocs), num_ints))
        # for i in range(num_chunks):
        #     packets_chunk = packets[i * max_photons:(i + 1) * max_photons]
        output = multiprocessing.Queue()
        inqueue = multiprocessing.Queue()
        packqueue = multiprocessing.Queue()
        jobs = []

        for i in range(sp.num_processes):
            p = multiprocessing.Process(target=LCmap_worker,
                                        args=(inqueue, output, packqueue))
            jobs.append(p)
            p.start()
            # print 'ip', i
        for idx in range(len(xlocs) * len(ylocs)):
            # print 'idx', idx
            inqueue.put(idx)
        lower = 0
        # for ix, iy in zip(xlocs,ylocs):
        for ix, iy in list(itertools.product(xlocs, ylocs)):
            print ix, iy, 'ix iy'  #'idx', idx
            # print inqueue.qsize(), output.qsize(), packqueue.qsize(), ' 3queues'
            diff = 0
            span = lower
            while diff == 0:
                diff = packets[span, 3] - iy
                span += 1
                if span == len(packets):
                    break
            # print 'lower and span', lower, span
            upper = span - 1
            packets_chunk = packets[lower:upper]
            lower = upper
            packqueue.put(packets_chunk)
            LClist = output.get()
            # if ix == 1 and iy == 1:
            #     exit()
            # print LClist, 'LClist'
            # binned_chunk = num_ints / num_chunks
            # print debprint((len(LClist[0]), binned_chunk))
            # for idx in idxs:
            # ix = idx / len(xlocs)
            # iy = idx % len(xlocs)
            # LCmap[ix, iy, i * binned_chunk:(i + 1) * binned_chunk] = LClist  # [idx]
            LCmap[ix, iy] = LClist  # [idx]
            # print LClist
        print inqueue.qsize(), output.qsize(), packqueue.qsize(
        ), 'line380 3queues'
        output.put(None)
        # packqueue.put(None)
        print inqueue.qsize(), output.qsize(), packqueue.qsize(
        ), 'line383 3queues'
        for i in range(sp.num_processes):
            # Send the sentinal to tell Simulation to end
            inqueue.put(sentinel)
            print 'second i', i
            print 'line 205', tp.detector
            print inqueue.qsize(), output.qsize(), packqueue.qsize(
            ), 'line389 3queues'
        for i, p in enumerate(jobs):
            p.join()
            print 'third i', i

        print col, type(col)
        LCmaps[col] = LCmap
    return LCmaps
Example #4
0
def LCmap_speedup():
    packets = pipe.read_obs()
    packets = packets[:,2:]
    print('Sorting packets (takes a while)')
    ind = np.lexsort((packets[:, 1], packets[:, 2]))
    packets = packets[ind]

    print(packets.shape, sp.num_processes)
    # exit()
    num_ints = int(cp.frame_time * ap.numframes / mp.bin_time)
    LCmap = np.zeros((len(xlocs), len(ylocs), num_ints))
    # for i in range(num_chunks):
    #     packets_chunk = packets[i * max_photons:(i + 1) * max_photons]
    output = multiprocessing.Queue()
    inqueue = multiprocessing.Queue()
    packqueue = multiprocessing.Queue()
    jobs = []

    for i in range(sp.num_processes):
        p = multiprocessing.Process(target=LCmap_worker, args=(inqueue, output, packqueue))
        jobs.append(p)
        p.start()
        # print 'ip', i
    for idx in range(len(xlocs) * len(ylocs)):
        # print 'idx', idx
        inqueue.put(idx)
    lower=0
    # for ix, iy in zip(xlocs,ylocs):
    for ix, iy in list(itertools.product(xlocs, ylocs)):
        print(ix, iy, 'ix iy')#'idx', idx
        # print inqueue.qsize(), output.qsize(), packqueue.qsize(), ' 3queues'
        diff = 0
        span = lower
        while diff == 0:
            # print diff, packets[span,1], iy,  span
            diff = packets[span,1] - iy
            span += 1
            if span == ap.star_photons*ap.numframes:
                break
        print('lower and span', lower, span)
        upper = span -1
        packets_chunk = packets[lower:upper]
        lower=upper
        packqueue.put(packets_chunk)
        LClist = output.get()
        # if ix == 1 and iy == 1:
        #     exit()
        # print LClist, 'LClist'
        # binned_chunk = num_ints / num_chunks
        # print debprint((len(LClist[0]), binned_chunk))
        # for idx in idxs:
        # ix = idx / len(xlocs)
        # iy = idx % len(xlocs)
        # LCmap[ix, iy, i * binned_chunk:(i + 1) * binned_chunk] = LClist  # [idx]
        LCmap[ix, iy] = LClist  # [idx]
    print(inqueue.qsize(), output.qsize(), packqueue.qsize(),  'line380 3queues')
    output.put(None)
    # packqueue.put(None)
    print(inqueue.qsize(), output.qsize(), packqueue.qsize(),  'line383 3queues')
    for i in range(sp.num_processes):
        # Send the sentinal to tell Simulation to end
        inqueue.put(sentinel)
        print('second i', i)
        print('line 205', tp.detector)
        print(inqueue.qsize(), output.qsize(), packqueue.qsize(), 'line389 3queues')
    for i, p in enumerate(jobs):
        p.join()
        print('third i', i)

    return LCmap
Example #5
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)