How to use the xarray.testing.assert_equal function in xarray

To help you get started, we’ve selected a few xarray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github corteva / rioxarray / test / integration / test_integration__io.py View on Github external
with env:
            with rasterio.open(url) as src:
                with rasterio.vrt.WarpedVRT(src, crs="epsg:4326") as vrt:
                    expected_shape = (vrt.width, vrt.height)
                    expected_crs = vrt.crs
                    expected_res = vrt.res
                    # Value of single pixel in center of image
                    lon, lat = vrt.xy(vrt.width // 2, vrt.height // 2)
                    expected_val = next(vrt.sample([(lon, lat)]))
                    with xr.open_rasterio(vrt) as da:
                        actual_shape = (da.sizes["x"], da.sizes["y"])
                        actual_crs = da.crs
                        actual_res = da.res
                        actual_val = da.sel(dict(x=lon, y=lat), method="nearest").data

                        assert_equal(actual_shape, expected_shape)
                        assert_equal(actual_crs, expected_crs)
                        assert_equal(actual_res, expected_res)
                        assert_equal(expected_val, actual_val)
github PyPSA / atlite / test / test_preparation_and_conversion.py View on Github external
def update_feature_test(cutout, red):
    """atlite should be able to overwrite a feature."""
    red.data = cutout.data.drop_vars('influx_direct')
    red.prepare('influx', overwrite=True)
    assert_equal(red.data.influx_direct, cutout.data.influx_direct)
github rsokl / noggin / tests / test_utils.py View on Github external
assert plotter._pltkwargs["nrows"] * plotter._pltkwargs["ncols"] >= len(
        plotter.metrics
    )

    figsize = kwargs.get("figsize")
    if figsize is not None:
        assert plotter.figsize == figsize

    train_batch_expected, train_epoch_expected = logger.to_xarray("train")
    test_batch_expected, test_epoch_expected = logger.to_xarray("test")

    train_batch_actual, train_epoch_actual = plotter.to_xarray("train")
    test_batch_actual, test_epoch_actual = plotter.to_xarray("test")

    assert_equal(train_batch_actual, train_batch_expected)
    assert_equal(test_batch_actual, test_batch_expected)
    assert_equal(train_epoch_actual, train_epoch_expected)
    assert_equal(test_epoch_actual, test_epoch_expected)
github pennmem / ptsa_new / tests / test_filters.py View on Github external
def test_ButterwothFilter(self):

        from xarray.testing import assert_equal

        b_filter = ButterworthFilter(timeseries=self.base_eegs, freq_range=[58., 62.], filt_type='stop', order=4)
        base_eegs_filtered_1 = b_filter.filter()

        base_eegs_filtered_2 = self.base_eegs.filtered(freq_range=[58., 62.], filt_type='stop', order=4)

        assert_equal(base_eegs_filtered_1, base_eegs_filtered_2)

        with self.assertRaises(AssertionError):
            assert_equal(base_eegs_filtered_1, self.base_eegs)
github Unidata / MetPy / tests / calc / test_calc_tools.py View on Github external
# Assert results match expectations
    xr.testing.assert_allclose(deriv_x, truth_x)
    assert deriv_x.metpy.units == truth_x.metpy.units
    xr.testing.assert_allclose(deriv_y, truth_y)
    assert deriv_y.metpy.units == truth_y.metpy.units
    xr.testing.assert_allclose(deriv_p, truth_p)
    assert deriv_p.metpy.units == truth_p.metpy.units

    # Assert alternative specifications give same results (up to attribute differences)
    xr.testing.assert_equal(deriv_x_alt1, deriv_x)
    xr.testing.assert_equal(deriv_y_alt1, deriv_y)
    xr.testing.assert_equal(deriv_p_alt1, deriv_p)
    xr.testing.assert_equal(deriv_x_alt2, deriv_x)
    xr.testing.assert_equal(deriv_y_alt2, deriv_y)
    xr.testing.assert_equal(deriv_p_alt2, deriv_p)
github pennmem / ptsa_new / tests / test_filters.py View on Github external
def test_ButterwothFilter(self):

        from xarray.testing import assert_equal

        b_filter = ButterworthFilter(timeseries=self.base_eegs, freq_range=[58., 62.], filt_type='stop', order=4)
        base_eegs_filtered_1 = b_filter.filter()

        base_eegs_filtered_2 = self.base_eegs.filtered(freq_range=[58., 62.], filt_type='stop', order=4)

        assert_equal(base_eegs_filtered_1, base_eegs_filtered_2)

        with self.assertRaises(AssertionError):
            assert_equal(base_eegs_filtered_1, self.base_eegs)
github PyPSA / atlite / test / test_creation.py View on Github external
def test_xy_reversed_coords(ref):
    cutout = Cutout(path="xy_r", module="era5", time=TIME,
                    x=slice(X1, X0), y = slice(Y1, Y0))
    assert_equal(cutout.coords.to_dataset(), ref.coords.to_dataset())
github Unidata / MetPy / tests / calc / test_calc_tools.py View on Github external
coords=(('isobaric', test_da_xy['isobaric']),)
    )
    _, truth_p = xr.broadcast(test_da_xy, partial)
    truth_p.coords['crs'] = test_da_xy['crs']
    truth_p.attrs['units'] = 'kelvin / hectopascal'

    # Assert results match expectations
    xr.testing.assert_allclose(deriv_x, truth_x)
    assert deriv_x.metpy.units == truth_x.metpy.units
    xr.testing.assert_allclose(deriv_y, truth_y)
    assert deriv_y.metpy.units == truth_y.metpy.units
    xr.testing.assert_allclose(deriv_p, truth_p)
    assert deriv_p.metpy.units == truth_p.metpy.units

    # Assert alternative specifications give same results (up to attribute differences)
    xr.testing.assert_equal(deriv_x_alt1, deriv_x)
    xr.testing.assert_equal(deriv_y_alt1, deriv_y)
    xr.testing.assert_equal(deriv_p_alt1, deriv_p)
    xr.testing.assert_equal(deriv_x_alt2, deriv_x)
    xr.testing.assert_equal(deriv_y_alt2, deriv_y)
    xr.testing.assert_equal(deriv_p_alt2, deriv_p)
github iiasa / ixmp / ixmp / reporting / testing.py View on Github external
:meth:`as_quantity`.
    """
    if not check_type:
        a = Quantity(a)
        b = Quantity(b)

    if Quantity.CLASS == 'AttrSeries':
        try:
            a = a.sort_index()
            b = b.sort_index()
        except TypeError:
            pass
        assert_series_equal(a, b, check_dtype=False, **kwargs)
    else:
        import xarray.testing
        xarray.testing.assert_equal(a, b, **kwargs)

    # check attributes are equal
    if check_attrs:
        assert a.attrs == b.attrs
github timeflux / timeflux / test / helpers / test_mne.py View on Github external
def test_mne_dataarray_conversions():
    epochs = xarray_to_mne(original_data, original_meta, context_key, event_id)
    after_conversion_data, after_conversion_meta = mne_to_xarray(epochs, context_key, event_id)
    # assert that the passage in mne keeps the data unchanged
    xr.testing.assert_equal(after_conversion_data, original_data)
    assert original_meta == after_conversion_meta