def test_multiplication(self): # should divide with another scalarfield if coherent axis system tmp_SF = self.SF.copy() tmp_SF.values *= 3 res_SF = tmp_SF * self.SF assert np.allclose(res_SF.values, self.SF.values*3*self.SF.values) assert np.allclose(res_SF.mask, self.SF.mask) assert Field.__eq__(res_SF, self.SF) # should divide with another array if coherent size values = self.SF.values.copy() values *= 3 res_SF = self.SF * values assert np.allclose(res_SF.values, self.SF.values**2*3) assert np.allclose(res_SF.mask, self.SF.mask) assert Field.__eq__(res_SF, self.SF) values = self.SF.values.copy() values *= 3 res_SF = self.SF.__rmul__(values) assert np.allclose(res_SF.values, self.SF.values**2*3) assert np.allclose(res_SF.mask, self.SF.mask) assert Field.__eq__(res_SF, self.SF) # # should add with cropped scalarfield if coherent axis system # tmp_SF = self.SF.copy().crop(intervx=[10, 50], ind=True) # tmp_SF.values *= 3 # res_SF = tmp_SF / self.SF # assert res_SF.shape == tmp_SF.shape # assert res_SF.shape[0] == 41 # assert np.allclose(res_SF.values, 3) # assert np.allclose(res_SF.mask, self.SF.mask) # assert not Field.__eq__(res_SF, self.SF) # should add with numbers tmp_SF = self.SF * 5 assert np.allclose(tmp_SF.values, self.SF.values*5) assert np.allclose(tmp_SF.mask, self.SF.mask) assert Field.__eq__(tmp_SF, self.SF) # should add with units if coherent tmp_SF = self.SF * 5.2*units.m assert np.allclose(tmp_SF.values, self.SF.values*5.2) assert tmp_SF.unit_values.strUnit() == '[m2/s]' assert np.allclose(tmp_SF.mask, self.SF.mask) assert Field.__eq__(tmp_SF, self.SF) # shoudl raise error if incoherent axis tmp_SF = self.SF.copy() tmp_SF.axis_x += 1 with pytest.raises(ValueError): tmp_SF * self.SF tmp_SF = self.SF.copy() tmp_SF.axis_y += 3.4 with pytest.raises(ValueError): tmp_SF * self.SF # should raise an error if incoherent units tmp_SF = self.SF.copy() tmp_SF.unit_x = 'Hz' with pytest.raises(unum.IncompatibleUnitsError): tmp_SF * self.SF
def test_scale(self): # should scale SF = self.SF tmp_SF = SF.scale(scalex=2.2) assert tmp_SF.dx == 2.2*SF.dx assert np.all(tmp_SF.axis_x == 2.2*SF.axis_x) tmp_SF = SF.scale(scaley=1.43) assert tmp_SF.dy == 1.43*SF.dy assert np.all(tmp_SF.axis_y == 1.43*SF.axis_y) tmp_SF = SF.scale(scalex=10, scaley=1.43) assert tmp_SF.dx == 10*SF.dx assert np.all(tmp_SF.axis_x == 10*SF.axis_x) assert tmp_SF.dy == 1.43*SF.dy assert np.all(tmp_SF.axis_y == 1.43*SF.axis_y) tmp_SF = self.SF.scale(scalev=5.4) assert np.allclose(SF.values*5.4, tmp_SF.values) assert Field.__eq__(tmp_SF, SF) # should scale inplace SF = self.SF tmp_SF = SF.copy() tmp_SF = SF.scale(scalex=10, scaley=1.43, scalev=5.4) assert tmp_SF.dx == 10*SF.dx assert np.all(tmp_SF.axis_x == 10*SF.axis_x) assert tmp_SF.dy == 1.43*SF.dy assert np.all(tmp_SF.axis_y == 1.43*SF.axis_y) assert np.allclose(SF.values*5.4, tmp_SF.values) # should scale with units SF = self.SF sx = -2.2*units.m sy = -1.43*units.Hz sv = -5.4*1/(units.m/units.s) tmp_SF = SF.scale(scalex=sx) assert np.isclose(tmp_SF.dx, 2.2*SF.dx) assert np.allclose(tmp_SF.axis_x, -2.2*SF.axis_x[::-1]) assert tmp_SF.unit_x.strUnit() == '[m2]' tmp_SF = SF.scale(scaley=sy) assert np.isclose(tmp_SF.dy, 1.43*SF.dy) assert np.all(tmp_SF.axis_y == -1.43*SF.axis_y[::-1]) assert tmp_SF.unit_y.strUnit() == '[Hz.mm]' tmp_SF = SF.scale(scalex=sx, scaley=sy) assert np.isclose(tmp_SF.dx, 2.2*SF.dx) assert np.all(tmp_SF.axis_x == -2.2*SF.axis_x[::-1]) assert np.isclose(tmp_SF.dy, 1.43*SF.dy) assert tmp_SF.unit_y.strUnit() == '[Hz.mm]' assert tmp_SF.unit_x.strUnit() == '[m2]' assert np.allclose(tmp_SF.axis_y, -1.43*SF.axis_y[::-1]) tmp_SF = self.SF.scale(scalev=sv) assert np.allclose(SF.values*-5.4, tmp_SF.values) assert tmp_SF.unit_values.strUnit() == '[]' assert Field.__eq__(tmp_SF, SF)
def test_substitutaion(self): # should add other scalarfield if coherent axis system tmp_SF = self.SF.copy() tmp_SF.values *= 3 res_SF = tmp_SF - self.SF assert np.allclose(res_SF.values, 2*self.SF.values) assert np.all(res_SF.mask == 2*self.SF.mask) assert Field.__eq__(res_SF, self.SF)
def test_substitutaion(self): # should add other vectorfield if coherent axis system tmp_VF = self.VF.copy() tmp_VF.comp_x *= 3 res_VF = tmp_VF - self.VF assert np.allclose(res_VF.comp_x, 2 * self.VF.comp_x) assert np.all(res_VF.mask == 2 * self.VF.mask) assert Field.__eq__(res_VF, self.VF)
def test_addition(self): # should add other scalarfield if coherent axis system tmp_SF = self.SF.copy() tmp_SF.values *= 3 res_SF = tmp_SF + self.SF assert np.all(res_SF.values == 4*self.SF.values) assert np.all(res_SF.mask == self.SF.mask) assert Field.__eq__(res_SF, self.SF) # should add with cropped scalarfield if coherent axis system tmp_SF = self.SF.copy().crop(intervx=[10, 50], ind=True) tmp_SF.values *= 3 res_SF = tmp_SF + self.SF assert res_SF.shape == tmp_SF.shape assert res_SF.shape[0] == 41 assert np.all(res_SF.values == 4*self.SF.values[10:51]) assert np.all(res_SF.mask == self.SF.mask[10:51]) assert not Field.__eq__(res_SF, self.SF) # should add with numbers tmp_SF = self.SF + 5 assert np.all(tmp_SF.values == 5 + self.SF.values) assert np.all(tmp_SF.mask == self.SF.mask) assert Field.__eq__(tmp_SF, self.SF) # should add with units if coherent tmp_SF = self.SF + 5.2*units.m/units.s assert np.all(tmp_SF.values == 5.2 + self.SF.values) assert np.all(tmp_SF.mask == self.SF.mask) assert Field.__eq__(tmp_SF, self.SF) # shoudl raise error if incoherent axis tmp_SF = self.SF.copy() tmp_SF.axis_x += 1 with pytest.raises(ValueError): tmp_SF + self.SF tmp_SF = self.SF.copy() tmp_SF.axis_y += 3.4 with pytest.raises(ValueError): tmp_SF + self.SF # should raise an error if incoherent units tmp_SF = self.SF.copy() tmp_SF.unit_x = 'Hz' with pytest.raises(unum.IncompatibleUnitsError): tmp_SF + self.SF
def test_power(self): # should raise to the power tmp_SF = self.SF**3.14 values = tmp_SF.values values[~tmp_SF.mask] = values[~tmp_SF.mask]**3.14 tmp_SF.values = values assert np.allclose(tmp_SF.values[~tmp_SF.mask], self.SF.values[~tmp_SF.mask]**3.14) assert Field.__eq__(tmp_SF, self.SF) # should rais error if not numbers with pytest.raises(TypeError): a = 'test' tmp_SF**a
def test_power(self): # should raise to the power tmp_VF = self.VF**3.14 comp_x = tmp_VF.comp_x comp_x[~tmp_VF.mask] = comp_x[~tmp_VF.mask]**3.14 tmp_VF.comp_x = comp_x assert np.allclose(tmp_VF.comp_x[~tmp_VF.mask], self.VF.comp_x[~tmp_VF.mask]**3.14) assert Field.__eq__(tmp_VF, self.VF) # should rais error if not numbers with pytest.raises(TypeError): a = 'test' tmp_VF**a
def test_abs(self): # should return absolute tmp_SF = abs(self.SF) assert np.allclose(tmp_SF.values, abs(self.SF.values)) assert np.allclose(tmp_SF.mask, self.SF.mask) assert Field.__eq__(tmp_SF, self.SF)
def test_abs(self): # should return absolute tmp_VF = abs(self.VF) assert np.allclose(tmp_VF.comp_x, abs(self.VF.comp_x)) assert np.allclose(tmp_VF.mask, self.VF.mask) assert Field.__eq__(tmp_VF, self.VF)
def test_division(self): # should divide with another vectorfield if coherent axis system tmp_VF = self.VF.copy() tmp_VF.comp_x *= 3 res_VF = tmp_VF / self.VF assert np.allclose(res_VF.comp_x, 3) assert np.allclose(res_VF.mask, self.VF.mask) assert Field.__eq__(res_VF, self.VF) # should divide with another array if coherent size comp_x = self.VF.comp_x.copy() comp_x *= 3 res_VF = self.VF / comp_x assert np.allclose(res_VF.comp_x, 1 / 3) assert np.allclose(res_VF.mask, self.VF.mask) assert Field.__eq__(res_VF, self.VF) comp_x = self.VF.comp_x.copy() comp_x *= 3 res_VF = self.VF.__rtruediv__(comp_x) assert np.allclose(res_VF.comp_x, 3) assert np.allclose(res_VF.mask, self.VF.mask) assert Field.__eq__(res_VF, self.VF) # # should add with cropped vectorfield if coherent axis system # tmp_VF = self.VF.copy().crop(intervx=[10, 50], ind=True) # tmp_VF.comp_x *= 3 # res_VF = tmp_VF / self.VF # assert res_VF.shape == tmp_VF.shape # assert res_VF.shape[0] == 41 # assert np.allclose(res_VF.comp_x, 3) # assert np.allclose(res_VF.mask, self.VF.mask) # assert not Field.__eq__(res_VF, self.VF) # should add with numbers tmp_VF = self.VF / 5 assert np.allclose(tmp_VF.comp_x, self.VF.comp_x / 5) assert np.allclose(tmp_VF.mask, self.VF.mask) assert Field.__eq__(tmp_VF, self.VF) tmp_VF = 5 / self.VF assert np.allclose(tmp_VF.comp_x, 5 / self.VF.comp_x) assert np.allclose(tmp_VF.mask, self.VF.mask) assert Field.__eq__(tmp_VF, self.VF) # should add with units if coherent tmp_VF = self.VF / (5.2 * units.m / units.s) assert np.allclose(tmp_VF.comp_x, self.VF.comp_x / 5.2) assert tmp_VF.unit_values.strUnit() == '[]' assert np.allclose(tmp_VF.mask, self.VF.mask) assert Field.__eq__(tmp_VF, self.VF) tmp_VF = self.VF.__rtruediv__(5.2 * units.m / units.s) assert np.allclose(tmp_VF.comp_x, 5.2 / self.VF.comp_x) assert tmp_VF.unit_values.strUnit() == '[]' assert np.allclose(tmp_VF.mask, self.VF.mask) assert Field.__eq__(tmp_VF, self.VF) # shoudl raise error if incoherent axis tmp_VF = self.VF.copy() tmp_VF.axis_x += 1 with pytest.raises(ValueError): tmp_VF / self.VF tmp_VF = self.VF.copy() tmp_VF.axis_y += 3.4 with pytest.raises(ValueError): tmp_VF / self.VF # should raise an error if incoherent units tmp_VF = self.VF.copy() tmp_VF.unit_x = 'Hz' with pytest.raises(unum.IncompatibleUnitsError): tmp_VF / self.VF