def create_atmospheric_errors_gaintable_rsexecute_workflow(
        sub_bvis_list,
        sub_components,
        r0=5e3,
        screen=None,
        height=3e5,
        type_atmosphere='iono',
        show=False,
        basename='',
        **kwargs):
    """ Create gaintable for atmospheric errors

    :param sub_bvis_list: List of vis (or graph)
    :param sub_components: List of components (or graph)
    :param r0: r0 in m
    :param screen:
    :param height: Height (in m) of screen above telescope e.g. 3e5
    :param type_atmosphere: 'ionosphere' or 'troposhere'
    :param show: Plot the results
    :param basename: Base name for the plots
    :return: (list of error-free gaintables, list of error gaintables) or graph
    """

    # One pointing table per visibility

    error_gt_list = [
        rsexecute.execute(create_gaintable_from_screen)(
            vis,
            sub_components,
            r0=r0,
            screen=screen,
            height=height,
            type_atmosphere=type_atmosphere)
        for ivis, vis in enumerate(sub_bvis_list)
    ]

    # Create the gain tables, one per Visibility and per component
    no_error_gt_list = [[
        rsexecute.execute(create_gaintable_from_blockvisibility)(bvis,
                                                                 **kwargs)
        for cmp in sub_components
    ] for ibv, bvis in enumerate(sub_bvis_list)]
    if show:
        tmp_gt_list = rsexecute.compute(error_gt_list, sync=True)

        plot_file = 'gaintable_%s.png' % r0

        plot_gaintable(tmp_gt_list,
                       title="%s: dish 0 gain phase, %s" % (basename, r0),
                       value='phase',
                       plot_file=plot_file)

    return no_error_gt_list, error_gt_list
def create_polarisation_gaintable_rsexecute_workflow(band,
                                                     sub_bvis_list,
                                                     sub_components,
                                                     use_radec=False,
                                                     show=True,
                                                     basename='',
                                                     normalise=True):
    """ Create gaintable for polarisation effects

    Compare with nominal and actual voltage patterns

    :param band: B1, B2 or Ku
    :param sub_bvis_list: List of vis (or graph)
    :param sub_components: List of components (or graph)
    :param use_radec: Use RADEC coordinate (False)
    :param show: Plot the results
    :param basename: Base name for the plots
    :param normalise: Normalise peak of each receptor
    :return: (list of error-free gaintables, list of error gaintables) or graph
     """
    def find_vp_actual(band):
        telescope = "MID_FEKO_{}".format(band)
        vp = create_vp(telescope=telescope)
        if normalise:
            g = numpy.zeros([4])
            g[0] = numpy.max(numpy.abs(vp.data[:, 0, ...]))
            g[3] = numpy.max(numpy.abs(vp.data[:, 3, ...]))
            g[1] = g[2] = numpy.sqrt(g[0] * g[3])
            for chan in range(4):
                vp.data[:, chan, ...] /= g[chan]
        return vp

    def find_vp_nominal(band):
        vp = find_vp_actual(band)
        vpsym = 0.5 * (vp.data[:, 0, ...] + vp.data[:, 3, ...])
        if normalise:
            vpsym.data /= numpy.max(numpy.abs(vpsym.data))

        vp.data[:, 1:2, ...] = 0.0 + 0.0j
        vp.data[:, 0, ...] = vpsym
        vp.data[:, 3, ...] = vpsym
        return vp

    vp_nominal_list = [
        rsexecute.execute(find_vp_nominal)(band) for bv in sub_bvis_list
    ]
    vp_actual_list = [
        rsexecute.execute(find_vp_actual)(band) for bv in sub_bvis_list
    ]

    # Create the gain tables, one per Visibility and per component
    no_error_gt_list = [
        rsexecute.execute(simulate_gaintable_from_voltage_pattern)(
            bvis, sub_components, vp_nominal_list[ibv], use_radec=use_radec)
        for ibv, bvis in enumerate(sub_bvis_list)
    ]
    error_gt_list = [
        rsexecute.execute(simulate_gaintable_from_voltage_pattern)(
            bvis, sub_components, vp_actual_list[ibv], use_radec=use_radec)
        for ibv, bvis in enumerate(sub_bvis_list)
    ]
    if show:
        plot_file = 'voltage_pattern_gaintable.png'
        error_gt_list = rsexecute.compute(error_gt_list, sync=True)
        plot_gaintable(error_gt_list,
                       plot_file=plot_file,
                       title=basename + " errors")
        no_error_gt_list = rsexecute.compute(no_error_gt_list, sync=True)
        plot_gaintable(no_error_gt_list,
                       plot_file=plot_file,
                       title=basename + " nominal")

    return no_error_gt_list, error_gt_list
def create_surface_errors_gaintable_rsexecute_workflow(band,
                                                       sub_bvis_list,
                                                       sub_components,
                                                       vp_directory,
                                                       use_radec=False,
                                                       elevation_sampling=5.0,
                                                       show=False,
                                                       basename=''):
    """ Create gaintable for surface errors
    :param band: B1, B2 or Ku
    :param sub_bvis_list: List of vis (or graph)
    :param sub_components: List of components (or graph)
    :param vp_directory: Location of voltage patterns
    :param use_radec: Use RADEC coordinate (False)
    :param elevation_sampling: Sampling in elevation (degrees)
    :param show: Plot the results
    :param basename: Base name for the plots
    :return: (list of error-free gaintables, list of error gaintables) or graph
     """
    def get_band_vp(band, el):

        if band == 'B1':
            vpa = import_image_from_fits(
                '%s/B1_%d_0565_real_interpolated.fits' %
                (vp_directory, int(el)))
            vpa_imag = import_image_from_fits(
                '%s/B1_%d_0565_imag_interpolated.fits' %
                (vp_directory, int(el)))
        elif band == 'B2':
            vpa = import_image_from_fits(
                '%s/B2_%d_1360_real_interpolated.fits' %
                (vp_directory, int(el)))
            vpa_imag = import_image_from_fits(
                '%s/B2_%d_1360_imag_interpolated.fits' %
                (vp_directory, int(el)))
        elif band == 'Ku':
            vpa = import_image_from_fits(
                '%s/Ku_%d_11700_real_interpolated.fits' %
                (vp_directory, int(el)))
            vpa_imag = import_image_from_fits(
                '%s/Ku_%d_11700_imag_interpolated.fits' %
                (vp_directory, int(el)))
        else:
            raise ValueError("Unknown band %s" % band)

        vpa.data = vpa.data + 1j * vpa_imag.data
        return vpa

    def find_vp(band, vis):
        ha = calculate_blockvisibility_hourangles(vis).to('rad').value
        dec = vis.phasecentre.dec.rad
        latitude = vis.configuration.location.lat.rad
        az, el = hadec_to_azel(ha, dec, latitude)

        el_deg = el * 180.0 / numpy.pi
        el_table = max(
            0.0,
            min(
                90.1,
                elevation_sampling *
                ((el_deg + elevation_sampling / 2.0) // elevation_sampling)))
        return get_band_vp(band, el_table)

    def find_vp_nominal(band):
        el_nominal_deg = 45.0
        return get_band_vp(band, el_nominal_deg)

    actual_pt_list = [
        rsexecute.execute(create_pointingtable_from_blockvisibility)(bvis)
        for bvis in sub_bvis_list
    ]
    nominal_pt_list = [
        rsexecute.execute(create_pointingtable_from_blockvisibility)(bvis)
        for bvis in sub_bvis_list
    ]

    vp_nominal_list = [
        rsexecute.execute(find_vp_nominal)(band) for bv in sub_bvis_list
    ]
    vp_actual_list = [
        rsexecute.execute(find_vp)(band, bv) for bv in sub_bvis_list
    ]

    # Create the gain tables, one per Visibility and per component
    nominal_gt_list = [
        rsexecute.execute(simulate_gaintable_from_pointingtable)(
            bvis,
            sub_components,
            nominal_pt_list[ibv],
            vp_nominal_list[ibv],
            use_radec=use_radec) for ibv, bvis in enumerate(sub_bvis_list)
    ]
    actual_gt_list = [
        rsexecute.execute(simulate_gaintable_from_pointingtable)(
            bvis,
            sub_components,
            actual_pt_list[ibv],
            vp_actual_list[ibv],
            use_radec=use_radec) for ibv, bvis in enumerate(sub_bvis_list)
    ]
    if show:
        plot_file = 'gaintable_actual.png'
        tmp_gt_list = rsexecute.compute(actual_gt_list, sync=True)
        plot_gaintable(tmp_gt_list,
                       plot_file=plot_file,
                       title=basename + " actual")
        plot_file = 'gaintable_nominal.png'
        tmp_gt_list = rsexecute.compute(nominal_gt_list, sync=True)
        plot_gaintable(tmp_gt_list,
                       plot_file=plot_file,
                       title=basename + " nominal")

    return nominal_gt_list, actual_gt_list
def create_pointing_errors_gaintable_rsexecute_workflow(
        sub_bvis_list,
        sub_components,
        sub_vp_list,
        use_radec=False,
        pointing_error=0.0,
        static_pointing_error=None,
        global_pointing_error=None,
        time_series='',
        time_series_type='',
        seed=None,
        pointing_directory=None,
        show=False,
        basename=''):
    """ Create gaintable for pointing errors

    :param sub_bvis_list: List of vis (or graph)
    :param sub_components: List of components (or graph)
    :param sub_vp_list: List of model voltage patterns (or graph)
    :param use_radec: Use RADEC coordinate (False)
    :param pointing_error: rms pointing error
    :param static_pointing_error: static pointing error
    :param global_pointing_error: global pointing error
    :param time_series: Time series PSD file
    :param time_series_type: Type of time series 'wind'|''
    :param seed: Random number seed
    :param pointing_directory: Location of pointing files
    :param show: Plot the results
    :param basename: Base name for the plots
    :return: (list of error-free gaintables, list of error gaintables) or graph
    """
    if global_pointing_error is None:
        global_pointing_error = [0.0, 0.0]

    # One pointing table per visibility

    error_pt_list = [
        rsexecute.execute(create_pointingtable_from_blockvisibility)(bvis)
        for bvis in sub_bvis_list
    ]
    no_error_pt_list = [
        rsexecute.execute(create_pointingtable_from_blockvisibility)(bvis)
        for bvis in sub_bvis_list
    ]

    if time_series is '':
        error_pt_list = [
            rsexecute.execute(simulate_pointingtable)(
                pt,
                pointing_error=pointing_error,
                static_pointing_error=static_pointing_error,
                global_pointing_error=global_pointing_error,
                seed=seed) for ipt, pt in enumerate(error_pt_list)
        ]
    else:
        error_pt_list = [
            rsexecute.execute(simulate_pointingtable_from_timeseries)(
                pt,
                type=time_series,
                time_series_type=time_series_type,
                pointing_directory=pointing_directory,
                seed=seed) for ipt, pt in enumerate(error_pt_list)
        ]

    if show:
        tmp_error_pt_list = rsexecute.compute(error_pt_list, sync=True)
        if time_series != "":
            plot_file = 'pointing_error_%s.png' % (time_series_type)
        else:
            r2s = 180 * 3600.0 / numpy.pi
            plot_file = 'pointing_error_dynamic_%.2f_static_(%.2f,%.2f)_global_(%.2f,%.2f).png' % \
                        (r2s * pointing_error, r2s * static_pointing_error[0],
                         r2s * static_pointing_error[1],
                         r2s * global_pointing_error[0], r2s * global_pointing_error[1])

        plot_pointingtable(tmp_error_pt_list,
                           plot_file=plot_file,
                           title=basename)

    # Create the gain tables, one per Visibility and per component
    no_error_gt_list = [
        rsexecute.execute(simulate_gaintable_from_pointingtable)(
            bvis,
            sub_components,
            no_error_pt_list[ibv],
            sub_vp_list[ibv],
            use_radec=use_radec) for ibv, bvis in enumerate(sub_bvis_list)
    ]
    error_gt_list = [
        rsexecute.execute(simulate_gaintable_from_pointingtable)(
            bvis,
            sub_components,
            error_pt_list[ibv],
            sub_vp_list[ibv],
            use_radec=use_radec) for ibv, bvis in enumerate(sub_bvis_list)
    ]
    if show:
        tmp_gt_list = rsexecute.compute(error_gt_list, sync=True)

        if time_series_type != "":
            plot_file = 'gaintable_%s.png' % time_series_type
        else:
            r2s = 180 * 3600.0 / numpy.pi
            plot_file = 'gaintable_dynamic_%.2f_static_(%.2f,%.2f)_global_(%.2f,%.2f).png' % \
                        (r2s * pointing_error, r2s * static_pointing_error[0],
                         r2s * static_pointing_error[1],
                         r2s * global_pointing_error[0], r2s * global_pointing_error[1])

        plot_gaintable(tmp_gt_list,
                       title="%s: dish 0 amplitude gain, %s" %
                       (basename, time_series_type),
                       plot_file=plot_file)

    return no_error_gt_list, error_gt_list
Beispiel #5
0
def create_surface_errors_gaintable_rsexecute_workflow(band,
                                                       sub_bvis_list,
                                                       sub_components,
                                                       vp_directory,
                                                       use_radec=False,
                                                       elevation_sampling=5.0,
                                                       show=False,
                                                       basename=''):
    def get_band_vp(band, el):

        if band == 'B1':
            vpa = import_image_from_fits(
                '%s/B1_%d_0565_real_interpolated.fits' %
                (vp_directory, int(el)))
            vpa_imag = import_image_from_fits(
                '%s/B1_%d_0565_imag_interpolated.fits' %
                (vp_directory, int(el)))
        elif band == 'B2':
            vpa = import_image_from_fits(
                '%s/B2_%d_1360_real_interpolated.fits' %
                (vp_directory, int(el)))
            vpa_imag = import_image_from_fits(
                '%s/B2_%d_1360_imag_interpolated.fits' %
                (vp_directory, int(el)))
        elif band == 'Ku':
            vpa = import_image_from_fits(
                '%s/Ku_%d_11700_real_interpolated.fits' %
                (vp_directory, int(el)))
            vpa_imag = import_image_from_fits(
                '%s/Ku_%d_11700_imag_interpolated.fits' %
                (vp_directory, int(el)))
        else:
            raise ValueError("Unknown band %s" % band)

        vpa.data = vpa.data + 1j * vpa_imag.data
        return vpa

    def find_vp(band, vis):
        ha = numpy.pi * numpy.average(vis.time) / 43200.0
        dec = vis.phasecentre.dec.rad
        latitude = vis.configuration.location.lat.rad
        az, el = hadec_to_azel(ha, dec, latitude)

        el_deg = el * 180.0 / numpy.pi
        el_table = max(
            0.0,
            min(
                90.1,
                elevation_sampling *
                ((el_deg + elevation_sampling / 2.0) // elevation_sampling)))
        return get_band_vp(band, el_table)

    def find_vp_nominal(band):
        el_nominal_deg = 45.0
        return get_band_vp(band, el_nominal_deg)

    error_pt_list = [
        rsexecute.execute(create_pointingtable_from_blockvisibility)(bvis)
        for bvis in sub_bvis_list
    ]
    no_error_pt_list = [
        rsexecute.execute(create_pointingtable_from_blockvisibility)(bvis)
        for bvis in sub_bvis_list
    ]

    vp_nominal_list = [
        rsexecute.execute(find_vp_nominal)(band) for bv in sub_bvis_list
    ]
    vp_actual_list = [
        rsexecute.execute(find_vp)(band, bv) for bv in sub_bvis_list
    ]

    # Create the gain tables, one per Visibility and per component
    no_error_gt_list = [
        rsexecute.execute(simulate_gaintable_from_pointingtable)(
            bvis,
            sub_components,
            no_error_pt_list[ibv],
            vp_nominal_list[ibv],
            use_radec=use_radec) for ibv, bvis in enumerate(sub_bvis_list)
    ]
    error_gt_list = [
        rsexecute.execute(simulate_gaintable_from_pointingtable)(
            bvis,
            sub_components,
            error_pt_list[ibv],
            vp_actual_list[ibv],
            use_radec=use_radec) for ibv, bvis in enumerate(sub_bvis_list)
    ]
    if show:
        plot_file = 'gaintable.png'
        tmp_gt_list = rsexecute.compute(error_gt_list, sync=True)
        plot_gaintable(tmp_gt_list, plot_file=plot_file, title=basename)

    return no_error_gt_list, error_gt_list
Beispiel #6
0
def create_pointing_errors_gaintable_rsexecute_workflow(
        sub_bvis_list,
        sub_components,
        sub_vp_list,
        use_radec=False,
        pointing_error=0.0,
        static_pointing_error=None,
        global_pointing_error=None,
        time_series='',
        time_series_type='',
        seed=None,
        pointing_directory=None,
        show=False,
        basename=''):
    if global_pointing_error is None:
        global_pointing_error = [0.0, 0.0]

    # One pointing table per visibility

    error_pt_list = [
        rsexecute.execute(create_pointingtable_from_blockvisibility)(bvis)
        for bvis in sub_bvis_list
    ]
    no_error_pt_list = [
        rsexecute.execute(create_pointingtable_from_blockvisibility)(bvis)
        for bvis in sub_bvis_list
    ]

    if time_series is '':
        error_pt_list = [
            rsexecute.execute(simulate_pointingtable)(
                pt,
                pointing_error=pointing_error,
                static_pointing_error=static_pointing_error,
                global_pointing_error=global_pointing_error,
                seed=seed) for ipt, pt in enumerate(error_pt_list)
        ]
    else:
        error_pt_list = [
            rsexecute.execute(simulate_pointingtable_from_timeseries)(
                pt,
                type=time_series,
                time_series_type=time_series_type,
                pointing_directory=pointing_directory,
                seed=seed) for ipt, pt in enumerate(error_pt_list)
        ]

    if show:
        tmp_error_pt_list = rsexecute.compute(error_pt_list, sync=True)
        if time_series != "":
            plot_file = 'pointing_error_%s.png' % (time_series_type)
        else:
            r2s = 180 * 3600.0 / numpy.pi
            plot_file = 'pointing_error_dynamic_%.2f_static_(%.2f,%.2f)_global_(%.2f,%.2f).png' % \
                        (r2s * pointing_error, r2s * static_pointing_error[0], r2s * static_pointing_error[1],
                         r2s * global_pointing_error[0], r2s * global_pointing_error[1])

        plot_pointingtable(tmp_error_pt_list,
                           plot_file=plot_file,
                           title=basename)

    # Create the gain tables, one per Visibility and per component
    no_error_gt_list = [
        rsexecute.execute(simulate_gaintable_from_pointingtable)(
            bvis,
            sub_components,
            no_error_pt_list[ibv],
            sub_vp_list[ibv],
            use_radec=use_radec) for ibv, bvis in enumerate(sub_bvis_list)
    ]
    error_gt_list = [
        rsexecute.execute(simulate_gaintable_from_pointingtable)(
            bvis,
            sub_components,
            error_pt_list[ibv],
            sub_vp_list[ibv],
            use_radec=use_radec) for ibv, bvis in enumerate(sub_bvis_list)
    ]
    if show:
        tmp_gt_list = rsexecute.compute(error_gt_list, sync=True)

        if time_series_type != "":
            plot_file = 'gaintable_%s.png' % time_series_type
        else:
            r2s = 180 * 3600.0 / numpy.pi
            plot_file = 'gaintable_dynamic_%.2f_static_(%.2f,%.2f)_global_(%.2f,%.2f).png' % \
                        (r2s * pointing_error, r2s * static_pointing_error[0], r2s * static_pointing_error[1],
                         r2s * global_pointing_error[0], r2s * global_pointing_error[1])

        plot_gaintable(tmp_gt_list,
                       title="%s: dish 0 amplitude gain, %s" %
                       (basename, time_series_type),
                       plot_file=plot_file)

    return no_error_gt_list, error_gt_list