@Test public void testNormalizer() throws Exception { ExtSed sed1 = new ExtSed("Sed1"); ExtSed sed2 = new ExtSed("Sed2"); ExtSed sed3 = new ExtSed("Sed3"); Segment seg1 = new Segment(); for (int k = 0; k < x1.length; k++) { y1[k] = y1[k] * 1e23; yerr1[k] = yerr1[k] * 1e23; } seg1.setFluxAxisValues(y1); seg1.setSpectralAxisValues(x1); seg1.setFluxAxisUnits("Jy"); seg1.setSpectralAxisUnits("Angstrom"); seg1.setDataValues(yerr1, UTYPE.FLUX_STAT_ERROR); sed1.addSegment(seg1); Segment seg2 = new Segment(); seg2.setFluxAxisValues(y2); seg2.setSpectralAxisValues(x2); seg2.setFluxAxisUnits("erg/s/cm2/Hz"); seg2.setSpectralAxisUnits("Angstrom"); seg2.setDataValues(yerr2, UTYPE.FLUX_STAT_ERROR); sed2.addSegment(seg2); Segment seg3 = new Segment(); seg3.setFluxAxisValues(y3); // convert the values in x3 to nm so I can test the unit conversions // too. for (int k = 0; k < x3.length; k++) { x3[k] = x3[k] * 0.1; } seg3.setSpectralAxisValues(x3); seg3.setFluxAxisUnits("erg/s/cm2/Hz"); seg3.setSpectralAxisUnits("nm"); seg3.setDataValues(yerr3, UTYPE.FLUX_STAT_ERROR); sed3.addSegment(seg3); SedStack stack = new SedStack("Stack"); stack.add(sed1); stack.add(sed2); stack.add(sed3); // setup the redshift configuration NormalizationConfiguration config = new NormalizationConfiguration(); config.setMultiply(true); config.setIntegrate(true); config.setStats("Average"); config.setXUnits("Angstrom"); config.setXmax(Double.POSITIVE_INFINITY); config.setXmin(Double.NEGATIVE_INFINITY); config.setIntegrateValueYUnits("erg/s/cm2/Hz"); config.setYValue(1.0); // normalize the Stack SedStackerNormalizer normalizer = new SedStackerNormalizer(client, Default.getInstance().getUnitsManager()); normalizer.normalize(stack, config); List<double[]> xs = new ArrayList<>(); List<double[]> ys = new ArrayList<>(); xs.add(x1); xs.add(x2); xs.add(x3); ys.add(y1); ys.add(y2); ys.add(y3); // stack.getOrigSeds() should return original seds for (int j = 0; j < stack.getOrigSeds().size(); j++) { ExtSed origSed = stack.getOrigSeds().get(j); double[] x = xs.get(j); double[] y = ys.get(j); for (int i = 0; i < stack.getOrigSeds().get(j).getSegment(0).getLength(); i++) { double xOrigValue = origSed.getSegment(0).getSpectralAxisValues()[i]; double yOrigValue = origSed.getSegment(0).getFluxAxisValues()[i]; assertEquals(xOrigValue, x[i], EPSILON); assertEquals(yOrigValue, y[i], EPSILON); } } for (int j = 0; j < stack.getSed(0).getSegment(0).getLength(); j++) assertEquals( 0.49234923 * y1[j], stack.getSed(0).getSegment(0).getFluxAxisValues()[j], EPSILON * 0.49234923 * y1[j]); for (int j = 0; j < stack.getSed(1).getSegment(0).getLength(); j++) assertEquals(9.846 * y2[j], stack.getSed(1).getSegment(0).getFluxAxisValues()[j], EPSILON); assertEquals( 1.1529274, Double.valueOf(stack.getSed(2).getAttachment(NORM_CONSTANT).toString()), EPSILON); }
@Test public void testStacker() throws Exception { ExtSed sed1 = new ExtSed("Sed1"); ExtSed sed2 = new ExtSed("Sed2"); ExtSed sed3 = new ExtSed("Sed3"); Segment seg1 = new Segment(); for (int k = 0; k < x1.length; k++) { y1[k] = y1[k] * 1e23; yerr1[k] = yerr1[k] * 1e23; } seg1.setFluxAxisValues(y1); seg1.setSpectralAxisValues(x1); seg1.setFluxAxisUnits("Jy"); seg1.setSpectralAxisUnits("Angstrom"); seg1.setDataValues(yerr1, UTYPE.FLUX_STAT_ERROR); sed1.addSegment(seg1); Segment seg2 = new Segment(); seg2.setFluxAxisValues(y2); seg2.setSpectralAxisValues(x2); seg2.setFluxAxisUnits("erg/s/cm2/Hz"); seg2.setSpectralAxisUnits("Angstrom"); seg2.setDataValues(yerr2, UTYPE.FLUX_STAT_ERROR); sed2.addSegment(seg2); Segment seg3 = new Segment(); seg3.setFluxAxisValues(y3); // convert the values in x3 to nm so I can test the unit conversions // too. int k = 0; for (double x : x3) { x3[k] = x * 0.1; k++; } seg3.setSpectralAxisValues(x3); seg3.setFluxAxisUnits("erg/s/cm2/Hz"); seg3.setSpectralAxisUnits("nm"); seg3.setDataValues(yerr3, UTYPE.FLUX_STAT_ERROR); sed3.addSegment(seg3); SedStack stack = new SedStack("Stack"); stack.add(sed1); stack.add(sed2); stack.add(sed3); // setup the stacking configuration StackConfiguration config = new StackConfiguration(); config.setBinsize(2.0); config.setBinsizeUnit("Angstrom"); config.setLogbin(false); config.setSmooth(false); config.setSmoothBinsize(20.); config.setStatistic("avg"); config.setYUnits("erg/s/cm2/Hz"); // stack stacker = new SedStackerStacker(client, (UnitsManager) null); ExtSed result = stacker.stack(stack, config); List<double[]> xs = new ArrayList<>(); List<double[]> ys = new ArrayList<>(); xs.add(x1); xs.add(x2); xs.add(x3); ys.add(y1); ys.add(y2); ys.add(y3); // stack.getOrigSeds() should return original seds for (int j = 0; j < stack.getOrigSeds().size(); j++) { ExtSed origSed = stack.getOrigSeds().get(j); double[] x = xs.get(j); double[] y = ys.get(j); for (int i = 0; i < stack.getOrigSeds().get(j).getSegment(0).getLength(); i++) { double xOrigValue = origSed.getSegment(0).getSpectralAxisValues()[i]; double yOrigValue = origSed.getSegment(0).getFluxAxisValues()[i]; assertEquals(xOrigValue, x[i], EPSILON); assertEquals(yOrigValue, y[i], EPSILON); } } double[] controlY = new double[] {5.0, 5.36666667, 4.5, 2.66666667, 4.0, 6.5, 1.5, 10.5, 5.0, 10.0}; double[] controlX = new double[] {0., 2., 4., 6., 8., 10., 16., 22., 50., 100.}; // double[] controlYerr = new double[] {0.5, 0.501120965, 0.3640055, // 0.18104634, 0.4, 0.48102899, 0.15, 1.05, 0.5, 1.0}; // calculated // from errors [sqrt(sum(errors^2))/N] double[] controlYerr = new double[] {0, 6.82169741, 2.5, 1.64991582, 0., 5.21216526, 0., 0., 0., 0.}; // calculated // from // stddev(flux) double[] controlCounts = new double[] {1, 3, 2, 3, 1, 3, 1, 1, 1, 1}; // test values of stacked Sed double[] yerrValues = (double[]) result.getSegment(0).getDataValues(UTYPE.FLUX_STAT_ERROR); double[] counts = (double[]) result.getAttachment(COUNTS); for (int i = 0; i < result.getSegment(0).getLength(); i++) { double xValue = result.getSegment(0).getSpectralAxisValues()[i]; double yValue = result.getSegment(0).getFluxAxisValues()[i]; assertEquals(controlX[i], xValue, EPSILON); assertEquals(controlY[i], yValue, EPSILON); assertEquals(controlYerr[i], yerrValues[i], EPSILON); assertEquals(controlCounts[i], counts[i], EPSILON); } }
@Test public void testNormalizerOutsideRange() throws Exception { ExtSed sed1 = new ExtSed("Sed1"); ExtSed sed2 = new ExtSed("Sed2"); ExtSed sed3 = new ExtSed("Sed3"); Segment seg1 = new Segment(); // for (int k=0; k<x1.length; k++) { // y1[k] = y1[k]*1e23; // yerr1[k] = yerr1[k]*1e23; // } seg1.setFluxAxisValues(y1); seg1.setSpectralAxisValues(x1); seg1.setFluxAxisUnits("erg/s/cm2/Angstrom"); seg1.setSpectralAxisUnits("Angstrom"); seg1.setDataValues(yerr1, UTYPE.FLUX_STAT_ERROR); sed1.addSegment(seg1); Segment seg2 = new Segment(); seg2.setFluxAxisValues(y2); seg2.setSpectralAxisValues(x2); seg2.setFluxAxisUnits("erg/s/cm2/Angstrom"); seg2.setSpectralAxisUnits("Angstrom"); seg2.setDataValues(yerr2, UTYPE.FLUX_STAT_ERROR); sed2.addSegment(seg2); Segment seg3 = new Segment(); seg3.setFluxAxisValues(y3); // convert the values in x3 to nm so I can test the unit conversions // too. for (int k = 0; k < x3.length; k++) { x3[k] = x3[k] * 0.1; } seg3.setSpectralAxisValues(x3); seg3.setFluxAxisUnits("erg/s/cm2/Angstrom"); seg3.setSpectralAxisUnits("nm"); seg3.setDataValues(yerr3, UTYPE.FLUX_STAT_ERROR); sed3.addSegment(seg3); SedStack stack = new SedStack("Stack"); stack.add(sed1); stack.add(sed2); stack.add(sed3); // setup the redshift configuration NormalizationConfiguration config = new NormalizationConfiguration(); config.setMultiply(true); config.setIntegrate(true); config.setStats("Value"); config.setXUnits("Angstrom"); config.setXmax(9.0); config.setXmin(1.5); config.setIntegrateValueYUnits("erg/s/cm2"); config.setYValue(1.0); // normalize the Stack normalizeWithWindowInterceptor(stack, config); List<double[]> xs = new ArrayList<>(); List<double[]> ys = new ArrayList<>(); xs.add(x1); xs.add(x2); xs.add(x3); ys.add(y1); ys.add(y2); ys.add(y3); // stack.getOrigSeds() should return original seds for (int j = 0; j < stack.getOrigSeds().size(); j++) { ExtSed origSed = stack.getOrigSeds().get(j); double[] x = xs.get(j); double[] y = ys.get(j); for (int i = 0; i < stack.getOrigSeds().get(j).getSegment(0).getLength(); i++) { double xOrigValue = origSed.getSegment(0).getSpectralAxisValues()[i]; double yOrigValue = origSed.getSegment(0).getFluxAxisValues()[i]; assertEquals(xOrigValue, x[i], EPSILON); assertEquals(yOrigValue, y[i], EPSILON); } } for (int j = 0; j < stack.getSed(0).getSegment(0).getLength(); j++) assertEquals(y1[j], stack.getSed(0).getSegment(0).getFluxAxisValues()[j], EPSILON); for (int j = 0; j < stack.getSed(1).getSegment(0).getLength(); j++) assertEquals(0.0625 * y2[j], stack.getSed(1).getSegment(0).getFluxAxisValues()[j], EPSILON); assertEquals( 0.035714285714, Double.valueOf(stack.getSed(2).getAttachment(NORM_CONSTANT).toString()), EPSILON); }