use of fr.jmmc.aspro.model.oi.TargetUserInformations in project aspro by JMMC-OpenDev.
the class ObservationTableModel method getValueAt.
/**
* Returns the value for the cell at
* <code>columnIndex</code> and
* <code>rowIndex</code>.
*
* @param rowIndex the row whose value is to be queried
* @param columnIndex the column whose value is to be queried
* @return the value Object at the specified cell
*/
@Override
public Object getValueAt(final int rowIndex, final int columnIndex) {
final TargetObservation to = getObsAt(rowIndex);
final ObservationSetting obs = to.getObservation();
final Target target = to.getTarget();
final TargetUserInformations targetUserInfos = obs.getTargetUserInfos();
final ColumnDesc columnDesc = getColumnDesc(columnIndex);
switch(ColumnDef.valueOf(columnDesc.getName())) {
case ID:
return obs.getName();
case TYPE:
return (targetUserInfos != null && targetUserInfos.isCalibrator(target)) ? ObservationType.CALIBRATOR : ObservationType.SCIENCE;
case PROGRAM_ID:
// TODO
return null;
// Interferometer:
case INTERF_NAME:
return obs.getInterferometerConfiguration().getInterferometerConfiguration().getInterferometer().getName();
case INTERF_VERSION:
return obs.getInterferometerConfiguration().getInterferometerConfiguration().getVersion();
case STATIONS:
return obs.getInstrumentConfiguration().getStations();
case POPS:
return obs.getInstrumentConfiguration().getPops();
// Instrument mode:
case INS_NAME:
return obs.getInstrumentConfiguration().getName();
case INS_MODE:
return obs.getInstrumentConfiguration().getInstrumentMode();
// Target:
case TARGET_NAME:
return target.getName();
// coords (deg)
case TARGET_RA:
return target.getRADeg();
case TARGET_DEC:
return target.getDECDeg();
// coords (hms / dms)
case TARGET_RA_HMS:
return target.getRA();
case TARGET_DEC_DMS:
return target.getDEC();
// when :
case MJD_START:
// TODO to.getMjdStart();
return null;
// Atmosphere quality ?
case TAU0:
// s
return AtmosphereQualityUtils.getCoherenceTime(obs.getWhen().getAtmosphereQuality()) * 0.001;
case SEEING:
return AtmosphereQualityUtils.getSeeing(obs.getWhen().getAtmosphereQuality());
case EXP_TIME:
// s
return obs.getInstrumentConfiguration().getAcquisitionTime();
case DATE:
return obs.getWhen().getDate().toString();
case TIME:
return null;
case LST_START:
return null;
default:
}
return null;
}
use of fr.jmmc.aspro.model.oi.TargetUserInformations in project aspro by JMMC-OpenDev.
the class ExportOBXmlAction method process.
/**
* Execute the action.
*
* @param targets list of targets to export as Observing blocks
*/
public void process(final List<Target> targets) {
logger.debug("process");
if (targets.isEmpty()) {
return;
}
final boolean exportAll = targets.size() > 1;
File file;
if (exportAll) {
file = FileChooser.showDirectoryChooser("Export targets as Observing Blocks (XML)", null, MIMETYPE);
} else {
final Target target = targets.get(0);
file = FileChooser.showSaveFileChooser("Export the target [" + target.getName() + "] as an Observing Block (XML)", null, MIMETYPE, ExportOBXml.generateOBFileName(target));
}
logger.debug("Selected file: {}", file);
// If a file was defined (No cancel in the dialog)
if (file != null) {
final String directory = (exportAll) ? file.getPath() : file.getParent();
// report buffer :
final StringBuilder sb = new StringBuilder(1024);
// use main observation :
final ObservationSetting observation = ObservationManager.getInstance().getMainObservation();
final double minElev = observation.getInterferometerConfiguration().getMinElevation();
try {
// Compute Observability data using astronomical night (-18 deg) without night restrictions :
final ObservabilityService os = ExportOBXml.processObservability(observation);
final TargetUserInformations targetUserInfos = observation.getTargetUserInfos();
if (exportAll) {
// report buffer :
sb.append("Observing Blocks exported for all targets with following settings:\n");
sb.append(" - minimum elevation set to ").append(DF1.format(minElev)).append(" deg\n");
sb.append(" - output folder :\n").append(directory).append("\n\n");
// Export all SCI/CAL OBs:
for (Target target : targets) {
// generate one XML document per science OB:
if (targetUserInfos != null && !targetUserInfos.isCalibrator(target)) {
file = new File(directory, ExportOBXml.generateOBFileName(target));
ExportOBXml.process(file, observation, os, target);
sb.append(file.getName()).append('\n');
}
}
StatusBar.show("Observing blocks saved in " + directory + ".");
} else {
final File mainFile = new File(directory, file.getName());
final Target target = targets.get(0);
// report buffer :
sb.append("Observing Blocks exported for target [").append(target.getName()).append("] with following settings:\n");
sb.append(" - minimum elevation set to ").append(DF1.format(minElev)).append(" deg\n");
sb.append(" - output folder :\n").append(directory).append("\n\n");
ExportOBXml.process(mainFile, observation, os, target);
sb.append(mainFile.getName()).append('\n');
StatusBar.show(mainFile.getName() + " created.");
}
// display report message :
MessagePane.showMessage(sb.toString());
} catch (IOException ioe) {
MessagePane.showErrorMessage("Could not export to file : " + file.getAbsolutePath(), ioe);
}
}
}
use of fr.jmmc.aspro.model.oi.TargetUserInformations in project aspro by JMMC-OpenDev.
the class ObservationManager method removeTargetAndCalibrators.
/**
* Remove the given targets (science and calibrators) from the target list
* and fires a target change and an observation change event
* @param removeTargets targets to remove
*/
public void removeTargetAndCalibrators(final List<Target> removeTargets) {
if (!CollectionUtils.isEmpty(removeTargets)) {
final List<Target> targets = getTargets();
final TargetUserInformations targetUserInfos = getTargetUserInfos();
boolean changed = false;
// Remove first science targets:
for (Target target : removeTargets) {
if (!isCalibrator(target)) {
if (Target.removeTarget(target, targets, targetUserInfos)) {
logger.trace("removeTarget: {}", target);
changed = true;
}
}
}
// Remove calibrator targets:
for (Target calibrator : removeTargets) {
if (isCalibrator(calibrator)) {
Target.removeCalibratorReferences(calibrator, targets, targetUserInfos);
if (Target.removeTarget(calibrator, targets, targetUserInfos)) {
logger.trace("removeCalibrator: {}", calibrator);
changed = true;
}
}
}
if (changed) {
// check and update target references :
getMainObservation().checkReferences();
// fire change events :
this.fireTargetChangedEvents();
}
}
}
use of fr.jmmc.aspro.model.oi.TargetUserInformations in project aspro by JMMC-OpenDev.
the class ExportOBGravity method generate.
/**
* Generate the OB file for the given target
* @param file file to save
* @param observation observation settings
* @param os observability service with computed data
* @param target target to process
*
* @throws IllegalStateException if the template file is not found or can not be read
* @throws IOException if an I/O exception occurred while writing the observing block
*/
public static void generate(final File file, final ObservationSetting observation, final ObservabilityService os, final Target target) throws IllegalStateException, IOException {
logger.debug("generate file: {}", file);
// get OB template :
final String template = ResourceUtils.readResource(TEMPLATE_FILE);
// process common VLTI part :
String document = processCommon(template, file.getName(), observation, os, target, GRAVITY_VAL_CATEGORY_SCIENCE, GRAVITY_VAL_CATEGORY_CALIBRATOR);
// Magnitudes for H, K :
document = document.replaceFirst(KEY_HMAG, df3.format(getMagnitude(target.getFLUXH())));
document = document.replaceFirst(KEY_KMAG, df3.format(getMagnitude(target.getFLUXK())));
// Coude Guided Star = Science (= mag V) :
document = document.replaceFirst(KEY_COUDE_GS_MAG, df3.format(getMagnitude(target.getFLUXV())));
// Mode (INS.DISP.NAME) among "FREE" or "GRISM":
final String instrumentMode = observation.getInstrumentConfiguration().getInstrumentMode();
// Parse Aspro2's instrument mode:
// [LOW-COMBINED, LOW-SPLIT, MEDIUM-COMBINED, MEDIUM-SPLIT, HIGH-COMBINED, HIGH-SPLIT]
String res;
final String pola;
final int pos = instrumentMode.indexOf('-');
if (pos == -1) {
logger.warn("Invalid instrument mode for GRAVITY: {}", instrumentMode);
res = "LOW";
pola = "IN";
} else {
res = instrumentMode.substring(0, pos);
if ("MEDIUM".equals(res)) {
res = "MED";
}
/*
pour les deux polariseurs (SPEC.POL et FT.POL):
SPLIT -> IN
COMBINED -> OUT
*/
pola = ("COMBINED".equals(instrumentMode.substring(pos + 1))) ? "OUT" : "IN";
}
document = document.replaceAll(KEY_INS_SPEC_RES, res);
document = document.replaceAll(KEY_INS_POLA_MODE, pola);
// Calibrator Angular diameter (mas)
final TargetUserInformations targetUserInfos = observation.getTargetUserInfos();
Double diameter = null;
if (targetUserInfos != null && targetUserInfos.isCalibrator(target)) {
diameter = target.getDiameter(SpectralBand.K);
}
if (diameter == null) {
diameter = 0.0;
}
document = document.replaceFirst(KEY_DIAMETER, df3.format(diameter));
// Finally, write the file :
FileUtils.writeFile(file, document);
}
use of fr.jmmc.aspro.model.oi.TargetUserInformations in project aspro by JMMC-OpenDev.
the class ExportOBVLTIAction method process.
/**
* Execute the action.
*
* @param targets list of targets to export as VLTI Observing blocks
*/
public void process(final List<Target> targets) {
logger.debug("process");
if (targets.isEmpty()) {
return;
}
final boolean exportAll = targets.size() > 1;
File file;
if (exportAll) {
file = FileChooser.showDirectoryChooser("Export targets as Observing Blocks", null, MIMETYPE);
} else {
final Target target = targets.get(0);
file = FileChooser.showSaveFileChooser("Export the target [" + target.getName() + "] as an Observing Block", null, MIMETYPE, ExportOBVLTI.generateOBFileName(target));
}
logger.debug("Selected file: {}", file);
// If a file was defined (No cancel in the dialog)
if (file != null) {
final String directory = (exportAll) ? file.getPath() : file.getParent();
// report buffer :
final StringBuilder sb = new StringBuilder(1024);
// use main observation :
final ObservationSetting observation = ObservationManager.getInstance().getMainObservation();
final double minElev = observation.getInterferometerConfiguration().getMinElevation();
try {
// Compute Observability data using astronomical night (-18 deg)
// (date and night restrictions depend on the current observation) :
final ObservabilityService os = new ObservabilityService(observation);
// compute observability data:
os.compute();
final TargetUserInformations targetUserInfos = observation.getTargetUserInfos();
if (exportAll) {
// report buffer :
sb.append("Observing Blocks exported for all targets with following settings:\n");
sb.append(" - minimum elevation set to ").append(DF1.format(minElev)).append(" deg\n");
sb.append(" - output folder :\n").append(directory).append("\n\n");
// Export all SCI/CAL OBs:
for (Target target : targets) {
file = new File(directory, ExportOBVLTI.generateOBFileName(target));
ExportOBVLTI.process(file, observation, os, target);
sb.append(file.getName()).append('\n');
}
// Export concatenation OBs:
for (Target target : targets) {
file = new File(directory, ExportOBVLTI.generateOBFileName(target));
final String conFileName = ExportOBVLTI.generateConcatenation(file, targetUserInfos, target);
if (conFileName != null) {
sb.append(conFileName).append('\n');
}
}
StatusBar.show("Observing blocks saved in " + directory + ".");
} else {
final File mainFile = new File(directory, ExportOBVLTI.fixFileName(file.getName()) + '.' + MIMETYPE.getExtension());
final Target target = targets.get(0);
// report buffer :
sb.append("Observing Blocks exported for target [").append(target.getName()).append("] with following settings:\n");
sb.append(" - minimum elevation set to ").append(DF1.format(minElev)).append(" deg\n");
sb.append(" - output folder :\n").append(directory).append("\n\n");
ExportOBVLTI.process(mainFile, observation, os, target);
sb.append(mainFile.getName()).append('\n');
// Generate all calibrator OBs for a science target :
if (targetUserInfos != null && !targetUserInfos.isCalibrator(target)) {
final TargetInformation targetInfo = targetUserInfos.getTargetInformation(target);
if (targetInfo != null) {
final List<Target> calibrators = targetInfo.getCalibrators();
if (!calibrators.isEmpty()) {
for (Target calibrator : calibrators) {
file = new File(directory, ExportOBVLTI.generateOBFileName(calibrator));
ExportOBVLTI.process(file, observation, os, calibrator);
sb.append(file.getName()).append('\n');
}
final String conFileName = ExportOBVLTI.generateConcatenation(mainFile, targetUserInfos, target);
if (conFileName != null) {
sb.append(conFileName).append('\n');
}
}
}
}
StatusBar.show(mainFile.getName() + " created.");
}
// display report message :
MessagePane.showMessage(sb.toString());
// PoP up to validate OB file against ESO CfP :
DismissableMessagePane.show("Please check that your observing blocks \n" + "conform to the current ESO Call for Proposal \n (object magnitudes, instrument limits ...)", Preferences.getInstance(), "ESO_OB_WARNING");
} catch (IOException ioe) {
MessagePane.showErrorMessage("Could not export to file : " + file.getAbsolutePath(), ioe);
}
}
}
Aggregations