예제 #1
0
  @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);
  }
예제 #2
0
  @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);
  }