def test_outside_norm_ranges(self): sed1 = IrisSed(x=[1,2,3,4,5], y=[1,2,3,4,5], id='sed1') sed2 = IrisSed(x=[10,20,30,40], y=[1,2,3,4], id='sed2') stack = IrisStack([sed1, sed2]) norm_stack = stack.normalize_by_int(minWavelength=2, maxWavelength=9) self.assertEqual(norm_stack.excluded[0], 'sed2') sed3 = IrisSed(x=[20,30,40], y=[1,2,3], id='sed3') stack.add_segment(sed3) norm_stack = stack.normalize_by_int(minWavelength=2, maxWavelength=9) numpy.testing.assert_array_equal(norm_stack.excluded, ['sed2', 'sed3']) self.assertEqual(len(norm_stack), 3)
def test_normalize_by_int_avg_add(self): sed1 = IrisSed(x=self.x,y=self.y,yerr=self.yerr) sed2 = IrisSed(x=numpy.array([2,4,5,8,10]), y=numpy.arange(5)+1.0, yerr=numpy.arange(5)+1.0*0.1) y = numpy.array([5.0, 15.0, 7.0, 4.5, 13.5, 10.5]) x = numpy.array([0.5, 1.5, 3.0, 5.0, 10.5, 21.0]) sed3 = IrisSed(x=x, y=y, yerr=y*0.1) stack = IrisStack([sed1, sed2, sed3]) # normalize SEDs with avg statistic norm_stack = stack.normalize_by_int(stats='avg', norm_operator=1) numpy.testing.assert_array_almost_equal(norm_stack[0].y, 0 - 253.8 + sed1.y) numpy.testing.assert_array_almost_equal(norm_stack[1].y, 221.15 + sed2.y) self.assertAlmostEqual(norm_stack[2].norm_constant, 32.65)
def test_normalize_by_int_median_mult(self): sed1 = IrisSed(x=self.x,y=self.y,yerr=self.yerr) sed2 = IrisSed(x=numpy.array([2,4,5,8,10]), y=numpy.arange(5)+1.0, yerr=numpy.arange(5)+1.0*0.1) y = numpy.array([5.0, 15.0, 7.0, 4.5, 13.5, 10.5]) x = numpy.array([0.5, 1.5, 3.0, 5.0, 10.5, 21.0]) sed3 = IrisSed(x=x, y=y, yerr=y*0.1) stack = IrisStack([sed1, sed2, sed3]) # normalize SEDs with avg statistic norm_stack = stack.normalize_by_int(stats='median') numpy.testing.assert_array_almost_equal(norm_stack[0].y, 0.4270427*sed1.y) numpy.testing.assert_array_almost_equal(norm_stack[1].y, 8.54*sed2.y) self.assertAlmostEqual(norm_stack[2].norm_constant, 1.0)
def test_normalize_by_int_avg_mult(self): sed1 = IrisSed(x=self.x,y=self.y,yerr=self.yerr) sed2 = IrisSed(x=numpy.array([2,4,5,8,10]), y=numpy.arange(5)+1.0, yerr=numpy.arange(5)+1.0*0.1) y = numpy.array([5.0, 15.0, 7.0, 4.5, 13.5, 10.5]) x = numpy.array([0.5, 1.5, 3.0, 5.0, 10.5, 21.0]) sed3 = IrisSed(x=x, y=y, yerr=y*0.1) stack = IrisStack([sed1, sed2, sed3]) # normalize SEDs with avg statistic norm_stack = stack.normalize_by_int(minWavelength='min', maxWavelength='max', stats='avg', y0=1.0, norm_operator=0, correct_flux=False, z0=None) numpy.testing.assert_array_almost_equal(norm_stack[0].y, 0.49234923*sed1.y) numpy.testing.assert_array_almost_equal(norm_stack[1].y, 9.846*sed2.y) self.assertAlmostEqual(norm_stack[2].norm_constant, 1.1529274)