# Path: freesas/test/utilstests.py
# def get_datafile(name):
#     """Provides the full path of a test file,
#     downloading it from the internet if needed
# 
#     :param name: name of the file to get
#     :return: full path of the datafile
#     """
#     logger.info(f"Download file {name}")
#     fullpath = downloader.getfile(name)
#     return fullpath
# 
# Path: freesas/autorg.py
# def auto_gpa(data, Rg_min=1.0, qRg_max=1.3, qRg_min=0.5):
#     def curate_data(data):
# def auto_guinier(data, Rg_min=1.0, qRg_max=1.3, relax=1.2):
#         I = data.T[1]
#         I = I[range0]
#         I0 = I[p1] * numpy.exp(q2[p1] * Rg ** 2 / 3.0)
#         I1 = I[range1]
# 
# Path: freesas/invariants.py
# def calc_Rambo_Tainer(data,
#                       guinier, qmax=2.0):
#     """calculates the invariants Vc and Qr from the Rambo & Tainer 2013 Paper,
#     also the the mass estimate based on Qr for proteins
#     
#     :param data: data in q,I,dI format, q in nm^-1
#     :param guinier: RG_RESULT instance with result from the Guinier fit
#     :param qmax: maximum q-value for the calculation in nm^-1
#     @return: dict with Vc, Qr and mass plus errors
#     """
#     scale_prot = 1.0 / 0.1231
#     power_prot = 1.0
# 
#     imax = abs(data[:, 0] - qmax).argmin()
#     if (imax <= guinier.start_point) or (guinier.start_point < 0):  # unlikely but can happened
#         logger.error("Guinier region start too late for Rambo_Tainer invariants calculation")
#         return None
#     vc = calc_Vc(data[:imax, :], guinier.Rg, guinier.sigma_Rg, guinier.I0, guinier.sigma_I0, guinier.start_point)
# 
#     qr = vc[0] ** 2 / (guinier.Rg)
#     mass = scale_prot * qr ** power_prot
# 
#     dqr = qr * (guinier.sigma_Rg / guinier.Rg + 2 * ((vc[1]) / (vc[0])))
#     dmass = mass * dqr / qr
# 
#     return RT_RESULT(vc[0], vc[1], qr, dqr, mass, dmass)


import logging
import unittest
import numpy
from math import sqrt, pi
from scipy.stats import linregress
from .utilstests import get_datafile
from ..autorg import (
    autoRg,
    RG_RESULT,
    linear_fit,
    auto_gpa,
    auto_guinier,
)
from .._autorg import curate_data  # pylint: disable=E0401
from ..invariants import calc_Rambo_Tainer
from .._bift import distribution_sphere  # pylint: disable=E0401
            59.93,
            61.29,
            63.11,
            64.47,
            66.28,
            68.1,
            69.92,
            72.19,
            74.46,
        ]
        testw = [1.0] * 15
        testintercept = -39.061956
        testslope = +61.2721865
        fit_result = linear_fit(testx, testy, testw)
        # print(fit_result)
        self.assertAlmostEqual(
            fit_result.intercept,
            testintercept,
            5,
            "Intercept fits wihtin 4(?) digits",
        )
        self.assertAlmostEqual(
            fit_result.slope, testslope, 5, "Intercept fits wihtin 4(?) digits"
        )

    def test_linspace(self):
        size = 100
        x = numpy.linspace(-10, 10, size)
        y = numpy.linspace(10, 0, size)
        w = numpy.random.random(size)

# Path: freesas/test/utilstests.py
# def get_datafile(name):
#     """Provides the full path of a test file,
#     downloading it from the internet if needed
# 
#     :param name: name of the file to get
#     :return: full path of the datafile
#     """
#     logger.info(f"Download file {name}")
#     fullpath = downloader.getfile(name)
#     return fullpath
# 
# Path: freesas/autorg.py
# def auto_gpa(data, Rg_min=1.0, qRg_max=1.3, qRg_min=0.5):
#     def curate_data(data):
# def auto_guinier(data, Rg_min=1.0, qRg_max=1.3, relax=1.2):
#         I = data.T[1]
#         I = I[range0]
#         I0 = I[p1] * numpy.exp(q2[p1] * Rg ** 2 / 3.0)
#         I1 = I[range1]
# 
# Path: freesas/invariants.py
# def calc_Rambo_Tainer(data,
#                       guinier, qmax=2.0):
#     """calculates the invariants Vc and Qr from the Rambo & Tainer 2013 Paper,
#     also the the mass estimate based on Qr for proteins
#     
#     :param data: data in q,I,dI format, q in nm^-1
#     :param guinier: RG_RESULT instance with result from the Guinier fit
#     :param qmax: maximum q-value for the calculation in nm^-1
#     @return: dict with Vc, Qr and mass plus errors
#     """
#     scale_prot = 1.0 / 0.1231
#     power_prot = 1.0
# 
#     imax = abs(data[:, 0] - qmax).argmin()
#     if (imax <= guinier.start_point) or (guinier.start_point < 0):  # unlikely but can happened
#         logger.error("Guinier region start too late for Rambo_Tainer invariants calculation")
#         return None
#     vc = calc_Vc(data[:imax, :], guinier.Rg, guinier.sigma_Rg, guinier.I0, guinier.sigma_I0, guinier.start_point)
# 
#     qr = vc[0] ** 2 / (guinier.Rg)
#     mass = scale_prot * qr ** power_prot
# 
#     dqr = qr * (guinier.sigma_Rg / guinier.Rg + 2 * ((vc[1]) / (vc[0])))
#     dmass = mass * dqr / qr
# 
#     return RT_RESULT(vc[0], vc[1], qr, dqr, mass, dmass)


# Path: freesas/test/test_autorg.py
import logging
import unittest
import numpy
from math import sqrt, pi
from scipy.stats import linregress
from .utilstests import get_datafile
from ..autorg import (
    autoRg,
    RG_RESULT,
    linear_fit,
    auto_gpa,
    auto_guinier,
)
from .._autorg import curate_data  # pylint: disable=E0401
from ..invariants import calc_Rambo_Tainer
from .._bift import distribution_sphere  # pylint: disable=E0401

            59.93,
            61.29,
            63.11,
            64.47,
            66.28,
            68.1,
            69.92,
            72.19,
            74.46,
        ]
        testw = [1.0] * 15
        testintercept = -39.061956
        testslope = +61.2721865
        fit_result = linear_fit(testx, testy, testw)
        # print(fit_result)
        self.assertAlmostEqual(
            fit_result.intercept,
            testintercept,
            5,
            "Intercept fits wihtin 4(?) digits",
        )
        self.assertAlmostEqual(
            fit_result.slope, testslope, 5, "Intercept fits wihtin 4(?) digits"
        )

    def test_linspace(self):
        size = 100
        x = numpy.linspace(-10, 10, size)
        y = numpy.linspace(10, 0, size)
        w = numpy.random.random(size)

        fit_result = linear_fit(x, y, w)