Search in sources :

Example 1 with BaseValue

use of fr.jmmc.aspro.model.oi.BaseValue in project aspro by JMMC-OpenDev.

the class CalibratorInfoTableModel method addFieldValue.

/**
 * Add the field value of the given name to table rows if not null
 * @param calInfos calibrator informations
 * @param name field name
 */
private void addFieldValue(final CalibratorInformations calInfos, final String name) {
    final BaseValue value = calInfos.getField(name);
    addValue(value);
}
Also used : BaseValue(fr.jmmc.aspro.model.oi.BaseValue)

Example 2 with BaseValue

use of fr.jmmc.aspro.model.oi.BaseValue in project aspro by JMMC-OpenDev.

the class ObservationManager method defineCalibratorDiameter.

/**
 * Update diameter parameter of uniform disk models for the given list of calibrator targets
 * using their CalibratorInformations (SearchCal) :
 *
 * find correct diameter among UD_ for the observation instrument band
 * or using alternate diameters (in order of priority) : UD, LD, UDDK, DIA12
 *
 * @param calibrators list of calibrator targets
 * @return true if any diameter value changed
 */
public boolean defineCalibratorDiameter(final List<Target> calibrators) {
    boolean changed = false;
    final ObservationSetting observation = getMainObservation();
    // Find instrument band from main observation :
    FocalInstrumentMode insMode = observation.getInstrumentConfiguration().getFocalInstrumentMode();
    if (insMode == null) {
        // use the first instrument mode of the instrument:
        final Vector<String> instrumentModes = ConfigurationManager.getInstance().getInstrumentModes(observation.getInterferometerConfiguration().getName(), observation.getInstrumentConfiguration().getName());
        if (instrumentModes.isEmpty()) {
            throw new IllegalStateException("The instrumentMode is empty !");
        }
        insMode = ConfigurationManager.getInstance().getInstrumentMode(observation.getInterferometerConfiguration().getName(), observation.getInstrumentConfiguration().getName(), instrumentModes.get(0));
        logger.info("The instrumentMode is empty; using first instrument Mode {}", insMode.getName());
    }
    final double lambda = insMode.getWaveLength();
    if (logger.isDebugEnabled()) {
        logger.debug("lambda: {}", lambda);
    }
    final Band band = Band.findBand(lambda);
    final SpectralBand insBand = SpectralBandUtils.findBand(band);
    if (logger.isDebugEnabled()) {
        logger.debug("band: {}", band);
        logger.debug("insBand: {}", insBand);
    }
    for (Target cal : calibrators) {
        // set disk diameter according to instrument band :
        if (!cal.getModels().isEmpty()) {
            final Model diskModel = cal.getModels().get(0);
            if (ModelDefinition.MODEL_DISK.equals(diskModel.getType())) {
                final Parameter diameterParameter = diskModel.getParameter(ModelDefinition.PARAM_DIAMETER);
                if (diameterParameter != null) {
                    // if UD_<band> diameter is missing, use other values ...
                    final Double udBand = cal.getCalibratorInfos().getUDDiameter(insBand);
                    if (udBand != null) {
                        if (logger.isInfoEnabled()) {
                            logger.info("Define uniform disk diameter for calibrator [" + cal.getName() + "] using diameter UD_" + insBand + " = " + udBand);
                        }
                        diameterParameter.setValue(udBand.doubleValue());
                        changed = true;
                    } else {
                        // use alternate diameter (in order of priority) :
                        final BaseValue diam = cal.getCalibratorInfos().getAlternateDiameter();
                        if (diam != null) {
                            if (logger.isInfoEnabled()) {
                                logger.info("Define uniform disk diameter for calibrator [" + cal.getName() + "] using diameter " + diam.getName() + " = " + diam.getValue());
                            }
                            diameterParameter.setValue(diam.getNumber().doubleValue());
                            changed = true;
                        } else {
                            if (logger.isInfoEnabled()) {
                                logger.info("No diameter available for calibrator [{}], set to 0.0", cal.getName());
                            }
                            diameterParameter.setValue(0d);
                            changed = true;
                        }
                    }
                }
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("diameter(s) changed: {}", changed);
    }
    return changed;
}
Also used : SpectralBand(fr.jmmc.aspro.model.oi.SpectralBand) ObservationSetting(fr.jmmc.aspro.model.oi.ObservationSetting) BaseValue(fr.jmmc.aspro.model.oi.BaseValue) FocalInstrumentMode(fr.jmmc.aspro.model.oi.FocalInstrumentMode) Band(fr.jmmc.jmal.Band) SpectralBand(fr.jmmc.aspro.model.oi.SpectralBand) Target(fr.jmmc.aspro.model.oi.Target) Model(fr.jmmc.jmal.model.targetmodel.Model) UserModel(fr.jmmc.aspro.model.oi.UserModel) Parameter(fr.jmmc.jmal.model.targetmodel.Parameter)

Example 3 with BaseValue

use of fr.jmmc.aspro.model.oi.BaseValue in project aspro by JMMC-OpenDev.

the class SearchCalVOTableHandler method processMessage.

/**
 * Process the given votable
 *
 * @param votable votable to process
 * @param searchCalVersion SearchCal GUI version
 * @return true if the votable was processed i.e. contains proper SearchCal data
 *
 * @throws IOException if an I/O exception occured
 * @throws IllegalArgumentException if the file is not an Observation
 */
static boolean processMessage(final String votable, final String searchCalVersion) throws IOException {
    // use an XSLT to transform the SearchCal votable document to an Aspro 2 Observation:
    final long start = System.nanoTime();
    final String document = XslTransform.transform(votable, XSLT_FILE).trim();
    logger.info("VOTable transformation (XSLT) duration = {} ms.", 1e-6d * (System.nanoTime() - start));
    if (document.length() == 0) {
        logger.debug("document is empty (probably not a SearchCal VOTable)");
        return false;
    }
    logger.debug("document:\n{}", document);
    final ObservationManager om = ObservationManager.getInstance();
    try {
        final ObservationSetting searchCalObservation = om.load(new StringReader(document));
        // check GetStar / SearchCal command:
        final String cmdName = searchCalObservation.getName();
        logger.debug("cmdName: {}", cmdName);
        if (!GET_STAR_NAME.equalsIgnoreCase(cmdName)) {
            // SearchCal case:
            final List<Target> calibrators = searchCalObservation.getTargets();
            final Target scienceTarget;
            if (calibrators.isEmpty()) {
                scienceTarget = null;
            } else {
                // first target is the science target (partial information only):
                scienceTarget = calibrators.remove(0);
                // format the target name:
                scienceTarget.updateNameAndIdentifier();
                logger.debug("science target: {}", scienceTarget);
                if (logger.isDebugEnabled()) {
                    logger.debug("calibrators:");
                    for (Target cal : calibrators) {
                        logger.debug(cal.toString());
                    }
                }
                // @note SCIENCE_DISTANCE_CHECK : filter science target if distance is less than science object detection distance preference (1 arcsec):
                for (Iterator<Target> it = calibrators.iterator(); it.hasNext(); ) {
                    final Target cal = it.next();
                    final BaseValue dist = cal.getCalibratorInfos().getField(CalibratorInformations.FIELD_DISTANCE);
                    if (dist != null) {
                        final double rowDistance = dist.getNumber().doubleValue();
                        // If the distance is close enough to be detected as a science object
                        if (rowDistance < SCIENCE_DETECTION_DISTANCE) {
                            if (logger.isInfoEnabled()) {
                                logger.info("calibrator distance is [{}] - skip this calibrator considered as science object: {} - IDS = {}", rowDistance, cal, cal.getIDS());
                            }
                            it.remove();
                            // reuse science target data to update scienceTarget object:
                            Target.merge(scienceTarget, cal);
                        }
                    }
                }
                // Add the SearchCalGuiVersion parameter to calibrators if missing:
                final StringValue paramSearchCalVersion = new StringValue();
                paramSearchCalVersion.setName(CalibratorInformations.PARAMETER_SCL_GUI_VERSION);
                paramSearchCalVersion.setValue(searchCalVersion);
                for (Target cal : calibrators) {
                    if (cal.getCalibratorInfos().getParameter(CalibratorInformations.PARAMETER_SCL_GUI_VERSION) == null) {
                        cal.getCalibratorInfos().getParameters().add(paramSearchCalVersion);
                    }
                }
            }
            // Use invokeLater to avoid concurrency and ensure that
            // data model is modified and fire events using Swing EDT:
            SwingUtils.invokeEDT(new Runnable() {

                @Override
                public void run() {
                    // check the number of calibrators:
                    if (calibrators.isEmpty()) {
                        MessagePane.showErrorMessage("No calibrator found in SearchCal response !");
                        return;
                    }
                    if (!TargetImporter.confirmImport(calibrators.size())) {
                        return;
                    }
                    // find correct diameter among UD_ for the Aspro instrument band ...
                    // or using alternate diameters (in order of priority): UD, LD, UDDK, DIA12
                    om.defineCalibratorDiameter(calibrators);
                    final TargetEditorDialog targetEditor = TargetEditorDialog.getTargetEditor();
                    // Prepare the data model (editable targets and user infos) :
                    final TargetEditContext editTargetCtx = (targetEditor != null) ? targetEditor.getTargetEditCtx() : om.getMainObservation().createTargetEditContext();
                    final List<Target> editTargets = editTargetCtx.getTargets();
                    final TargetUserInformations editTargetUserInfos = editTargetCtx.getTargetUserInfos();
                    if (logger.isDebugEnabled()) {
                        logger.debug("initial targets:");
                        for (Target t : editTargets) {
                            logger.debug(t.toString());
                        }
                    }
                    // Find any target (id + position) within 5 arcsecs:
                    Target currentScienceTarget = Target.matchTarget(scienceTarget, editTargets);
                    if (currentScienceTarget == null) {
                        logger.info("Target '{}' not found in targets; adding it (partial information).", scienceTarget.getName());
                        editTargets.add(scienceTarget);
                        currentScienceTarget = scienceTarget;
                    }
                    final String report = mergeTargets(editTargets, editTargetUserInfos, currentScienceTarget, calibrators);
                    if (logger.isDebugEnabled()) {
                        logger.debug("updated targets:");
                        for (Target t : editTargets) {
                            logger.debug(t.toString());
                        }
                    }
                    if (targetEditor != null) {
                        // refresh target editor:
                        targetEditor.refreshDialog();
                    } else {
                        // update the complete list of targets and force to update references:
                        // needed to replace old target references by the new calibrator targets:
                        om.updateTargets(editTargetCtx);
                    }
                    if (logger.isInfoEnabled()) {
                        logger.info(report);
                    }
                    // display report message:
                    MessagePane.showMessage(report);
                }
            });
        } else {
            // GetStar case:
            final List<Target> targets = searchCalObservation.getTargets();
            if (logger.isDebugEnabled()) {
                logger.debug("targets:");
                for (Target t : targets) {
                    logger.debug(t.toString());
                }
            }
            // Use invokeLater to avoid concurrency and ensure that
            // data model is modified and fire events using Swing EDT:
            SwingUtils.invokeEDT(new Runnable() {

                @Override
                public void run() {
                    // check the number of targets:
                    if (targets.isEmpty()) {
                        MessagePane.showErrorMessage("No target found in GetStar response !");
                        return;
                    }
                    if (!TargetImporter.confirmImport(targets.size())) {
                        return;
                    }
                    // find correct diameter among UD_ for the Aspro instrument band ...
                    // or using alternate diameters (in order of priority): UD, LD, UDDK, DIA12
                    om.defineCalibratorDiameter(targets);
                    final TargetEditorDialog targetEditor = TargetEditorDialog.getTargetEditor();
                    // Prepare the data model (editable targets and user infos) :
                    final TargetEditContext editTargetCtx = (targetEditor != null) ? targetEditor.getTargetEditCtx() : om.getMainObservation().createTargetEditContext();
                    final List<Target> editTargets = editTargetCtx.getTargets();
                    if (logger.isDebugEnabled()) {
                        logger.debug("initial targets:");
                        for (Target t : editTargets) {
                            logger.debug(t.toString());
                        }
                    }
                    final String report = mergeTargets(editTargets, targets);
                    if (logger.isDebugEnabled()) {
                        logger.debug("updated targets:");
                        for (Target t : editTargets) {
                            logger.debug(t.toString());
                        }
                    }
                    if (targetEditor != null) {
                        // refresh target editor:
                        targetEditor.refreshDialog();
                    } else {
                        // update the complete list of targets and force to update references:
                        // needed to replace old target references by the new calibrator targets:
                        om.updateTargets(editTargetCtx);
                    }
                    if (logger.isInfoEnabled()) {
                        logger.info(report);
                    }
                    // display report message:
                    MessagePane.showMessage(report);
                }
            });
        }
    } catch (IllegalArgumentException iae) {
        // Report both Observation and VOTable in a new IllegalArgumentException to get them in the feedback report:
        throw new IllegalArgumentException("Invalid generated Aspro2 Observation:\n\n" + document + "\n\nSAMP VOTable argument:\n\n" + votable, iae);
    }
    // interpreted as SearchCal votable:
    return true;
}
Also used : ObservationSetting(fr.jmmc.aspro.model.oi.ObservationSetting) BaseValue(fr.jmmc.aspro.model.oi.BaseValue) ObservationManager(fr.jmmc.aspro.model.ObservationManager) Target(fr.jmmc.aspro.model.oi.Target) TargetEditContext(fr.jmmc.aspro.model.TargetEditContext) StringReader(java.io.StringReader) List(java.util.List) TargetUserInformations(fr.jmmc.aspro.model.oi.TargetUserInformations) StringValue(fr.jmmc.aspro.model.oi.StringValue) TargetEditorDialog(fr.jmmc.aspro.gui.TargetEditorDialog)

Example 4 with BaseValue

use of fr.jmmc.aspro.model.oi.BaseValue in project aspro by JMMC-OpenDev.

the class CalibratorInfoTableModel method processData.

/**
 * Fill the table data members using the given calibrator informations
 * @param calInfos calibrator informations
 */
private void processData(final CalibratorInformations calInfos) {
    if (calInfos != null) {
        final java.util.HashSet<String> usedNames = new java.util.HashSet<String>(64);
        // First add parameters :
        for (String name : CalibratorInformations.PARAMETERS_SCL) {
            addParameterValue(calInfos, name);
            usedNames.add(name);
        }
        // add remaining parameters:
        for (BaseValue value : calInfos.getParameters()) {
            if (!usedNames.contains(value.getName())) {
                addValue(value);
            }
        }
        // Secondly add fields :
        usedNames.clear();
        for (String name : CalibratorInformations.FIELDS_SCL) {
            addFieldValue(calInfos, name);
            usedNames.add(name);
        }
        // add remaining fields:
        for (BaseValue value : calInfos.getFields()) {
            if (!usedNames.contains(value.getName())) {
                addValue(value);
            }
        }
    }
}
Also used : BaseValue(fr.jmmc.aspro.model.oi.BaseValue)

Example 5 with BaseValue

use of fr.jmmc.aspro.model.oi.BaseValue in project aspro by JMMC-OpenDev.

the class CalibratorInfoTableModel method addParameterValue.

/**
 * Add the parameter value of the given name to table rows if not null
 * @param calInfos calibrator informations
 * @param name parameter name
 */
private void addParameterValue(final CalibratorInformations calInfos, final String name) {
    final BaseValue value = calInfos.getParameter(name);
    addValue(value);
}
Also used : BaseValue(fr.jmmc.aspro.model.oi.BaseValue)

Aggregations

BaseValue (fr.jmmc.aspro.model.oi.BaseValue)5 ObservationSetting (fr.jmmc.aspro.model.oi.ObservationSetting)2 Target (fr.jmmc.aspro.model.oi.Target)2 TargetEditorDialog (fr.jmmc.aspro.gui.TargetEditorDialog)1 ObservationManager (fr.jmmc.aspro.model.ObservationManager)1 TargetEditContext (fr.jmmc.aspro.model.TargetEditContext)1 FocalInstrumentMode (fr.jmmc.aspro.model.oi.FocalInstrumentMode)1 SpectralBand (fr.jmmc.aspro.model.oi.SpectralBand)1 StringValue (fr.jmmc.aspro.model.oi.StringValue)1 TargetUserInformations (fr.jmmc.aspro.model.oi.TargetUserInformations)1 UserModel (fr.jmmc.aspro.model.oi.UserModel)1 Band (fr.jmmc.jmal.Band)1 Model (fr.jmmc.jmal.model.targetmodel.Model)1 Parameter (fr.jmmc.jmal.model.targetmodel.Parameter)1 StringReader (java.io.StringReader)1 List (java.util.List)1