示例#1
0
文件: test_fss.py 项目: andsor/pyfssa
    def test_no_error_if_not_da_all_positive(self):
        """
        Test that function does not raise ValueError if any da is not positive
        """

        # da should have only positive entries
        args = copy.deepcopy(self.default_params)
        args['da'][1, 1] = 0.
        fssa.scaledata(**args)

        args = copy.deepcopy(self.default_params)
        args['da'][1, 0] = -1.
        fssa.scaledata(**args)
示例#2
0
文件: test_fss.py 项目: andsor/pyfssa
    def test_rho_c_in_range(self):
        """
        Test that function issues warning when rho_c is out of range
        """

        args = copy.deepcopy(self.default_params)
        args['rho_c'] = args['rho'].max() + 1.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            fssa.scaledata(**args)
            assert len(w) == 1
            assert issubclass(w[-1].category, RuntimeWarning)
            assert "out of range" in str(w[-1].message)
示例#3
0
    def test_no_error_if_not_da_all_positive(self):
        """
        Test that function does not raise ValueError if any da is not positive
        """

        # da should have only positive entries
        args = copy.deepcopy(self.default_params)
        args['da'][1, 1] = 0.
        fssa.scaledata(**args)

        args = copy.deepcopy(self.default_params)
        args['da'][1, 0] = -1.
        fssa.scaledata(**args)
示例#4
0
    def test_rho_c_in_range(self):
        """
        Test that function issues warning when rho_c is out of range
        """

        args = copy.deepcopy(self.default_params)
        args['rho_c'] = args['rho'].max() + 1.
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            fssa.scaledata(**args)
            assert len(w) == 1
            assert issubclass(w[-1].category, RuntimeWarning)
            assert "out of range" in str(w[-1].message)
示例#5
0
 def setUp(self):
     rho = np.linspace(-1, 1, num=11)
     l = np.logspace(1, 3, num=3)
     l_mesh, rho_mesh = np.meshgrid(l, rho, indexing='ij')
     a = 1. / (1. + np.exp(-np.log10(l_mesh) * rho_mesh))
     da = np.ones_like(a) * 1e-2
     self.scaled_data = fssa.scaledata(l, rho, a, da, 0, 1, 0)
示例#6
0
文件: test_fss.py 项目: andsor/pyfssa
 def setUp(self):
     rho = np.linspace(-1, 1, num=11)
     l = np.logspace(1, 3, num=3)
     l_mesh, rho_mesh = np.meshgrid(l, rho, indexing='ij')
     a = 1. / (1. + np.exp(- np.log10(l_mesh) * rho_mesh))
     da = np.ones_like(a) * 1e-2
     self.scaled_data = fssa.scaledata(l, rho, a, da, 0, 1, 0)
示例#7
0
 def test_zero_zeta_keeps_y_values(self):
     """
     Check that $\zeta = 0$ does not affect the y values
     """
     args = copy.deepcopy(self.default_params)
     args['zeta'] = 0.0
     result = fssa.scaledata(**self.default_params)
     self.assertTrue(np.all(args['a'] == result.y))
示例#8
0
文件: test_fss.py 项目: andsor/pyfssa
 def test_zero_zeta_keeps_y_values(self):
     """
     Check that $\zeta = 0$ does not affect the y values
     """
     args = copy.deepcopy(self.default_params)
     args['zeta'] = 0.0
     result = fssa.scaledata(**self.default_params)
     self.assertTrue(np.all(args['a'] == result.y))
示例#9
0
文件: test_fss.py 项目: andsor/pyfssa
 def test_output_namedtuple(self):
     """
     Test that function returns namedtuple with correct field names
     """
     result = fssa.scaledata(**self.default_params)
     fields = ['x', 'y', 'dy']
     for i in range(len(fields)):
         try:  # python 3
             with self.subTest(i=i):
                 self.assertTrue(hasattr(result, fields[i]))
                 self.assertIs(getattr(result, fields[i]), result[i])
         except AttributeError:  # python 2
             self.assertTrue(hasattr(result, fields[i]))
             self.assertIs(getattr(result, fields[i]), result[i])
示例#10
0
 def test_output_namedtuple(self):
     """
     Test that function returns namedtuple with correct field names
     """
     result = fssa.scaledata(**self.default_params)
     fields = ['x', 'y', 'dy']
     for i in range(len(fields)):
         try:  # python 3
             with self.subTest(i=i):
                 self.assertTrue(hasattr(result, fields[i]))
                 self.assertIs(getattr(result, fields[i]), result[i])
         except AttributeError:  # python 2
             self.assertTrue(hasattr(result, fields[i]))
             self.assertIs(getattr(result, fields[i]), result[i])
示例#11
0
文件: test_fss.py 项目: andsor/pyfssa
    def test_values(self):
        """
        Check some arbitrary value
        """

        l = self.default_params['l'][2]
        rho = self.default_params['rho'][3]
        rho_c = self.default_params['rho_c']
        nu = self.default_params['nu']
        zeta = self.default_params['zeta']
        a = self.default_params['a'][2, 3]
        da = self.default_params['da'][2, 3]

        result = fssa.scaledata(**self.default_params)
        self.assertAlmostEqual(result.x[2, 3], l ** (1. / nu) * (rho - rho_c))
        self.assertAlmostEqual(result.y[2, 3], l ** (- zeta / nu) * a)
        self.assertAlmostEqual(result.dy[2, 3], l ** (- zeta / nu) * da)
示例#12
0
 def test_output_shape(self):
     """
     Test that function returns three ndarrays of correct shape
     """
     correct_shape = (
         self.default_params['l'].size,
         self.default_params['rho'].size,
     )
     result = fssa.scaledata(**self.default_params)
     for i in range(3):
         try:  # python 3
             with self.subTest(i=i):
                 self.assertTupleEqual(
                     np.asarray(result[i]).shape, correct_shape)
         except AttributeError:  # python 2
             self.assertTupleEqual(
                 np.asarray(result[i]).shape, correct_shape)
示例#13
0
    def test_values(self):
        """
        Check some arbitrary value
        """

        l = self.default_params['l'][2]
        rho = self.default_params['rho'][3]
        rho_c = self.default_params['rho_c']
        nu = self.default_params['nu']
        zeta = self.default_params['zeta']
        a = self.default_params['a'][2, 3]
        da = self.default_params['da'][2, 3]

        result = fssa.scaledata(**self.default_params)
        self.assertAlmostEqual(result.x[2, 3], l**(1. / nu) * (rho - rho_c))
        self.assertAlmostEqual(result.y[2, 3], l**(-zeta / nu) * a)
        self.assertAlmostEqual(result.dy[2, 3], l**(-zeta / nu) * da)
示例#14
0
文件: test_fss.py 项目: andsor/pyfssa
 def test_output_shape(self):
     """
     Test that function returns three ndarrays of correct shape
     """
     correct_shape = (
         self.default_params['l'].size,
         self.default_params['rho'].size,
     )
     result = fssa.scaledata(**self.default_params)
     for i in range(3):
         try:  # python 3
             with self.subTest(i=i):
                 self.assertTupleEqual(
                     np.asarray(result[i]).shape,
                     correct_shape
                 )
         except AttributeError:  # python 2
             self.assertTupleEqual(
                 np.asarray(result[i]).shape, correct_shape
             )
    L_C[2][i] = C_20[i]
    L_C[3][i] = C_25[i]

d_L_C = np.zeros((len(L), len(C_5)))
for i in range(len(C_5)):
    d_L_C[0][i] = C_10_s[i]
    d_L_C[1][i] = C_15_s[i]
    d_L_C[2][i] = C_20_s[i]
    d_L_C[3][i] = C_25_s[i]

C_reg = 9999
f_reg = 9999

C_reg_array = np.linspace(0, 3, 10000)
for C_0 in C_reg_array:
    scaled_data = fssa.scaledata(L, T, L_C + C_0, d_L_C, 1 / 0.2216, 0.62997,
                                 0.11008)
    f = fssa.quality(scaled_data.x, scaled_data.y, scaled_data.dy)

    if f < f_reg:
        C_reg = C_0
        f_reg = f
        print(C_reg, f_reg)

ret = fssa.autoscale(L, T, L_C + C_reg, d_L_C, 1 / 0.2216, 0.62997, 0.11008)
print("C_reg:", C_reg)
print("rho:", ret.rho, ret.drho)
print("nu:", ret.nu, ret.dnu)
print("zeta:", ret.zeta, ret.dzeta)
print("f:", ret.fun)

data = fssa.scaledata(L, T, L_C + C_reg, d_L_C, ret.rho, ret.nu, ret.zeta)
示例#16
0
文件: test_fss.py 项目: andsor/pyfssa
 def test_output_len(self):
     """
     Test that function returns at least three items
     """
     result = fssa.scaledata(**self.default_params)
     self.assertGreaterEqual(len(result), 3)
示例#17
0
 def test_output_len(self):
     """
     Test that function returns at least three items
     """
     result = fssa.scaledata(**self.default_params)
     self.assertGreaterEqual(len(result), 3)