def get_observation_single_channel(source_population, baseline_table, min_l,
                                   faulty_dipole, faulty_tile, beam_type,
                                   frequency_range, calibrate,
                                   frequency_index):
    sky_image, l_coordinates = source_population.create_sky_image(
        frequency_channels=frequency_range[frequency_index],
        resolution=min_l,
        oversampling=1)
    ll, mm = numpy.meshgrid(l_coordinates, l_coordinates)

    # Create Beam
    #############################################################################
    if beam_type == "MWA":
        tt, pp, = from_lm_to_theta_phi(ll, mm)
        ideal_beam = ideal_mwa_beam_loader(tt,
                                           pp,
                                           frequency_range[frequency_index],
                                           load=False)
        broken_beam = broken_mwa_beam_loader(tt,
                                             pp,
                                             frequency_range[frequency_index],
                                             faulty_dipole,
                                             load=False)

    elif beam_type == "gaussian":
        ideal_beam = ideal_gaussian_beam(ll, mm,
                                         frequency_range[frequency_index])
        broken_beam = broken_gaussian_beam(ll, mm,
                                           frequency_range[frequency_index],
                                           faulty_dipole)
    else:
        raise ValueError(
            "The only valid option for the beam are 'MWA' or 'gaussian'")

    if calibrate:
        correction = 16 / 15
    else:
        correction = 1

    ##Determine the indices of the broken baselines and calulcate the visibility measurements
    ##################################################################

    broken_baseline_indices = numpy.where(
        (baseline_table.antenna_id1 == faulty_tile)
        | (baseline_table.antenna_id2 == faulty_tile))[0]

    ideal_measured_visibilities = visibility_extractor(
        baseline_table, sky_image, frequency_range[frequency_index],
        ideal_beam, ideal_beam)

    broken_measured_visibilities = ideal_measured_visibilities.copy()
    broken_measured_visibilities[
        broken_baseline_indices] = visibility_extractor(
            baseline_table.sub_table(broken_baseline_indices), sky_image,
            frequency_range[frequency_index], ideal_beam,
            broken_beam) * correction

    return ideal_measured_visibilities, broken_measured_visibilities
예제 #2
0
def apparent_fluxes_numba(source_population, frequency_range, antenna_diameter = 4):
    ff = numpy.tile(frequency_range, (len(source_population.fluxes), 1))
    ss = numpy.tile(source_population.fluxes, (len(frequency_range), 1 ))
    ll = numpy.tile(source_population.l_coordinates, (len(frequency_range), 1 ))
    mm = numpy.tile(source_population.m_coordinates, (len(frequency_range), 1 ))

    antenna_response = ideal_gaussian_beam(ll.T, mm.T, ff, diameter=antenna_diameter)

    apparent_fluxes = antenna_response*numpy.conj(antenna_response)*ss.T
    return apparent_fluxes.astype(complex)
예제 #3
0
def get_observations_analytic(source_population, baseline_table, frequency_range):
    observations = numpy.zeros((baseline_table.number_of_baselines, len(frequency_range)), dtype=complex)
    ff = numpy.tile(frequency_range, (baseline_table.number_of_baselines, 1))

    for source_index in range(len(source_population.fluxes)):
        source_flux = source_population.fluxes[source_index]
        source_l = source_population.l_coordinates[source_index]
        source_m = source_population.m_coordinates[source_index]

        antenna_response = ideal_gaussian_beam(source_l, source_m, ff)

        observations += source_flux*antenna_response*numpy.conj(antenna_response)*numpy.exp(
            -2*numpy.pi*1j*(source_l*baseline_table.u(frequency_range) + source_m*baseline_table.v(frequency_range)))

    return observations
예제 #4
0
def get_observations_single(sky_cube, l_coordinates, baseline_table, frequency_range, frequency_index):
    observations = numpy.zeros((baseline_table.number_of_baselines), dtype=complex)
    ll, mm = numpy.meshgrid(l_coordinates, l_coordinates)

    # Create Beam
    #############################################################################
    antenna_response1 = ideal_gaussian_beam(ll, mm, frequency_range[frequency_index])
    antenna_response2 = antenna_response1.copy()

    observations = visibility_extractor(baseline_table,
                                                              sky_cube[..., frequency_index],
                                                              frequency_range[frequency_index],
                                                              antenna_response1,
                                                              antenna_response2, interpolation='spline')
    return observations
예제 #5
0
def get_observations_dumb(source_population, baseline_table, frequency_range):
    observations = numpy.zeros((baseline_table.number_of_baselines, len(frequency_range)), dtype=complex)
    for source_index in range(len(source_population.fluxes)):

        source_flux = source_population.fluxes[source_index]
        source_l = source_population.l_coordinates[source_index]
        source_m = source_population.m_coordinates[source_index]

        for frequency_index in range(len(frequency_range)):
            u = baseline_table.u(frequency_range[frequency_index])
            v = baseline_table.v(frequency_range[frequency_index])

            for baseline_index in range(baseline_table.number_of_baselines):

                beam_1 = ideal_gaussian_beam(source_l, source_m, frequency_range[frequency_index])
                beam_2 = numpy.conj(beam_1)
                kernel = numpy.exp(-2*numpy.pi*1j*(source_l*u[baseline_index] + source_m*v[baseline_index]))
                observations[baseline_index, frequency_index] += source_flux*beam_1*beam_2*kernel

    return observations
def get_obsersvations_all_channels(source_population=None,
                                   baseline_table=None,
                                   frequency_range=None,
                                   faulty_dipole=None,
                                   faulty_tile=None,
                                   beam_type='gaussian',
                                   calibrate=False,
                                   oversampling=2):

    #Determine maximum resolution
    max_frequency = frequency_range[-1]
    max_u = numpy.max(numpy.abs(baseline_table.u(max_frequency)))
    max_v = numpy.max(numpy.abs(baseline_table.v(max_frequency)))
    max_b = max(max_u, max_v)
    # sky_resolutions
    min_l = 1. / (2 * max_b) * 1 / oversampling

    sky_cube, l_coordinates = source_population.create_sky_image(
        resolution=min_l, frequency_channels=frequency_range, oversampling=1)
    ll, mm, ff = numpy.meshgrid(l_coordinates, l_coordinates, frequency_range)

    # Create Beam
    #############################################################################
    if beam_type == "MWA":
        tt, pp, = from_lm_to_theta_phi(ll, mm)
        antenna_response1 = ideal_mwa_beam_loader(tt, pp, ff)
        if faulty_dipole is None:
            antenna_response2 = antenna_response1.copy()
        else:
            antenna_response2 = broken_mwa_beam_loader(tt, pp, ff,
                                                       faulty_dipole)
    elif beam_type == "gaussian":
        antenna_response1 = ideal_gaussian_beam(ll, mm, ff)
        if faulty_dipole is None:
            antenna_response2 = antenna_response1.copy()
        else:
            antenna_response2 = broken_gaussian_beam(ll, mm, ff, faulty_dipole)
    else:
        raise ValueError(
            "The only valid option for the beam are 'MWA' or 'gaussian'")

    if calibrate:
        correction = 16 / 15
    else:
        correction = 1

    ##Determine the indices of the broken baselines and calculcate the visibility measurements
    ##################################################################

    #apparent_sky = sky_cube * antenna_response1 * numpy.conj(antenna_response2)
    #pad_size = padding_factor * apparent_sky.shape[0]

    #padded_shifted_sky = numpy.fft.ifftshift(numpy.pad(apparent_sky, ((pad_size, pad_size), (pad_size, pad_size),
    #                                                                  (0, 0)), mode="constant"), axes=(0, 1))
    #visibility_grid, uv_coordinates = powerbox.dft.fft(padded_shifted_sky, L=2 * (2 * padding_factor + 1), axes=(0, 1))

    observations = numpy.zeros(
        (baseline_table.number_of_baselines, len(frequency_range)),
        dtype=complex)

    for frequency_index in range(len(frequency_range)):
        observations[..., frequency_index] = visibility_extractor(
            baseline_table, sky_cube, frequency_range, antenna_response1,
            antenna_response2)

    return observations * correction