def test_scale_merged_intensities_phenix(hewl_merged, ref_hewl,
                                         mean_intensity_method):
    """
    Compare phenix.french_wilson to scale_merged_intensities(). Current
    test criteria are that >95% of I, SigI, F, and SigF are within 2%.
    """
    mtz = hewl_merged.dropna()
    scaled = scale_merged_intensities(
        mtz, "IMEAN", "SIGIMEAN", mean_intensity_method=mean_intensity_method)

    # Assert no reflections were dropped
    assert len(scaled) == len(ref_hewl)

    # Intensities should be identical
    assert np.array_equal(scaled["IMEAN"].to_numpy(), ref_hewl["I"].to_numpy())
    assert np.array_equal(scaled["SIGIMEAN"].to_numpy(),
                          ref_hewl["SIGI"].to_numpy())

    rsF = scaled["FW-F"].to_numpy()
    rsSigF = scaled["FW-SIGF"].to_numpy()
    refF = ref_hewl["F"].to_numpy()
    refSigF = ref_hewl["SIGF"].to_numpy()

    rsI = scaled["FW-I"].to_numpy()
    rsSigI = scaled["FW-SIGI"].to_numpy()
    refI = ref_hewl["I"].to_numpy()
    refSigI = ref_hewl["SIGI"].to_numpy()

    assert (np.isclose(rsI, refI, rtol=0.02).sum() / len(scaled)) >= 0.95
    assert (np.isclose(rsSigI, refSigI, rtol=0.02).sum() / len(scaled)) >= 0.95

    assert (np.isclose(rsF, refF, rtol=0.02).sum() / len(scaled)) >= 0.95
    assert (np.isclose(rsSigF, refSigF, rtol=0.02).sum() / len(scaled)) >= 0.95
Beispiel #2
0
def test_scale_merged_intensities_validdata(hewl_merged, inplace, output_columns,
                                            mean_intensity_method):
    """
    Confirm scale_merged_intensities() returns all positive values
    """
    scaled = scale_merged_intensities(hewl_merged, "IMEAN", "SIGIMEAN",
                                      output_columns=output_columns,
                                      inplace=inplace,
                                      mean_intensity_method=mean_intensity_method)

    # Confirm inplace returns same object if true
    if inplace:
        assert id(scaled) == id(hewl_merged)
    else:
        assert id(scaled) != id(hewl_merged)

    defaults = ("FW-I", "FW-SIGI", "FW-F", "FW-SIGF")
    if output_columns:
        o1, o2, o3, o4 = output_columns
    else:
        o1, o2, o3, o4 = defaults
        
    # Confirm output columns are of desired types
    assert isinstance(scaled[o1].dtype, rs.IntensityDtype)
    assert isinstance(scaled[o2].dtype, rs.StandardDeviationDtype)
    assert isinstance(scaled[o3].dtype, rs.StructureFactorAmplitudeDtype)
    assert isinstance(scaled[o4].dtype, rs.StandardDeviationDtype)

    # Confirm output columns are strictly positive
    assert (scaled[o1].to_numpy() >= 0).all()
    assert (scaled[o2].to_numpy() >= 0).all()
    assert (scaled[o3].to_numpy() >= 0).all()
    assert (scaled[o4].to_numpy() >= 0).all()
Beispiel #3
0
def test_scale_merged_intensities_dropna(data_hewl_all, dropna):
    """
    Test scale_merged_intensities() using data containing NaNs in different
    columns.
    """
    keys = ["IMEAN", "SIGIMEAN"]
    nan_in_intensity = data_hewl_all[keys].isna().to_numpy().any()

    if nan_in_intensity and not dropna:
        with pytest.raises(ValueError):
            scaled = scale_merged_intensities(data_hewl_all, "IMEAN",
                                              "SIGIMEAN", dropna=dropna)
    else:
        scaled = scale_merged_intensities(data_hewl_all, "IMEAN", "SIGIMEAN",
                                          dropna=dropna)
        assert id(scaled) != id(data_hewl_all)
        assert (scaled["FW-I"].to_numpy() >= 0.).all()