def test_issue417(): X = scp.read_omnic("irdata/nh4y-activation.spg") x = X - X[-1] print("--subtract with ds from read_omnic") print(f"mean x: {np.mean(x.data)}") print(f"var x: {np.var(x.data)}") print("") f = X.write("X.scp") X_r = scp.read("X.scp") f.unlink() assert_array_equal(X.data, X_r.data) assert_dataset_equal(X, X_r) assert_equal_units(X.units, X_r.units) assert_dataset_equal(X[-1], X_r[-1]) x_r = X_r - X_r[-1] print("--subtract after write/read_scp") print(f"mean x_r: {np.mean(x_r.data)}") print(f"var x_r: {np.var(x_r.data)}") print("") x_r2 = X_r - X_r[-1].data print("--subtract with data field") print(f"mean x_r2: {np.mean(x_r2.data)}") print(f"var x_r2: {np.var(x_r2.data)}") assert_array_equal(x.data, x_r2.data) assert_array_equal(x.data, x_r.data) assert_dataset_equal(x, x_r)
def test_arithmetic_unit_calculation(unit1, unit2, op, result_units): ndd1 = NDDataset(np.array([1]), units=unit1) ndd2 = NDDataset(np.array([1]), units=unit2) ndd1_method = ndd1.__getattribute__(op) result = ndd1_method(ndd2) try: assert result.units == result_units except AssertionError: assert_equal_units(ndd1_method(ndd2).units, result_units)
def test_coord_unit_conversion_operators(operation, result_units): in_km = Coord(data=np.linspace(4000, 1000, 10), units='km', mask=None, title='something') scalar = 2. operator_km = in_km.__getattribute__(operation) combined = operator_km(scalar) debug_(f'{operation}, {combined}') assert_equal_units(combined.units, result_units)
def test_coord_unit_conversion_operators_a(operation, result_units): print(operation, result_units) in_km = Coord(data=np.linspace(4000, 1000, 10), units='km', mask=None, title='something') scalar_in_m = 2. * ur.m operator_km = in_km.__getattribute__(operation) combined = operator_km(scalar_in_m) assert_equal_units(combined.units, result_units)
def test_compare_units(): testing.assert_equal_units(ur.km, ur.m) with pytest.raises(AssertionError): testing.assert_equal_units(ur.km, ur.m, strict=True) with pytest.raises(AssertionError): testing.assert_equal_units(ur.absorbance, ur.transmittance)
def test_ndmath_unit_conversion_operators(operation, result_units): in_km = NDDataset(np.array([1, 1]), units=ur.km) in_m = NDDataset(in_km.data * 1000, units=ur.m) operator_km = in_km.__getattribute__(operation) combined = operator_km(in_m) assert_equal_units(combined.units, result_units)