#!/usr/bin/env python
# Copyright (c) 2011-2021, wradlib developers.
# Distributed under the MIT License. See LICENSE.txt for more info.

from dataclasses import dataclass

import numpy as np
import pytest

from wradlib import comp, georef, io, ipol, util

from . import requires_data, requires_gdal


@pytest.fixture
def comp_data():
    @dataclass(init=False, repr=False, eq=False)
    class Data:
        filename = "dx/raa00-dx_10908-0806021655-fbg---bin.gz"
        dx_file = util.get_wradlib_data_file(filename)
        data, metadata = io.read_dx(dx_file)
        radar_location = (8.005, 47.8744, 1517)
        elevation = 0.5  # in degree
        azimuths = np.arange(0, 360)  # in degrees
        ranges = np.arange(0, 128000.0, 1000.0)  # in meters
        polargrid = np.meshgrid(ranges, azimuths)
        coords, rad = georef.spherical_to_xyz(
            polargrid[0], polargrid[1], elevation, radar_location
        )
        x = coords[..., 0]
        y = coords[..., 1]

    yield Data


class TestCompose:
    @requires_data
    @requires_gdal
    def test_extract_circle(self, comp_data):
        x = comp_data.x
        y = comp_data.y
        xgrid = np.linspace(x.min(), x.mean(), 100)
        ygrid = np.linspace(y.min(), y.mean(), 100)
        grid_xy = np.meshgrid(xgrid, ygrid)
        grid_xy = np.vstack((grid_xy[0].ravel(), grid_xy[1].ravel())).transpose()