Beispiel #1
0
def test_CFMaskCoder_decode_dask() -> None:
    original = xr.Variable(("x", ), [0, -1, 1], {"_FillValue": -1}).chunk()
    expected = xr.Variable(("x", ), [0, np.nan, 1])
    coder = variables.CFMaskCoder()
    encoded = coder.decode(original)
    assert isinstance(encoded.data, da.Array)
    assert_identical(expected, encoded)
Beispiel #2
0
def test_CFMaskCoder_encode_missing_fill_values_conflict():
    original = xr.Variable(
        ("x", ),
        [0.0, -1.0, 1.0],
        encoding={
            "_FillValue": np.float32(1e20),
            "missing_value": np.float64(1e20)
        },
    )
    coder = variables.CFMaskCoder()
    encoded = coder.encode(original)

    assert encoded.dtype == encoded.attrs["missing_value"].dtype
    assert encoded.dtype == encoded.attrs["_FillValue"].dtype

    with pytest.warns(variables.SerializationWarning):
        roundtripped = coder.decode(coder.encode(original))
        assert_identical(roundtripped, original)
Beispiel #3
0
def test_coder_roundtrip() -> None:
    original = xr.Variable(("x", ), [0.0, np.nan, 1.0])
    coder = variables.CFMaskCoder()
    roundtripped = coder.decode(coder.encode(original))
    assert_identical(original, roundtripped)
Beispiel #4
0
def test_CFMaskCoder_decode() -> None:
    original = xr.Variable(("x", ), [0, -1, 1], {"_FillValue": -1})
    expected = xr.Variable(("x", ), [0, np.nan, 1])
    coder = variables.CFMaskCoder()
    encoded = coder.decode(original)
    assert_identical(expected, encoded)