Beispiel #1
0
def test_integration_time_is_within_limits():
    """
    Verify that integration time is no greater than 1400
    """
    _ = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0)
    with pytest.raises(ValueError):
        _ = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 0, 0)
    with pytest.raises(ValueError):
        _ = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1540, 0)
Beispiel #2
0
def test_integration_time_must_be_multiple_of_140():
    """
    Verify that integration time is multiple of 140
    """
    _ = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 140, 0)
    with pytest.raises(ValueError):
        _ = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 139, 0)
    with pytest.raises(ValueError):
        _ = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 141, 0)
Beispiel #3
0
def test_corr_bandwidth_range():
    """
    Verify that corr_bandwidth is in the range of 0 to 6
    """
    corr_bandwidth = -1
    with pytest.raises(ValueError):
        _ = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 140, corr_bandwidth)
    corr_bandwidth = 7
    with pytest.raises(ValueError):
        _ = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 140, corr_bandwidth)
Beispiel #4
0
def test_fsp_id_range():
    """
    Verify that fsp id is in the range of 1 to 27
    """
    fsp_id = 0
    with pytest.raises(ValueError):
        _ = FSPConfiguration(fsp_id, FSPFunctionMode.CORR, 1, 140, 0)
    fsp_id = 28
    with pytest.raises(ValueError):
        _ = FSPConfiguration(fsp_id, FSPFunctionMode.CORR, 1, 140, 0)
Beispiel #5
0
def test_fsp_slice_id_range():
    """
    Verify that fsp slice id is in the range of 1 to 26
    """
    fsp_slice_id = 0
    with pytest.raises(ValueError):
        _ = FSPConfiguration(1, FSPFunctionMode.CORR, fsp_slice_id, 140, 0)
    fsp_slice_id = 27
    with pytest.raises(ValueError):
        _ = FSPConfiguration(1, FSPFunctionMode.CORR, fsp_slice_id, 140, 0)
Beispiel #6
0
def test_configure_request_eq():
    """
    Verify that ConfigurationRequest objects are considered equal when:
      - they point to the same target
      - they set the same receiver band
      - their SDP configuration is the same
      - their CSP configuration is the same
    """

    pointing_config = PointingConfiguration(Target(1, 1))
    dish_config = DishConfiguration(receiver_band=ReceiverBand.BAND_1)
    sdp_config = SDPConfiguration("science_A")
    channel_avg_map = list(zip(itertools.count(1, 744), [2] + 19 * [0]))
    csp_id = "sbi-mvp01-20200325-00001-science_A"
    fsp_config = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 140, 0,
                                  channel_avg_map)
    csp_config = CSPConfiguration(csp_id=csp_id,
                                  frequency_band=ReceiverBand.BAND_1,
                                  fsp_configs=[fsp_config])
    request_1 = ConfigureRequest(pointing=pointing_config,
                                 dish=dish_config,
                                 sdp=sdp_config,
                                 csp=csp_config)
    request_2 = ConfigureRequest(pointing=pointing_config,
                                 dish=dish_config,
                                 sdp=sdp_config,
                                 csp=csp_config)
    assert request_1 == request_2
Beispiel #7
0
def test_csp_configuration_support_only_new_or_old_request_in_same_call():
    """
    Verify that CSPConfiguration objects are considered equal when all
    attributes are equal.
    """
    csp_id = "sbi-mvp01-20200325-00001-science_A"
    frequency_band = ReceiverBand.BAND_1
    fsp = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0)
    subarray_id = 1
    subarray_name = "Test Subarray"
    interface = "https://schema.skatelescope.org/ska-csp-configure/1.0"

    subarray_config = SubarrayConfiguration(subarray_name)
    common_config = CommonConfiguration(csp_id, frequency_band, subarray_id)
    cbf_config = CBFConfiguration([fsp])
    pst_config = None
    pss_config = None

    with pytest.raises(ValueError):
        _ = CSPConfiguration(interface=interface,
                             csp_id=csp_id,
                             frequency_band=frequency_band,
                             fsp_configs=[],
                             subarray_config=subarray_config,
                             common_config=common_config,
                             cbf_config=cbf_config,
                             pst_config=pst_config,
                             pss_config=pss_config)
Beispiel #8
0
    def create(self, data, **_):  # pylint: disable=no-self-use
        """
         Convert parsed JSON back into a FSPConfiguration object.

        :param data: dict containing parsed JSON values
        :param _: kwargs passed by Marshmallow
        :return: FSPConfiguration instance populated to match JSON
        """
        fsp_id = data["fsp_id"]
        function_mode = data["function_mode"]
        function_mode_enum = FSPFunctionMode(function_mode)
        frequency_slice_id = int(data["frequency_slice_id"])
        corr_bandwidth = data["corr_bandwidth"]
        integration_time = data["integration_time"]

        # optional arguments
        channel_averaging_map = data.get("channel_averaging_map", None)
        output_link_map = data.get("output_link_map", None)
        fsp_channel_offset = data.get("fsp_channel_offset", None)
        zoom_window_tuning = data.get("zoom_window_tuning", None)

        return FSPConfiguration(
            fsp_id,
            function_mode_enum,
            frequency_slice_id,
            integration_time,
            corr_bandwidth,
            channel_averaging_map=channel_averaging_map,
            output_link_map=output_link_map,
            fsp_channel_offset=fsp_channel_offset,
            zoom_window_tuning=zoom_window_tuning,
        )
Beispiel #9
0
def test_fsp_configuration_not_equal_to_other_objects():
    """
    Verify that FSPConfiguration objects are not considered equal to objects
    of other types.
    """
    config = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0)
    assert config != 1
def test_marshall_cspconfiguration_does_not_modify_original():
    """
    Verify that serialising a CspConfiguration does not change the object.
    """
    config = CSPConfiguration(
        csp_id="csp ID goes here",
        frequency_band=ReceiverBand.BAND_5A,
        fsp_configs=[FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0)])
    original_config = copy.deepcopy(config)
    CSPConfigurationSchema().dumps(config)
    assert config == original_config
Beispiel #11
0
def test_csp_configuration_not_equal_to_other_objects():
    """
    Verify that CSPConfiguration objects are not considered equal to objects
    of other types.
    """
    csp_id = "sbi-mvp01-20200325-00001-science_A"
    frequency_band = ReceiverBand.BAND_1
    fsp = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0)
    config = CSPConfiguration(csp_id=csp_id,
                              frequency_band=frequency_band,
                              fsp_configs=[fsp])
    assert config != 1
Beispiel #12
0
def test_cbf_configuration_equals():
    """
    Verify that CBFConfiguration objects are considered equal when all
    attributes are equal.
    """
    fsp = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0)

    config1 = CBFConfiguration([fsp])
    config2 = CBFConfiguration([fsp])
    assert config1 == config2

    assert config1 != CBFConfiguration([fsp, fsp])
Beispiel #13
0
    def convert(self, fsp_configuration: FSPConfiguration, **_):  # pylint: disable=no-self-use
        """
        Process FSPConfiguration instance so that it is ready for conversion
        to JSON.

        :param fsp_configuration: FSP configuration to process
        :param _: kwargs passed by Marshmallow
        :return: FspConfiguration instance populated to match JSON
        """
        # Convert Python Enum to its string value
        fsp_configuration.function_mode = fsp_configuration.function_mode.value
        return fsp_configuration
Beispiel #14
0
def csp_config_for_test():
    """
    Fixture which returns an CSPConfiguration object

    :return: CSPConfiguration
    """

    csp_id = "sbi-mvp01-20200325-00001-science_A"
    # TODO refactor this as a builder, consolidate duplicate code
    fsp_config_1 = FSPConfiguration(1,
                                    FSPFunctionMode.CORR,
                                    1,
                                    1400,
                                    0,
                                    channel_averaging_map=[(0, 2), (744, 0)],
                                    fsp_channel_offset=0,
                                    output_link_map=[(0, 0), (200, 1)])
    fsp_config_2 = FSPConfiguration(
        2,
        FSPFunctionMode.CORR,
        2,
        1400,
        1,
        channel_averaging_map=[(0, 2), (744, 0)],
        fsp_channel_offset=744,
        output_link_map=[(0, 4), (200, 5)],
        zoom_window_tuning=4700000,
    )

    cbf_config = CBFConfiguration([fsp_config_1, fsp_config_2])
    csp_subarray_config = SubarrayConfiguration('science period 23')
    csp_common_config = CommonConfiguration(csp_id, ReceiverBand.BAND_1, 1)
    csp_config = CSPConfiguration(
        interface="https://schema.skatelescope.org/ska-csp-configure/1.0",
        subarray_config=csp_subarray_config,
        common_config=csp_common_config,
        cbf_config=cbf_config)
    return csp_config
def test_marshall_fsp_configuration_with_undefined_optional_parameters():
    """
    Verify that optional FSPConfiguration parameters are removed when they are
    left unset.
    """
    fsp_config = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0)
    schema = FSPConfigurationSchema()
    marshalled = schema.dumps(fsp_config)

    optional_fields = [
        field.data_key for name, field in schema.fields.items()
        if field.required is False
    ]
    for field in optional_fields:
        assert field not in marshalled
Beispiel #16
0
def test_csp_configuration_equals_with_all_parameters():
    """
    Verify that CSPConfiguration objects are considered equal when all
    attributes are equal.
    """
    csp_id = "sbi-mvp01-20200325-00001-science_A"
    frequency_band = ReceiverBand.BAND_1
    fsp = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0)
    subarray_id = 1
    subarray_name = "Test Subarray"

    interface = "https://schema.skatelescope.org/ska-csp-configure/1.0"
    subarray_config = SubarrayConfiguration(subarray_name)
    common_config = CommonConfiguration(csp_id, frequency_band, subarray_id)
    cbf_config = CBFConfiguration([fsp])
    pst_config = None
    pss_config = None

    config1 = CSPConfiguration(csp_id=csp_id,
                               frequency_band=frequency_band,
                               fsp_configs=[fsp])
    config2 = CSPConfiguration(csp_id=csp_id,
                               frequency_band=frequency_band,
                               fsp_configs=[fsp])

    config3 = CSPConfiguration(interface=interface,
                               subarray_config=subarray_config,
                               common_config=common_config,
                               cbf_config=cbf_config,
                               pst_config=pst_config,
                               pss_config=pss_config)
    config4 = CSPConfiguration(interface=interface,
                               subarray_config=subarray_config,
                               common_config=common_config,
                               cbf_config=cbf_config,
                               pst_config=pst_config,
                               pss_config=pss_config)

    assert config1 == config2
    assert config3 == config4

    assert config1 != CSPConfiguration(
        csp_id=csp_id, frequency_band=ReceiverBand.BAND_2, fsp_configs=[fsp])
    assert config3 != CSPConfiguration(subarray_config=subarray_config,
                                       common_config=common_config,
                                       cbf_config=cbf_config,
                                       pst_config=pst_config,
                                       pss_config=pss_config)
Beispiel #17
0
def test_fsp_configuration_equals():
    """
    Verify that FSPConfigurations are considered equal when all attributes are
    equal.
    """
    fsp_id = 1
    mode = FSPFunctionMode.CORR
    slice_id = 1
    bandwidth = 0
    channel_avg_map = list(zip(itertools.count(1, 744), 20 * [0]))
    integration_time = 140

    config1 = FSPConfiguration(fsp_id, mode, slice_id, integration_time,
                               bandwidth, channel_avg_map)
    config2 = FSPConfiguration(fsp_id, mode, slice_id, integration_time,
                               bandwidth, channel_avg_map)
    assert config1 == config2

    assert config1 != FSPConfiguration(2, mode, slice_id, integration_time,
                                       bandwidth, channel_avg_map)
    assert config1 != FSPConfiguration(
        fsp_id,
        FSPFunctionMode.PSS_BF,
        slice_id,
        integration_time,
        bandwidth,
        channel_avg_map,
    )
    assert config1 != FSPConfiguration(fsp_id, mode, 2, integration_time,
                                       bandwidth, channel_avg_map)
    assert config1 != FSPConfiguration(fsp_id, mode, slice_id, 280, bandwidth,
                                       channel_avg_map)
    assert config1 != FSPConfiguration(fsp_id, mode, slice_id,
                                       integration_time, 1, channel_avg_map)
    assert config1 != FSPConfiguration(
        fsp_id,
        mode,
        slice_id,
        integration_time,
        bandwidth,
        list(zip(itertools.count(1, 744), 20 * [1])),
    )
Beispiel #18
0
def test_configure_request_is_not_equal_to_other_objects():
    """
    Verify that ConfigureRequest is not equal to other objects.
    """
    pointing_config = PointingConfiguration(Target(1, 1))
    dish_config = DishConfiguration(receiver_band=ReceiverBand.BAND_1)
    sdp_config = SDPConfiguration("science_A")
    channel_avg_map = list(zip(itertools.count(1, 744), [2] + 19 * [0]))
    csp_id = "sbi-mvp01-20200325-00001-science_A"
    fsp_config = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 140, 0,
                                  channel_avg_map)
    csp_config = CSPConfiguration(csp_id=csp_id,
                                  frequency_band=ReceiverBand.BAND_1,
                                  fsp_configs=[fsp_config])
    request = ConfigureRequest(pointing=pointing_config,
                               dish=dish_config,
                               sdp=sdp_config,
                               csp=csp_config)
    assert request != object
Beispiel #19
0
def test_csp_configuration_equals():
    """
    Verify that CSPConfiguration objects are considered equal when all
    attributes are equal.
    """
    csp_id = "sbi-mvp01-20200325-00001-science_A"
    frequency_band = ReceiverBand.BAND_1
    fsp = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0)

    config1 = CSPConfiguration(csp_id=csp_id,
                               frequency_band=frequency_band,
                               fsp_configs=[fsp])
    config2 = CSPConfiguration(csp_id=csp_id,
                               frequency_band=frequency_band,
                               fsp_configs=[fsp])
    assert config1 == config2

    assert config1 != CSPConfiguration(
        csp_id=csp_id, frequency_band=ReceiverBand.BAND_2, fsp_configs=[fsp])
    assert config1 != CSPConfiguration(
        csp_id=csp_id, frequency_band=frequency_band, fsp_configs=[fsp, fsp])
def test_marshall_fsp_configuration_with_optional_parameters_as_none():
    """
    Verify that optional FSPConfiguration parameters are removed when None is
    passed in as their constructor value.
    """
    constructor_signature = inspect.signature(FSPConfiguration.__init__)
    optional_kwarg_names = [
        name for name, parameter in constructor_signature.parameters.items()
        if parameter.kind == inspect.Parameter.KEYWORD_ONLY
    ]
    null_kwargs = {name: None for name in optional_kwarg_names}

    fsp_config = FSPConfiguration(1, FSPFunctionMode.CORR, 1, 1400, 0,
                                  **null_kwargs)
    schema = FSPConfigurationSchema()
    marshalled = schema.dumps(fsp_config)

    # optional constructor args are optional fields in the schema
    optional_fields = [
        field.data_key for name, field in schema.fields.items()
        if field.required is False
    ]
    for field in optional_fields:
        assert field not in marshalled
Beispiel #21
0
         frame="icrs",
         unit=("hourangle", "deg"),
     )),
 dish=DishConfiguration(receiver_band=ReceiverBand.BAND_1),
 sdp=SDPConfiguration("science_A"),
 csp=CSPConfiguration(
     interface="https://schema.skatelescope.org/ska-csp-configure/1.0",
     subarray_config=SubarrayConfiguration('science period 23'),
     common_config=CommonConfiguration("sbi-mvp01-20200325-00001-science_A",
                                       ReceiverBand.BAND_1, 1),
     cbf_config=CBFConfiguration([
         FSPConfiguration(
             1,
             FSPFunctionMode.CORR,
             1,
             1400,
             0,
             channel_averaging_map=[(0, 2), (744, 0)],
             fsp_channel_offset=0,
             output_link_map=[(0, 0), (200, 1)],
         ),
         FSPConfiguration(
             2,
             FSPFunctionMode.CORR,
             2,
             1400,
             1,
             channel_averaging_map=[(0, 2), (744, 0)],
             fsp_channel_offset=744,
             output_link_map=[(0, 4), (200, 5)],
             zoom_window_tuning=4700000,
         )