Exemplo n.º 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;
  }
Exemplo n.º 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);
    }
  }
Exemplo n.º 3
0
  @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);
  }
Exemplo n.º 4
0
 protected SEDException getException(Response rspns) {
   try {
     String message = (String) rspns.getResult().get("message");
     return new SEDException(message);
   } catch (Exception ex) {
     Logger.getLogger(SherpaClient.class.getName()).log(Level.SEVERE, null, ex);
     return new SEDException(ex);
   }
 }
Exemplo n.º 5
0
  /** Does the work for the main method. */
  public static int runMain(String[] args) {
    String usage =
        new StringBuffer()
            .append("\n   Usage:")
            .append("\n      ")
            .append(HubMonitor.class.getName())
            .append("\n           ")
            .append(" [-help]")
            .append(" [+/-verbose]")
            .append("\n           ")
            .append(" [-auto <secs>]")
            .append(" [-nomsg]")
            .append(" [-nogui]")
            .append("\n           ")
            .append(" [-mtype <pattern>]")
            .append("\n")
            .toString();
    List argList = new ArrayList(Arrays.asList(args));
    int verbAdjust = 0;
    boolean gui = true;
    boolean trackMsgs = true;
    int autoSec = 3;
    Subscriptions subs = new Subscriptions();
    for (Iterator it = argList.iterator(); it.hasNext(); ) {
      String arg = (String) it.next();
      if (arg.startsWith("-auto") && it.hasNext()) {
        it.remove();
        String sauto = (String) it.next();
        it.remove();
        autoSec = Integer.parseInt(sauto);
      } else if (arg.equals("-gui")) {
        it.remove();
        gui = true;
      } else if (arg.equals("-nogui")) {
        it.remove();
        gui = false;
      } else if (arg.equals("-msg")) {
        it.remove();
        trackMsgs = true;
      } else if (arg.equals("-nomsg")) {
        it.remove();
        trackMsgs = false;
      } else if (arg.startsWith("-mtype") && it.hasNext()) {
        it.remove();
        String mpat = (String) it.next();
        it.remove();
        subs.addMType(mpat);
      } else if (arg.startsWith("-v")) {
        it.remove();
        verbAdjust--;
      } else if (arg.startsWith("+v")) {
        it.remove();
        verbAdjust++;
      } else if (arg.startsWith("-h")) {
        it.remove();
        System.out.println(usage);
        return 0;
      } else {
        it.remove();
        System.err.println(usage);
        return 1;
      }
    }
    assert argList.isEmpty();

    // Adjust logging in accordance with verboseness flags.
    int logLevel = Level.WARNING.intValue() + 100 * verbAdjust;
    Logger.getLogger("org.astrogrid.samp").setLevel(Level.parse(Integer.toString(logLevel)));

    // Get profile.
    final ClientProfile profile = DefaultClientProfile.getProfile();

    // Create the HubMonitor.
    final HubMonitor monitor = new HubMonitor(profile, trackMsgs, autoSec);

    // Add a handler for extra MTypes if so requested.
    if (!subs.isEmpty()) {
      final Subscriptions extraSubs = subs;
      HubConnector connector = monitor.getHubConnector();
      final Response dummyResponse = new Response();
      dummyResponse.setStatus(Response.WARNING_STATUS);
      dummyResponse.setResult(new HashMap());
      dummyResponse.setErrInfo(new ErrInfo("Message logged, " + "no other action taken"));
      connector.addMessageHandler(
          new MessageHandler() {
            public Map getSubscriptions() {
              return extraSubs;
            }

            public void receiveNotification(
                HubConnection connection, String senderId, Message msg) {}

            public void receiveCall(
                HubConnection connection, String senderId, String msgId, Message msg)
                throws SampException {
              connection.reply(msgId, dummyResponse);
            }
          });
      connector.declareSubscriptions(connector.computeSubscriptions());
    }

    // Start the gui in a new window.
    final boolean isVisible = gui;
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            JFrame frame = new JFrame("SAMP HubMonitor");
            frame.getContentPane().add(monitor);
            frame.setIconImage(
                new ImageIcon(Metadata.class.getResource("images/eye.gif")).getImage());
            frame.pack();
            frame.setVisible(isVisible);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          }
        });
    return 0;
  }
Exemplo n.º 6
0
 protected boolean isException(Response rspns) {
   return !rspns.isOK();
 }
Exemplo n.º 7
0
 public void receiveCall(String senderId, String msgId, Message msg) throws SampException {
   receiveNotification(senderId, msg);
   connection_.reply(msgId, Response.createSuccessResponse(new HashMap()));
 }