Exemplo n.º 1
0
  private synchronized void display(ExtSed sed) {

    manageAssociatedManagerWindows(sed);

    try {

      SpectrumContainer container =
          (SpectrumContainer) sed.getAttachment(IrisDisplayManager.FIT_MODEL);

      // There is no Sed attachment, so build a model manager and attach it.

      if (container == null) {
        if (buildAttachment(sed)) {
          return;
        }
      }

      // VAOPD-879: spectrum name must be identical with Sed name.
      if (container != null) {
        container.getSpectrum().setName(sed.getId());
      }

      // Now display the Sed.

      idm.display(sed, sed.getId());

      // and add its frame to the workspace.

      JInternalFrame frame = idm.getInternalFrame();

      // VAOPD-863
      frame.setTitle(sed.getId());

      if (container != null) {
        JFrame modelManagerFrame = container.getModelManager().getFrame();
        if (modelManagerFrame != null) {
          modelManagerFrame.setTitle(sed.getId());
        }
      }

      if (frame != currentFrame) {
        lastLocation = null;
        disposeCurrentFrame();
        currentFrame = frame;
        currentFrame.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
        if (lastLocation != null) {
          currentFrame.setLocation(lastLocation);
        }
        frame.setTitle("Iris Visualizer");
        ws.addFrame(frame);
      }

    } catch (Exception ex) {
      LogEvent.getInstance().fire(this, new LogEntry("Error: " + ex.getMessage(), sed));
      Logger.getLogger("IrisVisualizer").log(Level.SEVERE, null, ex);
    }
  }
Exemplo n.º 2
0
  private void manageAssociatedManagerWindows(ExtSed sed) {

    ExtSed displaying = idm.getDisplaying();

    if (displaying != null) {
      if (!sed.getId().equals(displaying.getId())) {

        // displayed Sed is exiting: make its model manager and metadata windows invisible.

        SpectrumContainer container =
            (SpectrumContainer) displaying.getAttachment(IrisDisplayManager.FIT_MODEL);

        if (container != null) {

          ModelManager2 modelManager = container.getModelManager();
          modelManager.setVisible(false);
          SpectrumVisualEditor editor = idm.getVisualEditor();

          if (editor != null) {
            editor.getJFrame().setVisible(false);
          }
        }

        // new Sed is entering display: make its model manager window visible if active.

        if (sed != null) {

          container = (SpectrumContainer) sed.getAttachment(IrisDisplayManager.FIT_MODEL);

          if (container != null) {
            ModelManager2 modelManager = container.getModelManager();
            modelManager.setVisible(modelManager.isActive());
          }
        }
      }
    }
  }
Exemplo n.º 3
0
  public void invalidateModel(ExtSed sed) {
    if (sed != null) {
      SpectrumContainer container =
          (SpectrumContainer) sed.getAttachment(IrisDisplayManager.FIT_MODEL);
      if (container != null) {

        ModelManager2 mm = container.getModelManager();
        if (mm != null && mm.isActive()) {
          mm.dispose();
        }

        sed.removeAttachment(IrisDisplayManager.FIT_MODEL);
      }
    }
  }
Exemplo n.º 4
0
  @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);
    }
  }