Exemplo n.º 1
0
    def get_baselines(metafits_context: ct.POINTER(CMetafitsContextS),
                      correlator_context: ct.POINTER(CCorrelatorContextS),
                      voltage_context: ct.POINTER(CVoltageContextS)) -> []:
        """Retrieve all of the baseline metadata and populate a list of baselines."""
        baselines = []
        error_message: bytes = create_string_buffer(ERROR_MESSAGE_LEN)

        c_array_ptr = ct.POINTER(CBaselineS)()
        c_len_ptr = ct.c_size_t(0)

        if mwalib.mwalib_baselines_get(metafits_context, correlator_context,
                                       voltage_context, ct.byref(c_array_ptr),
                                       ct.byref(c_len_ptr), error_message,
                                       ERROR_MESSAGE_LEN) != 0:
            # Error
            raise ContextCorrelatorBaselinesGetError(
                f"Error getting baseline object: "
                f"{error_message.decode('utf-8').rstrip()}")
        else:
            for i in range(0, c_len_ptr.value):
                # Populate all the fields
                baselines.append(
                    Baseline(i, c_array_ptr[i].ant1_index,
                             c_array_ptr[i].ant2_index))

            # We're now finished with the C memory, so free it
            mwalib.mwalib_baselines_free(c_array_ptr, c_len_ptr.value)

            return baselines
Exemplo n.º 2
0
    def get_visibility_pols(metafits_context: ct.POINTER(CMetafitsContextS),
                            correlator_context: ct.POINTER(CCorrelatorContextS),
                            voltage_context: ct.POINTER(CVoltageContextS)) -> []:
        """Retrieve all of the visibility_pol metadata and populate a list of visibility_pols."""
        visibility_pols = []
        error_message: bytes = create_string_buffer(ERROR_MESSAGE_LEN)

        c_array_ptr = ct.POINTER(CVisibilityPolS)()
        c_len_ptr = ct.c_size_t(0)

        if mwalib.mwalib_visibility_pols_get(metafits_context,
                                             correlator_context,
                                             voltage_context,
                                             ct.byref(c_array_ptr),
                                             ct.byref(c_len_ptr),
                                             error_message,
                                             ERROR_MESSAGE_LEN) != 0:
            # Error
            raise ContextCorrelatorVisibilityPolsGetError(f"Error getting visibility_pol object: "
                                                          f"{error_message.decode('utf-8').rstrip()}")
        else:
            for i in range(0, c_len_ptr.value):
                # Populate all the fields
                visibility_pols.append(VisibilityPol(i, c_array_ptr[i].polarisation.decode("utf-8")))

            # We're now finished with the C memory, so free it
            mwalib.mwalib_visibility_pols_free(c_array_ptr, c_len_ptr.value)

            return visibility_pols
Exemplo n.º 3
0
    def get_antennas(metafits_context: ct.POINTER(CMetafitsContextS),
                     correlator_context: ct.POINTER(CCorrelatorContextS),
                     voltage_context: ct.POINTER(CVoltageContextS),
                     rf_inputs: []) -> []:
        """Retrieve all of the antenna metadata and populate a list of antennas."""
        antennas = []
        error_message: bytes = create_string_buffer(ERROR_MESSAGE_LEN)

        c_array_ptr = ct.POINTER(CAntennaS)()
        c_len_ptr = ct.c_size_t(0)

        if mwalib.mwalib_antennas_get(metafits_context, correlator_context,
                                      voltage_context, ct.byref(c_array_ptr),
                                      ct.byref(c_len_ptr), error_message,
                                      ERROR_MESSAGE_LEN) != 0:
            # Error
            raise ContextAntennasGetError(
                f"Error getting antennas object: "
                f"{error_message.decode('utf-8').rstrip()}")
        else:
            for i in range(0, c_len_ptr.value):
                # Populate all the fields
                antennas.append(
                    Antenna(i, c_array_ptr[i].ant, c_array_ptr[i].tile_id,
                            c_array_ptr[i].tile_name.decode("utf-8"),
                            rf_inputs[c_array_ptr[i].rfinput_x],
                            rf_inputs[c_array_ptr[i].rfinput_y]))

            # We're now finished with the C memory, so free it
            mwalib.mwalib_antennas_free(c_array_ptr, c_len_ptr.value)

            return antennas
Exemplo n.º 4
0
    def get_coarse_channels(
            correlator_context: ct.POINTER(CCorrelatorContextS),
            voltage_context: ct.POINTER(CVoltageContextS)) -> []:
        """Retrieve all of the coarse_channel metadata and populate a list of coarse_channels."""
        coarse_channels = []
        error_message: bytes = create_string_buffer(ERROR_MESSAGE_LEN)

        c_array_ptr = ct.POINTER(CCoarseChannelS)()
        c_len_ptr = ct.c_size_t(0)

        if correlator_context is not None:
            if mwalib.mwalib_correlator_coarse_channels_get(
                    correlator_context, ct.byref(c_array_ptr),
                    ct.byref(c_len_ptr), error_message,
                    ERROR_MESSAGE_LEN) != 0:
                # Error
                raise ContextCorrelatorCoarseChannelsGetError(
                    f"Error getting coarse_channel object: "
                    f"{error_message.decode('utf-8').rstrip()}")
        elif voltage_context is not None:
            if mwalib.mwalib_voltage_coarse_channels_get(
                    correlator_context, ct.byref(c_array_ptr),
                    ct.byref(c_len_ptr), error_message,
                    ERROR_MESSAGE_LEN) != 0:
                # Error
                raise ContextVoltageCoarseChannelsGetError(
                    f"Error getting coarse_channel object: "
                    f"{error_message.decode('utf-8').rstrip()}")
        else:
            raise ContextCoarseChannelsGetError(
                f"Error getting coarse_channel object: "
                f"neither correlator nor voltage context provided.")

        for i in range(0, c_len_ptr.value):
            # Populate all the fields
            coarse_channels.append(
                CoarseChannel(
                    i,
                    c_array_ptr[i].corr_chan_number,
                    c_array_ptr[i].rec_chan_number,
                    c_array_ptr[i].gpubox_number,
                    c_array_ptr[i].chan_width_hz,
                    c_array_ptr[i].chan_start_hz,
                    c_array_ptr[i].chan_centre_hz,
                    c_array_ptr[i].chan_end_hz,
                ))

        # We're now finished with the C memory, so free it
        mwalib.mwalib_coarse_channels_free(c_array_ptr, c_len_ptr.value)

        return coarse_channels
Exemplo n.º 5
0
    def get_timesteps(correlator_context: ct.POINTER(CCorrelatorContextS),
                      voltage_context: ct.POINTER(CVoltageContextS)) -> []:
        """Retrieve all of the timestep metadata and populate a list of timesteps."""
        timesteps = []
        error_message: bytes = create_string_buffer(ERROR_MESSAGE_LEN)

        c_array_ptr = ct.POINTER(CTimeStepS)()
        c_len_ptr = ct.c_size_t(0)

        if correlator_context is not None:
            if mwalib.mwalib_correlator_timesteps_get(
                    correlator_context, ct.byref(c_array_ptr),
                    ct.byref(c_len_ptr), error_message,
                    ERROR_MESSAGE_LEN) != 0:
                # Error
                raise ContextCorrelatorTimeStepsGetError(
                    f"Error getting timestep object: "
                    f"{error_message.decode('utf-8').rstrip()}")
        elif voltage_context is not None:
            if mwalib.mwalib_voltage_timesteps_get(
                    voltage_context, ct.byref(c_array_ptr),
                    ct.byref(c_len_ptr), error_message,
                    ERROR_MESSAGE_LEN) != 0:
                # Error
                raise ContextVoltageTimeStepsGetError(
                    f"Error getting timestep object: "
                    f"{error_message.decode('utf-8').rstrip()}")
        else:
            raise ContextTimeStepsGetError(
                f"Error getting timestep object: "
                f"neither correlator nor voltage context provided.")

        for i in range(0, c_len_ptr.value):
            # Populate all the fields
            timesteps.append(
                TimeStep(i, c_array_ptr[i].unix_time_ms,
                         c_array_ptr[i].gps_time_ms))

        # We're now finished with the C memory, so free it
        mwalib.mwalib_timesteps_free(c_array_ptr, c_len_ptr.value)

        return timesteps
Exemplo n.º 6
0
    def get_rfinputs(metafits_context: ct.POINTER(CMetafitsContextS),
                     correlator_context: ct.POINTER(CCorrelatorContextS),
                     voltage_context: ct.POINTER(CVoltageContextS)) -> []:
        """Retrieve all of the rf_input metadata and populate a list of rf_inputs."""
        rf_inputs = []
        error_message: bytes = create_string_buffer(ERROR_MESSAGE_LEN)

        c_array_ptr = ct.POINTER(CRFInputS)()
        c_len_ptr = ct.c_size_t(0)

        if mwalib.mwalib_rfinputs_get(metafits_context, correlator_context,
                                      voltage_context, ct.byref(c_array_ptr),
                                      ct.byref(c_len_ptr), error_message,
                                      ERROR_MESSAGE_LEN) != 0:
            # Error
            raise ContextRFInputsGetError(
                f"Error getting rf_inputs object: "
                f"{error_message.decode('utf-8').rstrip()}")
        else:
            for i in range(0, c_len_ptr.value):
                # Populate all the fields
                rf_inputs.append(
                    RFInput(i, c_array_ptr[i].input, c_array_ptr[i].ant,
                            c_array_ptr[i].tile_id,
                            c_array_ptr[i].tile_name.decode("utf-8"),
                            c_array_ptr[i].pol.decode("utf-8"),
                            c_array_ptr[i].electrical_length_m,
                            c_array_ptr[i].north_m, c_array_ptr[i].east_m,
                            c_array_ptr[i].height_m, c_array_ptr[i].vcs_order,
                            c_array_ptr[i].subfile_order,
                            c_array_ptr[i].flagged, c_array_ptr[i].rec_number,
                            c_array_ptr[i].rec_slot_number))

            # We're now finished with the C memory, so free it
            mwalib.mwalib_rfinputs_free(c_array_ptr, c_len_ptr.value)

            return rf_inputs