示例#1
0
  public ExtSed interpolate(ExtSed sed, InterpolationConfig interpConf) throws Exception {

    if (sed.getNumberOfSegments() == 0) {
      throw new SedNoDataException();
    }

    ExtSed newsed = ExtSed.flatten(sed, "Angstrom", "Jy");

    String intervUnits = interpConf.getUnits();
    Double xmin = interpConf.getXMin();
    Double xmax = interpConf.getXMax();

    if (xmin > Double.NEGATIVE_INFINITY)
      xmin = um.convertX(new double[] {xmin}, intervUnits, "Angstrom")[0];

    if (xmax < Double.POSITIVE_INFINITY)
      xmax = um.convertX(new double[] {xmax}, intervUnits, "Angstrom")[0];

    interpConf.setXMin(Math.min(xmin, xmax));
    interpConf.setXMax(Math.max(xmin, xmax));

    interpConf.setX(newsed.getSegment(0).getSpectralAxisValues());
    interpConf.setY(newsed.getSegment(0).getFluxAxisValues());
    SAMPMessage message =
        SAMPFactory.createMessage(INTERPOLATE_MTYPE, interpConf, InterpolationPayload.class);
    Response rspns = client.sendMessage(message);

    InterpolationPayload response =
        (InterpolationPayload) SAMPFactory.get(rspns.getResult(), InterpolationPayload.class);

    if (xmin > Double.NEGATIVE_INFINITY)
      xmin = um.convertX(new double[] {xmin}, "Angstrom", intervUnits)[0];

    if (xmax < Double.POSITIVE_INFINITY)
      xmax = um.convertX(new double[] {xmax}, "Angstrom", intervUnits)[0];

    interpConf.setXMin(Math.min(xmin, xmax));
    interpConf.setXMax(Math.max(xmin, xmax));

    double[] x = um.convertX(response.getX(), "Angstrom", intervUnits);

    Segment segment = new Segment();
    segment.setSpectralAxisValues(x);
    segment.setFluxAxisValues(response.getY());
    segment.setTarget(sed.getSegment(0).getTarget());
    segment.setSpectralAxisUnits(intervUnits);
    segment.setFluxAxisUnits("Jy");
    String ucd = "em.wl";
    if (intervUnits.equals("Hz")) ucd = "em.freq";
    else if (intervUnits.equals("keV")) ucd = "em.energy";
    segment.createChar().createSpectralAxis().setUcd(ucd);
    segment.createChar().createFluxAxis().setUcd("phot.flux.density;" + ucd);

    ExtSed newSed = manager.newSed(sed.getId() + "_" + interpConf.getMethod().replaceAll(" ", ""));
    newSed.addSegment(segment);
    newSed.checkChar();

    return newSed;
  }
示例#2
0
  @Test
  public void testStackAvg() throws Exception {

    payload = (SedStackerStackPayload) SAMPFactory.get(SedStackerStackPayload.class);

    // Setup the stack payload
    payload.addSegment(segment1);
    payload.addSegment(segment2);
    payload.addSegment(segment3);
    payload.setBinsize(2.0);
    payload.setLogBin(false);
    payload.setSmooth(false);
    payload.setSmoothBinsize(5.0);
    payload.setStatistic("avg");

    // Setup and send SAMP message
    SAMPMessage message =
        SAMPFactory.createMessage("stack.stack", payload, SedStackerStackPayload.class);

    Response rspns = client.sendMessage(message);

    SedStackerStackPayload response =
        (SedStackerStackPayload) SAMPFactory.get(rspns.getResult(), SedStackerStackPayload.class);

    // get response values
    SegmentPayload seg = response.getSegments().get(0);
    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};

    assertEquals(response.getSegments().size(), 1);

    // tests
    for (int i = 0; i < seg.getY().length; i++) {
      assertEquals(controlY[i], seg.getY()[i], EPSILON);
    }
    for (int i = 0; i < seg.getY().length; i++) {
      assertEquals(controlX[i], seg.getX()[i], EPSILON);
    }
    for (int i = 0; i < seg.getY().length; i++) {
      assertEquals(controlYerr[i], seg.getYerr()[i], EPSILON);
    }
    for (int i = 0; i < seg.getY().length; i++) {
      assertEquals(controlCounts[i], seg.getCounts()[i], EPSILON);
    }
  }
  @Test
  public void testNormalize() throws Exception {
    payload = (SedStackerNormalizePayload) SAMPFactory.get(SedStackerNormalizePayload.class);

    // Setup the normalization payload
    payload.addSegment(segment1);
    payload.addSegment(segment2);
    payload.addSegment(segment3);

    payload.setNormOperator(0);
    payload.setY0(1.0);
    payload.setXmin("MIN");
    payload.setXmax("MAX");
    payload.setStats("avg");
    payload.setIntegrate(Boolean.TRUE);

    // Setup and send SAMP message
    SAMPMessage message =
        SAMPFactory.createMessage("stack.normalize", payload, SedStackerNormalizePayload.class);

    Response rspns = client.sendMessage(message);

    SedStackerNormalizePayload response =
        (SedStackerNormalizePayload)
            SAMPFactory.get(rspns.getResult(), SedStackerNormalizePayload.class);

    // get response values
    double[] resy1 = response.getSegments().get(0).getY();
    double[] resy2 = response.getSegments().get(1).getY();
    Double resnorm3 = response.getSegments().get(2).getNormConstant();
    SegmentPayload seg1 = response.getSegments().get(0);
    Double z = seg1.getZ();
    Double norm = seg1.getNormConstant();

    assertEquals(response.getSegments().size(), 3);

    // tests
    for (int i = 0; i < resy1.length; i++) {
      assertEquals(0.49234923 * y1[i], resy1[i], EPSILON);
    }
    for (int i = 0; i < resy2.length; i++) {
      assertEquals(9.846 * y2[i], resy2[i], EPSILON);
    }
    assertEquals(1.1529274, resnorm3, EPSILON);
  }