예제 #1
0
    def gen_timeseries(self):
        """
        Time loop wrapper for prescriptions.

        :param inqueue: time index for parallelization (used by multiprocess)
        :param out_queue: series of intensity images (spectral image cube) in the multiprocessing format

        :return: returns the observation sequence, but through the multiprocessing tools, not through more standard
          return protocols.

        :timestep_field is the complex-valued E-field in the planes specified by sp.save_list.
            has shape [timestep, planes, wavelength, objects, x, y]
        :sampling is the final sampling per wavelength in the focal plane
        """
        start = time.time()

        for it, t in enumerate(iter(self.time_idx.get, sentinel)):
            kwargs = {'iter': t, 'params': [iop, sp, ap, tp, cdip]}
            timestep_field, sampling = proper.prop_run(tp.prescription, 1, sp.grid_size, PASSVALUE=kwargs,
                                                       VERBOSE=False, TABLE=False)  # 1 is dummy wavelength

            chunk_ind = it % self.chunk_steps

            self.fields_chunk[chunk_ind] = timestep_field
            self.seen_substeps[chunk_ind] = 1

            chunk_seen = np.all(self.seen_substeps)
            final_chunk_seen = it == sp.numframes-1 and np.all(self.seen_substeps[:self.final_chunk_size])
            while (chunk_ind == self.chunk_steps-1 and not chunk_seen) or \
                  (chunk_ind == self.final_chunk_size-1 and not final_chunk_seen):
                print(f'Waiting for chunk {it//self.chunk_steps} to finish being poplulated before saving') #if sp.verbose
                time.sleep(1)

            if chunk_seen or final_chunk_seen:  # chunk completed or simulation finished
                self.out_chunk.put((self.fields_chunk, sampling))
                if sp.save_to_disk:
                    self.save(self.fields_chunk, sampling)

                if sp.debug:
                    view_spectra(np.sum(np.abs(self.fields_chunk) ** 2, axis=(0, 1))[:, 0],
                                 title='Chunk Spectral Cube')

                self.init_fields_chunk()


        now = time.time()
        elapsed = float(now - start)
        each_iter = float(elapsed) / (sp.numframes + 1)

        print('***********************************')
        print(f'{elapsed/60.:.2f} minutes elapsed, each time step took {each_iter:.2f} minutes')
예제 #2
0
파일: MKIDS.py 프로젝트: jessmos/MEDIS
    def get_R_hyper(self, Rs, plot=False):
        """Each pixel of the array has a matrix of probabilities that depends on the input wavelength"""
        print('Creating a cube of R standard deviations')
        m = (mp.R_spec * Rs) / (ap.wvl_range[1] - ap.wvl_range[0]
                                )  # looses R of 10% over the 700 wvl_range
        c = Rs - m * ap.wvl_range[0]  # each c depends on the R @ 800
        waves = np.ones(
            (np.shape(m)[1],
             np.shape(m)[0], ap.n_wvl_final + 5)) * np.linspace(
                 ap.wvl_range[0], ap.wvl_range[1], ap.n_wvl_final + 5)
        waves = np.transpose(
            waves
        )  # make a tensor of 128x128x10 where every 10 vector is 800... 1500
        R_spec = m * waves + c  # 128x128x10 tensor is now lots of simple linear lines e.g. 50,49,.. 45
        # probs = np.ones((np.shape(R_spec)[0],np.shape(R_spec)[1],np.shape(R_spec)[2],
        #                 mp.res_elements))*np.linspace(0, 1, mp.res_elements)
        #                         # similar to waves but 0... 1 using 128 elements
        # R_spec = np.repeat(R_spec[:,:,:,np.newaxis], mp.res_elements, 3) # creat 128 repeats of R_spec so (10,128,128,128)
        # mp.R_probs = gaussian(0.5, R_spec, probs) #each xylocation is gaussian that gets wider for longer wavelengths
        sigs_w = (waves / R_spec) / 2.35  #R = w/dw & FWHM = 2.35*sig

        # plt.plot(range(0,1500),spec.phase_cal(np.arange(0,1500)))
        # plt.show()
        sigs_p = self.phase_cal(sigs_w) - self.phase_cal(
            np.zeros_like((sigs_w)))

        if plot:
            plt.figure()
            plt.plot(R_spec[:, 0, 0])
            plt.plot(R_spec[:, 50, 15])
            # plt.figure()
            # plt.plot(sigs_w[:,0,0])
            # plt.plot(sigs_w[:,50,15])
            # plt.figure()
            # plt.plot(sigs_p[:, 0, 0])
            # plt.plot(sigs_p[:, 50, 15])
            # plt.figure()
            # plt.imshow(sigs_p[:,:,0], aspect='auto')
            view_spectra(sigs_w, show=False)
            view_spectra(sigs_p, show=False)
            plt.figure()
            plt.plot(np.mean(sigs_w, axis=(1, 2)))
            plt.figure()
            plt.plot(np.mean(sigs_p, axis=(1, 2)))
            # plt.imshow(mp.R_probs[:,0,0,:])
            plt.show(block=True)
        return sigs_p
예제 #3
0
            title=f"White light image at timestep {sp.numframes} \n"  # img
            f"AO={tp.use_ao}",
            # f"Grid Size = {sp.grid_size}, Beam Ratio = {sp.beam_ratio} ",
            # f"sampling = {sampling*1e6:.4f} (um/gridpt)",
            logZ=True,
            dx=fp_sampling[0],
            vlim=(1e-7, 1e-3))

    # Plotting Spectra at last tstep
    if sp.show_spectra:
        tstep = sp.numframes - 1
        view_spectra(
            focal_plane[sp.numframes - 1],
            title=f"Intensity per Spectral Bin at Timestep {tstep} \n"
            f" AO={tp.use_ao}",
            # f"Beam Ratio = {sp.beam_ratio:.4f}",#  sampling = {sampling*1e6:.4f} [um/gridpt]",
            logZ=True,
            subplt_cols=sp.spectra_cols,
            vlim=(1e-4, 1e-1),
            dx=fp_sampling)

    # Plotting Timeseries in White Light
    if sp.show_tseries:
        img_tseries = np.sum(focal_plane, axis=1)  # sum over wavelength
        view_timeseries(img_tseries,
                        title=f"White Light Timeseries\n"
                        f"AO={tp.use_ao}",
                        subplt_cols=sp.tseries_cols,
                        logZ=True,
                        vlim=(1e-6, 1e-3))
        # dx=fp_sampling[0])
예제 #4
0
                # f"Grid Size = {sp.grid_size}, Beam Ratio = {sp.beam_ratio} ",
                # f"sampling = {sampling*1e6:.4f} (um/gridpt)",
                logZ=False,
                # dx=fp_sampling[0],
                zlabel='photon counts',
                vlim=(0, 800),
                show=False)  # (1e-3, 1e-1) (None,None)

    # Plotting Spectra at last tstep
    if sp.show_spectra:
        tstep = sp.numframes - 1
        view_spectra(
            focal_plane[sp.numframes - 1],
            title=f"Intensity per Spectral Bin at Timestep {tstep} \n"
            f"CDI={cdi.use_cdi}, Atmos={tp.use_atmos}, Aberrations={tp.use_aber}",
            # f"Beam Ratio = {sp.beam_ratio:.4f}",#  sampling = {sampling*1e6:.4f} [um/gridpt]",
            logZ=True,
            subplt_cols=sp.spectra_cols,
            #vlim=(1e-7, 1e-3),
            dx=fp_sampling,
            show=False)

    # Plotting Timeseries in White Light
    if sp.show_tseries:
        img_tseries = np.sum(focal_plane, axis=1)  # sum over wavelength
        view_timeseries(
            img_tseries,
            cdi,
            title=f"White Light Timeseries\n"
            f"CDI={cdi.use_cdi}, Atmos={tp.use_atmos}, Aberrations={tp.use_aber}",
            subplt_cols=sp.tseries_cols,
            logZ=True,
예제 #5
0
}

if __name__ == '__main__':
    # =======================================================================
    # Run it!!!!!!!!!!!!!!!!!
    # =======================================================================

    cpx_sequence, sampling = mm.RunMedis().telescope()
    # cpx_sequence, sampling = mm.run_medis('Fields')

    # med = mm.Medis()
    #
    # cpx_sequence, sampling = mm.RunMedis().telescope()
    fp_sampling = sampling[-1][:]
    print(fp_sampling)
    for o in range(len(ap.contrast) + 1):
        print(cpx_sequence.shape)
        datacube = np.sum(np.abs(cpx_sequence)**2, axis=(0, 1))[:, o]
        print(o, datacube.shape)
        view_spectra(datacube,
                     logZ=True,
                     title='Spectral Channels',
                     dx=fp_sampling)
    # fp_sampling = sampling[-1][:]
    # print(fp_sampling)
    # for o in range(len(ap.contrast)+1):
    #     print(cpx_sequence.shape)
    #     datacube = np.sum(np.abs(cpx_sequence)**2, axis=(0,1))[:,o]
    #     print(o, datacube.shape)
    #     view_spectra(datacube, logZ=True, title='Spectral Channels', dx=fp_sampling)