コード例 #1
0
def full_modes_from_file(datadir):
    """
    Read all modes into an array of hcipy.Fields and an array of 2D arrays.
    :param datadir: string, path to overall data directory containing matrix and results folder
    :return: all_modes as array of Fields, mode_cube as array of 2D arrays (hcipy vs matplotlib)
    """

    mode_cube = hc.read_fits(
        os.path.join(datadir, 'results', 'modes', 'fits', 'cube_modes.fits'))
    all_modes = hc.Field(mode_cube.ravel())

    return all_modes, mode_cube
コード例 #2
0
    fried_parameter = float(fried_parameter)
    time_between = float(time_between)
    numb = int(numb)
else:
    fried_parameter = 4 # meter //increased from 0.2 to reduce atmos effects
    time_between = 0.7
    numb = 10

print("generating: "+str(numb)+" psfs with:\n  fried parameter: "+str(fried_parameter)+"\n  sample time: "+str(time_between))

D_tel = 8.2 # meter
wavelength = 1e-6 # meter
oversampling = 8

# loading the files required for generating the vAPP.
amplitude_temp = read_fits(amplitude_file)
phase_temp     = read_fits(phase_file)

# number of pixels along one axis in the pupil
Npix = amplitude_temp.shape[0]

# generating the grids
pupil_grid = make_pupil_grid(Npix, D_tel)
focal_grid = make_focal_grid(pupil_grid, 4, 25, wavelength=wavelength)

#kolmogorov: verdeling voor sterkte special freq
spectral_noise_factory = SpectralNoiseFactoryFFT(kolmogorov_psd, pupil_grid, oversampling)
turbulence_layers = make_standard_multilayer_atmosphere(fried_parameter=fried_parameter, wavelength=wavelength)
# create phase screen
atmospheric_model = AtmosphericModel(spectral_noise_factory, turbulence_layers)
コード例 #3
0
    # How many repetitions for Monte Carlo?
    n_repeat = 100

    nseg = 120
    wvln = 638e-9

    print('Setting up optics...')
    print('Data folder: {}'.format(workdir))
    print('Coronagraph: {}'.format(apodizer_design))

    # Create SM
    # Read pupil and indexed pupil
    inputdir = '/Users/ilaginja/Documents/LabWork/ultra/LUVOIR_delivery_May2019/'
    aper_path = 'inputs/TelAp_LUVOIR_gap_pad01_bw_ovsamp04_N1000.fits'
    aper_ind_path = 'inputs/TelAp_LUVOIR_gap_pad01_bw_ovsamp04_N1000_indexed.fits'
    aper_read = hc.read_fits(os.path.join(inputdir, aper_path))
    aper_ind_read = hc.read_fits(os.path.join(inputdir, aper_ind_path))

    # Sample them on a pupil grid and make them hc.Fields
    pupil_grid = hc.make_pupil_grid(dims=aper_ind_read.shape[0], diameter=15)
    aper = hc.Field(aper_read.ravel(), pupil_grid)
    aper_ind = hc.Field(aper_ind_read.ravel(), pupil_grid)

    # Create the wavefront on the aperture
    wf_aper = hc.Wavefront(aper, wvln)

    # Load segment positions from fits header
    hdr = fits.getheader(os.path.join(inputdir, aper_ind_path))
    poslist = []
    for i in range(nseg):
        segname = 'SEG' + str(i + 1)
コード例 #4
0
def clean_vapp():
    import numpy as np
    import matplotlib.pyplot as plt 

    from hcipy import read_fits, make_pupil_grid, make_focal_grid, FraunhoferPropagator, circular_aperture, evaluate_supersampled, imshow_field, imsave_field, Field, LyotCoronagraph, Wavefront

    script_path = os.path.realpath(__file__).split("vApp_reduction",1)[0]
    full_path = script_path+"vApp_reduction/data/"
    amplitude_file = full_path+'SCExAO_vAPP_amplitude_resampled.fits'
    phase_file     = full_path+'SCExAO_vAPP_phase_resampled.fits'

    # loading the files required for generating the vAPP. 
    amplitude_temp = read_fits(amplitude_file)
    phase_temp     = read_fits(phase_file)

    # number of pixels along one axis in the pupil
    Npix = amplitude_temp.shape[0]

    # generating the grids 
    pupil_grid = make_pupil_grid(Npix)
    focal_grid = make_focal_grid(pupil_grid, 4, 25)

    # Mapping from pupil plane to focal plane
    propagator = FraunhoferPropagator(pupil_grid, focal_grid)

    # converting the amplitude and phase to fields 
    amplitude = Field(amplitude_temp.ravel(), pupil_grid)
    phase     = Field(phase_temp.ravel(), pupil_grid)

    # the wavefront for the three PSFs 
    pupil_wf_PSF_1 = Wavefront(amplitude * np.exp(1j * phase)) # coronagraphic PSF 1
    pupil_wf_PSF_2 = Wavefront(amplitude * np.exp(-1j * phase)) # coronagraphic PSF 2
    pupil_wf_PSF_3 = Wavefront(amplitude) # leakage

    # Propagating them to the focal plane 
    focal_wf_PSF_1 = propagator(pupil_wf_PSF_1)
    focal_wf_PSF_2 = propagator(pupil_wf_PSF_2)
    focal_wf_PSF_3 = propagator(pupil_wf_PSF_3)

    # setting the total power in the images 
    focal_wf_PSF_1.total_power = 1
    focal_wf_PSF_2.total_power = 1
    focal_wf_PSF_3.total_power = 1

    # the strenght of the leakage term
    leakage = 0.02

    # getting the power and scaling with leakage 
    PSF_1_pwr = focal_wf_PSF_1.power * (1 - leakage / 2)
    PSF_2_pwr = focal_wf_PSF_2.power * (1 - leakage / 2)
    PSF_3_pwr = focal_wf_PSF_3.power * leakage

    # generating the total PSF of the vAPP
    total_PSF = PSF_1_pwr + PSF_2_pwr + PSF_3_pwr

    # normalizing to sum = 1
    total_PSF /= np.sum(total_PSF)

    fig = plt.figure()
    imshow_field(np.log10(total_PSF / total_PSF.max()), vmin=-5, vmax=0)
    cbar = plt.colorbar()
    cbar.set_label(r"$^{10}\log(contrast)$")
    plt.ylabel(r"$\lambda/D$")
    plt.xlabel(r"$\lambda/D$")

    plt.show()
    output_path = get_output_path("miscellaneous")
    fig.savefig(output_path+"clean_vapp")
コード例 #5
0
def clean_vapp():
    import numpy as np
    import matplotlib.pyplot as plt

    from hcipy import read_fits, make_pupil_grid, make_focal_grid, FraunhoferPropagator, circular_aperture, evaluate_supersampled, imshow_field, imsave_field, Field, LyotCoronagraph, Wavefront

    script_path = os.path.realpath(__file__).split("vApp_reduction", 1)[0]
    full_path = script_path + "vApp_reduction/data/"
    amplitude_file = full_path + 'SCExAO_vAPP_amplitude_resampled.fits'
    phase_file = full_path + 'SCExAO_vAPP_phase_resampled.fits'

    # loading the files required for generating the vAPP.
    amplitude_temp = read_fits(amplitude_file)
    phase_temp = read_fits(phase_file)

    # number of pixels along one axis in the pupil
    Npix = amplitude_temp.shape[0]

    # generating the grids
    pupil_grid = make_pupil_grid(Npix)
    focal_grid = make_focal_grid(pupil_grid, 4, 25)

    # Mapping from pupil plane to focal plane
    propagator = FraunhoferPropagator(pupil_grid, focal_grid)

    # converting the amplitude and phase to fields
    amplitude = Field(amplitude_temp.ravel(), pupil_grid)
    phase = Field(phase_temp.ravel(), pupil_grid)

    # the wavefront for the three PSFs
    pupil_wf_PSF_1 = Wavefront(amplitude *
                               np.exp(1j * phase))  # coronagraphic PSF 1
    pupil_wf_PSF_2 = Wavefront(amplitude *
                               np.exp(-1j * phase))  # coronagraphic PSF 2
    pupil_wf_PSF_3 = Wavefront(amplitude)  # leakage

    # Propagating them to the focal plane
    focal_wf_PSF_1 = propagator(pupil_wf_PSF_1)
    focal_wf_PSF_2 = propagator(pupil_wf_PSF_2)
    focal_wf_PSF_3 = propagator(pupil_wf_PSF_3)

    # setting the total power in the images
    focal_wf_PSF_1.total_power = 1
    focal_wf_PSF_2.total_power = 1
    focal_wf_PSF_3.total_power = 1

    # the strenght of the leakage term
    leakage = 0.02

    # getting the power and scaling with leakage
    PSF_1_pwr = focal_wf_PSF_1.power * (1 - leakage / 2)
    PSF_2_pwr = focal_wf_PSF_2.power * (1 - leakage / 2)
    PSF_3_pwr = focal_wf_PSF_3.power * leakage

    # generating the total PSF of the vAPP
    total_PSF = PSF_1_pwr + PSF_2_pwr + PSF_3_pwr

    # normalizing to sum = 1
    total_PSF /= np.sum(total_PSF)

    fig = plt.figure()
    imshow_field(np.log10(total_PSF / total_PSF.max()), vmin=-5, vmax=0)

    cbar = plt.colorbar()
    cbar.set_label(r"$^{10}\log(contrast)$")
    plt.ylabel(r"$\lambda/D$")
    plt.xlabel(r"$\lambda/D$")

    plt.show()
    output_path = get_output_path("miscellaneous")
    fig.savefig(output_path + "clean_vapp")

    fig = plt.figure()
    imshow_field(np.log10(total_PSF / total_PSF.max()), vmin=-5, vmax=0)

    bbox_props = dict(boxstyle="circle,pad=0.3",
                      fill=False,
                      alpha=1,
                      fc=None,
                      ec="red",
                      lw=5)
    plt.text(10.3,
             10.7,
             " ",
             ha="center",
             va="center",
             rotation=45,
             size=110,
             bbox=bbox_props)
    plt.text(-10.3,
             -10.7,
             " ",
             ha="center",
             va="center",
             rotation=45,
             size=110,
             bbox=bbox_props)
    bbox_props = dict(boxstyle="circle,pad=0.3",
                      fill=False,
                      alpha=1,
                      fc=None,
                      ec="white",
                      lw=5)
    plt.text(0,
             0,
             " ",
             ha="center",
             va="center",
             rotation=45,
             size=55,
             bbox=bbox_props)
    plt.text(8,
             -15,
             " ",
             ha="center",
             va="center",
             rotation=45,
             size=55,
             bbox=bbox_props)
    plt.text(-8,
             15,
             " ",
             ha="center",
             va="center",
             rotation=45,
             size=55,
             bbox=bbox_props)

    cbar = plt.colorbar()
    cbar.set_label(r"$^{10}\log(contrast)$")
    plt.ylabel(r"$\lambda/D$")
    plt.xlabel(r"$\lambda/D$")

    plt.show()
    output_path = get_output_path("miscellaneous")
    fig.savefig(output_path + "clean_vapp_annotated")
コード例 #6
0
    def __init__(self, input_dir, apod_design, samp):
        self.nseg = 120
        self.wvln = 638e-9  # m
        self.diam = 15.  # m
        self.sampling = samp
        self.lam_over_d = self.wvln / self.diam
        self.apod_dict = {
            'small': {
                'pxsize':
                1000,
                'fpm_rad':
                3.5,
                'fpm_px':
                150,
                'iwa':
                3.4,
                'owa':
                12.,
                'fname':
                '0_LUVOIR_N1000_FPM350M0150_IWA0340_OWA01200_C10_BW10_Nlam5_LS_IDD0120_OD0982_no_ls_struts.fits'
            },
            'medium': {
                'pxsize':
                1000,
                'fpm_rad':
                6.82,
                'fpm_px':
                250,
                'iwa':
                6.72,
                'owa':
                23.72,
                'fname':
                '0_LUVOIR_N1000_FPM682M0250_IWA0672_OWA02372_C10_BW10_Nlam5_LS_IDD0120_OD0982_no_ls_struts.fits'
            },
            'large': {
                'pxsize':
                1000,
                'fpm_rad':
                13.38,
                'fpm_px':
                400,
                'iwa':
                13.28,
                'owa':
                46.88,
                'fname':
                '0_LUVOIR_N1000_FPM1338M0400_IWA1328_OWA04688_C10_BW10_Nlam5_LS_IDD0120_OD0982_no_ls_struts.fits'
            }
        }
        self.imlamD = 1.2 * self.apod_dict[apod_design]['owa']

        # Pupil plane optics
        aper_path = 'inputs/TelAp_LUVOIR_gap_pad01_bw_ovsamp04_N1000.fits'
        aper_ind_path = 'inputs/TelAp_LUVOIR_gap_pad01_bw_ovsamp04_N1000_indexed.fits'
        apod_path = os.path.join(input_dir, 'luvoir_stdt_baseline_bw10',
                                 apod_design + '_fpm', 'solutions',
                                 self.apod_dict[apod_design]['fname'])
        ls_fname = 'inputs/LS_LUVOIR_ID0120_OD0982_no_struts_gy_ovsamp4_N1000.fits'

        pup_read = hc.read_fits(os.path.join(input_dir, aper_path))
        aper_ind_read = hc.read_fits(os.path.join(input_dir, aper_ind_path))
        apod_read = hc.read_fits(os.path.join(input_dir, apod_path))
        ls_read = hc.read_fits(os.path.join(input_dir, ls_fname))

        pupil_grid = hc.make_pupil_grid(
            dims=self.apod_dict[apod_design]['pxsize'], diameter=self.diam)

        self.aperture = hc.Field(pup_read.ravel(), pupil_grid)
        self.aper_ind = hc.Field(aper_ind_read.ravel(), pupil_grid)
        self.apod = hc.Field(apod_read.ravel(), pupil_grid)
        self.ls = hc.Field(ls_read.ravel(), pupil_grid)

        # Load segment positions from fits header
        hdr = fits.getheader(os.path.join(input_dir, aper_ind_path))

        poslist = []
        for i in range(self.nseg):
            segname = 'SEG' + str(i + 1)
            xin = hdr[segname + '_X']
            yin = hdr[segname + '_Y']
            poslist.append((xin, yin))

        poslist = np.transpose(np.array(poslist))
        self.seg_pos = hc.CartesianGrid(poslist)

        # Focal plane mask
        samp_foc = self.apod_dict[apod_design]['fpm_px'] / (
            self.apod_dict[apod_design]['fpm_rad'] * 2)
        focal_grid_fpm = hc.make_focal_grid(
            pupil_grid=pupil_grid,
            q=samp_foc,
            num_airy=self.apod_dict[apod_design]['fpm_rad'],
            wavelength=self.wvln)
        self.fpm = 1 - hc.circular_aperture(
            2 * self.apod_dict[apod_design]['fpm_rad'] *
            self.lam_over_d)(focal_grid_fpm)

        # Final focal plane grid (detector)
        self.focal_det = hc.make_focal_grid(pupil_grid=pupil_grid,
                                            q=self.sampling,
                                            num_airy=self.imlamD,
                                            wavelength=self.wvln)

        luvoir_params = {
            'wavelength': self.wvln,
            'diameter': self.diam,
            'imlamD': self.imlamD,
            'fpm_rad': self.apod_dict[apod_design]['fpm_rad']
        }

        # Initialize the general segmented telescope with APLC class, includes the SM
        super().__init__(aper=self.aperture,
                         indexed_aperture=self.aper_ind,
                         seg_pos=self.seg_pos,
                         apod=self.apod,
                         lyotst=self.ls,
                         fpm=self.fpm,
                         focal_grid=self.focal_det,
                         params=luvoir_params)

        # Propagators
        self.coro = hc.LyotCoronagraph(pupil_grid, self.fpm, self.ls)
        self.prop = hc.FraunhoferPropagator(pupil_grid, self.focal_det)
        self.coro_no_ls = hc.LyotCoronagraph(pupil_grid, self.fpm)
コード例 #7
0
    time_between = float(time_between)
    numb = int(numb)
else:
    fried_parameter = 4  # meter //increased from 0.2 to reduce atmos effects
    time_between = 0.7
    numb = 10

print("generating: " + str(numb) + " psfs with:\n  fried parameter: " +
      str(fried_parameter) + "\n  sample time: " + str(time_between))

D_tel = 8.2  # meter
wavelength = 1e-6  # meter
oversampling = 8

# loading the files required for generating the vAPP.
amplitude_temp = read_fits(amplitude_file)
phase_temp = read_fits(phase_file)

# number of pixels along one axis in the pupil
Npix = amplitude_temp.shape[0]

# generating the grids
pupil_grid = make_pupil_grid(Npix, D_tel)
focal_grid = make_focal_grid(pupil_grid, 4, 25, wavelength=wavelength)

#kolmogorov: verdeling voor sterkte special freq
spectral_noise_factory = SpectralNoiseFactoryFFT(kolmogorov_psd, pupil_grid,
                                                 oversampling)
turbulence_layers = make_standard_multilayer_atmosphere(
    fried_parameter=fried_parameter, wavelength=wavelength)
# create phase screen