# Copyright (c) 2018 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Test the `slices` module."""

import numpy as np
import pytest
import xarray as xr

from metpy.interpolate import cross_section, geodesic, interpolate_to_slice
from metpy.testing import assert_array_almost_equal


@pytest.fixture()
def test_ds_lonlat():
    """Return dataset on a lon/lat grid with no time coordinate for use in tests."""
    data_temp = np.linspace(250, 300, 5 * 6 * 7).reshape((5, 6, 7))
    data_rh = np.linspace(0, 1, 5 * 6 * 7).reshape((5, 6, 7))
    ds = xr.Dataset(
        {
            'temperature': (['isobaric', 'lat', 'lon'], data_temp),
            'relative_humidity': (['isobaric', 'lat', 'lon'], data_rh)
        },
        coords={
            'isobaric': xr.DataArray(
                np.linspace(1000, 500, 5),
                name='isobaric',
                dims=['isobaric'],
                attrs={'units': 'hPa'}
            ),
            'lat': xr.DataArray(
                np.linspace(30, 45, 6),
                name='lat',
                dims=['lat'],
                attrs={'units': 'degrees_north'}
            ),
            'lon': xr.DataArray(
                np.linspace(255, 275, 7),
                name='lon',
                dims=['lon'],
                attrs={'units': 'degrees_east'}
            )
        }
    )
    ds['temperature'].attrs['units'] = 'kelvin'
    ds['relative_humidity'].attrs['units'] = 'dimensionless'
    return ds.metpy.parse_cf()


@pytest.fixture()
def test_ds_xy():
    """Return dataset on a x/y grid with a time coordinate for use in tests."""
    data_temperature = np.linspace(250, 300, 5 * 6 * 7).reshape((1, 5, 6, 7))
    ds = xr.Dataset(
        {
            'temperature': (['time', 'isobaric', 'y', 'x'], data_temperature),
            'lambert_conformal': ([], '')
        },
        coords={
            'time': xr.DataArray(
                np.array([np.datetime64('2018-07-01T00:00')]),
                name='time',
                dims=['time']
            ),
            'isobaric': xr.DataArray(
                np.linspace(1000, 500, 5),
                name='isobaric',
                dims=['isobaric'],
                attrs={'units': 'hPa'}
            ),
            'y': xr.DataArray(
                np.linspace(-1500, 0, 6),
                name='y',
                dims=['y'],
                attrs={'units': 'km'}
            ),
            'x': xr.DataArray(
                np.linspace(-500, 3000, 7),
                name='x',
                dims=['x'],
                attrs={'units': 'km'}
            )
        }
    )
    ds['temperature'].attrs = {
        'units': 'kelvin',