示例#1
0
if __name__ == '__main__':
    # =======================================================================
    # Run it!!!!!!!!!!!!!!!!!
    # =======================================================================
    sim = mm.RunMedis(name=testname, product='fields')

    observation = sim()
    cpx_sequence = observation['fields']
    sampling = observation['sampling']

    # =======================================================================
    # Focal Plane Processing
    # =======================================================================
    # obs_sequence = np.array(obs_sequence)  # obs sequence is returned by gen_timeseries (called above)
    # (n_timesteps ,n_planes, n_waves_init, n_astro_bodies, nx ,ny)
    cpx_sequence = opx.interp_wavelength(cpx_sequence,
                                         2)  # interpolate over wavelength
    focal_plane = opx.extract_plane(cpx_sequence,
                                    'detector')  # eliminates object axis
    # convert to intensity THEN sum over object, keeping the dimension of tstep even if it's one
    focal_plane = np.sum(opx.cpx_to_intensity(focal_plane), axis=2)
    fp_sampling = np.copy(sampling[cpx_sequence.shape[1] - 1, :])
    # numpy arrays have some weird effects that make copying the array necessary

    # =======================================================================
    # Plotting
    # =======================================================================
    # White Light, Last Timestep
    if sp.show_wframe:
        # vlim = (np.min(spectralcube) * 10, np.max(spectralcube))  # setting z-axis limits
        img = np.sum(focal_plane[sp.numframes - 1],
                     axis=0)  # sum over wavelength
示例#2
0
    def create_fields(self):
        """ Create fields tensor for an initialised Telecope instance """

        t0 = sp.startframe
        self.kwargs = {}
        self.cpx_sequence = None

        if self.markov:  # time steps are independent
            ceil_num_chunks = int(np.ceil(self.num_chunks))
            if ceil_num_chunks > 1:
                print('Only partial observation will be in memory at one time')
            final_chunk_size = sp.numframes - int(np.floor(
                self.num_chunks)) * self.chunk_steps
            for ichunk in range(ceil_num_chunks):
                fractional_step = final_chunk_size != 0 and ichunk == ceil_num_chunks - 1
                chunk_steps = final_chunk_size if fractional_step else self.chunk_steps

                cpx_sequence = np.empty(
                    (chunk_steps, len(sp.save_list), ap.n_wvl_init,
                     1 + len(ap.contrast), sp.grid_size, sp.grid_size),
                    dtype=np.complex64)
                chunk_range = ichunk * self.chunk_steps + t0 + np.arange(
                    chunk_steps)
                if sp.num_processes == 1:
                    seq_samp_list = [self.run_timestep(t) for t in chunk_range]
                else:
                    print(f'Using multiprocessing of timesteps {chunk_range}')
                    # it appears as though the with statement is neccesssary when recreating Pools like this
                    with multiprocessing.Pool(processes=sp.num_processes) as p:
                        seq_samp_list = p.map(self.run_timestep, chunk_range)
                self.cpx_sequence = np.array([tup[0] for tup in seq_samp_list])
                self.sampling = seq_samp_list[0][1]

                if ap.n_wvl_init < ap.n_wvl_final:
                    self.cpx_sequence = opx.interp_wavelength(
                        self.cpx_sequence, ax=2)
                    self.sampling = opx.interp_sampling(self.sampling)

                if sp.save_to_disk: self.save_fields(self.cpx_sequence)

        else:
            self.cpx_sequence = np.zeros(
                (sp.numframes, len(sp.save_list), ap.n_wvl_init,
                 1 + len(ap.contrast), sp.grid_size, sp.grid_size),
                dtype=np.complex)
            self.sampling = np.zeros((len(sp.save_list), ap.n_wvl_init))

            for it, t in enumerate(range(t0, sp.numframes + t0)):
                WFS_ind = ['wfs' in plane for plane in sp.save_list]
                if t > sp.ao_delay:
                    self.kwargs['WFS_field'] = self.cpx_sequence[it -
                                                                 sp.ao_delay,
                                                                 WFS_ind, :, 0]
                    self.kwargs['AO_field'] = self.cpx_sequence[it -
                                                                sp.ao_delay,
                                                                AO_ind, :, 0]
                else:
                    self.kwargs['WFS_field'] = np.zeros(
                        (ap.n_wvl_init, sp.grid_size, sp.grid_size),
                        dtype=np.complex)
                    self.kwargs['AO_field'] = np.zeros(
                        (ap.n_wvl_init, sp.grid_size, sp.grid_size),
                        dtype=np.complex)
                self.cpx_sequence[it], self.sampling = self.run_timestep(t)

            print('************************')
            if sp.save_to_disk: self.save_fields(self.cpx_sequence)