# Path: blimpy/utils.py
# def db(x, offset=0):
# def lin(x):
# def closest(xarr, val):
# def rebin(d, n_x=None, n_y=None, n_z=None):
# def unpack(data, nbit):
# def unpack_1to8(data):
# def unpack_2to8(data):
# def unpack_4to8(data):
# def change_the_ext(path, old_ext, new_ext):


from blimpy import utils
import numpy as np
import pytest


def test_utils():
    assert utils.db(100) == 20.0
    assert utils.lin(20)  == 100.0
    assert utils.closest(np.array([0,1,2,3,4,5]), 2.2) == 2

def test_rebin():
    # 1D
    a = np.array([1, 1, 1, 1])
    aR = utils.rebin(a, 2)
    assert np.allclose(aR, np.array([1, 1]))

    # 2D
    b = np.array([[1,1,1,1], [2,2,2,2]])
    bR = utils.rebin(b, 1, 2)
    assert np.allclose(bR, [[1,1], [2,2]])

# Path: blimpy/utils.py
# def db(x, offset=0):
# def lin(x):
# def closest(xarr, val):
# def rebin(d, n_x=None, n_y=None, n_z=None):
# def unpack(data, nbit):
# def unpack_1to8(data):
# def unpack_2to8(data):
# def unpack_4to8(data):
# def change_the_ext(path, old_ext, new_ext):


# Path: tests/test_utils.py
from blimpy import utils
import numpy as np
import pytest



def test_utils():
    assert utils.db(100) == 20.0
    assert utils.lin(20)  == 100.0
    assert utils.closest(np.array([0,1,2,3,4,5]), 2.2) == 2

def test_rebin():
    # 1D
    a = np.array([1, 1, 1, 1])
    aR = utils.rebin(a, 2)
    assert np.allclose(aR, np.array([1, 1]))

    # 2D
    b = np.array([[1,1,1,1], [2,2,2,2]])
    bR = utils.rebin(b, 1, 2)
    assert np.allclose(bR, [[1,1], [2,2]])

    bR = utils.rebin(b, None, 2)