def test_normalize_by_int(self): sed1 = Sed( x=numpy.arange(1000, 10001, 500), y=numpy.arange(1000, 10001, 500), yerr=numpy.arange(1000, 10001, 500) * 0.01, ) sed2 = Spectrum( x=numpy.arange(3000, 9501, 10), y=numpy.arange(3000, 9501, 10), yerr=numpy.arange(3000, 9501, 10) * 0.01 ) sed3 = Sed( x=numpy.arange(30000, 40001, 500), y=numpy.arange(30000, 40001, 500), yerr=numpy.arange(30000, 40001, 500) * 0.01, ) aggsed = AggregateSed([sed1, sed2, sed3]) norm_aggsed = aggsed.normalize_by_int() x = numpy.hstack([sed1.x, sed2.x, sed3.x]) y = numpy.hstack([sed1.y, sed2.y, sed3.y]) points = [] for i, point in enumerate(x): points.append((x[i], y[i])) points = zip(*sorted(points)) tot_flux = numpy.trapz(points[1], points[0]) control_norm_constant = 1.0 / tot_flux # 1.0/779625000.0 self.assertAlmostEqual(norm_aggsed.norm_constant, control_norm_constant) # The AggregateSed should retain all Segments after the normalization. self.assertEqual(len(norm_aggsed), len(aggsed))
def test_add_segment(self): sed1 = Sed(x=[1, 5, 10, 57, 60], y=[1, 1, 1, 1, 1], yerr=[0.1, 0.1, 0.1, 0.1, 0.1]) sed2 = Spectrum(x=[0.5, 2, 15, 50, 60], y=[2, 2, 2, 2, 2], yerr=[0.2, 0.2, 0.2, 0.2, 0.2]) sed3 = Sed(x=[3, 6, 9, 20], y=[3, 3, 3, 3], yerr=[0.3, 0.3, 0.3, 0.3]) aggsed = AggregateSed([sed1, sed2]) aggsed.add_segment(sed3) self.assertEqual(len(aggsed), 3) numpy.testing.assert_array_equal(aggsed[2].x, [3, 6, 9, 20]) # to see if the class methods are working properly # with the added segment norm_aggsed = aggsed.normalize_by_int() integral = numpy.trapz( numpy.array([2, 1, 2, 3, 1, 3, 3, 1, 2, 3, 2, 1, 1, 2]), numpy.array([0.5, 1, 2, 3, 5, 6, 9, 10, 15, 20, 50, 57, 60, 60]), ) control_norm_constant = 1.0 / integral self.assertAlmostEqual(norm_aggsed.norm_constant, control_norm_constant)